Skip to content

Commit

Permalink
Fixes for saving History data in LBFs and for reading History data wi…
Browse files Browse the repository at this point in the history
…th identical timestamps.
  • Loading branch information
sunsetsystems authored and bradymiller committed Aug 2, 2022
1 parent 41b4888 commit d85d330
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions interface/forms/LBF/new.php
Expand Up @@ -8,7 +8,7 @@
* @author Rod Roark <rod@sunsetsystems.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @author Jerry Padgett <sjpadgett@gmail.com>
* @copyright Copyright (c) 2009-2021 Rod Roark <rod@sunsetsystems.com>
* @copyright Copyright (c) 2009-2022 Rod Roark <rod@sunsetsystems.com>
* @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2018-2020 Jerry Padgett <sjpadgett@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
Expand Down Expand Up @@ -245,6 +245,7 @@ function end_row()
);
}

$newhistorydata = array();
$sets = "";
$fres = sqlStatement("SELECT * FROM layout_options " .
"WHERE form_id = ? AND uor > 0 AND field_id != '' AND " .
Expand Down Expand Up @@ -273,8 +274,9 @@ function end_row()
if ($source == 'D' || $source == 'H') {
// Save to patient_data, employer_data or history_data.
if ($source == 'H') {
$new = array($field_id => $value);
updateHistoryData($pid, $new);
// Do not call updateHistoryData() here! That would create multiple rows
// in the history_data table for a single form save.
$newhistorydata[$field_id] = $value;
} elseif (strpos($field_id, 'em_') === 0) {
$field_id = substr($field_id, 3);
$new = array($field_id => $value);
Expand Down Expand Up @@ -331,6 +333,11 @@ function end_row()
}
} // end while save

// Save any history data that was collected above.
if (!empty($newhistorydata)) {
updateHistoryData($pid, $newhistorydata);
}

if ($portalid) {
// Delete the request from the portal.
$result = cms_portal_call(array('action' => 'delpost', 'postid' => $portalid));
Expand Down
8 changes: 4 additions & 4 deletions library/patient.inc
Expand Up @@ -359,13 +359,13 @@ function getHistoryData($pid, $given = "*", $dateStart = '', $dateEnd = '')
}

if ($dateStart && $dateEnd) {
$res = sqlQuery("select $given from history_data where $where pid = ? and date >= ? and date <= ? order by date DESC limit 0,1", array($pid,$dateStart,$dateEnd));
$res = sqlQuery("select $given from history_data where $where pid = ? and date >= ? and date <= ? order by date DESC, id DESC limit 0,1", array($pid,$dateStart,$dateEnd));
} elseif ($dateStart && !$dateEnd) {
$res = sqlQuery("select $given from history_data where $where pid = ? and date >= ? order by date DESC limit 0,1", array($pid,$dateStart));
$res = sqlQuery("select $given from history_data where $where pid = ? and date >= ? order by date DESC, id DESC limit 0,1", array($pid,$dateStart));
} elseif (!$dateStart && $dateEnd) {
$res = sqlQuery("select $given from history_data where $where pid = ? and date <= ? order by date DESC limit 0,1", array($pid,$dateEnd));
$res = sqlQuery("select $given from history_data where $where pid = ? and date <= ? order by date DESC, id DESC limit 0,1", array($pid,$dateEnd));
} else {
$res = sqlQuery("select $given from history_data where $where pid=? order by date DESC limit 0,1", array($pid));
$res = sqlQuery("select $given from history_data where $where pid = ? order by date DESC, id DESC limit 0,1", array($pid));
}

return $res;
Expand Down

0 comments on commit d85d330

Please sign in to comment.