|
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
|
|
|
const VERSION = '1.0.4'; |
|
73
|
|
|
|
|
74
|
|
|
use RealmCodesTrait; |
|
75
|
|
|
use TypeIdTrait; |
|
76
|
|
|
use TemplateIdsTrait; |
|
77
|
|
|
use IdTrait; |
|
78
|
|
|
use CodeTrait; |
|
79
|
|
|
use TitleTrait; |
|
80
|
|
|
use EffectiveTimeTrait; |
|
81
|
|
|
use ConfidentialityCodeTrait; |
|
82
|
|
|
use LanguageCodeTrait; |
|
83
|
|
|
use SetIdTrait; |
|
84
|
|
|
use VersionNumberTrait; |
|
85
|
|
|
use CompletionCodeTrait; |
|
86
|
|
|
use CopyTimeTrait; |
|
87
|
|
|
use RecordTargetsTrait; |
|
88
|
|
|
use AuthorsTrait; |
|
89
|
|
|
use DataEntererTrait; |
|
90
|
|
|
use InformantsTrait; |
|
91
|
|
|
use CustodianTrait; |
|
92
|
|
|
use InformationRecipientsTrait; |
|
93
|
|
|
use legalAuthenticatorTrait; |
|
94
|
|
|
use AuthenticatorTrait; |
|
95
|
|
|
use ParticipantsTrait; |
|
96
|
|
|
// use InFulfillmentOfsTrait; |
|
97
|
|
|
use DocumentationOfsTrait; |
|
98
|
|
|
// use RelatedDocumentsTrait; |
|
99
|
|
|
use AuthorizationTrait; |
|
100
|
|
|
|
|
101
|
|
|
// use ComponentOfTrait; |
|
102
|
|
|
// use ComponentTrait; |
|
103
|
|
|
use ClassCodeTrait; |
|
104
|
|
|
use MoodCodeTrait; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Referer assigned to this document * |
|
108
|
|
|
* |
|
109
|
|
|
* @var ReferenceManager |
|
110
|
|
|
*/ |
|
111
|
|
|
private $referenceManager; |
|
112
|
|
|
/** |
|
113
|
|
|
* the root component |
|
114
|
|
|
* |
|
115
|
|
|
* @var Component\RootBodyComponent |
|
116
|
|
|
*/ |
|
117
|
|
|
private $rootComponent; |
|
118
|
|
|
private $informationRecipient; |
|
|
|
|
|
|
119
|
|
|
private $inFulfillmentOf; |
|
|
|
|
|
|
120
|
|
|
private $documentationOf; |
|
|
|
|
|
|
121
|
|
|
private $relatedDocument; |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** @var string the xmlns:ext attribute - leave empty string to not render.*/ |
|
124
|
|
|
private $attributeXmlnsExt; |
|
125
|
|
|
/** @var string the xmlns:xs attribute - leave as empty string to not render*/ |
|
126
|
|
|
private $attributeXmlNsXs; |
|
127
|
|
|
/** @var array the three parameters of the attribute Namespace*/ |
|
128
|
|
|
private $attributeNs; |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* ClinicalDocument constructor. |
|
132
|
|
|
*/ |
|
133
|
|
|
public function __construct () |
|
134
|
|
|
{ |
|
135
|
|
|
$this->rootComponent = new Component\RootBodyComponent(); |
|
136
|
|
|
$this->referenceManager = new ReferenceManager(); |
|
137
|
|
|
$this->setTypeId(new TypeId(new InstanceIdentifier('2.16.840.1.113883.1.3', 'POCD_HD000040'))) |
|
138
|
|
|
->setAttributeNs(self::NS_XSI_URI, 'xsi:schemaLocation', 'CDA-ES-v1_3.xsd') |
|
139
|
|
|
->setAttributeXmlnsExt('http://ns.electronichealth.net.au/Ci/Cda/Extensions/3.0') |
|
140
|
|
|
->setAttributeXmlNsXs('http://www.w3.org/2001/XMLSchema') |
|
141
|
|
|
->setAcceptableClassCodes(['', ClassCodeInterface::CLINICAL_DOCUMENT]) |
|
142
|
|
|
->setClassCode('') |
|
143
|
|
|
->setAcceptableMoodCodes(['', MoodCodeInterface::EVENT]) |
|
144
|
|
|
->setMoodCode(''); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* |
|
149
|
|
|
* @return ReferenceManager |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getReferenceManager (): ReferenceManager |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->referenceManager; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* |
|
158
|
|
|
* @param \DOMDocument|null $doc |
|
159
|
|
|
* |
|
160
|
|
|
* @return \DOMDocument |
|
161
|
|
|
*/ |
|
162
|
|
|
public function toDOMDocument (\DOMDocument $doc = NULL): \DOMDocument |
|
163
|
|
|
{ |
|
164
|
|
|
$doc = $doc ?? new \DOMDocument('1.0', 'UTF-8'); |
|
165
|
|
|
$el = $doc->createElementNS(self::NS_CDA_URI, 'ClinicalDocument'); |
|
166
|
|
|
$doc->appendChild($el); |
|
167
|
|
|
// set the NS |
|
168
|
|
|
if (implode('',$this->getAttributeNs())) |
|
169
|
|
|
{ |
|
170
|
|
|
$el->setAttributeNS( |
|
171
|
|
|
$this->getAttributeNs()[0], |
|
172
|
|
|
$this->getAttributeNs()[1], |
|
173
|
|
|
$this->getAttributeNs()[2] |
|
174
|
|
|
); |
|
175
|
|
|
} |
|
176
|
|
|
if ($xmlNsExt = $this->getAttributeXmlnsExt()) |
|
177
|
|
|
{ |
|
178
|
|
|
$el->setAttribute('xmlns:ext', $xmlNsExt); |
|
179
|
|
|
} |
|
180
|
|
|
if ($xmlNsXs = $this->getAttributeXmlNsXs()) |
|
181
|
|
|
{ |
|
182
|
|
|
$el->setAttribute('xmlns:xs', $xmlNsXs); |
|
183
|
|
|
} |
|
184
|
|
|
if ($this->hasClassCode()) |
|
185
|
|
|
{ |
|
186
|
|
|
$el->setAttribute('classCode', $this->getClassCode()); |
|
187
|
|
|
} |
|
188
|
|
|
if ($this->hasMoodCode()) |
|
189
|
|
|
{ |
|
190
|
|
|
$el->setAttribute('moodCode', $this->getMoodCode()); |
|
191
|
|
|
} |
|
192
|
|
|
$this->renderRealmCodes($el, $doc) |
|
193
|
|
|
->renderTypeId($el, $doc) |
|
194
|
|
|
->renderTemplateIds($el, $doc) |
|
195
|
|
|
->renderId($el, $doc) |
|
196
|
|
|
->renderCode($el, $doc) |
|
197
|
|
|
->renderTitle($el, $doc) |
|
198
|
|
|
->renderEffectiveTime($el, $doc) |
|
199
|
|
|
->renderConfidentialityCode($el, $doc) |
|
200
|
|
|
->renderLanguageCode($el, $doc) |
|
201
|
|
|
->renderSetId($el, $doc) |
|
202
|
|
|
->renderVersionNumber($el, $doc) |
|
203
|
|
|
->renderCopyTime($el, $doc) |
|
204
|
|
|
->renderCompletionCode($el, $doc) |
|
205
|
|
|
->renderRecordTargets($el, $doc) |
|
206
|
|
|
->renderAuthors($el, $doc) |
|
207
|
|
|
->renderDataEnter($el, $doc) |
|
208
|
|
|
->renderInformants($el, $doc) |
|
209
|
|
|
->renderCustodian($el, $doc) |
|
210
|
|
|
->renderInformationRecipients($el, $doc) |
|
211
|
|
|
->renderLegalAuthenticator($el, $doc) |
|
212
|
|
|
->renderAuthenticator($el, $doc) |
|
213
|
|
|
->renderParticipants($el, $doc) |
|
214
|
|
|
// todo inFulfillmentOf |
|
215
|
|
|
->renderDocumentationOfs($el, $doc) |
|
216
|
|
|
// todo relatedDocument |
|
217
|
|
|
->renderAuthorization($el, $doc); |
|
218
|
|
|
// todo componentOf |
|
219
|
|
|
// add components |
|
220
|
|
|
if (FALSE === $this->getRootComponent()->isEmpty()) |
|
221
|
|
|
{ |
|
222
|
|
|
$el->appendChild($this->getRootComponent()->toDOMElement($doc)); |
|
223
|
|
|
} |
|
224
|
|
|
return $doc; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* |
|
229
|
|
|
* @return Component\RootBodyComponent |
|
230
|
|
|
*/ |
|
231
|
|
|
public function getRootComponent (): Component\RootBodyComponent |
|
232
|
|
|
{ |
|
233
|
|
|
return $this->rootComponent; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getAttributeXmlnsExt (): string |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->attributeXmlnsExt; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @param string $attributeXmlnsExt |
|
246
|
|
|
* |
|
247
|
|
|
* @return self |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setAttributeXmlnsExt (string $attributeXmlnsExt): self |
|
250
|
|
|
{ |
|
251
|
|
|
$this->attributeXmlnsExt = $attributeXmlnsExt; |
|
252
|
|
|
return $this; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @return string |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getAttributeXmlNsXs (): string |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->attributeXmlNsXs; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @param string $attributeXmlNsXs |
|
265
|
|
|
* |
|
266
|
|
|
* @return self |
|
267
|
|
|
*/ |
|
268
|
|
|
public function setAttributeXmlNsXs (string $attributeXmlNsXs): self |
|
269
|
|
|
{ |
|
270
|
|
|
$this->attributeXmlNsXs = $attributeXmlNsXs; |
|
271
|
|
|
return $this; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @param string $namespaceUri |
|
276
|
|
|
* @param string $qualifiedName |
|
277
|
|
|
* @param string $value |
|
278
|
|
|
* |
|
279
|
|
|
* @return ClinicalDocument |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setAttributeNs (string $namespaceUri, string $qualifiedName, string $value): self |
|
282
|
|
|
{ |
|
283
|
|
|
$this->attributeNs = [$namespaceUri, $qualifiedName, $value]; |
|
284
|
|
|
return $this; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @return array |
|
289
|
|
|
*/ |
|
290
|
|
|
public function getAttributeNs (): array |
|
291
|
|
|
{ |
|
292
|
|
|
return $this->attributeNs; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|