Skip to content

Commit

Permalink
port PR #5978 CCDA import merge duplicate fix (#5979)
Browse files Browse the repository at this point in the history
* port PR #5978 CCDA import merge duplicate fix
- ensure if unstructured and CDA then combine/merge
- fix deleter to auto close after 2 sec or immediate for encounters.

* - fix careplan report to use passed in encounter id instead of session data.

* - additional attempt to get author for portal using hie_primary

* - ensure newly create users aren't duplicated one day I'll get this right!
  • Loading branch information
sjpadgett committed Nov 28, 2022
1 parent 3fc616e commit 4f6a815
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
21 changes: 8 additions & 13 deletions interface/forms/care_plan/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

require_once(__DIR__ . "/../../globals.php");
require_once($GLOBALS["srcdir"] . "/api.inc");
require_once($GLOBALS["srcdir"] . "/options.inc.php");

function care_plan_report($pid, $encounter, $cols, $id)
function care_plan_report($pid, $encounter, $cols, $id): void
{
$count = 0;
$encounter = !empty($encounter) ? $encounter : $_SESSION["encounter"] ?? 0;
$pid = !empty($pid) ? $pid : $_SESSION["pid"] ?? 0;

$sql = "SELECT * FROM `form_care_plan` WHERE id=? AND pid = ? AND encounter = ?";
$res = sqlStatement($sql, array($id, $_SESSION["pid"], $_SESSION["encounter"]));
$res = sqlStatement($sql, array($id, $pid, $encounter));

for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
$data[$iter] = $row;
}

if ($data) {
?>
if ($data) { ?>
<table class="table w-100">
<thead>
<tr>
Expand All @@ -44,8 +44,7 @@ function care_plan_report($pid, $encounter, $cols, $id)
</thead>
<tbody>
<?php
foreach ($data as $key => $value) {
?>
foreach ($data as $key => $value) { ?>
<tr>
<td class="border p-1"><span class='text'><?php echo text($value['user']); ?></span></td>
<td class="border p-1"><span class='text'><?php echo text(getListItemTitle('Plan_of_Care_Type', $value['care_plan_type'])); ?></span></td>
Expand All @@ -54,13 +53,9 @@ function care_plan_report($pid, $encounter, $cols, $id)
<td class="border p-1"><span class=text><?php echo text($value['description']); ?></span></td>
<td class="border p-1"><span class=text><?php echo text($value['date']); ?></span></td>
</tr>
<?php
}
?>
<?php } ?>
</tbody>
</table>
<?php
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,20 @@ public function insert_patient($audit_master_id, $document_id)
}
if ($table == 'patient_data') {
$createFlag = true;
if (!empty($newdata['patient_data']['referrerID']) && $this->is_unstructured_import) {
$uuid = $newdata['patient_data']['referrerID'];
if (!empty($newdata['patient_data']['referrerID'])) {
// 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'];
if (!empty($pid_exist) && is_numeric($pid_exist ?? null)) {
$pid = $pid_exist;
$createFlag = false;
// 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;
// If not CDA and not unstructured means unstructured already created a new PID
// otherwise merge one or the other to each other.
if ((!$this->is_unstructured_import && empty($enc_exist)) || $this->is_unstructured_import) {
$pid = $pid_exist;
$createFlag = false;
}
}
}
updatePatientData($pid, $newdata['patient_data'], $createFlag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,19 @@ private function getDocumentAuthorRecord($pid, $encounter)
}
if (!$details) {
$providerId = $this->getProviderId($pid);
if (empty($providerId)) {
// at this point we really can't do anything as we can't provide an author piece
(new SystemLogger())->errorLogCaller("Failed to find author for c-cda document, no hie_author_id, authUserID in session, or provider relationship");
return null;
if (!empty($providerId)) {
$details = $this->getDetails(intval($providerId));
}
if (!$details) {
$details = $this->getDetails('hie_primary_care_provider_id');
}
$details = $this->getDetails(intval($providerId));
}
if (!$details) {
// at this point we really can't do anything as we can't provide an author piece
(new SystemLogger())->errorLogCaller("Failed to find author for c-cda document, no hie_author_id, authUserID in session, or provider relationship");
return null;
}

return $details;
}

Expand Down
10 changes: 8 additions & 2 deletions interface/patient_file/deleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,14 @@ function popup_close() {
echo "let message = " . js_escape($info_msg) . ";
(async (message, time) => {
await asyncAlertMsg(message, time, 'success', 'lg');
})(message, 5000)
.then(res => {});";
})(message, 2000)
.then(res => {";
// auto close on msg timeout with just enough time to show success or errors.
if ($GLOBALS['sql_string_no_show_screen']) {
echo "dlgclose();";
}
echo "});"; // close function.
// any close will call below.
echo " opener.dlgSetCallBack('imdeleted', false);\n";
} else {
echo " dlgclose('imdeleted', false);\n";
Expand Down
24 changes: 15 additions & 9 deletions src/Services/Cda/CdaTemplateImportDispose.php
Original file line number Diff line number Diff line change
Expand Up @@ -1371,22 +1371,28 @@ public function insertImportedUser($value, $create_user_name = false)
$appTable = new ApplicationTable();
$userName = "";

// so for those that don't use NPI's or npi was missed we'll take a look for user by name.
$is_user = sqlQuery(
"Select id From users
Where fname = ? And lname = ?",
array($value['provider_fname'] ?? null, $value['provider_lname'] ?? null)
);
if (!empty($is_user['id'])) {
return $is_user['id'];
}
if (!empty($value['provider_fname'])) {
$value['provider_name'] = ($value['provider_fname'] ?? '') ?: 'External';
}
if (!empty($value['provider_lname'])) {
$value['provider_family'] = ($value['provider_lname'] ?? '') ?: 'Provider';
}

// so for those that don't use NPI's or npi was missed we'll take a look for user by name.
$is_user = sqlQuery(
"Select id From users Where fname = ? And lname = ?",
array($value['provider_name'] ?? null, $value['provider_family'] ?? null)
);
if (empty($is_user['id'])) {
$is_user = sqlQuery(
"Select id From users Where fname = ? And lname = ?",
array('External', 'Provider')
);
}
if (!empty($is_user['id'])) {
return $is_user['id'];
}

if ($create_user_name) {
$userName = (($value['provider_name'] ?? '') ?: 'External') . (($value['provider_family'] ?? '') ?: 'Provider');
}
Expand Down

0 comments on commit 4f6a815

Please sign in to comment.