Esempio n. 1
0
 /**
  * Method setAllergiesSection()
  */
 private function setAllergiesSection()
 {
     $Allergies = new Allergies();
     $allergiesData = $Allergies->getPatientAllergiesByPid($this->pid);
     unset($Allergies);
     if ($this->isExcluded('allergies') || empty($allergiesData)) {
         $allergies['@attributes'] = ['nullFlavor' => 'NI'];
     }
     $allergies['templateId'] = ['@attributes' => ['root' => $this->requiredAllergies ? '2.16.840.1.113883.10.20.22.2.6.1' : '2.16.840.1.113883.10.20.22.2.6']];
     $allergies['code'] = ['@attributes' => ['code' => '48765-2', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']];
     $allergies['title'] = 'Allergies, Adverse Reactions, Alerts';
     $allergies['text'] = '';
     if ($this->isExcluded('allergies')) {
         $this->addSection(['section' => $allergies]);
         return;
     }
     if (!empty($allergiesData)) {
         $allergies['text'] = ['table' => ['@attributes' => ['border' => '1', 'width' => '100%'], 'thead' => ['tr' => [['th' => [['@value' => 'Substance'], ['@value' => 'Reaction'], ['@value' => 'Severity'], ['@value' => 'Status']]]]], 'tbody' => ['tr' => []]]];
         $allergies['entry'] = [];
         foreach ($allergiesData as $item) {
             $hasBeginDate = preg_match('/^\\d{4}-\\d{2}-\\d{2}/', $item['begin_date']);
             $hasEndDate = preg_match('/^\\d{4}-\\d{2}-\\d{2}/', $item['end_date']);
             $allergies['text']['table']['tbody']['tr'][] = ['td' => [['@value' => $item['allergy']], ['@value' => $item['reaction']], ['@value' => $item['severity']], ['@value' => 'Status Data']]];
             $entry = ['act' => ['@attributes' => ['classCode' => 'ACT', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.30']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['code' => '48765-2', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']]]];
             $entry['act']['statusCode'] = ['@attributes' => ['code' => $item['status_code'] == '55561003' ? 'active' : 'completed']];
             $entry['act']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]];
             if ($hasEndDate) {
                 $entry['act']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]];
             } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) {
                 $entry['act']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']];
             }
             $entry['act']['entryRelationship'] = ['@attributes' => ['typeCode' => 'SUBJ'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.7']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['code' => 'ASSERTION', 'codeSystem' => '2.16.840.1.113883.5.4']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]];
             // If it is unknown when the allergy began, this effectiveTime
             // SHALL contain low/@nullFLavor="UNK" (CONF:9103)
             $entry['act']['entryRelationship']['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']];
             if ($hasBeginDate) {
                 $entry['act']['entryRelationship']['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]];
             } else {
                 $entry['act']['entryRelationship']['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']];
             }
             if ($hasEndDate) {
                 $entry['act']['entryRelationship']['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]];
             } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) {
                 $entry['act']['entryRelationship']['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']];
             }
             // 420134006    SNOMEDCT    Propensity to adverse reactions
             // 418038007    SNOMEDCT    Propensity to adverse reactions to substance
             // 419511003    SNOMEDCT    Propensity to adverse reactions to drug
             // 418471000    SNOMEDCT    Propensity to adverse reactions to food
             // 419199007    SNOMEDCT    Allergy to substance
             // 416098002    SNOMEDCT    Drug allergy
             // 414285001    SNOMEDCT    Food allergy
             // 59037007     SNOMEDCT    Drug intolerance
             // 235719002    SNOMEDCT    Food intolerance
             $entry['act']['entryRelationship']['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['allergy_type_code'], 'displayName' => $item['allergy_type'], 'codeSystemName' => $item['allergy_type_code_type'], 'codeSystem' => $this->codes($item['allergy_type_code_type'])]];
             $entry['act']['entryRelationship']['observation']['participant'] = ['@attributes' => ['typeCode' => 'CSM'], 'participantRole' => ['@attributes' => ['classCode' => 'MANU'], 'playingEntity' => ['@attributes' => ['classCode' => 'MMAT'], 'code' => ['@attributes' => ['code' => $item['allergy_code'], 'displayName' => $item['allergy'], 'codeSystemName' => $item['allergy_code_type'], 'codeSystem' => $this->codes($item['allergy_code_type'])]]]]];
             // Allergy Status Observation
             $entryRelationship = ['@attributes' => ['typeCode' => 'SUBJ', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.28']], 'code' => ['@attributes' => ['code' => '33999-4', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]];
             $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']];
             if ($hasBeginDate) {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]];
             } else {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']];
             }
             if ($hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]];
             } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']];
             }
             $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CE', 'code' => $item['status_code'], 'displayName' => $item['status'], 'codeSystemName' => $item['status_code_type'], 'codeSystem' => $this->codes($item['status_code_type'])]];
             $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship;
             unset($entryRelationship);
             // Reaction Observation
             $entryRelationship = ['@attributes' => ['typeCode' => 'MFST', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.9']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['nullFlavor' => 'NA']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]];
             $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']];
             if ($hasBeginDate) {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]];
             } else {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']];
             }
             if ($hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]];
             } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']];
             }
             $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['reaction_code'], 'displayName' => $item['reaction'], 'codeSystemName' => $item['reaction_code_type'], 'codeSystem' => $this->codes($item['reaction_code_type'])]];
             $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship;
             unset($entryRelationship);
             // Severity Observation
             $entryRelationship = ['@attributes' => ['typeCode' => 'SUBJ', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.8']], 'code' => ['@attributes' => ['code' => 'SEV', 'codeSystemName' => 'ActCode', 'codeSystem' => '2.16.840.1.113883.5.4', 'displayName' => 'Severity Observation']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]];
             $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']];
             if ($hasBeginDate) {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]];
             } else {
                 $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']];
             }
             if ($hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]];
             } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) {
                 $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']];
             }
             $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['severity_code'], 'displayName' => $item['severity'], 'codeSystemName' => $item['severity_code_type'], 'codeSystem' => $this->codes($item['severity_code_type'])]];
             $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship;
             unset($entryRelationship);
             $allergies['entry'][] = $entry;
         }
     }
     if ($this->requiredAllergies || !empty($allergies['entry'])) {
         $this->addSection(['section' => $allergies]);
     }
     unset($allergiesData, $allergies);
 }