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
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Root class for clinical document |
44
|
|
|
* |
45
|
|
|
* @author Julien Fastré <[email protected]> |
46
|
|
|
*/ |
47
|
|
|
class ClinicalDocument |
48
|
|
|
{ |
49
|
|
|
const NS_CDA = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* the templateId of the document. Will be inserted into doc, like |
53
|
|
|
* |
54
|
|
|
* ``` |
55
|
|
|
* <typeId> |
56
|
|
|
* ``` |
57
|
|
|
* |
58
|
|
|
* TODO : always equals to '2.16.840.1.113883.3.27.1776' |
59
|
|
|
* |
60
|
|
|
* @var TypeId |
61
|
|
|
*/ |
62
|
|
|
private $typeId; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* the title of the document |
66
|
|
|
* |
67
|
|
|
* @var Title |
68
|
|
|
*/ |
69
|
|
|
private $title; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* the root component |
73
|
|
|
* |
74
|
|
|
* @var Component\RootBodyComponent |
75
|
|
|
*/ |
76
|
|
|
private $rootComponent; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @var EffectiveTime |
81
|
|
|
*/ |
82
|
|
|
private $effectiveTime; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* |
86
|
|
|
* @var Id |
87
|
|
|
*/ |
88
|
|
|
private $id; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
* @var Code |
93
|
|
|
*/ |
94
|
|
|
private $code; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* |
98
|
|
|
* @var RecordTarget |
99
|
|
|
*/ |
100
|
|
|
private $recordTarget; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* |
104
|
|
|
* @var ConfidentialityCode |
105
|
|
|
*/ |
106
|
|
|
private $confidentialityCode; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
* @var Custodian |
111
|
|
|
*/ |
112
|
|
|
private $custodian; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* |
116
|
|
|
* @var Author |
117
|
|
|
*/ |
118
|
|
|
private $author; |
119
|
|
|
|
120
|
|
|
public function __construct() |
121
|
|
|
{ |
122
|
|
|
$this->rootComponent = new Component\RootBodyComponent(); |
123
|
|
|
|
124
|
|
|
$typeIdIdentifier = new InstanceIdentifier( |
125
|
|
|
"2.16.840.1.113883.1.3", |
126
|
|
|
"POCD_HD000040" |
127
|
|
|
); |
128
|
|
|
$this->typeId = new TypeId($typeIdIdentifier); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getTitle() |
136
|
|
|
{ |
137
|
|
|
return $this->title; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* |
142
|
|
|
* @param \PHPHealth\CDA\Elements\Title $title |
143
|
|
|
* @return \PHPHealth\CDA2\ClinicalDocument |
144
|
|
|
*/ |
145
|
|
|
public function setTitle(Title $title) |
146
|
|
|
{ |
147
|
|
|
$this->title = $title; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* |
154
|
|
|
* @return EffectiveTime |
155
|
|
|
*/ |
156
|
|
|
public function getEffectiveTime() |
157
|
|
|
{ |
158
|
|
|
return $this->effectiveTime; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* |
163
|
|
|
* @param EffectiveTime $effectiveTime |
164
|
|
|
* @return $this |
165
|
|
|
*/ |
166
|
|
|
public function setEffectiveTime(EffectiveTime $effectiveTime) |
167
|
|
|
{ |
168
|
|
|
$this->effectiveTime = $effectiveTime; |
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* |
175
|
|
|
* @return Id |
176
|
|
|
*/ |
177
|
|
|
public function getId() |
178
|
|
|
{ |
179
|
|
|
return $this->id; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* |
184
|
|
|
* @param Id $id |
185
|
|
|
* @return $this |
186
|
|
|
*/ |
187
|
|
|
public function setId(Id $id) |
188
|
|
|
{ |
189
|
|
|
$this->id = $id; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get the code of the document |
196
|
|
|
* |
197
|
|
|
* @return Code |
198
|
|
|
*/ |
199
|
|
|
public function getCode() |
200
|
|
|
{ |
201
|
|
|
return $this->code; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set the code of the document |
206
|
|
|
* |
207
|
|
|
* @param Code $code |
208
|
|
|
* @return $this |
209
|
|
|
*/ |
210
|
|
|
public function setCode(Code $code) |
211
|
|
|
{ |
212
|
|
|
$this->code = $code; |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* |
219
|
|
|
* @return ConfidentialityCode |
220
|
|
|
*/ |
221
|
|
|
public function getConfidentialityCode() |
222
|
|
|
{ |
223
|
|
|
return $this->confidentialityCode; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* |
228
|
|
|
* @param ConfidentialityCode $confidentialityCode |
229
|
|
|
* @return $this |
230
|
|
|
*/ |
231
|
|
|
public function setConfidentialityCode(ConfidentialityCode $confidentialityCode) |
232
|
|
|
{ |
233
|
|
|
$this->confidentialityCode = $confidentialityCode; |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* |
241
|
|
|
* @return Component\RootBodyComponent |
242
|
|
|
*/ |
243
|
|
|
public function getRootComponent() |
244
|
|
|
{ |
245
|
|
|
return $this->rootComponent; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getRecordTarget() |
249
|
|
|
{ |
250
|
|
|
return $this->recordTarget; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function setRecordTarget(RecordTarget $recordTarget) |
254
|
|
|
{ |
255
|
|
|
$this->recordTarget = $recordTarget; |
256
|
|
|
|
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function getAuthor(): Author |
261
|
|
|
{ |
262
|
|
|
return $this->author; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function hasAuthor() |
266
|
|
|
{ |
267
|
|
|
return $this->author !== null; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function setAuthor(Author $author) |
271
|
|
|
{ |
272
|
|
|
$this->author = $author; |
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* |
278
|
|
|
* @return Custodian |
279
|
|
|
*/ |
280
|
|
|
public function getCustodian() |
281
|
|
|
{ |
282
|
|
|
return $this->custodian; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* |
287
|
|
|
* @param Custodian $custodian |
288
|
|
|
* @return $this |
289
|
|
|
*/ |
290
|
|
|
public function setCustodian(Custodian $custodian) |
291
|
|
|
{ |
292
|
|
|
$this->custodian = $custodian; |
293
|
|
|
return $this; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* |
302
|
|
|
* @return \DOMDocument |
303
|
|
|
*/ |
304
|
|
|
public function toDOMDocument() |
305
|
|
|
{ |
306
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
307
|
|
|
|
308
|
|
|
$doc = $dom->createElementNS('urn:hl7-org:v3', 'ClinicalDocument'); |
309
|
|
|
$dom->appendChild($doc); |
310
|
|
|
// set the NS |
311
|
|
|
$doc->setAttributeNS( |
312
|
|
|
'http://www.w3.org/2001/XMLSchema-instance', |
313
|
|
|
'xsi:schemaLocation', |
314
|
|
|
'urn:hl7-org:v3 CDA.xsd' |
315
|
|
|
); |
316
|
|
|
// add typeId |
317
|
|
|
$doc->appendChild($this->typeId->toDOMElement($dom)); |
318
|
|
|
// add id |
319
|
|
|
if ($this->getId() !== null) { |
320
|
|
|
$doc->appendChild($this->getId()->toDOMElement($dom)); |
321
|
|
|
} |
322
|
|
|
// add code |
323
|
|
|
if ($this->getCode() !== null) { |
324
|
|
|
$doc->appendChild($this->getCode()->toDOMElement($dom)); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
// add title |
328
|
|
|
if ($this->getTitle() !== null) { |
329
|
|
|
$doc->appendChild($this->getTitle()->toDOMElement($dom)); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
//add effective time |
333
|
|
|
if ($this->getEffectiveTime() !== null) { |
334
|
|
|
$doc->appendChild($this->getEffectiveTime()->toDOMElement($dom)); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
// add confidentialityCode |
338
|
|
|
if ($this->getConfidentialityCode() !== null) { |
339
|
|
|
$doc->appendChild($this->confidentialityCode->toDOMElement($dom)); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
// add recordTarget |
343
|
|
|
if ($this->getRecordTarget() !== null) { |
344
|
|
|
$doc->appendChild($this->recordTarget->toDOMElement($dom)); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
// add author |
348
|
|
|
if ($this->hasAuthor()) { |
349
|
|
|
$doc->appendChild($this->getAuthor()->toDOMElement($dom)); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
if ($this->getCustodian()) { |
353
|
|
|
$doc->appendChild($this->getCustodian()->toDOMElement($dom)); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
// add components |
357
|
|
|
if (!$this->getRootComponent()->isEmpty()) { |
358
|
|
|
$doc->appendChild($this->getRootComponent()->toDOMElement($dom)); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
return $dom; |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|