fixed color for facility style calendar
[openemr.git] / interface / practice / ins_search.php
blob47aa4c4112ee65bbecf4d3269ddb61bd1fd048fc
1 <?php
2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
3 //
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()
18 // function.
20 include_once("../globals.php");
21 include_once("$srcdir/acl.inc");
23 // Putting a message here will cause a popup window to display it.
24 $info_msg = "";
26 // This is copied from InsuranceCompany.class.php. It should
27 // really be in a SQL table.
28 $freeb_type_array = array(''
29 , xl('Other HCFA')
30 , xl('Medicare Part B')
31 , xl('Medicaid')
32 , xl('ChampUSVA')
33 , xl('ChampUS')
34 , xl('Blue Cross Blue Shield')
35 , xl('FECA')
36 , xl('Self Pay')
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.')
46 , xl('Disability')
47 , xl('Health Maintenance Organization')
48 , xl('Liability')
49 , xl('Liability Medical')
50 , xl('Other Federal Program')
51 , xl('Title V')
52 , xl('Veterans Administration Plan')
53 , xl('Workers Compensation Health Plan')
54 , xl('Mutually Defined')
58 <html>
59 <head>
60 <title><?php xl('Insurance Company Search/Add','e');?></title>
61 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
63 <style>
64 td { font-size:10pt; }
65 .search { background-color:#aaffaa }
67 #form_entry {
68 display:block;
71 #form_list {
72 display:none;
75 </style>
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.
92 function dosearch() {
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();
110 return false;
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.');
117 else
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;
130 // Onsubmit handler.
131 function validate(f) {
132 // If save was not clicked then default to searching.
133 if (! save_clicked) return dosearch();
134 save_clicked = false;
136 msg = '';
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.';
143 if (msg) {
144 alert(msg);
145 return false;
148 top.restoreSession();
149 return true;
152 </script>
154 </head>
156 <body class="body_top" onunload='imclosing()'>
157 <?php
158 // If we are saving, then save and close the window.
160 if ($_POST['form_save']) {
161 $ins_id = '';
162 $ins_name = $_POST['form_name'];
164 if ($ins_id) {
165 // sql for updating could go here if this script is enhanced to support
166 // editing of existing insurance companies.
167 } else {
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 " .
172 ") VALUES ( " .
173 $ins_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'] . "' " .
180 ")");
182 sqlInsert("INSERT INTO addresses ( " .
183 "id, line1, line2, city, state, zip, country, foreign_id " .
184 ") VALUES ( " .
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'] . "', " .
192 $ins_id . " " .
193 ")");
195 $phone_parts = array();
196 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
197 $phone_parts);
199 sqlInsert("INSERT INTO phone_numbers ( " .
200 "id, country_code, area_code, prefix, number, type, foreign_id " .
201 ") VALUES ( " .
202 generate_id() . ", " .
203 "'+1'" . ", " .
204 "'" . $phone_parts[1] . "', " .
205 "'" . $phone_parts[2] . "', " .
206 "'" . $phone_parts[3] . "', " .
207 "'2'" . ", " .
208 $ins_id . " " .
209 ")");
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";
220 exit();
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)'>
232 <center>
235 <table border='0' width='100%'>
237 <!--
238 <tr>
239 <td valign='top' width='1%' nowrap>&nbsp;</td>
240 <td>
241 Note: Green fields are searchable.
242 </td>
243 </tr>
246 <tr>
247 <td valign='top' width='1%' nowrap><b><?php xl('Name','e');?>:</b></td>
248 <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');?> />
251 </td>
252 </tr>
254 <tr>
255 <td valign='top' nowrap><b><?php xl('Attention','e');?>:</b></td>
256 <td>
257 <input type='text' size='20' name='form_attn' maxlength='35'
258 class='search' style='width:100%' title=".xl('Contact name')." />
259 </td>
260 </tr>
262 <tr>
263 <td valign='top' nowrap><b><?php xl('Address1','e');?>:</b></td>
264 <td>
265 <input type='text' size='20' name='form_addr1' maxlength='35'
266 class='search' style='width:100%' title='First address line' />
267 </td>
268 </tr>
270 <tr>
271 <td valign='top' nowrap><b><?php xl('Address2','e');?>:</b></td>
272 <td>
273 <input type='text' size='20' name='form_addr2' maxlength='35'
274 class='search' style='width:100%' title='Second address line, if any' />
275 </td>
276 </tr>
278 <tr>
279 <td valign='top' nowrap><b><?php xl('City/State','e');?>:</b></td>
280 <td>
281 <input type='text' size='20' name='form_city' maxlength='25'
282 class='search' title='City name' />
283 &nbsp;
284 <input type='text' size='3' name='form_state' maxlength='35'
285 class='search' title='State or locality' />
286 </td>
287 </tr>
289 <tr>
290 <td valign='top' nowrap><b><?php xl('Zip/Country:','e'); ?></b></td>
291 <td>
292 <input type='text' size='20' name='form_zip' maxlength='10'
293 class='search' title='Postal code' />
294 &nbsp;
295 <input type='text' size='20' name='form_country' value='USA' maxlength='35'
296 title='Country name' />
297 </td>
298 </tr>
300 <tr>
301 <td valign='top' nowrap><b><?php xl('Phone','e');?>:</b></td>
302 <td>
303 <input type='text' size='20' name='form_phone' maxlength='20'
304 class='search' title='Telephone number' />
305 </td>
306 </tr>
308 <!--
309 <tr>
310 <td valign='top' width='1%' nowrap>&nbsp;</td>
311 <td>
312 &nbsp;<br><b>Other data:</b>
313 </td>
314 </tr>
317 <tr>
318 <td valign='top' nowrap><b><?php xl('CMS ID','e');?>:</b></td>
319 <td>
320 <input type='text' size='20' name='form_cms_id' maxlength='15'
321 class='search' title='Identifier assigned by CMS' />
322 </td>
323 </tr>
325 <tr>
326 <td valign='top' nowrap><b><?php xl('Payer Type','e');?>:</b></td>
327 <td>
328 <select name='form_freeb_type'>
329 <?php
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";
336 </select>
337 </td>
338 </tr>
340 <tr>
341 <td valign='top' nowrap><b><?php xl('X12 Partner','e');?>:</b></td>
342 <td>
343 <select name='form_partner' title='Default X12 Partner'>
344 <option value=""><?php xl('None','e','-- ',' --'); ?></option>
345 <?php
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";
352 </select>
353 </td>
354 </tr>
356 </table>
358 <p>&nbsp;<br>
359 <input type='button' value='<?php xl('Search','e'); ?>' class='search' onclick='dosearch()' />
360 &nbsp;
361 <input type='submit' value='<?php xl('Save as New','e'); ?>' name='form_save' onmousedown='save_clicked=true' />
362 &nbsp;
363 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='parent.$.fn.fancybox.close();'/>
364 </p>
366 </center>
367 </form>
368 </div>
370 <div id="form_list">
371 </div>
373 </body>
374 </html>