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 }
77 <script type
="text/javascript" src
="../../library/topdialog.js"></script
>
78 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
79 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
81 <script language
="JavaScript">
83 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
85 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
87 function doescape(value
) {
88 return encodeURIComponent(value
);
91 // This is invoked when our Search button is clicked.
94 $
("#form_entry").hide();
95 var f
= document
.forms
[0];
96 var search_list
= 'ins_list.php' +
97 '?form_name=' +
doescape(f
.form_name
.value
) +
98 '&form_attn=' +
doescape(f
.form_attn
.value
) +
99 '&form_addr1=' +
doescape(f
.form_addr1
.value
) +
100 '&form_addr2=' +
doescape(f
.form_addr2
.value
) +
101 '&form_city=' +
doescape(f
.form_city
.value
) +
102 '&form_state=' +
doescape(f
.form_state
.value
) +
103 '&form_zip=' +
doescape(f
.form_zip
.value
) +
104 '&form_phone=' +
doescape(f
.form_phone
.value
) +
105 '&form_cms_id=' +
doescape(f
.form_cms_id
.value
);
107 top
.restoreSession();
108 $
("#form_list").load( search_list
).show();
113 // The ins_list.php window calls this to set the selected insurance.
114 function set_insurance(ins_id
, ins_name
) {
115 if (opener
.closed ||
! opener
.set_insurance
)
116 alert('The target form was closed; I cannot apply your selection.');
118 opener
.set_insurance(ins_id
, ins_name
);
119 parent
.$
.fn
.fancybox
.close();
120 parent
.location
.reload();
121 top
.restoreSession();
124 // This is set to true on a mousedown of the Save button. The
125 // reason is so we can distinguish between clicking on the Save
126 // button vs. hitting the Enter key, as we prefer the "default"
127 // action to be search and not save.
128 var save_clicked
= false;
131 function validate(f
) {
132 // If save was not clicked then default to searching.
133 if (! save_clicked
) return dosearch();
134 save_clicked
= false;
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.';
148 top
.restoreSession();
156 <body
class="body_top" onunload
='imclosing()'>
158 // If we are saving, then save and close the window.
160 if ($_POST['form_save']) {
162 $ins_name = $_POST['form_name'];
165 // sql for updating could go here if this script is enhanced to support
166 // editing of existing insurance companies.
168 $ins_id = generate_id();
170 sqlInsert("INSERT INTO insurance_companies ( " .
171 "id, name, attn, cms_id, freeb_type, x12_receiver_id, x12_default_partner_id " .
174 "'" . $ins_name . "', " .
175 "'" . $_POST['form_attn'] . "', " .
176 "'" . $_POST['form_cms_id'] . "', " .
177 "'" . $_POST['form_freeb_type'] . "', " .
178 "'" . $_POST['form_partner'] . "', " .
179 "'" . $_POST['form_partner'] . "' " .
182 sqlInsert("INSERT INTO addresses ( " .
183 "id, line1, line2, city, state, zip, country, foreign_id " .
185 generate_id() . ", " .
186 "'" . $_POST['form_addr1'] . "', " .
187 "'" . $_POST['form_addr2'] . "', " .
188 "'" . $_POST['form_city'] . "', " .
189 "'" . $_POST['form_state'] . "', " .
190 "'" . $_POST['form_zip'] . "', " .
191 "'" . $_POST['form_country'] . "', " .
195 $phone_parts = array();
196 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
199 sqlInsert("INSERT INTO phone_numbers ( " .
200 "id, country_code, area_code, prefix, number, type, foreign_id " .
202 generate_id() . ", " .
204 "'" . $phone_parts[1] . "', " .
205 "'" . $phone_parts[2] . "', " .
206 "'" . $phone_parts[3] . "', " .
212 // Close this window and tell our opener to select the new company.
214 echo "<script language='JavaScript'>\n";
215 if ($info_msg) echo " alert('$info_msg');\n";
216 echo " parent.$.fn.fancybox.close();\n";
217 echo " top.restoreSession();\n";
218 echo " if (parent.set_insurance) parent.set_insurance($ins_id,'$ins_name');\n";
219 echo "</script></body></html>\n";
223 // Query x12_partners.
224 $xres = sqlStatement(
225 "SELECT id, name FROM x12_partners ORDER BY name"
228 <div id
="form_entry">
230 <form method
='post' name
='theform' action
='ins_search.php'
231 onsubmit
='return validate(this)'>
235 <table border
='0' width
='100%'>
239 <td valign
='top' width
='1%' nowrap
> 
;</td
>
241 Note
: Green fields are searchable
.
247 <td valign
='top' width
='1%' nowrap
><b
><?php
xl('Name','e');?
>:</b
></td
>
249 <input type
='text' size
='20' name
='form_name' maxlength
='35'
250 class='search' style
='width:100%' title
=<?php
xl('Name of insurance company','e');?
> />
255 <td valign
='top' nowrap
><b
><?php
xl('Attention','e');?
>:</b
></td
>
257 <input type
='text' size
='20' name
='form_attn' maxlength
='35'
258 class='search' style
='width:100%' title
=".xl('Contact name')." />
263 <td valign
='top' nowrap
><b
><?php
xl('Address1','e');?
>:</b
></td
>
265 <input type
='text' size
='20' name
='form_addr1' maxlength
='35'
266 class='search' style
='width:100%' title
='First address line' />
271 <td valign
='top' nowrap
><b
><?php
xl('Address2','e');?
>:</b
></td
>
273 <input type
='text' size
='20' name
='form_addr2' maxlength
='35'
274 class='search' style
='width:100%' title
='Second address line, if any' />
279 <td valign
='top' nowrap
><b
><?php
xl('City/State','e');?
>:</b
></td
>
281 <input type
='text' size
='20' name
='form_city' maxlength
='25'
282 class='search' title
='City name' />
284 <input type
='text' size
='3' name
='form_state' maxlength
='35'
285 class='search' title
='State or locality' />
290 <td valign
='top' nowrap
><b
><?php
xl('Zip/Country:','e'); ?
></b
></td
>
292 <input type
='text' size
='20' name
='form_zip' maxlength
='10'
293 class='search' title
='Postal code' />
295 <input type
='text' size
='20' name
='form_country' value
='USA' maxlength
='35'
296 title
='Country name' />
301 <td valign
='top' nowrap
><b
><?php
xl('Phone','e');?
>:</b
></td
>
303 <input type
='text' size
='20' name
='form_phone' maxlength
='20'
304 class='search' title
='Telephone number' />
310 <td valign
='top' width
='1%' nowrap
> 
;</td
>
312  
;<br
><b
>Other data
:</b
>
318 <td valign
='top' nowrap
><b
><?php
xl('CMS ID','e');?
>:</b
></td
>
320 <input type
='text' size
='20' name
='form_cms_id' maxlength
='15'
321 class='search' title
='Identifier assigned by CMS' />
326 <td valign
='top' nowrap
><b
><?php
xl('Payer Type','e');?
>:</b
></td
>
328 <select name
='form_freeb_type'>
330 for ($i = 1; $i < count($freeb_type_array); ++
$i) {
331 echo " <option value='$i'";
332 // if ($i == $row['freeb_type']) echo " selected";
333 echo ">" . $freeb_type_array[$i] . "\n";
341 <td valign
='top' nowrap
><b
><?php
xl('X12 Partner','e');?
>:</b
></td
>
343 <select name
='form_partner' title
='Default X12 Partner'>
344 <option value
=""><?php
xl('None','e','-- ',' --'); ?
></option
>
346 while ($xrow = sqlFetchArray($xres)) {
347 echo " <option value='" . $xrow['id'] . "'";
348 // if ($xrow['id'] == $row['x12_default_partner_id']) echo " selected";
349 echo ">" . $xrow['name'] . "</option>\n";
359 <input type
='button' value
='<?php xl('Search
','e
'); ?>' class='search' onclick
='dosearch()' />
361 <input type
='submit' value
='<?php xl('Save
as New','e
'); ?>' name
='form_save' onmousedown
='save_clicked=true' />
363 <input type
='button' value
='<?php xl('Cancel
','e
'); ?>' onclick
='parent.$.fn.fancybox.close();'/>