|
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\DataType\Name; |
|
28
|
|
|
|
|
29
|
|
|
use i3Soft\CDA\ClinicalDocument as CDA; |
|
30
|
|
|
use i3Soft\CDA\Interfaces\UseAttributeInterface; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @author Julien Fastré <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class PersonName extends EntityName |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
const HONORIFIC = 'prefix'; |
|
39
|
|
|
const FIRST_NAME = 'given'; |
|
40
|
|
|
const LAST_NAME = 'family'; |
|
41
|
|
|
const SUFFIX = 'suffix'; |
|
42
|
|
|
const possible_parts = [ |
|
43
|
|
|
self::HONORIFIC, |
|
44
|
|
|
self::FIRST_NAME, |
|
45
|
|
|
self::LAST_NAME, |
|
46
|
|
|
self::SUFFIX |
|
47
|
|
|
]; |
|
48
|
|
|
protected $name_tuples = array(); // tuples is an array of addPart values. |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* PersonName constructor. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct () |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct(NULL); |
|
56
|
|
|
$this->name_tuples =[]; |
|
57
|
|
|
// use name attributes must conform to: AS 5017-2006: Health Care Client Name Usage |
|
58
|
|
|
$this->acceptable_use_attributes = UseAttributeInterface::NameValues; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param $part |
|
63
|
|
|
* @param $value |
|
64
|
|
|
* @param null $qualifier |
|
|
|
|
|
|
65
|
|
|
* |
|
66
|
|
|
* @return self |
|
67
|
|
|
*/ |
|
68
|
|
|
public function addPart ($part, $value, $qualifier = NULL): self |
|
69
|
|
|
{ |
|
70
|
|
|
if (\in_array($part, self::possible_parts, TRUE) === FALSE) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
$this->name_tuples[] = ['part' => $part, 'value' => $value, 'qualifier' => $qualifier]; |
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param \DOMElement $el |
|
80
|
|
|
* @param \DOMDocument|NULL $doc |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setValueToElement (\DOMElement $el, \DOMDocument $doc) |
|
83
|
|
|
{ |
|
84
|
|
|
if (\count($this->name_tuples) > 0) |
|
85
|
|
|
{ |
|
86
|
|
|
$name = $doc->createElement(CDA::NS_CDA . 'name'); |
|
87
|
|
|
if (FALSE === empty($this->getUseAttribute())) |
|
88
|
|
|
{ |
|
89
|
|
|
$name->setAttribute(CDA::NS_CDA . 'use', $this->getUseAttribute()); |
|
90
|
|
|
} |
|
91
|
|
|
$el->appendChild($name); |
|
92
|
|
|
foreach ($this->name_tuples as $tuple) |
|
93
|
|
|
{ |
|
94
|
|
|
$partElement = $doc->createElement(CDA::NS_CDA . $tuple['part'], $tuple['value']); |
|
95
|
|
|
if ($tuple['qualifier']) |
|
96
|
|
|
{ |
|
97
|
|
|
$partElement->setAttribute('qualifier', $tuple['qualifier']); |
|
98
|
|
|
} |
|
99
|
|
|
$name->appendChild($partElement); |
|
100
|
|
|
} |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if ($this->string !== NULL) |
|
105
|
|
|
{ |
|
106
|
|
|
parent::setValueToElement($el, $doc); |
|
107
|
|
|
} |
|
108
|
|
|
else |
|
109
|
|
|
{ |
|
110
|
|
|
throw new \InvalidArgumentException('the element does not contains any parts nor string'); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return PersonName |
|
116
|
|
|
*/ |
|
117
|
|
|
public function resetNameTuples ():self |
|
118
|
|
|
{ |
|
119
|
|
|
$this->name_tuples = []; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|