Skip to content

Commit

Permalink
fix: set default x12 partner for item in billing manager (openemr#7513)
Browse files Browse the repository at this point in the history
* fix: set default x12 partner for item in billing manager

* remove unused sql
  • Loading branch information
stephenwaite authored Jun 24, 2024
1 parent 0cfa65e commit 16229d2
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions interface/billing/billing_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -1115,45 +1115,19 @@ function criteriaSelectHasValue(select) {
$lhtml .= "&nbsp;<span class='form-group'>" . xlt('Bill') . ": ";
$lhtml .= "<select name='claims[" . attr($this_encounter_id) . "][payer]' onchange='onNewPayer(event)' class='form-control'>";

$query = "SELECT id.provider AS id, id.type, id.date, " .
"ic.x12_default_partner_id AS ic_x12id, ic.name AS provider " .
"FROM insurance_data AS id, insurance_companies AS ic WHERE " .
"ic.id = id.provider AND " .
"id.pid = ? AND " .
"(id.date <= ? OR id.date IS NULL) AND " .
"(id.date_end >= ? OR id.date_end IS NULL) " .
"ORDER BY id.type ASC, id.date DESC";

$result = sqlStatement(
$query,
array(
$iter['enc_pid'],
$raw_encounter_date,
$raw_encounter_date
)
);
$count = 0;
$default_x12_partner = $iter['x12_partner_id'] ?? null;
$prevtype = '';

while ($row = sqlFetchArray($result)) {
if (strcmp($row['type'], $prevtype) == 0) {
continue;
$last_level_closed = sqlQuery("SELECT `last_level_closed` FROM `form_encounter` WHERE `encounter` = ?", array($iter['enc_encounter']))['last_level_closed'];
$effective_insurances = getEffectiveInsurances($iter['pid'], $iter['enc_date']);

foreach ($effective_insurances as $key => $row) {
$insuranceName = sqlQuery("SELECT `name` FROM `insurance_companies` WHERE `id` = ?", array($row['provider']))['name'];
$x12Partner = sqlQuery("SELECT `x12_default_partner_id` FROM `insurance_companies` WHERE `id` = ?", array($row['provider']))['x12_default_partner_id'];
$lhtml .= "<option value=\"" . attr(substr($row['type'], 0, 1) . $row['provider']) . "\"";
if ($key == $last_level_closed) {
$lhtml .= " selected";
$default_x12_partner = $x12Partner;
}
$prevtype = $row['type'];
if (strlen($row['provider']) > 0) {
// This preserves any existing insurance company selection, which is
// important when EOB posting has re-queued for secondary billing.
$lhtml .= "<option value=\"" . attr(substr($row['type'], 0, 1) . $row['id']) . "\"";
if (($count == 0 && !$iter['payer_id']) || $row['id'] == $iter['payer_id']) {
$lhtml .= " selected";
if (!is_numeric($default_x12_partner)) {
$default_x12_partner = $row['ic_x12id'];
}
}
$lhtml .= " data-partner='" . attr($row['ic_x12id']) . "'>" . text($row['type']) . ": " . text($row['provider']) . "</option>";
}
$count++;

$lhtml .= " data-partner='" . attr($x12Partner) . "'>" . text($row['type']) . ": " . text($insuranceName) . "</option>";
}

$lhtml .= "<option value='-1'>" . xlt("Unassigned") . "</option>\n";
Expand Down

0 comments on commit 16229d2

Please sign in to comment.