Skip to content

Commit

Permalink
feat: show collection balance in billing widget (openemr#7454)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwaite authored May 24, 2024
1 parent 4e8432a commit 610b811
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
21 changes: 16 additions & 5 deletions library/patient.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ function getAllinsurances($pid)
* @param int Optional encounter id. If value is passed, will fetch only bills from specified encounter.
* @return number The balance.
*/
function get_patient_balance($pid, $with_insurance = false, $eid = false)
function get_patient_balance($pid, $with_insurance = false, $eid = false, $in_collection = false)
{
$balance = 0;
$bindarray = array($pid);
Expand All @@ -1609,6 +1609,11 @@ function get_patient_balance($pid, $with_insurance = false, $eid = false)
$sqlstatement .= " AND encounter = ?";
array_push($bindarray, $eid);
}

if ($in_collection) {
$sqlstatement .= " AND in_collection = ?";
array_push($bindarray, 1);
}
$feres = sqlStatement($sqlstatement, $bindarray);
while ($ferow = sqlFetchArray($feres)) {
$encounter = $ferow['encounter'];
Expand Down Expand Up @@ -1641,10 +1646,16 @@ function get_patient_balance($pid, $with_insurance = false, $eid = false)
$balance += $ptbal;
}
} else {
// Including insurance or not out to insurance, everything is due.
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
if (!$with_insurance && $ferow['last_level_closed'] >= $inscount && $in_collection) {
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
} else {
// Including insurance or not out to insurance, everything is due.
$brow = sqlQuery("SELECT SUM(fee) AS amount FROM billing WHERE " .
"pid = ? AND encounter = ? AND " .
"activity = 1", array($pid, $encounter));
}
$drow = sqlQuery("SELECT SUM(pay_amount) AS payments, " .
"SUM(adj_amount) AS adjustments FROM ar_activity WHERE " .
"deleted IS NULL AND pid = ? AND encounter = ?", array($pid, $encounter));
Expand Down
2 changes: 2 additions & 0 deletions src/Patient/Cards/BillingViewCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function setupBillingData()
$insurancebalance = get_patient_balance($pid, true) - $patientbalance;
$totalbalance = $patientbalance + $insurancebalance;
$unallocated_amt = get_unallocated_patient_balance($pid);
$collectionbalance = get_patient_balance($pid, false, false, true);

$id = self::CARD_ID . "_ps_expand";
$dispatchResult = $ed->dispatch(new RenderEvent('billing'), RenderEvent::EVENT_HANDLE);
Expand All @@ -79,6 +80,7 @@ private function setupBillingData()
'patientBalance' => $patientbalance,
'insuranceBalance' => $insurancebalance,
'totalBalance' => $totalbalance,
'collectionBalance' => $collectionbalance,
'unallocated' => $unallocated_amt,
'forceAlwaysOpen' => $forceBillingExpandAlways,
'prependedInjection' => $dispatchResult->getPrependedInjection(),
Expand Down
7 changes: 7 additions & 0 deletions templates/patient/card/billing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
</div>
{% endif %}

{% if collectionBalance > 0 %}
<div class="row alert-danger">
<div class="col-4">{{ "Collection Balance"|xlt }}</div>
<div class="col">{{ collectionBalance|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 610b811

Please sign in to comment.