4 * This module is used to find and add insurance companies.
5 * It is opened as a popup window. The opener may have a
6 * JavaScript function named set_insurance(id, name), in which
7 * case selecting or adding an insurance company will cause the
8 * function to be called passing the ID and name of that company.
10 * When used for searching, this module will in turn open another
11 * popup window ins_list.php, which lists the matched results and
12 * permits selection of one of them via the same set_insurance()
16 * @link http://www.open-emr.org
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @author Brady Miller <brady.g.miller@gmail.com>
19 * @author Tyler Wrenn <tyler@tylerwrenn.com>
20 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
21 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
22 * @copyright Copyright (c) 2020 Tyler Wrenn <tyler@tylerwrenn.com>
23 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
26 require_once("../globals.php");
28 use OpenEMR\Common\Csrf\CsrfUtils
;
29 use OpenEMR\Core\Header
;
30 use OpenEMR\Services\InsuranceCompanyService
;
32 // Putting a message here will cause a popup window to display it.
35 // Grab insurance type codes from service
36 $insuranceCompany = new InsuranceCompanyService();
37 $ins_type_code_array = $insuranceCompany->getInsuranceTypes();
42 <title
><?php
echo xlt('Insurance Company Search/Add');?
></title
>
44 <?php Header
::setupHeader(['opener','topdialog']); ?
>
63 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
65 // This is invoked when our Search button is clicked.
68 $
("#form_entry").hide();
69 var f
= document
.forms
[0];
70 var search_list
= 'ins_list.php' +
71 '?form_name=' +
encodeURIComponent(f
.form_name
.value
) +
72 '&form_attn=' +
encodeURIComponent(f
.form_attn
.value
) +
73 '&form_addr1=' +
encodeURIComponent(f
.form_addr1
.value
) +
74 '&form_addr2=' +
encodeURIComponent(f
.form_addr2
.value
) +
75 '&form_city=' +
encodeURIComponent(f
.form_city
.value
) +
76 '&form_state=' +
encodeURIComponent(f
.form_state
.value
) +
77 '&form_zip=' +
encodeURIComponent(f
.form_zip
.value
) +
78 '&form_phone=' +
encodeURIComponent(f
.form_phone
.value
) +
79 '&form_cms_id=' +
encodeURIComponent(f
.form_cms_id
.value
) +
80 '&csrf_token_form=' +
<?php
echo js_url(CsrfUtils
::collectCsrfToken()); ?
>;
83 $
("#form_list").load( search_list
).show();
88 // The ins_list.php window calls this to set the selected insurance.
89 function set_insurance(ins_id
, ins_name
) {
90 if (opener
.closed ||
! opener
.set_insurance
)
91 alert('The target form was closed; I cannot apply your selection.');
93 opener
.set_insurance(ins_id
, ins_name
);
94 dlgclose('InsSaveClose',false);
97 // This is set to true on a mousedown of the Save button. The
98 // reason is so we can distinguish between clicking on the Save
99 // button vs. hitting the Enter key, as we prefer the "default"
100 // action to be search and not save.
101 var save_clicked
= false;
104 function validate(f
) {
105 // If save was not clicked then default to searching.
106 if (! save_clicked
) return dosearch();
107 save_clicked
= false;
110 if (! f
.form_name
.value
.length
) msg +
= 'Company name is missing. ';
111 if (! f
.form_addr1
.value
.length
) msg +
= 'Address is missing. ';
112 if (! f
.form_city
.value
.length
) msg +
= 'City is missing. ';
113 if (! f
.form_state
.value
.length
) msg +
= 'State is missing. ';
114 if (! f
.form_zip
.value
.length
) msg +
= 'Zip is missing.';
121 top
.restoreSession();
129 <body
class="body_top">
131 // If we are saving, then save and close the window.
133 if ($_POST['form_save']) {
134 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
135 CsrfUtils
::csrfNotVerified();
139 $ins_name = $_POST['form_name'];
142 // sql for updating could go here if this script is enhanced to support
143 // editing of existing insurance companies.
145 $ins_id = $insuranceCompany->insert(
148 'attn' => $_POST['form_attn'],
149 'cms_id' => $_POST['form_cms_id'],
150 'ins_type_code' => $_POST['form_ins_type_code'],
151 'x12_receiver_id' => $_POST['form_partner'],
152 'x12_default_parter_id' => $_POST['form_partner'],
157 sqlStatement("INSERT INTO addresses ( " .
158 "id, line1, line2, city, state, zip, country, foreign_id " .
160 "'" . add_escape_custom(generate_id()) . "', " .
161 "'" . add_escape_custom($_POST['form_addr1']) . "', " .
162 "'" . add_escape_custom($_POST['form_addr2']) . "', " .
163 "'" . add_escape_custom($_POST['form_city']) . "', " .
164 "'" . add_escape_custom($_POST['form_state']) . "', " .
165 "'" . add_escape_custom($_POST['form_zip']) . "', " .
166 "'" . add_escape_custom($_POST['form_country']) . "', " .
167 "'" . add_escape_custom($ins_id) . "' " .
170 $phone_parts = array();
172 "/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",
173 $_POST['form_phone'],
177 sqlStatement("INSERT INTO phone_numbers ( " .
178 "id, country_code, area_code, prefix, number, type, foreign_id " .
180 "'" . add_escape_custom(generate_id()) . "', " .
182 "'" . add_escape_custom($phone_parts[1]) . "', " .
183 "'" . add_escape_custom($phone_parts[2]) . "', " .
184 "'" . add_escape_custom($phone_parts[3]) . "', " .
186 "'" . add_escape_custom($ins_id) . "' " .
190 // Close this window and tell our opener to select the new company.
194 echo " alert(" . js_escape($info_msg) . ");\n";
197 echo " top.restoreSession();\n";
198 echo " if (opener.set_insurance) opener.set_insurance(" . js_escape($ins_id) . "," . js_escape($ins_name) . ");\n";
199 echo " dlgclose();\n";
200 echo "</script></body></html>\n";
204 // Query x12_partners.
205 $xres = sqlStatement(
206 "SELECT id, name FROM x12_partners ORDER BY name"
209 <div id
="form_entry">
211 <form method
='post' name
='theform' action
='ins_search.php' onsubmit
='return validate(this)'>
212 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
216 <table
class="w-100 border-0">
218 <td
class="font-weight-bold" width
='1%' nowrap
><?php
echo xlt('Name'); ?
>:</td
>
220 <input type
='text' size
='20' name
='form_name' maxlength
='35' class='form-control form-control-sm' title
='<?php echo xla('Name of insurance company
'); ?>' />
225 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Attention');?
>:</td
>
227 <input type
='text' size
='20' name
='form_attn' maxlength
='35' class='form-control form-control-sm' title
='<?php echo xla('Contact name
'); ?>' />
232 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Address1'); ?
>:</td
>
234 <input type
='text' size
='20' name
='form_addr1' maxlength
='35' class='form-control form-control-sm' title
='First address line' />
239 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Address2'); ?
>:</td
>
241 <input type
='text' size
='20' name
='form_addr2' maxlength
='35' class='form-control form-control-sm' title
='Second address line, if any' />
246 <td
class="font-weight-bold" nowrap
><?php
echo xlt('City/State'); ?
>:</td
>
247 <td
class="form-row">
249 <input type
='text' size
='20' name
='form_city' maxlength
='25' class='form-control form-control-sm' title
='City name' />
252 <input type
='text' size
='3' name
='form_state' maxlength
='35' class='form-control form-control-sm' title
='State or locality' />
258 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Zip/Country:'); ?
></td
>
259 <td
class="form-row">
261 <input type
='text' size
='20' name
='form_zip' maxlength
='10' class='form-control form-control-sm' title
='Postal code' />
264 <input type
='text' size
='20' class="form-control form-control-sm" name
='form_country' value
='USA' maxlength
='35' title
='Country name' />
270 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Phone'); ?
>:</td
>
272 <input type
='text' size
='20' name
='form_phone' maxlength
='20' class='form-control form-control-sm' title
='Telephone number' />
276 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Payer ID'); ?
>:</td
>
278 <input type
='text' size
='20' name
='form_cms_id' maxlength
='15' class='form-control form-control-sm' title
='Identifier assigned by CMS' />
283 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Payer Type'); ?
>:</td
>
285 <select name
='form_ins_type_code' class="form-control form-control-sm">
287 for ($i = 1; $i < count($ins_type_code_array); ++
$i) {
288 echo " <option value='" . attr($i) . "'";
289 echo ">" . text($ins_type_code_array[$i]) . "\n";
297 <td
class="font-weight-bold" nowrap
><?php
echo xlt('X12 Partner'); ?
>:</td
>
299 <select name
='form_partner' title
='Default X12 Partner' class="form-control form-control-sm">
300 <option value
=""><?php
echo '-- ' . xlt('None{{Partner}}') . ' --'; ?
></option
>
302 while ($xrow = sqlFetchArray($xres)) {
303 echo " <option value='" . attr($xrow['id']) . "'";
304 echo ">" . text($xrow['name']) . "</option>\n";
313 <input type
='button' value
='<?php echo xla('Search
'); ?>' class='btn btn-primary' onclick
='dosearch()' />
314 <input type
='submit' value
='<?php echo xla('Save
as New'); ?>' class='btn btn-primary' name
='form_save' onmousedown
='save_clicked=true' />
315 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' class='btn btn-primary' onclick
='window.close();'/>