Skip to content

Commit

Permalink
Insurance card information adjustments 3 (openemr#6105)
Browse files Browse the repository at this point in the history
* Bug fixes for insurance card

* Part two - PSR and adding supporting file

* PSR 2 corrections

* PSR 2 corrections

* PSR 7 corrections

* PSR 7 corrections

* UI updates remove fonts tag

* Improvements to code style

Consolidated a couple of conditions into ternary operators, removed a new logic overriding the status of an appointment, one minor whitespace change. Removed a font tag

* Removing ALB waz here

* Attempt to remove ALB entries.

* Set initial unallocated amount to a zero float instead of a string, resolving a fatal error

* psr12 fix
  • Loading branch information
juggernautsei committed Jan 17, 2023
1 parent 0011c6c commit e1b2a59
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 6 deletions.
46 changes: 44 additions & 2 deletions interface/patient_file/summary/demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,11 @@ function setMyPatient() {
$patientbalance = get_patient_balance($pid, false);
$insurancebalance = get_patient_balance($pid, true) - $patientbalance;
$totalbalance = $patientbalance + $insurancebalance;
$unallocated_amt = get_unallocated_patient_balance($pid);

$id = "billing_ps_expand";
$dispatchResult = $ed->dispatch(new CardRenderEvent('billing'), CardRenderEvent::EVENT_HANDLE);

$viewArgs = [
'title' => xl('Billing'),
'id' => $id,
Expand All @@ -1066,6 +1069,7 @@ function setMyPatient() {
'patientBalance' => $patientbalance,
'insuranceBalance' => $insurancebalance,
'totalBalance' => $totalbalance,
'unallocated' => $unallocated_amt,
'forceAlwaysOpen' => $forceBillingExpandAlways,
'prependedInjection' => $dispatchResult->getPrependedInjection(),
'appendedInjection' => $dispatchResult->getAppendedInjection(),
Expand Down Expand Up @@ -1119,6 +1123,8 @@ function setMyPatient() {
$params[] = $pid;
$params = array_merge($params, $insurance_array);
$res = sqlStatement($sql, $params);
$prior_ins_type = '';
$prev_eff_date = 'Present';

while ($row = sqlFetchArray($res)) {
if ($row['provider']) {
Expand All @@ -1142,6 +1148,33 @@ function setMyPatient() {
$row['dispFromDate'] = $row['date'] ? true : false;
$mname = ($row['subscriber_mname'] != "") ? $row['subscriber_mname'] : "";
$row['subscriber_full_name'] = str_replace("%mname%", $mname, "{$row['subscriber_fname']} %mname% {$row['subscriber_lname']}");
$row['until_date'] = ($row['isOld']) ? date_create($prev_eff_date)->modify('-1 days')->format('Y-m-d') : xlt('Present');
$insArr[] = $row;
$prev_eff_date = $row['date'];
$prior_ins_type = $row['type'];
} else {
$row['isOld'] = (strcmp($row['type'], $prior_ins_type) == 0) ? true : false;
$row['dispFromDate'] = $row['date'] ? true : false;
$row['insco'] = [
'name' => 'Self-Pay',
'address' => [
'line1' => '',
'line2' => '',
'city' => '',
'state' => '',
'postal' => '',
'country' => ''
],
];
$row['policy_type'] = false;
$mname = ''; //($row['subscriber_mname'] != "") ? $row['subscriber_mname'] : "";
$row['subscriber_full_name'] = ' '; // str_replace("%mname%", $mname, "{$row['subscriber_fname']} %mname% {$row['subscriber_lname']}");
$row['until_date'] = ($row['isOld']) ? date_create($prev_eff_date)->modify('-1 days')->format('Y-m-d') : xlt("Present");
$prev_eff_date = $row['date'];
$prior_ins_type = $row['type'];
if ($row['type'] != 'primary') {
continue;
}
$insArr[] = $row;
}
}
Expand Down Expand Up @@ -1652,6 +1685,8 @@ function setMyPatient() {
$etitle = xl('Comments') . ": " . ($row['pc_hometext']) . "\r\n" . $etitle;
}

$row['etitle'] = $etitle;

if ($extraApptDate && $count > $firstApptIndx) {
$apptStyle = $apptStyle2;
} else {
Expand All @@ -1665,6 +1700,9 @@ function setMyPatient() {

$row['pc_eventTime'] = sprintf("%02d", $disphour) . ":{$dispmin}";
$row['pc_status'] = generate_display_field(array('data_type' => '1', 'list_id' => 'apptstat'), $row['pc_apptstatus']);
if ($row['pc_status'] == 'None') {
$row['pc_status'] = 'Scheduled';
}

if (in_array($row['pc_catid'], $therapyGroupCategories)) {
$row['groupName'] = getGroup($row['pc_gid'])['group_name'];
Expand Down Expand Up @@ -1742,7 +1780,8 @@ function setMyPatient() {

if (isset($pid) && !$GLOBALS['disable_calendar'] && $showpast > 0 && AclMain::aclCheckCore('patients', 'appt')) {
$displayPastAppts = true;
$query = "SELECT e.pc_eid, e.pc_aid, e.pc_title, e.pc_eventDate, e.pc_startTime, e.pc_hometext, u.fname, u.lname, u.mname, c.pc_catname, e.pc_apptstatus

$query = "SELECT e.pc_eid, e.pc_aid, e.pc_title, e.pc_eventDate, e.pc_startTime, e.pc_hometext, u.fname, u.lname, u.mname, c.pc_catname, e.pc_apptstatus, e.pc_facility
FROM openemr_postcalendar_events AS e,
users AS u,
openemr_postcalendar_categories AS c
Expand All @@ -1759,7 +1798,7 @@ function setMyPatient() {
while ($row = sqlFetchArray($pres)) {
$count++;
$dayname = date("D", strtotime($row['pc_eventDate']));
$displayMeridiem = "am";
$displayMeridiem = ($GLOBALS['time_display_format'] == 0) ? "" : "am";
$disphour = substr($row['pc_startTime'], 0, 2) + 0;
$dispmin = substr($row['pc_startTime'], 3, 2);
if ($disphour >= 12) {
Expand All @@ -1773,9 +1812,12 @@ function setMyPatient() {
if ($row['pc_hometext'] != "") {
$petitle = xl('Comments') . ": " . ($row['pc_hometext']) . "\r\n" . $petitle;
}
$row['etitle'] = $petitle;

$row['pc_status'] = generate_display_field(array('data_type' => '1', 'list_id' => 'apptstat'), $row['pc_apptstatus']);

$row['dayName'] = $dayname;
$row['displayMeridiem'] = $displayMeridiem;
$row['pc_eventTime'] = sprintf("%02d", $disphour) . ":{$dispmin}";
$row['uname'] = text($row['fname'] . " " . $row['lname']);
$row['jsEvent'] = attr_js(preg_replace("/-/", "", $row['pc_eventDate'])) . ', ' . attr_js($row['pc_eid']);
Expand Down
40 changes: 38 additions & 2 deletions library/patient.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,47 @@ function getInsuranceDataByDate(
return sqlQuery($sql, array($pid,$date,$type));
}

function get_unallocated_patient_balance($pid)
{
$unallocated = 0.0;
$query = "SELECT a.session_id, a.pay_total, a.global_amount " .
"FROM ar_session AS a " .
"WHERE a.patient_id = ? AND " .
"a.adjustment_code = 'pre_payment' AND a.closed = 0";
$res = sqlStatement($query, array($pid));
while ($row = sqlFetchArray($res)) {
$total_amt = $row['pay_total'] - $row['global_amount'];
$rs = sqlQuery("SELECT sum(pay_amount) AS total_pay_amt FROM ar_activity WHERE session_id = ? AND pid = ? AND deleted IS NULL", array($row['session_id'], $pid));
$pay_amount = $rs['total_pay_amt'];
$unallocated += ($total_amt - $pay_amount);
}
return sprintf('%01.2f', $unallocated);
}

function getInsuranceNameByDate(
$pid,
$date,
$type,
$given = "ic.name as provider_name"
) {
// this must take the date in the following manner: YYYY-MM-DD
// this function recalls the insurance value that was most recently enterred from the
// given date. it will call up most recent records up to and on the date given,
// but not records enterred after the given date
$sql = "select $given from insurance_data as insd " .
"left join insurance_companies as ic on ic.id = provider " .
"where pid = ? and date_format(date,'%Y-%m-%d') <= ? and " .
"type = ? order by date DESC limit 1";

$row = sqlQuery($sql, array($pid, $date, $type));
return $row['provider_name'];
}

// To prevent sql injection on this function, if a variable is used for $given parameter, then
// it needs to be escaped via whitelisting prior to using this function.
function getEmployerData($pid, $given = "*")
{
$sql = "select $given from employer_data where pid=? order by date DESC limit 0,1";
$sql = "select $given from employer_data where pid = ? order by date DESC limit 0,1";
return sqlQuery($sql, array($pid));
}

Expand Down Expand Up @@ -630,7 +666,7 @@ function getPatientId($pid = "%", $given = "pid, id, lname, fname, mname, provid
function getByPatientDemographics($searchTerm = "%", $given = "pid, id, lname, fname, mname, providerID, DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS", $orderby = "lname ASC, fname ASC", $limit = "all", $start = "0")
{
$layoutCols = sqlStatement(
"SELECT field_id FROM layout_options WHERE form_id = 'DEM' AND field_id not like ? AND uor !=0",
"SELECT field_id FROM layout_options WHERE form_id = 'DEM' AND field_id not like ? AND uor != 0",
array('em\_%')
);

Expand Down
12 changes: 10 additions & 2 deletions templates/patient/card/billing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@
<div class="col">{{ insuranceBalance|money|text }}</div>
</div>
<div class="row">
<div class="col-4 font-weight-bold">{{ "Total Balance Due"|xlt }}</div>
<div class="col font-weight-bold">{{ totalBalance|money|text }}</div>
<div class="col-4">{{ "Total Balance Due"|xlt }}</div>
<div class="col">{{ totalBalance|money|text }}</div>
</div>

{% if unallocated > 0 %}
<div class="row">
<div class="col-4">{{ "Unallocated Patient Pre-Payment"|xlt }}</div>
<div class="col">{{ unallocated|money|text }}</font></div>
</div>
{% endif %}

{% if billingNote %}
<div class="row">
<div class="col-4">{{ "Billing Note"|xlt }}</div>
Expand Down

0 comments on commit e1b2a59

Please sign in to comment.