pgee70 /
cda
| 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; |
||
| 28 | |||
| 29 | use i3Soft\CDA\DataType\Identifier\InstanceIdentifier; |
||
| 30 | use i3Soft\CDA\Elements\TypeId; |
||
| 31 | use i3Soft\CDA\Helper\ReferenceManager; |
||
| 32 | use i3Soft\CDA\Interfaces\ClassCodeInterface; |
||
| 33 | use i3Soft\CDA\Interfaces\MoodCodeInterface; |
||
| 34 | use i3Soft\CDA\Traits\AuthenticatorTrait; |
||
| 35 | use i3Soft\CDA\Traits\AuthorizationTrait; |
||
| 36 | use i3Soft\CDA\Traits\AuthorsTrait; |
||
| 37 | use i3Soft\CDA\Traits\ClassCodeTrait; |
||
| 38 | use i3Soft\CDA\Traits\CodeTrait; |
||
| 39 | use i3Soft\CDA\Traits\CompletionCodeTrait; |
||
| 40 | use i3Soft\CDA\Traits\ConfidentialityCodeTrait; |
||
| 41 | use i3Soft\CDA\Traits\CopyTimeTrait; |
||
| 42 | use i3Soft\CDA\Traits\CustodianTrait; |
||
| 43 | use i3Soft\CDA\Traits\DataEntererTrait; |
||
| 44 | use i3Soft\CDA\Traits\DocumentationOfsTrait; |
||
| 45 | use i3Soft\CDA\Traits\EffectiveTimeTrait; |
||
| 46 | use i3Soft\CDA\Traits\IdTrait; |
||
| 47 | use i3Soft\CDA\Traits\InformantsTrait; |
||
| 48 | use i3Soft\CDA\Traits\InformationRecipientsTrait; |
||
| 49 | use i3Soft\CDA\Traits\LanguageCodeTrait; |
||
| 50 | use i3Soft\CDA\Traits\LegalAuthenticatorTrait; |
||
| 51 | use i3Soft\CDA\Traits\MoodCodeTrait; |
||
| 52 | use i3Soft\CDA\Traits\ParticipantsTrait; |
||
| 53 | use i3Soft\CDA\Traits\RealmCodesTrait; |
||
| 54 | use i3Soft\CDA\Traits\RecordTargetsTrait; |
||
| 55 | use i3Soft\CDA\Traits\SetIdTrait; |
||
| 56 | use i3Soft\CDA\Traits\TemplateIdsTrait; |
||
| 57 | use i3Soft\CDA\Traits\TitleTrait; |
||
| 58 | use i3Soft\CDA\Traits\TypeIdTrait; |
||
| 59 | use i3Soft\CDA\Traits\VersionNumberTrait; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Root class for clinical document |
||
| 63 | * |
||
| 64 | * @author Julien Fastré <[email protected]> |
||
| 65 | * @author Peter Gee <https://github.com/pgee70> |
||
| 66 | */ |
||
| 67 | class ClinicalDocument implements ClassCodeInterface, MoodCodeInterface |
||
| 68 | { |
||
| 69 | const NS_CDA_URI = 'urn:hl7-org:v3'; |
||
| 70 | const VERSION = '1.0.6'; |
||
| 71 | |||
| 72 | use RealmCodesTrait; |
||
| 73 | use TypeIdTrait; |
||
| 74 | use TemplateIdsTrait; |
||
| 75 | use IdTrait; |
||
| 76 | use CodeTrait; |
||
| 77 | use TitleTrait; |
||
| 78 | use EffectiveTimeTrait; |
||
| 79 | use ConfidentialityCodeTrait; |
||
| 80 | use LanguageCodeTrait; |
||
| 81 | use SetIdTrait; |
||
| 82 | use VersionNumberTrait; |
||
| 83 | use CompletionCodeTrait; |
||
| 84 | use CopyTimeTrait; |
||
| 85 | use RecordTargetsTrait; |
||
| 86 | use AuthorsTrait; |
||
| 87 | use DataEntererTrait; |
||
| 88 | use InformantsTrait; |
||
| 89 | use CustodianTrait; |
||
| 90 | use InformationRecipientsTrait; |
||
| 91 | use legalAuthenticatorTrait; |
||
| 92 | use AuthenticatorTrait; |
||
| 93 | use ParticipantsTrait; |
||
| 94 | // use InFulfillmentOfsTrait; |
||
| 95 | use DocumentationOfsTrait; |
||
| 96 | // use RelatedDocumentsTrait; |
||
| 97 | use AuthorizationTrait; |
||
| 98 | |||
| 99 | // use ComponentOfTrait; |
||
| 100 | // use ComponentTrait; |
||
| 101 | use ClassCodeTrait; |
||
| 102 | use MoodCodeTrait; |
||
| 103 | /** |
||
| 104 | * Referer assigned to this document * |
||
| 105 | * |
||
| 106 | * @var ReferenceManager |
||
| 107 | */ |
||
| 108 | private $referenceManager; |
||
| 109 | /** |
||
| 110 | * the root component |
||
| 111 | * |
||
| 112 | * @var Component\RootBodyComponent |
||
| 113 | */ |
||
| 114 | private $rootComponent; |
||
| 115 | private $informationRecipient; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 116 | private $inFulfillmentOf; |
||
|
0 ignored issues
–
show
|
|||
| 117 | private $documentationOf; |
||
|
0 ignored issues
–
show
|
|||
| 118 | private $relatedDocument; |
||
|
0 ignored issues
–
show
|
|||
| 119 | /** @var string the xmlns:ext attribute - leave empty string to not render. */ |
||
| 120 | private $attributeXmlnsExt; |
||
| 121 | /** @var string the xmlns:xs attribute - leave as empty string to not render */ |
||
| 122 | private $attributeXmlNsXs; |
||
| 123 | /** @var array the three parameters of the attribute Namespace */ |
||
| 124 | private $attributeNs; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * ClinicalDocument constructor. |
||
| 128 | */ |
||
| 129 | public function __construct () |
||
| 130 | { |
||
| 131 | $this->rootComponent = new Component\RootBodyComponent(); |
||
| 132 | $this->referenceManager = new ReferenceManager(); |
||
| 133 | $this->setTypeId(new TypeId(new InstanceIdentifier('2.16.840.1.113883.1.3', 'POCD_HD000040'))) |
||
| 134 | ->setAttributeNs(self::getNS_XSI_URI(), 'xsi:schemaLocation', 'CDA-ES-v1_3.xsd') |
||
| 135 | ->setAttributeXmlnsExt('http://ns.electronichealth.net.au/Ci/Cda/Extensions/3.0') |
||
| 136 | ->setAttributeXmlNsXs('http://www.w3.org/2001/XMLSchema') |
||
| 137 | ->setAcceptableClassCodes(['', ClassCodeInterface::CLINICAL_DOCUMENT]) |
||
| 138 | ->setClassCode('') |
||
| 139 | ->setAcceptableMoodCodes(['', MoodCodeInterface::EVENT]) |
||
| 140 | ->setMoodCode(''); |
||
| 141 | } |
||
| 142 | |||
| 143 | public static function getNS_XSI_URI (): string { return 'http://www.w3.org/2001/XMLSchema-instance'; } |
||
| 144 | |||
| 145 | public static function getNS (): string { return ''; } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * |
||
| 149 | * @return ReferenceManager |
||
| 150 | */ |
||
| 151 | public function getReferenceManager (): ReferenceManager |
||
| 152 | { |
||
| 153 | return $this->referenceManager; |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * |
||
| 158 | * @param \DOMDocument|null $doc |
||
| 159 | * |
||
| 160 | * @return \DOMDocument |
||
| 161 | */ |
||
| 162 | public function toDOMDocument (\DOMDocument $doc = NULL): \DOMDocument |
||
| 163 | { |
||
| 164 | $doc = $doc ?? new \DOMDocument('1.0', 'UTF-8'); |
||
| 165 | $el = $doc->createElementNS(self::NS_CDA_URI, 'ClinicalDocument'); |
||
| 166 | $doc->appendChild($el); |
||
| 167 | // set the NS |
||
| 168 | if (implode('', $this->getAttributeNs())) |
||
| 169 | { |
||
| 170 | $el->setAttributeNS( |
||
| 171 | $this->getAttributeNs()[0], |
||
| 172 | $this->getAttributeNs()[1], |
||
| 173 | $this->getAttributeNs()[2] |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | if ($xmlNsExt = $this->getAttributeXmlnsExt()) |
||
| 177 | { |
||
| 178 | $el->setAttribute('xmlns:ext', $xmlNsExt); |
||
| 179 | } |
||
| 180 | if ($xmlNsXs = $this->getAttributeXmlNsXs()) |
||
| 181 | { |
||
| 182 | $el->setAttribute('xmlns:xs', $xmlNsXs); |
||
| 183 | } |
||
| 184 | if ($this->hasClassCode()) |
||
| 185 | { |
||
| 186 | $el->setAttribute('classCode', $this->getClassCode()); |
||
| 187 | } |
||
| 188 | if ($this->hasMoodCode()) |
||
| 189 | { |
||
| 190 | $el->setAttribute('moodCode', $this->getMoodCode()); |
||
| 191 | } |
||
| 192 | $this->renderRealmCodes($el, $doc) |
||
| 193 | ->renderTypeId($el, $doc) |
||
| 194 | ->renderTemplateIds($el, $doc) |
||
| 195 | ->renderId($el, $doc) |
||
| 196 | ->renderCode($el, $doc) |
||
| 197 | ->renderTitle($el, $doc) |
||
| 198 | ->renderEffectiveTime($el, $doc) |
||
| 199 | ->renderConfidentialityCode($el, $doc) |
||
| 200 | ->renderLanguageCode($el, $doc) |
||
| 201 | ->renderSetId($el, $doc) |
||
| 202 | ->renderVersionNumber($el, $doc) |
||
| 203 | ->renderCopyTime($el, $doc) |
||
| 204 | ->renderCompletionCode($el, $doc) |
||
| 205 | ->renderRecordTargets($el, $doc) |
||
| 206 | ->renderAuthors($el, $doc) |
||
| 207 | ->renderDataEnter($el, $doc) |
||
| 208 | ->renderInformants($el, $doc) |
||
| 209 | ->renderCustodian($el, $doc) |
||
| 210 | ->renderInformationRecipients($el, $doc) |
||
| 211 | ->renderLegalAuthenticator($el, $doc) |
||
| 212 | ->renderAuthenticator($el, $doc) |
||
| 213 | ->renderParticipants($el, $doc) |
||
| 214 | // todo inFulfillmentOf |
||
| 215 | ->renderDocumentationOfs($el, $doc) |
||
| 216 | // todo relatedDocument |
||
| 217 | ->renderAuthorization($el, $doc); |
||
| 218 | // todo componentOf |
||
| 219 | // add components |
||
| 220 | if (FALSE === $this->getRootComponent()->isEmpty()) |
||
| 221 | { |
||
| 222 | $el->appendChild($this->getRootComponent()->toDOMElement($doc)); |
||
| 223 | } |
||
| 224 | return $doc; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return array |
||
| 229 | */ |
||
| 230 | public function getAttributeNs (): array |
||
| 231 | { |
||
| 232 | return $this->attributeNs; |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param string $namespaceUri |
||
| 237 | * @param string $qualifiedName |
||
| 238 | * @param string $value |
||
| 239 | * |
||
| 240 | * @return ClinicalDocument |
||
| 241 | */ |
||
| 242 | public function setAttributeNs (string $namespaceUri, string $qualifiedName, string $value): self |
||
| 243 | { |
||
| 244 | $this->attributeNs = [$namespaceUri, $qualifiedName, $value]; |
||
| 245 | return $this; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | public function getAttributeXmlnsExt (): string |
||
| 252 | { |
||
| 253 | return $this->attributeXmlnsExt; |
||
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param string $attributeXmlnsExt |
||
| 258 | * |
||
| 259 | * @return self |
||
| 260 | */ |
||
| 261 | public function setAttributeXmlnsExt (string $attributeXmlnsExt): self |
||
| 262 | { |
||
| 263 | $this->attributeXmlnsExt = $attributeXmlnsExt; |
||
| 264 | return $this; |
||
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function getAttributeXmlNsXs (): string |
||
| 271 | { |
||
| 272 | return $this->attributeXmlNsXs; |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param string $attributeXmlNsXs |
||
| 277 | * |
||
| 278 | * @return self |
||
| 279 | */ |
||
| 280 | public function setAttributeXmlNsXs (string $attributeXmlNsXs): self |
||
| 281 | { |
||
| 282 | $this->attributeXmlNsXs = $attributeXmlNsXs; |
||
| 283 | return $this; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * |
||
| 288 | * @return Component\RootBodyComponent |
||
| 289 | */ |
||
| 290 | public function getRootComponent (): Component\RootBodyComponent |
||
| 291 | { |
||
| 292 | return $this->rootComponent; |
||
| 293 | } |
||
| 294 | } |
||
| 295 |