ClinicalDocument::setTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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
    const NS_CDA_URI = 'urn:hl7-org:v3';
53
    const NS_XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
54
    
55
    
56
    /**
57
     * Reference manager assigned to this document
58
     *
59
     * @var ReferenceManager
60
     */
61
    private $referenceManager;
62
    
63
    /**
64
     * the templateId of the document. Will be inserted into doc, like
65
     *
66
     * ```
67
     * <typeId>
68
     * ```
69
     *
70
     * TODO : always equals to '2.16.840.1.113883.3.27.1776'
71
     *
72
     * @var TypeId
73
     */
74
    private $typeId;
75
    
76
    /**
77
     *
78
     * @var InstanceIdentifier[]
79
     */
80
    private $templateId = array();
81
    
82
    /**
83
     *
84
     * @var CodedSimple
85
     */
86
    private $languageCode;
87
    
88
    /**
89
     * the title of the document
90
     *
91
     * @var Title
92
     */
93
    private $title;
94
    
95
    /**
96
     * the root component
97
     *
98
     * @var Component\RootBodyComponent
99
     */
100
    private $rootComponent;
101
    
102
    /**
103
     *
104
     * @var EffectiveTime
105
     */
106
    private $effectiveTime;
107
    
108
    /**
109
     *
110
     * @var Id
111
     */
112
    private $id;
113
    
114
    /**
115
     *
116
     * @var Code
117
     */
118
    private $code;
119
    
120
    /**
121
     *
122
     * @var RecordTarget
123
     */
124
    private $recordTarget;
125
    
126
    /**
127
     *
128
     * @var ConfidentialityCode
129
     */
130
    private $confidentialityCode;
131
    
132
    /**
133
     *
134
     * @var Custodian
135
     */
136
    private $custodian;
137
    
138
    /**
139
     *
140
     * @var Author
141
     */
142
    private $author;
143
    
144
    public function __construct()
145
    {
146
        $this->rootComponent = new Component\RootBodyComponent();
147
        $this->referenceManager = new ReferenceManager();
148
        
149
        $typeIdIdentifier = new InstanceIdentifier(
150
            "2.16.840.1.113883.1.3",
151
            "POCD_HD000040"
152
        );
153
        $this->typeId = new TypeId($typeIdIdentifier);
154
    }
155
    
156
    /**
157
     * 
158
     * @return ReferenceManager
159
     */
160
    function getReferenceManager(): ReferenceManager
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
161
    {
162
        return $this->referenceManager;
163
    }
164
    
165
    /**
166
     *
167
     * @return string
168
     */
169
    public function getTitle()
170
    {
171
        return $this->title;
172
    }
173
174
    /**
175
     *
176
     * @param \PHPHealth\CDA\Elements\Title $title
177
     * @return \PHPHealth\CDA2\ClinicalDocument
178
     */
179
    public function setTitle(Title $title)
180
    {
181
        $this->title = $title;
182
        
183
        return $this;
184
    }
185
    
186
    function getTemplateId(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
187
    {
188
        return $this->templateId;
189
    }
190
191
    function setTemplateId(array $templateId)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
192
    {
193
        $validate = \array_reduce($templateId, function($carry, $item) {
194
            if ($carry === false) {
195
                return false;
196
            }
197
            
198
            return $item instanceof InstanceIdentifier;
199
        });
200
        
201
        assert($validate, new \UnexpectedValueException());
202
        
203
        $this->templateId = $templateId;
204
        
205
        return $this;
206
    }
207
    
208
    function addTtemplateId(InstanceIdentifier $identifier)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
209
    {
210
        $this->templateId[] = $identifier;
211
    }
212
213
    function getLanguageCode()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
214
    {
215
        return $this->languageCode;
216
    }
217
218
    function setLanguageCode(CodedSimple $languageCode)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
219
    {
220
        $this->languageCode = $languageCode;
221
        
222
        return $this;
223
    }
224
225
            
226
    /**
227
     *
228
     * @return EffectiveTime
229
     */
230
    public function getEffectiveTime()
231
    {
232
        return $this->effectiveTime;
233
    }
234
235
    /**
236
     *
237
     * @param EffectiveTime $effectiveTime
238
     * @return $this
239
     */
240
    public function setEffectiveTime(EffectiveTime $effectiveTime)
241
    {
242
        $this->effectiveTime = $effectiveTime;
243
        
244
        return $this;
245
    }
246
    
247
    /**
248
     *
249
     * @return Id
250
     */
251
    public function getId()
252
    {
253
        return $this->id;
254
    }
255
256
    /**
257
     *
258
     * @param Id $id
259
     * @return $this
260
     */
261
    public function setId(Id $id)
262
    {
263
        $this->id = $id;
264
        
265
        return $this;
266
    }
267
268
    /**
269
     * Get the code of the document
270
     *
271
     * @return Code
272
     */
273
    public function getCode()
274
    {
275
        return $this->code;
276
    }
277
278
    /**
279
     * Set the code of the document
280
     *
281
     * @param Code $code
282
     * @return $this
283
     */
284
    public function setCode(Code $code)
285
    {
286
        $this->code = $code;
287
        
288
        return $this;
289
    }
290
    
291
    /**
292
     *
293
     * @return ConfidentialityCode
294
     */
295
    public function getConfidentialityCode()
296
    {
297
        return $this->confidentialityCode;
298
    }
299
300
    /**
301
     *
302
     * @param ConfidentialityCode $confidentialityCode
303
     * @return $this
304
     */
305
    public function setConfidentialityCode(ConfidentialityCode $confidentialityCode)
306
    {
307
        $this->confidentialityCode = $confidentialityCode;
308
        
309
        return $this;
310
    }
311
312
        
313
    /**
314
     *
315
     * @return Component\RootBodyComponent
316
     */
317
    public function getRootComponent()
318
    {
319
        return $this->rootComponent;
320
    }
321
    
322
    public function getRecordTarget()
323
    {
324
        return $this->recordTarget;
325
    }
326
327
    public function setRecordTarget(RecordTarget $recordTarget)
328
    {
329
        $this->recordTarget = $recordTarget;
330
        
331
        return $this;
332
    }
333
    
334
    public function getAuthor(): Author
335
    {
336
        return $this->author;
337
    }
338
    
339
    public function hasAuthor()
340
    {
341
        return $this->author !== null;
342
    }
343
344
    public function setAuthor(Author $author)
345
    {
346
        $this->author = $author;
347
        return $this;
348
    }
349
    
350
    /**
351
     * 
352
     * @return Custodian
353
     */
354
    public function getCustodian()
355
    {
356
        return $this->custodian;
357
    }
358
359
    /**
360
     * 
361
     * @param Custodian $custodian
362
     * @return $this
363
     */
364
    public function setCustodian(Custodian $custodian)
365
    {
366
        $this->custodian = $custodian;
367
        return $this;
368
    }
369
370
        
371
372
    
373
        
374
    /**
375
     *
376
     * @return \DOMDocument
377
     */
378
    public function toDOMDocument(\DOMDocument $dom = null)
379
    {
380
        $dom = $dom === null ? new \DOMDocument('1.0', 'UTF-8') : $dom;
381
        
382
        $doc = $dom->createElementNS(self::NS_CDA_URI, 'ClinicalDocument');
383
        $dom->appendChild($doc);
384
        // set the NS
385
        $doc->setAttributeNS(
386
            self::NS_XSI_URI,
387
            'xsi:schemaLocation',
388
            'urn:hl7-org:v3 CDA.xsd'
389
        );
390
        // add typeId
391
        $doc->appendChild($this->typeId->toDOMElement($dom));
392
        
393
        // add templateIds
394
        foreach ($this->getTemplateId() as $templateId) {
395
            $doc->appendChild((new Elements\TemplateId($templateId))
396
                ->toDOMElement($dom));
397
        }
398
        
399
        // add id
400
        if ($this->getId() !== null) {
401
            $doc->appendChild($this->getId()->toDOMElement($dom));
402
        }
403
        // add code
404
        if ($this->getCode() !== null) {
405
            $doc->appendChild($this->getCode()->toDOMElement($dom));
406
        }
407
     
408
        // add title
409
        if ($this->getTitle() !== null) {
410
            $doc->appendChild($this->getTitle()->toDOMElement($dom));
411
        }
412
        
413
        //add effective time
414
        if ($this->getEffectiveTime() !== null) {
415
            $doc->appendChild($this->getEffectiveTime()->toDOMElement($dom));
416
        }
417
418
        // add confidentialityCode
419
        if ($this->getConfidentialityCode() !== null) {
420
            $doc->appendChild($this->confidentialityCode->toDOMElement($dom));
421
        }
422
        
423
        // add language code
424
        if ($this->getLanguageCode() !== null) {
425
            $doc->appendChild(
426
                (new Elements\LanguageCode($this->getLanguageCode()))
427
                ->toDOMElement($dom));
428
        }
429
        
430
        // add recordTarget
431
        if ($this->getRecordTarget() !== null) {
432
            $doc->appendChild($this->recordTarget->toDOMElement($dom));
433
        }
434
        
435
        // add author
436
        if ($this->hasAuthor()) {
437
            $doc->appendChild($this->getAuthor()->toDOMElement($dom));
438
        }
439
        
440
        if ($this->getCustodian()) {
441
            $doc->appendChild($this->getCustodian()->toDOMElement($dom));
442
        }
443
444
        // add components
445
        if (!$this->getRootComponent()->isEmpty()) {
446
            $doc->appendChild($this->getRootComponent()->toDOMElement($dom));
447
        }
448
        
449
        return $dom;
450
    }
451
}
452