|
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 NONINFRINGEMENT. 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 PHPHealth\CDA; |
|
28
|
|
|
|
|
29
|
|
|
use PHPHealth\CDA\DataType\Quantity\DateAndTime\TimeStamp; |
|
30
|
|
|
use PHPHealth\CDA\DataType\Identifier\InstanceIdentifier; |
|
31
|
|
|
use PHPHealth\CDA\DataType\Code\CodedValue; |
|
32
|
|
|
use PHPHealth\CDA\Elements\Code; |
|
33
|
|
|
use PHPHealth\CDA\Elements\Title; |
|
34
|
|
|
use PHPHealth\CDA\Elements\EffectiveTime; |
|
35
|
|
|
use PHPHealth\CDA\Elements\Id; |
|
36
|
|
|
use PHPHealth\CDA\Elements\ConfidentialityCode; |
|
37
|
|
|
use PHPHealth\CDA\Elements\TypeId; |
|
38
|
|
|
use PHPHealth\CDA\RIM\Participation\RecordTarget; |
|
39
|
|
|
use PHPHealth\CDA\RIM\Participation\Author; |
|
40
|
|
|
use PHPHealth\CDA\RIM\Participation\Custodian; |
|
41
|
|
|
use PHPHealth\CDA\DataType\Code\CodedSimple; |
|
42
|
|
|
use PHPHealth\CDA\Helper\ReferenceManager; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Root class for clinical document |
|
46
|
|
|
* |
|
47
|
|
|
* @author Julien Fastré <[email protected]> |
|
48
|
|
|
*/ |
|
49
|
|
|
class ClinicalDocument |
|
50
|
|
|
{ |
|
51
|
|
|
const NS_CDA = ''; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Reference manager assigned to this document |
|
55
|
|
|
* |
|
56
|
|
|
* @var ReferenceManager |
|
57
|
|
|
*/ |
|
58
|
|
|
private $referenceManager; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* the templateId of the document. Will be inserted into doc, like |
|
62
|
|
|
* |
|
63
|
|
|
* ``` |
|
64
|
|
|
* <typeId> |
|
65
|
|
|
* ``` |
|
66
|
|
|
* |
|
67
|
|
|
* TODO : always equals to '2.16.840.1.113883.3.27.1776' |
|
68
|
|
|
* |
|
69
|
|
|
* @var TypeId |
|
70
|
|
|
*/ |
|
71
|
|
|
private $typeId; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* |
|
75
|
|
|
* @var InstanceIdentifier[] |
|
76
|
|
|
*/ |
|
77
|
|
|
private $templateId = array(); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* |
|
81
|
|
|
* @var CodedSimple |
|
82
|
|
|
*/ |
|
83
|
|
|
private $languageCode; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* the title of the document |
|
87
|
|
|
* |
|
88
|
|
|
* @var Title |
|
89
|
|
|
*/ |
|
90
|
|
|
private $title; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* the root component |
|
94
|
|
|
* |
|
95
|
|
|
* @var Component\RootBodyComponent |
|
96
|
|
|
*/ |
|
97
|
|
|
private $rootComponent; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* |
|
101
|
|
|
* @var EffectiveTime |
|
102
|
|
|
*/ |
|
103
|
|
|
private $effectiveTime; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* |
|
107
|
|
|
* @var Id |
|
108
|
|
|
*/ |
|
109
|
|
|
private $id; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* |
|
113
|
|
|
* @var Code |
|
114
|
|
|
*/ |
|
115
|
|
|
private $code; |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* |
|
119
|
|
|
* @var RecordTarget |
|
120
|
|
|
*/ |
|
121
|
|
|
private $recordTarget; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* |
|
125
|
|
|
* @var ConfidentialityCode |
|
126
|
|
|
*/ |
|
127
|
|
|
private $confidentialityCode; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* |
|
131
|
|
|
* @var Custodian |
|
132
|
|
|
*/ |
|
133
|
|
|
private $custodian; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* |
|
137
|
|
|
* @var Author |
|
138
|
|
|
*/ |
|
139
|
|
|
private $author; |
|
140
|
|
|
|
|
141
|
|
|
public function __construct() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->rootComponent = new Component\RootBodyComponent(); |
|
144
|
|
|
$this->referenceManager = new ReferenceManager(); |
|
145
|
|
|
|
|
146
|
|
|
$typeIdIdentifier = new InstanceIdentifier( |
|
147
|
|
|
"2.16.840.1.113883.1.3", |
|
148
|
|
|
"POCD_HD000040" |
|
149
|
|
|
); |
|
150
|
|
|
$this->typeId = new TypeId($typeIdIdentifier); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* |
|
155
|
|
|
* @return ReferenceManager |
|
156
|
|
|
*/ |
|
157
|
|
|
function getReferenceManager(): ReferenceManager |
|
|
|
|
|
|
158
|
|
|
{ |
|
159
|
|
|
return $this->referenceManager; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* |
|
164
|
|
|
* @return string |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getTitle() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->title; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* |
|
173
|
|
|
* @param \PHPHealth\CDA\Elements\Title $title |
|
174
|
|
|
* @return \PHPHealth\CDA2\ClinicalDocument |
|
175
|
|
|
*/ |
|
176
|
|
|
public function setTitle(Title $title) |
|
177
|
|
|
{ |
|
178
|
|
|
$this->title = $title; |
|
179
|
|
|
|
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
function getTemplateId(): array |
|
|
|
|
|
|
184
|
|
|
{ |
|
185
|
|
|
return $this->templateId; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
function setTemplateId(array $templateId) |
|
|
|
|
|
|
189
|
|
|
{ |
|
190
|
|
|
$validate = \array_reduce($templateId, function($carry, $item) { |
|
191
|
|
|
if ($carry === false) { |
|
192
|
|
|
return false; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
return $item instanceof InstanceIdentifier; |
|
196
|
|
|
}); |
|
197
|
|
|
|
|
198
|
|
|
assert($validate, new \UnexpectedValueException()); |
|
199
|
|
|
|
|
200
|
|
|
$this->templateId = $templateId; |
|
201
|
|
|
|
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
function addTtemplateId(InstanceIdentifier $identifier) |
|
|
|
|
|
|
206
|
|
|
{ |
|
207
|
|
|
$this->templateId[] = $identifier; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
function getLanguageCode() |
|
|
|
|
|
|
211
|
|
|
{ |
|
212
|
|
|
return $this->languageCode; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
function setLanguageCode(CodedSimple $languageCode) |
|
|
|
|
|
|
216
|
|
|
{ |
|
217
|
|
|
$this->languageCode = $languageCode; |
|
218
|
|
|
|
|
219
|
|
|
return $this; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* |
|
225
|
|
|
* @return EffectiveTime |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getEffectiveTime() |
|
228
|
|
|
{ |
|
229
|
|
|
return $this->effectiveTime; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* |
|
234
|
|
|
* @param EffectiveTime $effectiveTime |
|
235
|
|
|
* @return $this |
|
236
|
|
|
*/ |
|
237
|
|
|
public function setEffectiveTime(EffectiveTime $effectiveTime) |
|
238
|
|
|
{ |
|
239
|
|
|
$this->effectiveTime = $effectiveTime; |
|
240
|
|
|
|
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* |
|
246
|
|
|
* @return Id |
|
247
|
|
|
*/ |
|
248
|
|
|
public function getId() |
|
249
|
|
|
{ |
|
250
|
|
|
return $this->id; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* |
|
255
|
|
|
* @param Id $id |
|
256
|
|
|
* @return $this |
|
257
|
|
|
*/ |
|
258
|
|
|
public function setId(Id $id) |
|
259
|
|
|
{ |
|
260
|
|
|
$this->id = $id; |
|
261
|
|
|
|
|
262
|
|
|
return $this; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Get the code of the document |
|
267
|
|
|
* |
|
268
|
|
|
* @return Code |
|
269
|
|
|
*/ |
|
270
|
|
|
public function getCode() |
|
271
|
|
|
{ |
|
272
|
|
|
return $this->code; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* Set the code of the document |
|
277
|
|
|
* |
|
278
|
|
|
* @param Code $code |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setCode(Code $code) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->code = $code; |
|
284
|
|
|
|
|
285
|
|
|
return $this; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* |
|
290
|
|
|
* @return ConfidentialityCode |
|
291
|
|
|
*/ |
|
292
|
|
|
public function getConfidentialityCode() |
|
293
|
|
|
{ |
|
294
|
|
|
return $this->confidentialityCode; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* |
|
299
|
|
|
* @param ConfidentialityCode $confidentialityCode |
|
300
|
|
|
* @return $this |
|
301
|
|
|
*/ |
|
302
|
|
|
public function setConfidentialityCode(ConfidentialityCode $confidentialityCode) |
|
303
|
|
|
{ |
|
304
|
|
|
$this->confidentialityCode = $confidentialityCode; |
|
305
|
|
|
|
|
306
|
|
|
return $this; |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* |
|
312
|
|
|
* @return Component\RootBodyComponent |
|
313
|
|
|
*/ |
|
314
|
|
|
public function getRootComponent() |
|
315
|
|
|
{ |
|
316
|
|
|
return $this->rootComponent; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
public function getRecordTarget() |
|
320
|
|
|
{ |
|
321
|
|
|
return $this->recordTarget; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
public function setRecordTarget(RecordTarget $recordTarget) |
|
325
|
|
|
{ |
|
326
|
|
|
$this->recordTarget = $recordTarget; |
|
327
|
|
|
|
|
328
|
|
|
return $this; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
public function getAuthor(): Author |
|
332
|
|
|
{ |
|
333
|
|
|
return $this->author; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
public function hasAuthor() |
|
337
|
|
|
{ |
|
338
|
|
|
return $this->author !== null; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
public function setAuthor(Author $author) |
|
342
|
|
|
{ |
|
343
|
|
|
$this->author = $author; |
|
344
|
|
|
return $this; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* |
|
349
|
|
|
* @return Custodian |
|
350
|
|
|
*/ |
|
351
|
|
|
public function getCustodian() |
|
352
|
|
|
{ |
|
353
|
|
|
return $this->custodian; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* |
|
358
|
|
|
* @param Custodian $custodian |
|
359
|
|
|
* @return $this |
|
360
|
|
|
*/ |
|
361
|
|
|
public function setCustodian(Custodian $custodian) |
|
362
|
|
|
{ |
|
363
|
|
|
$this->custodian = $custodian; |
|
364
|
|
|
return $this; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* |
|
373
|
|
|
* @return \DOMDocument |
|
374
|
|
|
*/ |
|
375
|
|
|
public function toDOMDocument(\DOMDocument $dom = null) |
|
376
|
|
|
{ |
|
377
|
|
|
$dom = $dom === null ? new \DOMDocument('1.0', 'UTF-8') : $dom; |
|
378
|
|
|
|
|
379
|
|
|
$doc = $dom->createElementNS('urn:hl7-org:v3', 'ClinicalDocument'); |
|
380
|
|
|
$dom->appendChild($doc); |
|
381
|
|
|
// set the NS |
|
382
|
|
|
$doc->setAttributeNS( |
|
383
|
|
|
'http://www.w3.org/2001/XMLSchema-instance', |
|
384
|
|
|
'xsi:schemaLocation', |
|
385
|
|
|
'urn:hl7-org:v3 CDA.xsd' |
|
386
|
|
|
); |
|
387
|
|
|
// add typeId |
|
388
|
|
|
$doc->appendChild($this->typeId->toDOMElement($dom)); |
|
389
|
|
|
|
|
390
|
|
|
// add templateIds |
|
391
|
|
|
foreach ($this->getTemplateId() as $templateId) { |
|
392
|
|
|
$doc->appendChild((new Elements\TemplateId($templateId)) |
|
393
|
|
|
->toDOMElement($dom)); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
// add id |
|
397
|
|
|
if ($this->getId() !== null) { |
|
398
|
|
|
$doc->appendChild($this->getId()->toDOMElement($dom)); |
|
399
|
|
|
} |
|
400
|
|
|
// add code |
|
401
|
|
|
if ($this->getCode() !== null) { |
|
402
|
|
|
$doc->appendChild($this->getCode()->toDOMElement($dom)); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
// add title |
|
406
|
|
|
if ($this->getTitle() !== null) { |
|
407
|
|
|
$doc->appendChild($this->getTitle()->toDOMElement($dom)); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
//add effective time |
|
411
|
|
|
if ($this->getEffectiveTime() !== null) { |
|
412
|
|
|
$doc->appendChild($this->getEffectiveTime()->toDOMElement($dom)); |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
// add confidentialityCode |
|
416
|
|
|
if ($this->getConfidentialityCode() !== null) { |
|
417
|
|
|
$doc->appendChild($this->confidentialityCode->toDOMElement($dom)); |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
// add language code |
|
421
|
|
|
if ($this->getLanguageCode() !== null) { |
|
422
|
|
|
$doc->appendChild( |
|
423
|
|
|
(new Elements\LanguageCode($this->getLanguageCode())) |
|
424
|
|
|
->toDOMElement($dom)); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
// add recordTarget |
|
428
|
|
|
if ($this->getRecordTarget() !== null) { |
|
429
|
|
|
$doc->appendChild($this->recordTarget->toDOMElement($dom)); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
// add author |
|
433
|
|
|
if ($this->hasAuthor()) { |
|
434
|
|
|
$doc->appendChild($this->getAuthor()->toDOMElement($dom)); |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
if ($this->getCustodian()) { |
|
438
|
|
|
$doc->appendChild($this->getCustodian()->toDOMElement($dom)); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
// add components |
|
442
|
|
|
if (!$this->getRootComponent()->isEmpty()) { |
|
443
|
|
|
$doc->appendChild($this->getRootComponent()->toDOMElement($dom)); |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
return $dom; |
|
447
|
|
|
} |
|
448
|
|
|
} |
|
449
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.