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 * @author Stephen Nielson <snielson@discoverandchange.com>
21 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
22 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
23 * @copyright Copyright (c) 2020 Tyler Wrenn <tyler@tylerwrenn.com>
24 * @copyright Copyright (c) 2024 Care Management Solutions, Inc. <stephen.waite@cmsvt.com>
25 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
28 require_once("../globals.php");
30 use OpenEMR\Common\Csrf\CsrfUtils
;
31 use OpenEMR\Core\Header
;
32 use OpenEMR\Services\
{
34 InsuranceCompanyService
,
38 // Putting a message here will cause a popup window to display it.
41 // Grab insurance type codes from service
42 $insuranceCompany = new InsuranceCompanyService();
43 $phoneNumber = new PhoneNumberService();
44 $ins_type_code_array = $insuranceCompany->getInsuranceTypes();
49 <title
><?php
echo xlt('Insurance Company Search/Add');?
></title
>
51 <?php Header
::setupHeader(['opener','topdialog']); ?
>
70 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
72 // This is invoked when our Search button is clicked.
75 $
("#form_entry").hide();
76 var f
= document
.forms
[0];
77 var search_list
= 'ins_list.php' +
78 '?form_name=' +
encodeURIComponent(f
.form_name
.value
) +
79 '&form_attn=' +
encodeURIComponent(f
.form_attn
.value
) +
80 '&form_addr1=' +
encodeURIComponent(f
.form_addr1
.value
) +
81 '&form_addr2=' +
encodeURIComponent(f
.form_addr2
.value
) +
82 '&form_city=' +
encodeURIComponent(f
.form_city
.value
) +
83 '&form_state=' +
encodeURIComponent(f
.form_state
.value
) +
84 '&form_zip=' +
encodeURIComponent(f
.form_zip
.value
) +
85 '&form_phone=' +
encodeURIComponent(f
.form_phone
.value
) +
86 '&form_cms_id=' +
encodeURIComponent(f
.form_cms_id
.value
) +
87 '&csrf_token_form=' +
<?php
echo js_url(CsrfUtils
::collectCsrfToken()); ?
>;
90 $
("#form_list").load( search_list
).show();
95 // The ins_list.php window calls this to set the selected insurance.
96 function set_insurance(ins_id
, ins_name
) {
97 window
.top
.restoreSession(); // make sure to restore the session before we do anything else
99 return; // nothing to do here as somehow we got here without the opener
102 action
: 'insurance-search-set-insurance'
104 ,insuranceName
: ins_name
106 // fire off a message so we can decouple things so we don't have to have a specific function
107 // name in the global scope of the opener
108 opener
.postMessage(postMessage
, window
.location
.origin
);
110 alert('The target form was closed; I cannot apply your selection.');
112 else if (opener
.set_insurance
) {
113 opener
.set_insurance(ins_id
, ins_name
);
114 dlgclose('InsSaveClose', false);
116 // if we don't have a set_insurance function then we will just close the window as the opener is
117 // using post message to receive events.
118 dlgclose('InsSaveClose', false);
122 // This is set to true on a mousedown of the Save button. The
123 // reason is so we can distinguish between clicking on the Save
124 // button vs. hitting the Enter key, as we prefer the "default"
125 // action to be search and not save.
126 var save_clicked
= false;
127 let update_clicked
= false;
130 function validate(f
) {
131 // If save was not clicked then default to searching.
132 if (!(save_clicked || update_clicked
)) return dosearch();
133 save_clicked
= false;
136 if (update_clicked
&& !f
.form_id
.value
.length
) msg +
= 'Id is missing for Update \n';
137 if (! f
.form_name
.value
.length
) msg +
= 'Company name is missing. ';
138 if (! f
.form_addr1
.value
.length
) msg +
= 'Address is missing. ';
139 if (! f
.form_city
.value
.length
) msg +
= 'City is missing. ';
140 if (! f
.form_state
.value
.length
) msg +
= 'State is missing. ';
141 if (! f
.form_zip
.value
.length
) msg +
= 'Zip is missing.';
142 update_clicked
= false;
149 top
.restoreSession();
153 function clearForm() {
154 let f
= document
.forms
[0];
155 f
.form_id
.value
= '';
156 f
.form_name
.value
= '';
157 f
.form_attn
.value
= '';
158 f
.form_addr1
.value
= '';
159 f
.form_addr2
.value
= '';
160 f
.form_city
.value
= '';
161 f
.form_state
.value
= '';
162 f
.form_country
.value
= '';
163 f
.form_zip
.value
= '';
164 f
.form_phone
.value
= '';
165 f
.form_cms_id
.value
= '';
166 f
.form_ins_type_code
.value
= '';
167 f
.form_partner
.value
= '';
168 f
.form_cqm_sop
.value
= '';
175 <body
class="body_top">
177 // If we are saving, then save and close the window.
180 ($_POST['form_save'] ??
'')
181 ||
($_POST['form_update'] ??
'')
183 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
184 CsrfUtils
::csrfNotVerified();
187 if (($_POST['form_save'] ??
'') == 'Save as New') {
190 $ins_id = $_POST['form_id'];
192 $ins_name = $_POST['form_name'];
195 // sql for updating could go here if this script is enhanced to support
196 // editing of existing insurance companies.
197 $insuranceCompany->update(
200 'attn' => $_POST['form_attn'],
201 'cms_id' => $_POST['form_cms_id'],
202 'ins_type_code' => $_POST['form_ins_type_code'],
203 'x12_receiver_id' => $_POST['form_x12_receiver'] ??
null,
204 'x12_default_partner_id' => $_POST['form_partner'],
205 'alt_cms_id' => null,
206 'line1' => $_POST['form_addr1'],
207 'line2' => $_POST['form_addr2'],
208 'city' => $_POST['form_city'],
209 'state' => $_POST['form_state'],
210 'zip' => $_POST['form_zip'],
211 'country' => $_POST['form_country'],
212 'phone' => $_POST['form_phone'],
213 'foreign_id' => $ins_id,
214 'cqm_sop' => $_POST['form_cqm_sop']
219 $ins_id = $insuranceCompany->insert(
222 'attn' => $_POST['form_attn'],
223 'cms_id' => $_POST['form_cms_id'],
224 'ins_type_code' => $_POST['form_ins_type_code'],
225 'x12_receiver_id' => $_POST['form_receiver'] ??
null,
226 'x12_default_partner_id' => $_POST['form_partner'],
227 'alt_cms_id' => null,
228 'line1' => $_POST['form_addr1'],
229 'line2' => $_POST['form_addr2'],
230 'city' => $_POST['form_city'],
231 'state' => $_POST['form_state'],
232 'zip' => $_POST['form_zip'],
233 'country' => $_POST['form_country'],
234 'phone' => $_POST['form_phone'],
235 'foreign_id' => $ins_id,
236 'cqm_sop' => $_POST['form_cqm_sop']
241 // Close this window and tell our opener to select the new company.
245 echo " alert(" . js_escape($info_msg) . ");\n";
248 // we need to follow the global settings for the display of this name so we will return the name in the set_insurance method
249 $ins_name = (new InsuranceCompanyService())->getInsuranceDisplayName($ins_id);
250 // call the set_insurance method in our header
251 echo " set_insurance(" . js_escape($ins_id) . "," . js_escape($ins_name) . ");\n";
252 echo "</script></body></html>\n";
255 $ins_co = (new InsuranceCompanyService())->getOneById($_GET['ins']) ??
null;
256 $ins_co_address = (new AddressService())->getOneByForeignId($_GET['ins']) ??
null;
257 $ins_co_phone = (new PhoneNumberService())->getOneByForeignId($_GET['ins']) ??
null;
260 // Query x12_partners.
261 $xres = sqlStatement(
262 "SELECT id, name FROM x12_partners ORDER BY name"
265 <div id
="form_entry">
267 <form method
='post' name
='theform' action
='ins_search.php' onsubmit
='return validate(this)'>
268 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
272 <table
class="w-100 border-0">
274 <td
class="font-weight-bold" width
='1%' nowrap
><?php
echo xlt('Id'); ?
>:</td
>
276 <input type
='text' size
='20' name
='form_id' maxlength
='35' class='form-control form-control-sm' title
='<?php echo xla('Id of insurance company
'); ?>'
277 readonly
='readonly' value
='<?php echo attr($ins_co['id
'] ?? ''); ?>' />
281 <td
class="font-weight-bold" width
='1%' nowrap
><?php
echo xlt('Name'); ?
>:</td
>
283 <input type
='text' size
='20' name
='form_name' maxlength
='35' class='form-control form-control-sm' title
='<?php echo xla('Name of insurance company
'); ?>'
284 value
='<?php echo attr($ins_co['name
'] ?? ''); ?>' />
289 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Attention');?
>:</td
>
291 <input type
='text' size
='20' name
='form_attn' maxlength
='35' class='form-control form-control-sm' title
='<?php echo xla('Contact name
'); ?>'
292 value
='<?php echo attr($ins_co['attn
'] ?? ''); ?>' />
297 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Address1'); ?
>:</td
>
299 <input type
='text' size
='20' name
='form_addr1' maxlength
='35' class='form-control form-control-sm' title
='First address line'
300 value
='<?php echo attr($ins_co_address['line1
'] ?? ''); ?>' />
305 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Address2'); ?
>:</td
>
307 <input type
='text' size
='20' name
='form_addr2' maxlength
='35' class='form-control form-control-sm' title
='Second address line, if any'
308 value
='<?php echo attr($ins_co_address['line2
'] ?? ''); ?>' />
313 <td
class="font-weight-bold" nowrap
><?php
echo xlt('City/State'); ?
>:</td
>
314 <td
class="form-row">
316 <input type
='text' size
='20' name
='form_city' maxlength
='25' class='form-control form-control-sm' title
='City name'
317 value
='<?php echo attr($ins_co_address['city
'] ?? ''); ?>' />
320 <input type
='text' size
='3' name
='form_state' maxlength
='35' class='form-control form-control-sm' title
='State or locality'
321 value
='<?php echo attr($ins_co_address['state
'] ?? ''); ?>' />
327 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Zip/Country:'); ?
></td
>
328 <td
class="form-row">
330 <input type
='text' size
='20' name
='form_zip' maxlength
='10' class='form-control form-control-sm' title
='Postal code'
331 value
='<?php echo attr(($ins_co_address['zip
'] ?? '') . ($ins_co_address['plus_four
'] ?? '')); ?>' />
334 <input type
='text' size
='20' class="form-control form-control-sm" name
='form_country' value
='USA' maxlength
='35' title
='Country name'
335 value
='<?php echo attr($ins_co_address['country
'] ?? ''); ?>' />
341 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Phone'); ?
>:</td
>
343 <input type
='text' size
='20' name
='form_phone' maxlength
='20' class='form-control form-control-sm' title
='Telephone number'
344 value
='<?php echo attr((
345 ($ins_co_phone['area_code
'] ?? '') .
346 ($ins_co_phone['prefix
'] ?? '') .
347 ($ins_co_phone['number
'] ?? '')
353 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Payer ID'); ?
>:</td
>
355 <input type
='text' size
='20' name
='form_cms_id' maxlength
='15' class='form-control form-control-sm' title
='Identifier assigned by CMS'
356 value
='<?php echo attr($ins_co['cms_id
'] ?? ''); ?>' />
361 <td
class="font-weight-bold" nowrap
><?php
echo xlt('Payer Type'); ?
>:</td
>
363 <select name
='form_ins_type_code' class="form-control form-control-sm">
365 for ($i = 1; $i < count($ins_type_code_array); ++
$i) {
366 echo " <option value='" . attr($i) . "'";
367 if (!empty($ins_co)) {
368 if ($i == $ins_co['ins_type_code'] ??
'') {
372 echo ">" . text($ins_type_code_array[$i]) . "\n";
380 <td
class="font-weight-bold" nowrap
><?php
echo xlt('X12 Partner'); ?
>:</td
>
382 <select name
='form_partner' title
='Default X12 Partner' class="form-control form-control-sm">
383 <option value
=""><?php
echo '-- ' . xlt('None{{Partner}}') . ' --'; ?
></option
>
385 while ($xrow = sqlFetchArray($xres)) {
386 echo " <option value='" . attr($xrow['id']) . "'";
387 if ($xrow['id'] == $ins_co['x12_default_partner_id']) {
390 echo ">" . text($xrow['name']) . "</option>\n";
398 <td
class="font-weight-bold" nowrap
><?php
echo xlt('CQM Source of Payment'); ?
>:</td
>
400 <select name
='form_cqm_sop' title
='CQM Source of Payment' class="form-control form-control-sm">
401 <option value
=""><?php
echo '-- ' . xlt('None{{CQM SOP}}') . ' --'; ?
></option
>
403 $cqm_sop_array = $insuranceCompany->getInsuranceCqmSop();
404 foreach ($cqm_sop_array as $key => $value) {
405 echo " <option value='" . attr($key) . "'";
406 echo ">" . text($value) . "</option>\n";
415 <input type
='button' value
='<?php echo xla('Search
'); ?>' class='btn btn-primary' onclick
='dosearch()' />
416 <input type
='submit' value
='<?php echo xla('Save
as New'); ?>' class='btn btn-primary' name
='form_save' onmousedown
='save_clicked=true' />
417 <input type
='submit' value
='<?php echo xla('Update
'); ?>' class='btn btn-primary' name
='form_update' onmousedown
='update_clicked=true' />
418 <input type
='button' value
='<?php echo xla('Clear
'); ?>' class='btn btn-primary' onclick
='clearForm()' />
419 <input type
='button' value
='<?php echo xla('Cancel
'); ?>' class='btn btn-primary' onclick
='window.close();'/>