Skip to content

Commit

Permalink
fix: ccda zip import and php warnings and deprecations (#7416) (#7421)
Browse files Browse the repository at this point in the history
* fix: php warns, deprecates

* fix: php warns, deprecates openemr-cmd irp

* check for non zero component count to start ccda zip import

* fix couple other php warnings

* remove conditional per Jerry's review
  • Loading branch information
stephenwaite committed May 7, 2024
1 parent a758a75 commit 77ca1dd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
Expand Up @@ -942,10 +942,14 @@ private function sanitizeZip($zipLocation)
$patientCountHash[$patientNameIndex];
}
} elseif ($componentCount == ($patientDocumentsIndex + 1)) {
if ($patientCountHash[$patientNameIndex] > $maxDocuments) {
if ($patientCountHash[$patientNameIndex] ?? '' > $maxDocuments) {
$shouldDeleteIndex = true;
} else {
$patientCountHash[$patientNameIndex] += 1;
if (!empty($patientCountHash[$patientNameIndex])) {
$patientCountHash[$patientNameIndex] += 1;
} else {
$patientCountHash[$patientNameIndex] = 0;
}
}
} else {
$shouldDeleteIndex = true;
Expand Down Expand Up @@ -1005,7 +1009,7 @@ private function importZipUpload($request)
$componentCount = count($fileComponents);

// now we need to do our document import for our ccda for this patient
if ($componentCount == 2) {
if ($componentCount > 0) {
// let's process the ccda
$file_name = basename($stat['name']);

Expand Down
Expand Up @@ -36,6 +36,7 @@ class CcdController extends AbstractActionController

protected $documentsTable;

protected $listenerObject;
/**
* @var Documents\Controller\DocumentsController
*/
Expand Down
Expand Up @@ -321,15 +321,15 @@ public function importCore($xml_content, $doc_id = null): void
} else {
$tel = $xml['recordTarget']['patientRole']['telecom'] ?? '';
if (!empty($tel)) {
if ($tel['use'] == 'MC') {
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') {
} 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') {
} 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') {
} 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) {
} 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;
Expand All @@ -338,7 +338,7 @@ public function importCore($xml_content, $doc_id = null): void
$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));
$this->documentData['field_name_value_array']['patient_data'][1]['phone_contact'] = preg_replace('/[^0-9]+/i', '', ($tel['value'] ?? ''));
}
}
}
Expand Down Expand Up @@ -519,7 +519,7 @@ public function insert_patient($audit_master_id, $document_id)
$item = trim($item['value'] ?? '');
}
} else {
$item = trim($item);
$item = trim($item ?? '');
}
$resfield[] = ['table_name' => trim($row['table_name']), 'field_name' => trim($itemKey), 'field_value' => $item, 'entry_identification' => trim($row['entry_identification'])];
}
Expand Down Expand Up @@ -582,7 +582,7 @@ public function insert_patient($audit_master_id, $document_id)
// patient UUID from exported
$uuid = trim($newdata['patient_data']['referrerID']);
// have we already imported for this UUID?
$pid_exist = sqlQuery("SELECT pid FROM `patient_data` WHERE `referrerID` = ? ORDER BY `pid` DESC Limit 1", array($uuid))['pid'];
$pid_exist = sqlQuery("SELECT pid FROM `patient_data` WHERE `referrerID` = ? ORDER BY `pid` DESC Limit 1", array($uuid))['pid'] ?? '';
if (!empty($pid_exist) && is_numeric($pid_exist ?? null)) {
// We did so let check the type. If encounters then a CDA
$enc_exist = sqlQuery("SELECT COUNT(`encounter`) as `cnt` FROM `form_encounter` WHERE `pid` = ? AND `encounter` > 0", array((int)$pid_exist))['cnt'] ?? 0;
Expand Down Expand Up @@ -677,9 +677,9 @@ public function insert_patient($audit_master_id, $document_id)
$arr_allergies['lists2'][$c]['outcome'] = $newdata['lists2']['outcome'];
$c++;
} elseif ($table == 'encounter') {
$arr_encounter['encounter'][$k]['extension'] = $newdata['encounter']['extension'];
$arr_encounter['encounter'][$k]['root'] = $newdata['encounter']['root'];
$arr_encounter['encounter'][$k]['date'] = $newdata['encounter']['date'];
$arr_encounter['encounter'][$k]['extension'] = $newdata['encounter']['extension'] ?? '';
$arr_encounter['encounter'][$k]['root'] = $newdata['encounter']['root'] ?? '';
$arr_encounter['encounter'][$k]['date'] = $newdata['encounter']['date'] ?? null;
$arr_encounter['encounter'][$k]['date_end'] = $newdata['encounter']['date_end'] ?? null;

$arr_encounter['encounter'][$k]['provider_npi'] = $newdata['encounter']['provider_npi'];
Expand Down
2 changes: 1 addition & 1 deletion library/classes/Document.class.php
Expand Up @@ -1006,7 +1006,7 @@ function createDocument(
* Else resume the local file storage
*/

if ($GLOBALS['documentStoredRemotely']) {
if ($GLOBALS['documentStoredRemotely'] ?? '') {
return xlt("Document was uploaded to remote storage"); // terminate processing
}

Expand Down
6 changes: 3 additions & 3 deletions src/Services/Cda/CdaTemplateImportDispose.php
Expand Up @@ -606,8 +606,8 @@ public function InsertEncounter($enc_array, $pid, CarecoordinationTable $carecoo
if (!empty($value['code_text'] ?? null)) {
$cat = explode('|', $value['code_text'] ?? null);
$catname = trim($cat[0]);
$reason = trim($cat[1]);
$pc_catid = sqlQuery("SELECT pc_catid FROM `openemr_postcalendar_categories` Where `pc_catname` = ?", array($catname))['pc_catid'];
$reason = trim($cat[1] ?? '');
$pc_catid = sqlQuery("SELECT pc_catid FROM `openemr_postcalendar_categories` Where `pc_catname` = ?", array($catname))['pc_catid'] ?? '';
}
if (empty($pc_catid) && !empty($catname)) {
// create a new category to match the import
Expand Down Expand Up @@ -2142,7 +2142,7 @@ public function findClosestEncounter($item_date, $item_pid): int
ORDER BY fe.encounter DESC, fe.date DESC Limit 1";
$rtn = sqlQuery($sql, array($item_date, $item_pid));

return (int)$rtn['encounter'] ?: 0;
return (int)($rtn['encounter'] ?? '') ?: 0;
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/Services/Cda/CdaTemplateParse.php
Expand Up @@ -373,12 +373,12 @@ public function fetchEncounterPerformed($entry): void
$i += count($this->templateData['field_name_value_array']['encounter']);
}

$this->templateData['field_name_value_array']['encounter'][$i]['extension'] = $entry['encounter']['id']['extension'];
$this->templateData['field_name_value_array']['encounter'][$i]['root'] = $entry['encounter']['id']['root'];
$this->templateData['field_name_value_array']['encounter'][$i]['extension'] = $entry['encounter']['id']['extension'] ?? '';
$this->templateData['field_name_value_array']['encounter'][$i]['root'] = $entry['encounter']['id']['root'] ?? '';
$this->templateData['field_name_value_array']['encounter'][$i]['date'] = ($entry['encounter']['effectiveTime']['value'] ?? null) ?: $entry['encounter']['effectiveTime']['low']['value'] ?? null;
$this->templateData['field_name_value_array']['encounter'][$i]['date_end'] = $entry['encounter']['effectiveTime']['high']['value'] ?? null;

$code_type = $entry['encounter']['code']['codeSystemName'] ?: $entry['encounter']['code']['codeSystem'] ?? '';
$code_type = $entry['encounter']['code']['codeSystemName'] ?? '' ?: $entry['encounter']['code']['codeSystem'] ?? '';
$code_text = $entry['encounter']['code']['displayName'] ?? '';
$code = $this->codeService->resolveCode($entry['encounter']['code']['code'], $code_type, $code_text);
$this->templateData['field_name_value_array']['encounter'][$i]['code'] = $code['formatted_code'];
Expand Down Expand Up @@ -495,18 +495,18 @@ public function fetchAllergyIntoleranceObservation($entry)
}

$this->templateData['field_name_value_array']['lists2'][$i]['type'] = 'allergy';
$this->templateData['field_name_value_array']['lists2'][$i]['extension'] = $entry['act']['id']['extension'];
$this->templateData['field_name_value_array']['lists2'][$i]['extension'] = $entry['act']['id']['extension'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['begdate'] = $entry['act']['effectiveTime']['low']['value'] ?? null;
$this->templateData['field_name_value_array']['lists2'][$i]['enddate'] = $entry['act']['effectiveTime']['high']['value'] ?? null;
$this->templateData['field_name_value_array']['lists2'][$i]['list_code'] = $entry['act']['entryRelationship']['observation']['participant']['participantRole']['playingEntity']['code']['code'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['list_code_text'] = $entry['act']['entryRelationship']['observation']['participant']['participantRole']['playingEntity']['code']['displayName'];
$this->templateData['field_name_value_array']['lists2'][$i]['codeSystemName'] = $entry['act']['entryRelationship']['observation']['participant']['participantRole']['playingEntity']['code']['codeSystemName'];
$this->templateData['field_name_value_array']['lists2'][$i]['codeSystemName'] = $entry['act']['entryRelationship']['observation']['participant']['participantRole']['playingEntity']['code']['codeSystemName'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['outcome'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][1]['observation']['value']['code'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['severity_al_code'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][2]['observation']['value']['code'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['severity_al'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][2]['observation']['value']['code'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['status'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][0]['observation']['value']['displayName'];
$this->templateData['field_name_value_array']['lists2'][$i]['status'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][0]['observation']['value']['displayName'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['reaction'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][1]['observation']['value']['code'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['reaction_text'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][1]['observation']['value']['displayName'];
$this->templateData['field_name_value_array']['lists2'][$i]['reaction_text'] = $entry['act']['entryRelationship']['observation']['entryRelationship'][1]['observation']['value']['displayName'] ?? '';
$this->templateData['field_name_value_array']['lists2'][$i]['modified_time'] = $entry['act']['entryRelationship']['observation']['performer']['assignedEntity']['time']['value'] ?? null;
$this->templateData['entry_identification_array']['lists2'][$i] = $i;
} elseif (!empty($entry['observation']['participant']['participantRole']['playingEntity']['code']['code'])) {
Expand Down Expand Up @@ -667,7 +667,7 @@ public function fetchImmunizationData($entry): void
$this->templateData['field_name_value_array']['immunization'][$i]['represented_organization'] = $entry['substanceAdministration']['performer']['assignedEntity']['representedOrganization']['name'] ?? null;
$this->templateData['field_name_value_array']['immunization'][$i]['represented_organization_tele'] = $entry['substanceAdministration']['performer']['assignedEntity']['representedOrganization']['telecom'] ?? null;

if ($entry['substanceAdministration']['entryRelationship']['observation']['value']['code']) {
if (($entry['substanceAdministration']['entryRelationship'] ?? '') && $entry['substanceAdministration']['entryRelationship']['observation']['value']['code']) {
$code = $this->codeService->resolveCode(
$entry['substanceAdministration']['entryRelationship']['observation']['value']['code'],
$entry['substanceAdministration']['entryRelationship']['observation']['value']['codeSystemName'] ?: $entry['substanceAdministration']['entryRelationship']['observation']['value']['codeSystem'] ?? '',
Expand Down Expand Up @@ -1527,7 +1527,9 @@ public function functionalCognitiveStatus($component)
$ccnt = 0;
if ($component['section']['entry'][0] ?? '') {
foreach ($component['section']['entry'] as $key => $value) {
$this->fetchFunctionalCognitiveStatusData($value, $component['section']['text'][$ccnt]);
if (!empty($component['section']['text'][$ccnt])) {
$this->fetchFunctionalCognitiveStatusData($value, $component['section']['text'][$ccnt]);
}
$ccnt++;
}
} else {
Expand Down

0 comments on commit 77ca1dd

Please sign in to comment.