Skip to content

Commit

Permalink
fix #6085, ins search fixes (#6087)
Browse files Browse the repository at this point in the history
* ins search fixes

* phone lookup

* improve query, restore sel2

* fix select2 save for ins

* style
  • Loading branch information
stephenwaite committed Jan 15, 2023
1 parent 2074df2 commit 927784d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion interface/new/new_comprehensive.php
Expand Up @@ -637,7 +637,7 @@ function end_group()
?>
</select>
<div class="input-group-append">
<a class='btn btn-primary text-white medium_modal' href='../practice/ins_search.php' onclick='ins_search(<?php echo attr($i); ?>)'><?php echo xlt('Search/Add Insurer'); ?></a>
<a class='btn btn-primary text-white medium_modal' href='../practice/ins_search.php' onclick='ins_search(<?php echo attr_js($i); ?>)'><?php echo xlt('Search/Add Insurer'); ?></a>
</div>
</div>
</div>
Expand Down
24 changes: 10 additions & 14 deletions interface/patient_file/summary/demographics_full.php
Expand Up @@ -340,18 +340,15 @@ function InsSaveClose() {
}
// The ins_search.php window calls this to set the selected insurance.
function set_insurance(ins_id, ins_name) {
var thesel = document.forms[0]['i' + insurance_index + 'provider'];
var theopts = thesel.options; // the array of Option objects
var i = 0;
for (; i < theopts.length; ++i) {
if (theopts[i].value == ins_id) {
theopts[i].selected = true;
return;
}
}
// no matching option was found so create one, append it to the
// end of the list, and select it.
theopts[i] = new Option(ins_name, ins_id, false, true);
thesel = $('#i' + insurance_index + 'provider');
if ($(thesel).find("option[value='" + ins_id + "']").length) {
thesel.val(ins_id).trigger('change');
} else {
// no matching option was found so create one, append it to the
// end of the list, and select it.
let newOption = new Option(ins_name, ins_id, true, true);
thesel.append(newOption).trigger('change');
}
}

// This capitalizes the first letter of each word in the passed input
Expand Down Expand Up @@ -637,7 +634,7 @@ function validate(f) {
<div class="col-md-9">
<a href="../../practice/ins_search.php" class="medium_modal btn btn-primary"
onclick="ins_search(<?php echo attr_js($i); ?>)"><?php echo xlt('Search/Add') ?></a>
<select name="i<?php echo attr($i); ?>provider" class="form-control form-control-sm sel2 mb-1" style="width: 250px;">
<select id="i<?php echo attr($i); ?>provider" name="i<?php echo attr($i); ?>provider" class="form-control form-control-sm sel2 mb-1" style="width: 250px;">
<option value=""><?php echo xlt('Unassigned'); ?></option>
<?php
foreach ($insurancei as $iid => $iname) {
Expand Down Expand Up @@ -1210,7 +1207,6 @@ class='text'>(<?php echo xlt('Browse'); ?>)</a>
width: 'resolve',
<?php require($GLOBALS['srcdir'] . '/js/xl/select2.js.php'); ?>
});

<?php if ($GLOBALS['usps_webtools_enable']) { ?>
$("#value_id_text_postal_code").append(
"<input type='button' class='btn btn-sm btn-secondary mb-1' onclick='address_verify()' value='<?php echo xla('Verify Address') ?>' />");
Expand Down
38 changes: 18 additions & 20 deletions interface/practice/ins_list.php
Expand Up @@ -53,6 +53,9 @@ function addwhere($where, $colname, $value)
$where = addwhere($where, 'a.zip', $_GET['form_zip']);

$phone_parts = array();
$area_code = null;
$prefix = null;
$digits = null;

// Search by area code if there is one.
if (
Expand All @@ -62,7 +65,8 @@ function addwhere($where, $colname, $value)
$phone_parts
)
) {
$where = addwhere($where, 'p.area_code', $phone_parts[1]);
$area_code = $phone_parts[1];
$where = addwhere($where, 'p.area_code', $area_code);
}

// If there is also an exchange, search for that too.
Expand All @@ -73,7 +77,8 @@ function addwhere($where, $colname, $value)
$phone_parts
)
) {
$where = addwhere($where, 'p.prefix', $phone_parts[1]);
$prefix = $phone_parts[1];
$where = addwhere($where, 'p.prefix', $prefix);
}

// If the last 4 phone number digits are given, search for that too.
Expand All @@ -84,27 +89,17 @@ function addwhere($where, $colname, $value)
$phone_parts
)
) {
$where = addwhere($where, 'p.number', $phone_parts[1]);
$digits = $phone_parts[1];
$where = addwhere($where, 'p.number', $digits);
}

$query = "SELECT " .
"i.id, i.name, i.attn, " .
"a.line1, a.line2, a.city, a.state, a.zip ";

$any_phone_numbers = sqlQuery("SELECT COUNT(*) AS count FROM phone_numbers");
if ($any_phone_numbers['count'] > 0) {
$query .= ", p.area_code, p.prefix, p.number " .
"FROM insurance_companies as i, addresses AS a " .
", phone_numbers AS p ";
} else {
$query .= "FROM insurance_companies AS i, addresses AS a ";
}

$query .= "WHERE a.foreign_id = i.id ";

if (!empty($phone_parts)) {
$query .= "AND p.foreign_id = i.id ";
}
"a.line1, a.line2, a.city, a.state, a.zip, " .
"p.area_code, p.prefix, p.number " .
"FROM insurance_companies i " .
"LEFT JOIN addresses a ON a.foreign_id = i.id " .
"LEFT JOIN phone_numbers p ON p.foreign_id = i.id WHERE 1=1 ";

$query .= $where . " ORDER BY i.name, a.zip";
$res = sqlStatement($query);
Expand Down Expand Up @@ -150,6 +145,9 @@ function setins(ins_id, ins_name) {
</tr>

<?php
if (empty($res->_numOfRows)) {
echo " <td>" . xlt('No matches found.') . "</td>";
}
while ($row = sqlFetchArray($res)) {
$anchor = "<a href=\"\" onclick=\"return setins(" .
attr_js($row['id']) . "," . attr_js($row['name']) . ")\">";
Expand All @@ -167,8 +165,8 @@ function setins(ins_id, ins_name) {
echo " <td valign='top'>" . text($row['state']) . "&nbsp;</td>\n";
echo " <td valign='top'>" . text($row['zip']) . "&nbsp;</td>\n";
echo " <td valign='top'>" . $phone . "</td>\n";
echo " </tr>\n";
}
echo " </tr>\n";
?>
</table>

Expand Down

0 comments on commit 927784d

Please sign in to comment.