2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This module is used to find and add insurance companies.
10 // It is opened as a popup window. The opener may have a
11 // JavaScript function named set_insurance(id, name), in which
12 // case selecting or adding an insurance company will cause the
13 // function to be called passing the ID and name of that company.
15 // When used for searching, this module will in turn open another
16 // popup window ins_list.php, which lists the matched results and
17 // permits selection of one of them via the same set_insurance()
20 include_once("../globals.php");
21 include_once("$srcdir/acl.inc");
23 // Putting a message here will cause a popup window to display it.
26 // This is copied from InsuranceCompany.class.php. It should
27 // really be in a SQL table.
28 $freeb_type_array = array(''
30 , xl('Medicare Part B')
34 , xl('Blue Cross Blue Shield')
37 , xl('Central Certification')
38 , xl('Other Non-Federal Programs')
39 , xl('Preferred Provider Organization (PPO)')
40 , xl('Point of Service (POS)')
41 , xl('Exclusive Provider Organization (EPO)')
42 , xl('Indemnity Insurance')
43 , xl('Health Maintenance Organization (HMO) Medicare Risk')
44 , xl('Automobile Medical')
45 , xl('Commercial Insurance Co.')
47 , xl('Health Maintenance Organization')
49 , xl('Liability Medical')
50 , xl('Other Federal Program')
52 , xl('Veterans Administration Plan')
53 , xl('Workers Compensation Health Plan')
54 , xl('Mutually Defined')
60 <title
><?php
xl('Insurance Company Search/Add','e');?
></title
>
61 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
64 td
{ font
-size
:10pt
; }
65 .search
{ background
-color
:#aaffaa }
68 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
69 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
71 <script language
="JavaScript">
73 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
75 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
77 function doescape(value
) {
81 // This is invoked when our Search button is clicked.
83 var f
= document
.forms
[0];
84 dlgopen('ins_list.php' +
85 '?form_name=' +
doescape(f
.form_name
.value
) +
86 '&form_attn=' +
doescape(f
.form_attn
.value
) +
87 '&form_addr1=' +
doescape(f
.form_addr1
.value
) +
88 '&form_addr2=' +
doescape(f
.form_addr2
.value
) +
89 '&form_city=' +
doescape(f
.form_city
.value
) +
90 '&form_state=' +
doescape(f
.form_state
.value
) +
91 '&form_zip=' +
doescape(f
.form_zip
.value
) +
92 '&form_phone=' +
doescape(f
.form_phone
.value
) +
93 '&form_cms_id=' +
doescape(f
.form_cms_id
.value
) +
94 '', '_blank', 780, 500);
99 // The ins_list.php window calls this to set the selected insurance.
100 function set_insurance(ins_id
, ins_name
) {
101 if (opener
.closed ||
! opener
.set_insurance
)
102 alert('The target form was closed; I cannot apply your selection.');
104 opener
.set_insurance(ins_id
, ins_name
);
108 // This is set to true on a mousedown of the Save button. The
109 // reason is so we can distinguish between clicking on the Save
110 // button vs. hitting the Enter key, as we prefer the "default"
111 // action to be search and not save.
112 var save_clicked
= false;
115 function validate(f
) {
116 // If save was not clicked then default to searching.
117 if (! save_clicked
) return dosearch();
118 save_clicked
= false;
121 if (! f
.form_name
.value
.length
) msg +
= 'Company name is missing. ';
122 if (! f
.form_addr1
.value
.length
) msg +
= 'Address is missing. ';
123 if (! f
.form_city
.value
.length
) msg +
= 'City is missing. ';
124 if (! f
.form_state
.value
.length
) msg +
= 'State is missing. ';
125 if (! f
.form_zip
.value
.length
) msg +
= 'Zip is missing.';
132 top
.restoreSession();
140 <body
class="body_top" onunload
='imclosing()'>
142 // If we are saving, then save and close the window.
144 if ($_POST['form_save']) {
146 $ins_name = $_POST['form_name'];
149 // sql for updating could go here if this script is enhanced to support
150 // editing of existing insurance companies.
152 $ins_id = generate_id();
154 sqlInsert("INSERT INTO insurance_companies ( " .
155 "id, name, attn, cms_id, freeb_type, x12_receiver_id, x12_default_partner_id " .
158 "'" . $ins_name . "', " .
159 "'" . $_POST['form_attn'] . "', " .
160 "'" . $_POST['form_cms_id'] . "', " .
161 "'" . $_POST['form_freeb_type'] . "', " .
162 "'" . $_POST['form_partner'] . "', " .
163 "'" . $_POST['form_partner'] . "' " .
166 sqlInsert("INSERT INTO addresses ( " .
167 "id, line1, line2, city, state, zip, country, foreign_id " .
169 generate_id() . ", " .
170 "'" . $_POST['form_addr1'] . "', " .
171 "'" . $_POST['form_addr2'] . "', " .
172 "'" . $_POST['form_city'] . "', " .
173 "'" . $_POST['form_state'] . "', " .
174 "'" . $_POST['form_zip'] . "', " .
175 "'" . $_POST['form_country'] . "', " .
179 $phone_parts = array();
180 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
183 sqlInsert("INSERT INTO phone_numbers ( " .
184 "id, country_code, area_code, prefix, number, type, foreign_id " .
186 generate_id() . ", " .
188 "'" . $phone_parts[1] . "', " .
189 "'" . $phone_parts[2] . "', " .
190 "'" . $phone_parts[3] . "', " .
196 // Close this window and tell our opener to select the new company.
198 echo "<script language='JavaScript'>\n";
199 if ($info_msg) echo " alert('$info_msg');\n";
200 echo " window.close();\n";
201 echo " if (opener.set_insurance) opener.set_insurance($ins_id,'$ins_name');\n";
202 echo "</script></body></html>\n";
206 // Query x12_partners.
207 $xres = sqlStatement(
208 "SELECT id, name FROM x12_partners ORDER BY name"
211 <form method
='post' name
='theform' action
='ins_search.php'
212 onsubmit
='return validate(this)'>
216 <table border
='0' width
='100%'>
220 <td valign
='top' width
='1%' nowrap
> 
;</td
>
222 Note
: Green fields are searchable
.
228 <td valign
='top' width
='1%' nowrap
><b
><?php
xl('Name','e');?
>:</b
></td
>
230 <input type
='text' size
='20' name
='form_name' maxlength
='35'
231 class='search' style
='width:100%' title
=<?php
xl('Name of insurance company','e');?
> />
236 <td valign
='top' nowrap
><b
><?php
xl('Attention','e');?
>:</b
></td
>
238 <input type
='text' size
='20' name
='form_attn' maxlength
='35'
239 class='search' style
='width:100%' title
=".xl('Contact name')." />
244 <td valign
='top' nowrap
><b
><?php
xl('Address1','e');?
>:</b
></td
>
246 <input type
='text' size
='20' name
='form_addr1' maxlength
='35'
247 class='search' style
='width:100%' title
='First address line' />
252 <td valign
='top' nowrap
><b
><?php
xl('Address2','e');?
>:</b
></td
>
254 <input type
='text' size
='20' name
='form_addr2' maxlength
='35'
255 class='search' style
='width:100%' title
='Second address line, if any' />
260 <td valign
='top' nowrap
><b
><?php
xl('City/State','e');?
>:</b
></td
>
262 <input type
='text' size
='20' name
='form_city' maxlength
='25'
263 class='search' title
='City name' />
265 <input type
='text' size
='3' name
='form_state' maxlength
='35'
266 class='search' title
='State or locality' />
271 <td valign
='top' nowrap
><b
><?php
xl('Zip/Country:','e'); ?
></b
></td
>
273 <input type
='text' size
='20' name
='form_zip' maxlength
='10'
274 class='search' title
='Postal code' />
276 <input type
='text' size
='20' name
='form_country' value
='USA' maxlength
='35'
277 title
='Country name' />
282 <td valign
='top' nowrap
><b
><?php
xl('Phone','e');?
>:</b
></td
>
284 <input type
='text' size
='20' name
='form_phone' maxlength
='20'
285 class='search' title
='Telephone number' />
291 <td valign
='top' width
='1%' nowrap
> 
;</td
>
293  
;<br
><b
>Other data
:</b
>
299 <td valign
='top' nowrap
><b
><?php
xl('CMS ID','e');?
>:</b
></td
>
301 <input type
='text' size
='20' name
='form_cms_id' maxlength
='15'
302 class='search' title
='Identifier assigned by CMS' />
307 <td valign
='top' nowrap
><b
><?php
xl('Payer Type','e');?
>:</b
></td
>
309 <select name
='form_freeb_type'>
311 for ($i = 1; $i < count($freeb_type_array); ++
$i) {
312 echo " <option value='$i'";
313 // if ($i == $row['freeb_type']) echo " selected";
314 echo ">" . $freeb_type_array[$i] . "\n";
322 <td valign
='top' nowrap
><b
><?php
xl('X12 Partner','e');?
>:</b
></td
>
324 <select name
='form_partner' title
='Default X12 Partner'>
325 <option value
=""><?php
xl('None','e','-- ',' --'); ?
></option
>
327 while ($xrow = sqlFetchArray($xres)) {
328 echo " <option value='" . $xrow['id'] . "'";
329 // if ($xrow['id'] == $row['x12_default_partner_id']) echo " selected";
330 echo ">" . $xrow['name'] . "</option>\n";
340 <input type
='button' value
='<?php xl('Search
','e
'); ?>' class='search' onclick
='dosearch()' />
342 <input type
='submit' value
='<?php xl('Save
as New','e
'); ?>' name
='form_save' onmousedown
='save_clicked=true' />
344 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='window.close()' />