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
|
|
|
/** |
30
|
|
|
* A name for a person, organization, place or thing. A sequence of name parts, |
31
|
|
|
* such as given name or family name, prefix, suffix, etc. Examples for entity |
32
|
|
|
* name values are "Jim Bob Walton, Jr.", "Health Level Seven, Inc.", |
33
|
|
|
* "Lake Tahoe", etc. An entity name may be as simple as a character string or |
34
|
|
|
* may consist of several entity name parts, such as, "Jim", "Bob", "Walton", |
35
|
|
|
* and "Jr.", "Health Level Seven" and "Inc.", "Lake" and "Tahoe". |
36
|
|
|
* |
37
|
|
|
* Structurally, the entity name data type is a sequence of entity name part |
38
|
|
|
* values with an added "use" code and a valid time range for information about |
39
|
|
|
* if and when the name can be used for a given purpose. |
40
|
|
|
* |
41
|
|
|
* @author Julien Fastré <[email protected]> |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
use i3Soft\CDA\ClinicalDocument as CDA; |
45
|
|
|
use i3Soft\CDA\DataType\AnyType; |
46
|
|
|
use i3Soft\CDA\Interfaces\UseAttributeInterface; |
47
|
|
|
|
48
|
|
|
class EntityName extends AnyType implements UseAttributeInterface |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $string = ''; |
55
|
|
|
|
56
|
|
|
protected $use_attribute = ''; |
57
|
|
|
|
58
|
|
|
protected $acceptable_use_attributes = array(); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* EntityName constructor. |
62
|
|
|
* |
63
|
|
|
* @param string $string |
64
|
|
|
*/ |
65
|
|
|
public function __construct ($string = '') |
66
|
|
|
{ |
67
|
|
|
$this->acceptable_use_attributes = UseAttributeInterface::AddressValues; |
68
|
|
|
$this->setString($string); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \DOMElement $el |
73
|
|
|
* @param \DOMDocument|NULL $doc |
74
|
|
|
*/ |
75
|
|
|
public function setValueToElement (\DOMElement $el, \DOMDocument $doc) |
76
|
|
|
{ |
77
|
|
|
$name = $doc->createElement('name'); |
78
|
|
|
$name->appendChild($doc->createTextNode($this->getString())); |
79
|
|
|
|
80
|
|
|
$el->appendChild($name); |
81
|
|
|
if (FALSE === empty($this->getUseAttribute())) |
82
|
|
|
{ |
83
|
|
|
$name->setAttribute(CDA::getNS() . 'use', $this->getUseAttribute()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getString (): string |
91
|
|
|
{ |
92
|
|
|
return $this->string; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $string |
97
|
|
|
* |
98
|
|
|
* @return self |
99
|
|
|
*/ |
100
|
|
|
public function setString ($string): self |
101
|
|
|
{ |
102
|
|
|
$this->string = $string; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getUseAttribute (): string |
110
|
|
|
{ |
111
|
|
|
return $this->use_attribute; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Note that overloads do validation as appropriate |
116
|
|
|
* |
117
|
|
|
* @param string $use_attribute |
118
|
|
|
* |
119
|
|
|
* @return EntityName |
120
|
|
|
*/ |
121
|
|
|
public function setUseAttribute (string $use_attribute): self |
122
|
|
|
{ |
123
|
|
|
if (\in_array($use_attribute, $this->acceptable_use_attributes, TRUE) === FALSE) |
124
|
|
|
{ |
125
|
|
|
throw new \InvalidArgumentException("The use attribute {$use_attribute} is not an acceptable value!"); |
126
|
|
|
} |
127
|
|
|
$this->use_attribute = $use_attribute; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|