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\Elements; |
||||||||
28 | |||||||||
29 | use i3Soft\CDA\ClinicalDocument as CDA; |
||||||||
30 | use i3Soft\CDA\DataType\Boolean\Boolean; |
||||||||
31 | use i3Soft\CDA\Interfaces\ClassCodeInterface; |
||||||||
32 | use i3Soft\CDA\Interfaces\ContextConductionIndInterface; |
||||||||
33 | use i3Soft\CDA\Interfaces\ContextControlCodeInterface; |
||||||||
34 | use i3Soft\CDA\Interfaces\DeterminerCodeInterface; |
||||||||
35 | use i3Soft\CDA\Interfaces\ElementInterface; |
||||||||
36 | use i3Soft\CDA\Interfaces\InversionIndInterface; |
||||||||
37 | use i3Soft\CDA\Interfaces\MediaTypeInterface; |
||||||||
38 | use i3Soft\CDA\Interfaces\MoodCodeInterface; |
||||||||
39 | use i3Soft\CDA\Interfaces\NegationInterface; |
||||||||
40 | use i3Soft\CDA\Interfaces\NullFlavourInterface; |
||||||||
41 | use i3Soft\CDA\Interfaces\TypeCodeInterface; |
||||||||
42 | use i3Soft\CDA\Interfaces\UseAttributeInterface; |
||||||||
43 | use i3Soft\CDA\Interfaces\XSITypeInterface; |
||||||||
44 | use i3Soft\CDA\RIM\Act\Observation; |
||||||||
45 | use i3Soft\CDA\RIM\Act\SubstanceAdministration; |
||||||||
46 | use i3Soft\CDA\RIM\Act\Supply; |
||||||||
47 | use i3Soft\CDA\RIM\Entity\AssignedPerson; |
||||||||
48 | use i3Soft\CDA\RIM\Entity\SpecimenPlayingEntity; |
||||||||
49 | use i3Soft\CDA\RIM\Extensions\ExtParticipantRole; |
||||||||
50 | use i3Soft\CDA\RIM\Participation\Consumable; |
||||||||
51 | use i3Soft\CDA\RIM\Participation\Performer; |
||||||||
52 | use i3Soft\CDA\RIM\Role\ManufacturedProduct; |
||||||||
53 | use i3Soft\CDA\RIM\Role\SpecimenRole; |
||||||||
54 | use i3Soft\CDA\Traits\NullFlavourTrait; |
||||||||
55 | use i3Soft\CDA\Traits\RealmCodesTrait; |
||||||||
56 | use i3Soft\CDA\Traits\TemplateIdsTrait; |
||||||||
57 | use i3Soft\CDA\Traits\TypeIdTrait; |
||||||||
58 | |||||||||
59 | /** |
||||||||
60 | * @author Julien Fastré <[email protected]> |
||||||||
61 | */ |
||||||||
62 | abstract class AbstractElement implements ElementInterface, NullFlavourInterface |
||||||||
63 | { |
||||||||
64 | use NullFlavourTrait; |
||||||||
65 | use RealmCodesTrait; |
||||||||
66 | use TypeIdTrait; |
||||||||
67 | use TemplateIdsTrait; |
||||||||
68 | |||||||||
69 | /** |
||||||||
70 | * @var array |
||||||||
71 | */ |
||||||||
72 | protected $attributes = array(); |
||||||||
73 | |||||||||
74 | /** |
||||||||
75 | * this is a total hack to add non-commonly used attributes. |
||||||||
76 | * don't use it lazy bones! |
||||||||
77 | * |
||||||||
78 | * @param $attribute |
||||||||
79 | * @param $value |
||||||||
80 | * |
||||||||
81 | * @return AbstractElement |
||||||||
82 | * @deprecated |
||||||||
83 | */ |
||||||||
84 | public function addAttribute ($attribute, $value): self |
||||||||
85 | { |
||||||||
86 | $this->attributes[$attribute] = $value; |
||||||||
87 | return $this; |
||||||||
88 | } |
||||||||
89 | |||||||||
90 | /** |
||||||||
91 | * @return TargetSiteCode |
||||||||
92 | */ |
||||||||
93 | public function returnTargetSiteCode (): TargetSiteCode |
||||||||
94 | { |
||||||||
95 | if ($this instanceof TargetSiteCode) |
||||||||
96 | { |
||||||||
97 | return $this; |
||||||||
98 | } |
||||||||
99 | throw new \RuntimeException('The method must be an instance of TargetSiteCode'); |
||||||||
100 | } |
||||||||
101 | |||||||||
102 | /** |
||||||||
103 | * @return Observation |
||||||||
104 | */ |
||||||||
105 | public function returnObservation (): Observation |
||||||||
106 | { |
||||||||
107 | if ($this instanceof Observation) |
||||||||
108 | { |
||||||||
109 | return $this; |
||||||||
110 | } |
||||||||
111 | throw new \RuntimeException('The method must be an instance of Observation'); |
||||||||
112 | } |
||||||||
113 | |||||||||
114 | /** |
||||||||
115 | * @return SubstanceAdministration |
||||||||
116 | */ |
||||||||
117 | public function returnSubstanceAdministration (): SubstanceAdministration |
||||||||
118 | { |
||||||||
119 | if ($this instanceof SubstanceAdministration) |
||||||||
120 | { |
||||||||
121 | return $this; |
||||||||
122 | } |
||||||||
123 | throw new \RuntimeException('The method must be an instance of SubstanceAdministration'); |
||||||||
124 | } |
||||||||
125 | |||||||||
126 | /** |
||||||||
127 | * @return SpecimenRole |
||||||||
128 | */ |
||||||||
129 | public function returnSpecimenRole (): SpecimenRole |
||||||||
130 | { |
||||||||
131 | if ($this instanceof SpecimenRole) |
||||||||
132 | { |
||||||||
133 | return $this; |
||||||||
134 | } |
||||||||
135 | throw new \RuntimeException('The method must be an instance of SpecimenRole'); |
||||||||
136 | } |
||||||||
137 | |||||||||
138 | /** |
||||||||
139 | * @return ManufacturedProduct |
||||||||
140 | */ |
||||||||
141 | public function returnManufacturedProduct (): ManufacturedProduct |
||||||||
142 | { |
||||||||
143 | if ($this instanceof ManufacturedProduct) |
||||||||
144 | { |
||||||||
145 | return $this; |
||||||||
146 | } |
||||||||
147 | throw new \RuntimeException('The method must be an instance of ManufacturedProduct'); |
||||||||
148 | } |
||||||||
149 | |||||||||
150 | /** |
||||||||
151 | * @return SpecimenPlayingEntity |
||||||||
152 | */ |
||||||||
153 | public function returnSpecimenPlayingEntity (): SpecimenPlayingEntity |
||||||||
154 | { |
||||||||
155 | if ($this instanceof SpecimenPlayingEntity) |
||||||||
156 | { |
||||||||
157 | return $this; |
||||||||
158 | } |
||||||||
159 | throw new \RuntimeException('The method must be an instance of SpecimenPlayingEntity'); |
||||||||
160 | } |
||||||||
161 | |||||||||
162 | /** |
||||||||
163 | * @return Consumable |
||||||||
164 | */ |
||||||||
165 | public function returnConsumable (): Consumable |
||||||||
166 | { |
||||||||
167 | if ($this instanceof Consumable) |
||||||||
168 | { |
||||||||
169 | return $this; |
||||||||
170 | } |
||||||||
171 | throw new \RuntimeException('The method must be an instance of Consumable'); |
||||||||
172 | } |
||||||||
173 | |||||||||
174 | /** |
||||||||
175 | * @return Performer |
||||||||
176 | */ |
||||||||
177 | public function returnPerformer (): Performer |
||||||||
178 | { |
||||||||
179 | if ($this instanceof Performer) |
||||||||
180 | { |
||||||||
181 | return $this; |
||||||||
182 | } |
||||||||
183 | throw new \RuntimeException('The method must be an instance of Performer'); |
||||||||
184 | } |
||||||||
185 | |||||||||
186 | /** |
||||||||
187 | * @return AssignedPerson |
||||||||
188 | */ |
||||||||
189 | public function returnAssignedPerson (): AssignedPerson |
||||||||
190 | { |
||||||||
191 | if ($this instanceof AssignedPerson) |
||||||||
192 | { |
||||||||
193 | return $this; |
||||||||
194 | } |
||||||||
195 | throw new \RuntimeException('The method must be an instance of AssignedPerson'); |
||||||||
196 | } |
||||||||
197 | |||||||||
198 | /** |
||||||||
199 | * @return ExtParticipantRole |
||||||||
200 | */ |
||||||||
201 | public function returnExtParticipantRole (): ExtParticipantRole |
||||||||
202 | { |
||||||||
203 | if ($this instanceof ExtParticipantRole) |
||||||||
204 | { |
||||||||
205 | return $this; |
||||||||
206 | } |
||||||||
207 | throw new \RuntimeException('The method must be an instance of ExtParticipantRole'); |
||||||||
208 | } |
||||||||
209 | |||||||||
210 | /** |
||||||||
211 | * @return Supply |
||||||||
212 | */ |
||||||||
213 | public function returnSupply (): Supply |
||||||||
214 | { |
||||||||
215 | if ($this instanceof Supply) |
||||||||
216 | { |
||||||||
217 | return $this; |
||||||||
218 | } |
||||||||
219 | throw new \RuntimeException('The method must be an instance of Supply'); |
||||||||
220 | } |
||||||||
221 | |||||||||
222 | /** |
||||||||
223 | * @param \DOMDocument $doc |
||||||||
224 | * @param array $properties |
||||||||
225 | * |
||||||||
226 | * @return \DOMElement |
||||||||
227 | */ |
||||||||
228 | protected function createElement (\DOMDocument $doc, array $properties = array()): \DOMElement |
||||||||
229 | { |
||||||||
230 | /* @var $el \DOMElement */ |
||||||||
231 | $el = $doc->createElement(CDA::getNS() . $this->getElementTag()); |
||||||||
232 | if ($this->hasNullFlavour()) |
||||||||
233 | { |
||||||||
234 | $el->setAttribute(CDA::getNS() . 'nullFlavor', $this->getNullFlavour()); |
||||||||
235 | return $el; |
||||||||
236 | } |
||||||||
237 | |||||||||
238 | // tag can have class code or type code, but not both. |
||||||||
239 | // can have a class code and a mood code, but not type code and mood code |
||||||||
240 | /** @noinspection PhpUndefinedMethodInspection */ |
||||||||
241 | if ($this instanceof ClassCodeInterface |
||||||||
242 | && $this->hasClassCode()) |
||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() The method
hasClassCode() does not exist on i3Soft\CDA\Interfaces\ClassCodeInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to i3Soft\CDA\Interfaces\ClassCodeInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
243 | { |
||||||||
244 | $el->setAttribute(CDA::getNS() . 'classCode', $this->getClassCode()); |
||||||||
245 | /** @noinspection PhpUndefinedMethodInspection */ |
||||||||
246 | if ($this instanceof MoodCodeInterface |
||||||||
247 | && $this->hasMoodCode()) |
||||||||
0 ignored issues
–
show
The method
hasMoodCode() does not exist on i3Soft\CDA\Elements\AbstractElement . It seems like you code against a sub-type of i3Soft\CDA\Elements\AbstractElement such as i3Soft\CDA\RIM\Act\Encounter or i3Soft\CDA\RIM\Extensions\ExtEntitlement or i3Soft\CDA\RIM\Act\ObservationMedia or i3Soft\CDA\RIM\Act\Organizer or i3Soft\CDA\Elements\Procedure or i3Soft\CDA\RIM\Extensions\ExtControlAct or i3Soft\CDA\RIM\Act\ObservationRange or i3Soft\CDA\RIM\Act\Supply or i3Soft\CDA\RIM\Act\Consent or i3Soft\CDA\RIM\Extensions\SubstitutionPermission or i3Soft\CDA\RIM\Act\Act or i3Soft\CDA\RIM\Act\ServiceEvent or i3Soft\CDA\RIM\Act\EncompassingEncounter or i3Soft\CDA\Component\SingleComponent\Section or i3Soft\CDA\RIM\Act\Criterion or i3Soft\CDA\Component\XMLBodyComponent .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
hasMoodCode() does not exist on i3Soft\CDA\Interfaces\MoodCodeInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to i3Soft\CDA\Interfaces\MoodCodeInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
hasMoodCode() does not exist on i3Soft\CDA\Interfaces\ClassCodeInterface . It seems like you code against a sub-type of i3Soft\CDA\Interfaces\ClassCodeInterface such as i3Soft\CDA\RIM\Act\Encounter or i3Soft\CDA\RIM\Act\Criterion or i3Soft\CDA\RIM\Extensions\ExtEntitlement or i3Soft\CDA\RIM\Act\ObservationMedia or i3Soft\CDA\Component\XMLBodyComponent or i3Soft\CDA\RIM\Act\Organizer or i3Soft\CDA\Elements\Procedure or i3Soft\CDA\RIM\Extensions\ExtControlAct or i3Soft\CDA\RIM\Act\ObservationRange or i3Soft\CDA\RIM\Act\Supply or i3Soft\CDA\ClinicalDocument or i3Soft\CDA\RIM\Act\Consent or i3Soft\CDA\RIM\Extensions\SubstitutionPermission or i3Soft\CDA\RIM\Act\Act or i3Soft\CDA\RIM\Act\ServiceEvent or i3Soft\CDA\RIM\Act\EncompassingEncounter or i3Soft\CDA\Component\SingleComponent\Section .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
248 | { |
||||||||
249 | $el->setAttribute(CDA::getNS() . 'moodCode', $this->getMoodCode()); |
||||||||
250 | } |
||||||||
251 | } |
||||||||
252 | /** @noinspection PhpUndefinedMethodInspection */ |
||||||||
253 | elseif ($this instanceof TypeCodeInterface && $this->hasTypeCode()) |
||||||||
0 ignored issues
–
show
The method
hasTypeCode() does not exist on i3Soft\CDA\Interfaces\TypeCodeInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to i3Soft\CDA\Interfaces\TypeCodeInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
hasTypeCode() does not exist on i3Soft\CDA\Elements\AbstractElement . Did you maybe mean hasTypeId() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
254 | { |
||||||||
255 | $el->setAttribute(CDA::getNS() . 'typeCode', $this->getTypeCode()); |
||||||||
256 | } |
||||||||
257 | |||||||||
258 | if ($this instanceof DeterminerCodeInterface |
||||||||
259 | && FALSE === empty($this->getDeterminerCode())) |
||||||||
260 | { |
||||||||
261 | $el->setAttribute(CDA::getNS() . 'determinerCode', $this->getDeterminerCode()); |
||||||||
262 | } |
||||||||
263 | |||||||||
264 | if ($this instanceof MediaTypeInterface && $this->getMediaType()) |
||||||||
265 | { |
||||||||
266 | $el->setAttribute(CDA::getNS() . 'mediaType', $this->getMediaType()); |
||||||||
267 | } |
||||||||
268 | |||||||||
269 | if ($this instanceof InversionIndInterface |
||||||||
270 | && $this->hasInversionInd()) |
||||||||
271 | { |
||||||||
272 | $negationInd = new Boolean('inversionInd', $this->getInversionInd()); |
||||||||
273 | $negationInd->setValueToElement($el, $doc); |
||||||||
274 | } |
||||||||
275 | |||||||||
276 | if ($this instanceof ContextConductionIndInterface |
||||||||
277 | && $this->hasContextConductionInd()) |
||||||||
278 | { |
||||||||
279 | $negationInd = new Boolean('contextConductionInd', $this->getContextConductionInd()); |
||||||||
280 | $negationInd->setValueToElement($el, $doc); |
||||||||
281 | } |
||||||||
282 | |||||||||
283 | if ($this instanceof NegationInterface |
||||||||
284 | && $this->hasNegationInd()) |
||||||||
285 | { |
||||||||
286 | $negationInd = new Boolean('negationInd', $this->getNegationInd()); |
||||||||
287 | $negationInd->setValueToElement($el, $doc); |
||||||||
288 | } |
||||||||
289 | if ($this instanceof UseAttributeInterface |
||||||||
290 | && FALSE === empty($this->getUseAttribute())) |
||||||||
291 | { |
||||||||
292 | $el->setAttribute(CDA::getNS() . 'use', $this->getUseAttribute()); |
||||||||
293 | } |
||||||||
294 | |||||||||
295 | if ($this instanceof ContextControlCodeInterface |
||||||||
296 | && FALSE === empty($this->getContextControlCode())) |
||||||||
297 | { |
||||||||
298 | |||||||||
299 | $el->setAttribute(CDA::getNS() . 'contextControlCode', $this->getContextControlCode()); |
||||||||
300 | } |
||||||||
301 | if ($this instanceof XSITypeInterface |
||||||||
302 | && FALSE === empty($this->getXSIType())) |
||||||||
303 | { |
||||||||
304 | $el->setAttribute(CDA::getNS() . 'xsi:type', $this->getXSIType()); |
||||||||
305 | } |
||||||||
306 | |||||||||
307 | foreach ($properties as $property) |
||||||||
308 | { |
||||||||
309 | $this->{$property}->setValueToElement($el, $doc); |
||||||||
310 | } |
||||||||
311 | |||||||||
312 | foreach ($this->attributes as $attribute => $value) |
||||||||
313 | { |
||||||||
314 | $el->setAttribute($attribute, $value); |
||||||||
315 | } |
||||||||
316 | // attributes have finished, now start adding the elements. |
||||||||
317 | // realm codes are used to store data like the organisation/country etc this tag conforms to. |
||||||||
318 | $this->renderRealmCodes($el, $doc) |
||||||||
319 | ->renderTypeId($el, $doc) |
||||||||
320 | ->renderTemplateIds($el, $doc); |
||||||||
321 | return $el; |
||||||||
322 | } |
||||||||
323 | |||||||||
324 | /** |
||||||||
325 | * get the element tag name |
||||||||
326 | * |
||||||||
327 | * @return string |
||||||||
328 | */ |
||||||||
329 | abstract protected function getElementTag (): string; |
||||||||
330 | |||||||||
331 | } |
||||||||
332 |