Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for empty postParseEvent ccda import #7348

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function insert_ccr_into_audit_data($var, $isQrdaDocument = false,
$detail_query_array[] = trim($field_value['value'] ?? '');
}
} else {
$detail_query_array[] = trim($field_value);
$detail_query_array[] = trim($field_value ?? '');
}

$detail_query_array[] = $audit_master_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ private function importZipUpload($request)

$auditMasterRecordId = $this->getCarecoordinationTable()->import($ob->get_id());
// we can use this to do any other processing as the files should be in order
$auditMasterRecordByPatients[$fileComponents[2]] = $auditMasterRecordId;
$auditMasterRecordByPatients[$fileComponents[2] ?? ''] = $auditMasterRecordId;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,31 +319,33 @@ public function importCore($xml_content, $doc_id = null): void
}
}
} else {
$tel = $xml['recordTarget']['patientRole']['telecom'];
if ($tel['use'] == 'MC') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_cell'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'HP') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_home'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'WP') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_biz'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'EC') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_contact'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif (stripos($tel['value'], 'mailto:') !== false) {
$regex = "/([a-z0-9_\-\.]+)" . "@" . "([a-z0-9-]{1,64})" . "\." . "([a-z]{2,10})/i";
$mail = explode('mailto:', ($tel['value'] ?? null));
$this->documentData['field_name_value_array']['patient_data'][1]['email'] = null;
if (!empty($mail[1])) {
$mailto = preg_replace($regex, '\\1@\\2.\\3', $mail[1]);
$this->documentData['field_name_value_array']['patient_data'][1]['email'] = $mailto;
$tel = $xml['recordTarget']['patientRole']['telecom'] ?? '';
if (!empty($tel)) {
if ($tel['use'] == 'MC') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_cell'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'HP') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_home'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'WP') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_biz'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif ($tel['use'] == 'EC') {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_contact'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
} elseif (stripos($tel['value'], 'mailto:') !== false) {
$regex = "/([a-z0-9_\-\.]+)" . "@" . "([a-z0-9-]{1,64})" . "\." . "([a-z]{2,10})/i";
$mail = explode('mailto:', ($tel['value'] ?? null));
$this->documentData['field_name_value_array']['patient_data'][1]['email'] = null;
if (!empty($mail[1])) {
$mailto = preg_replace($regex, '\\1@\\2.\\3', $mail[1]);
$this->documentData['field_name_value_array']['patient_data'][1]['email'] = $mailto;
}
} else {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_contact'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
}
} else {
$this->documentData['field_name_value_array']['patient_data'][1]['phone_contact'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? null));
}
}

$this->documentData['field_name_value_array']['patient_data'][1]['status'] = strtolower($xml['recordTarget']['patientRole']['patient']['maritalStatusCode']['displayName']) ?? $xml['recordTarget']['patientRole']['patient']['maritalStatusCode']['code'] ?? null;
$this->documentData['field_name_value_array']['patient_data'][1]['status'] = strtolower($xml['recordTarget']['patientRole']['patient']['maritalStatusCode']['displayName'] ?? '') ?? $xml['recordTarget']['patientRole']['patient']['maritalStatusCode']['code'] ?? null;
$this->documentData['field_name_value_array']['patient_data'][1]['religion'] = $xml['recordTarget']['patientRole']['patient']['religiousAffiliationCode']['displayName'] ?? null;
if (is_array($xml['recordTarget']['patientRole']['patient']['raceCode'][0])) {
if (is_array($xml['recordTarget']['patientRole']['patient']['raceCode'][0] ?? '')) {
$this->documentData['field_name_value_array']['patient_data'][1]['race'] = $xml['recordTarget']['patientRole']['patient']['raceCode'][0]['displayName'] ?? $xml['recordTarget']['patientRole']['patient']['raceCode'][0]['code'] ?? null;
} else {
$this->documentData['field_name_value_array']['patient_data'][1]['race'] = $xml['recordTarget']['patientRole']['patient']['raceCode']['displayName'] ?? $xml['recordTarget']['patientRole']['patient']['raceCode']['code'] ?? null;
Expand Down
42 changes: 24 additions & 18 deletions src/Services/Cda/CdaTemplateParse.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public function parseCDAEntryComponents($components): array
}
}
}
$this->templateData = $postParseEvent->getTemplateData();

if (!empty($postParseEvent) && $postParseEvent instanceof CDAPostParseEvent) {
$this->templateData = $postParseEvent->getTemplateData();
}
}
return $this->templateData;
}
Expand Down Expand Up @@ -690,8 +693,8 @@ public function fetchImmunizationData($entry): void
public function fetchProcedureActivityData($entry): void
{
if (
(!empty($entry['procedure']['code']['code']) || !empty($entry['procedure']['code']["nullFlavor"]))
&& $entry['procedure']['code']["nullFlavor"] != 'NI'
(!empty($entry['procedure']['code']['code']) || !empty($entry['procedure']['code']["nullFlavor"] ?? ''))
&& ($entry['procedure']['code']["nullFlavor"] ?? '') != 'NI'
) {
$i = 1;
if (!empty($this->templateData['field_name_value_array']['procedure'])) {
Expand Down Expand Up @@ -729,12 +732,12 @@ public function fetchProcedureActivityData($entry): void
}

// check for a reason code if observation.
if (is_array($entry['procedure']['entryRelationship'])) {
if (is_array($entry['procedure']['entryRelationship'] ?? '')) {
$entryRelationship = $entry['procedure']['entryRelationship'][1];
} else {
$entryRelationship = $entry['procedure']['entryRelationship'];
$entryRelationship = $entry['procedure']['entryRelationship'] ?? '';
}
if ($entryRelationship['observation']['value']['code']) {
if ($entryRelationship['observation']['value']['code'] ?? '') {
$code = $this->codeService->resolveCode(
$entryRelationship['observation']['value']['code'],
$entryRelationship['observation']['value']['codeSystemName'] ?: $entryRelationship['observation']['value']['codeSystem'] ?? '',
Expand Down Expand Up @@ -926,7 +929,7 @@ public function immunization($component)
$this->fetchImmunizationData($value);
}
} else {
$this->fetchImmunizationData($component['section']['entry']);
$this->fetchImmunizationData($component['section']['entry'] ?? '');
}
}

Expand Down Expand Up @@ -1242,7 +1245,7 @@ public function fetchSocialHistoryData($social_history_data)
'2.16.840.1.113883.10.20.22.4.78' => 'smoking'
);
$i = 0;
$code = $social_history_data['observation']['templateId']['root'];
$code = $social_history_data['observation']['templateId']['root'] ?? '';
if (!empty($this->templateData['field_name_value_array']['social_history'])) {
foreach ($this->templateData['field_name_value_array']['social_history'] as $key => $value) {
if (!array_key_exists($social_history_array[$code], $value)) {
Expand All @@ -1253,12 +1256,15 @@ public function fetchSocialHistoryData($social_history_data)
}
}

$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['extension'] = $social_history_data['observation']['id']['extension'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['root'] = $social_history_data['observation']['id']['root'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['status'] = $social_history_data['observation']['value']['code'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['begdate'] = $social_history_data['observation']['effectiveTime']['low']['value'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['enddate'] = $social_history_data['observation']['effectiveTime']['high']['value'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['value'] = $social_history_data['observation']['value']['displayName'];
if (!empty($this->templateData['field_name_value_array']['social_history'])) {
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['extension'] = $social_history_data['observation']['id']['extension'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['root'] = $social_history_data['observation']['id']['root'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['status'] = $social_history_data['observation']['value']['code'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['begdate'] = $social_history_data['observation']['effectiveTime']['low']['value'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['enddate'] = $social_history_data['observation']['effectiveTime']['high']['value'];
$this->templateData['field_name_value_array']['social_history'][$i][$social_history_array[$code]]['value'] = $social_history_data['observation']['value']['displayName'];
}

$this->templateData['entry_identification_array']['social_history'][$i] = $i;
}
}
Expand Down Expand Up @@ -1519,13 +1525,13 @@ public function functionalCognitiveStatus($component)
$component['section']['text'] = '';
}
$ccnt = 0;
if ($component['section']['entry'][0]) {
if ($component['section']['entry'][0] ?? '') {
foreach ($component['section']['entry'] as $key => $value) {
$this->fetchFunctionalCognitiveStatusData($value, $component['section']['text'][$ccnt]);
$ccnt++;
}
} else {
$this->fetchFunctionalCognitiveStatusData($component['section']['entry'], $component['section']['text']);
$this->fetchFunctionalCognitiveStatusData($component['section']['entry'] ?? '', $component['section']['text']);
}
}

Expand Down Expand Up @@ -1589,7 +1595,7 @@ public function fetchFunctionalCognitiveStatusData($entry, $section_text = null)

public function referral($component)
{
if ($component['section']['entry'][0]) {
if ($component['section']['entry'][0] ?? '') {
foreach ($component['section']['entry'] as $key => $value) {
$this->fetchReferralData($value);
}
Expand All @@ -1614,7 +1620,7 @@ public function fetchReferralData($referral_data)
if (!empty($this->templateData['field_name_value_array']['referral'])) {
$i += count($this->templateData['field_name_value_array']['referral']);
}
$this->templateData['field_name_value_array']['referral'][$i]['root'] = $referral_data['templateId']['root'];
$this->templateData['field_name_value_array']['referral'][$i]['root'] = $referral_data['templateId']['root'] ?? '';
$this->templateData['field_name_value_array']['referral'][$i]['body'] = (!empty($referral_data['text']['paragraph'])) ? preg_replace('/\s+/', ' ', $referral_data['text']['paragraph']) : '';

$this->templateData['entry_identification_array']['referral'][$i] = $i;
Expand Down