Passed
Push — master ( 26e0e4...4a85b9 )
by Peter
10:37
created

ClinicalDocument::getReferenceManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * The MIT License
5
 *
6
 * Copyright 2016 Julien Fastré <[email protected]>.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace i3Soft\CDA;
28
29
use i3Soft\CDA\DataType\Identifier\InstanceIdentifier;
30
use i3Soft\CDA\Elements\TypeId;
31
use i3Soft\CDA\Helper\ReferenceManager;
32
use i3Soft\CDA\Interfaces\ClassCodeInterface;
33
use i3Soft\CDA\Interfaces\MoodCodeInterface;
34
use i3Soft\CDA\Traits\AuthenticatorTrait;
35
use i3Soft\CDA\Traits\AuthorizationTrait;
36
use i3Soft\CDA\Traits\AuthorsTrait;
37
use i3Soft\CDA\Traits\ClassCodeTrait;
38
use i3Soft\CDA\Traits\CodeTrait;
39
use i3Soft\CDA\Traits\CompletionCodeTrait;
40
use i3Soft\CDA\Traits\ConfidentialityCodeTrait;
41
use i3Soft\CDA\Traits\CopyTimeTrait;
42
use i3Soft\CDA\Traits\CustodianTrait;
43
use i3Soft\CDA\Traits\DataEntererTrait;
44
use i3Soft\CDA\Traits\DocumentationOfsTrait;
45
use i3Soft\CDA\Traits\EffectiveTimeTrait;
46
use i3Soft\CDA\Traits\IdTrait;
47
use i3Soft\CDA\Traits\InformantsTrait;
48
use i3Soft\CDA\Traits\InformationRecipientsTrait;
49
use i3Soft\CDA\Traits\LanguageCodeTrait;
50
use i3Soft\CDA\Traits\LegalAuthenticatorTrait;
51
use i3Soft\CDA\Traits\MoodCodeTrait;
52
use i3Soft\CDA\Traits\ParticipantsTrait;
53
use i3Soft\CDA\Traits\RealmCodesTrait;
54
use i3Soft\CDA\Traits\RecordTargetsTrait;
55
use i3Soft\CDA\Traits\SetIdTrait;
56
use i3Soft\CDA\Traits\TemplateIdsTrait;
57
use i3Soft\CDA\Traits\TitleTrait;
58
use i3Soft\CDA\Traits\TypeIdTrait;
59
use i3Soft\CDA\Traits\VersionNumberTrait;
60
61
/**
62
 * Root class for clinical document
63
 *
64
 * @author Julien Fastré <[email protected]>
65
 * @author Peter Gee <https://github.com/pgee70>
66
 */
67
class ClinicalDocument implements ClassCodeInterface, MoodCodeInterface
68
{
69
    const NS_CDA     = '';
70
    const NS_CDA_URI = 'urn:hl7-org:v3';
71
    const NS_XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
72
73
    use RealmCodesTrait;
74
    use TypeIdTrait;
75
    use TemplateIdsTrait;
76
    use IdTrait;
77
    use CodeTrait;
78
    use TitleTrait;
79
    use EffectiveTimeTrait;
80
    use ConfidentialityCodeTrait;
81
    use LanguageCodeTrait;
82
    use SetIdTrait;
83
    use VersionNumberTrait;
84
    use CompletionCodeTrait;
85
    use CopyTimeTrait;
86
    use RecordTargetsTrait;
87
    use AuthorsTrait;
88
    use DataEntererTrait;
89
    use InformantsTrait;
90
    use CustodianTrait;
91
    use InformationRecipientsTrait;
92
    use legalAuthenticatorTrait;
93
    use AuthenticatorTrait;
94
    use ParticipantsTrait;
95
    // use InFulfillmentOfsTrait;
96
    use DocumentationOfsTrait;
97
    // use RelatedDocumentsTrait;
98
    use AuthorizationTrait;
99
100
    // use ComponentOfTrait;
101
    // use ComponentTrait;
102
    use ClassCodeTrait;
103
    use MoodCodeTrait;
104
105
    /**
106
     * Refeger assigned to this document  *
107
     *
108
     * @var ReferenceManager
109
     */
110
    private $referenceManager;
111
    /**
112
     * the root component
113
     *
114
     * @var Component\RootBodyComponent
115
     */
116
    private $rootComponent;
117
    private $informationRecipient;
0 ignored issues
show
introduced by
The private property $informationRecipient is not used, and could be removed.
Loading history...
118
    private $inFulfillmentOf;
0 ignored issues
show
introduced by
The private property $inFulfillmentOf is not used, and could be removed.
Loading history...
119
    private $documentationOf;
0 ignored issues
show
introduced by
The private property $documentationOf is not used, and could be removed.
Loading history...
120
    private $relatedDocument;
0 ignored issues
show
introduced by
The private property $relatedDocument is not used, and could be removed.
Loading history...
121
122
    /**
123
     * ClinicalDocument constructor.
124
     */
125
    public function __construct()
126
    {
127
        $this->rootComponent    = new Component\RootBodyComponent();
128
        $this->referenceManager = new ReferenceManager();
129
        $this->setTypeId(new TypeId(new InstanceIdentifier('2.16.840.1.113883.1.3', 'POCD_HD000040')))
130
          ->setAcceptableClassCodes(['', ClassCodeInterface::CLINICAL_DOCUMENT])
131
          ->setClassCode('')
132
          ->setAcceptableMoodCodes(['', MoodCodeInterface::EVENT])
133
          ->setMoodCode('');
134
    }
135
136
    /**
137
     *
138
     * @return ReferenceManager
139
     */
140
    public function getReferenceManager(): ReferenceManager
141
    {
142
        return $this->referenceManager;
143
    }
144
145
146
    /**
147
     *
148
     * @param \DOMDocument|null $doc
149
     *
150
     * @return \DOMDocument
151
     */
152
    public function toDOMDocument(\DOMDocument $doc = null): \DOMDocument
153
    {
154
        $doc = $doc ?? new \DOMDocument('1.0', 'UTF-8');
155
        $el  = $doc->createElementNS(self::NS_CDA_URI, 'ClinicalDocument');
156
        $doc->appendChild($el);
157
        // set the NS
158
        $el->setAttributeNS(
159
          self::NS_XSI_URI,
160
          'xsi:schemaLocation',
161
          'CDA-ES-V1_3.xsd'
162
        );
163
        $el->setAttribute('xmlns:ext', 'http://ns.electronichealth.net.au/Ci/Cda/Extensions/3.0');
164
        $el->setAttribute('xmlns:xs', 'http://www.w3.org/2001/XMLSchema');
165
        if ($this->hasClassCode()) {
166
            $el->setAttribute('classCode', $this->getClassCode());
167
        }
168
        if ($this->hasMoodCode()) {
169
            $el->setAttribute('moodCode', $this->getMoodCode());
170
        }
171
        $this->renderRealmCodes($el, $doc)
172
          ->renderTypeId($el, $doc)
173
          ->renderTemplateIds($el, $doc)
174
          ->renderId($el, $doc)
175
          ->renderCode($el, $doc)
176
          ->renderTitle($el, $doc)
177
          ->renderEffectiveTime($el, $doc)
178
          ->renderConfidentialityCode($el, $doc)
179
          ->renderLanguageCode($el, $doc)
180
          ->renderSetId($el, $doc)
181
          ->renderVersionNumber($el, $doc)
182
          ->renderCopyTime($el, $doc)
183
          ->renderCompletionCode($el, $doc)
184
          ->renderRecordTargets($el, $doc)
185
          ->renderAuthors($el, $doc)
186
          ->renderDataEnter($el, $doc)
187
          ->renderInformants($el, $doc)
188
          ->renderCustodian($el, $doc)
189
          ->renderInformationRecipients($el, $doc)
190
          ->renderLegalAuthenticator($el, $doc)
191
          ->renderAuthenticator($el, $doc)
192
          ->renderParticipants($el, $doc)
193
          // todo inFulfillmentOf
194
          ->renderDocumentationOfs($el, $doc)
195
          // todo relatedDocument
196
          ->renderAuthorization($el, $doc);
197
        // todo componentOf
198
        // add components
199
        if (false === $this->getRootComponent()->isEmpty()) {
200
            $el->appendChild($this->getRootComponent()->toDOMElement($doc));
201
        }
202
        return $doc;
203
    }
204
205
    /**
206
     *
207
     * @return Component\RootBodyComponent
208
     */
209
    public function getRootComponent(): Component\RootBodyComponent
210
    {
211
        return $this->rootComponent;
212
    }
213
214
}
215