fix empty directory bug
[openemr.git] / interface / practice / ins_search.php
blob545c4620d7233108f0490806470ea2dc06e11b28
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 }
66 </style>
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) {
78 return escape(value);
81 // This is invoked when our Search button is clicked.
82 function dosearch() {
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);
96 return false;
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.');
103 else
104 opener.set_insurance(ins_id, ins_name);
105 window.close();
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;
114 // Onsubmit handler.
115 function validate(f) {
116 // If save was not clicked then default to searching.
117 if (! save_clicked) return dosearch();
118 save_clicked = false;
120 msg = '';
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.';
127 if (msg) {
128 alert(msg);
129 return false;
132 top.restoreSession();
133 return true;
136 </script>
138 </head>
140 <body class="body_top" onunload='imclosing()'>
141 <?php
142 // If we are saving, then save and close the window.
144 if ($_POST['form_save']) {
145 $ins_id = '';
146 $ins_name = $_POST['form_name'];
148 if ($ins_id) {
149 // sql for updating could go here if this script is enhanced to support
150 // editing of existing insurance companies.
151 } else {
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 " .
156 ") VALUES ( " .
157 $ins_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'] . "' " .
164 ")");
166 sqlInsert("INSERT INTO addresses ( " .
167 "id, line1, line2, city, state, zip, country, foreign_id " .
168 ") VALUES ( " .
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'] . "', " .
176 $ins_id . " " .
177 ")");
179 $phone_parts = array();
180 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
181 $phone_parts);
183 sqlInsert("INSERT INTO phone_numbers ( " .
184 "id, country_code, area_code, prefix, number, type, foreign_id " .
185 ") VALUES ( " .
186 generate_id() . ", " .
187 "'+1'" . ", " .
188 "'" . $phone_parts[1] . "', " .
189 "'" . $phone_parts[2] . "', " .
190 "'" . $phone_parts[3] . "', " .
191 "'2'" . ", " .
192 $ins_id . " " .
193 ")");
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";
203 exit();
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)'>
213 <center>
216 <table border='0' width='100%'>
218 <!--
219 <tr>
220 <td valign='top' width='1%' nowrap>&nbsp;</td>
221 <td>
222 Note: Green fields are searchable.
223 </td>
224 </tr>
227 <tr>
228 <td valign='top' width='1%' nowrap><b><?php xl('Name','e');?>:</b></td>
229 <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');?> />
232 </td>
233 </tr>
235 <tr>
236 <td valign='top' nowrap><b><?php xl('Attention','e');?>:</b></td>
237 <td>
238 <input type='text' size='20' name='form_attn' maxlength='35'
239 class='search' style='width:100%' title=".xl('Contact name')." />
240 </td>
241 </tr>
243 <tr>
244 <td valign='top' nowrap><b><?php xl('Address1','e');?>:</b></td>
245 <td>
246 <input type='text' size='20' name='form_addr1' maxlength='35'
247 class='search' style='width:100%' title='First address line' />
248 </td>
249 </tr>
251 <tr>
252 <td valign='top' nowrap><b><?php xl('Address2','e');?>:</b></td>
253 <td>
254 <input type='text' size='20' name='form_addr2' maxlength='35'
255 class='search' style='width:100%' title='Second address line, if any' />
256 </td>
257 </tr>
259 <tr>
260 <td valign='top' nowrap><b><?php xl('City/State','e');?>:</b></td>
261 <td>
262 <input type='text' size='20' name='form_city' maxlength='25'
263 class='search' title='City name' />
264 &nbsp;
265 <input type='text' size='3' name='form_state' maxlength='35'
266 class='search' title='State or locality' />
267 </td>
268 </tr>
270 <tr>
271 <td valign='top' nowrap><b><?php xl('Zip/Country:','e'); ?></b></td>
272 <td>
273 <input type='text' size='20' name='form_zip' maxlength='10'
274 class='search' title='Postal code' />
275 &nbsp;
276 <input type='text' size='20' name='form_country' value='USA' maxlength='35'
277 title='Country name' />
278 </td>
279 </tr>
281 <tr>
282 <td valign='top' nowrap><b><?php xl('Phone','e');?>:</b></td>
283 <td>
284 <input type='text' size='20' name='form_phone' maxlength='20'
285 class='search' title='Telephone number' />
286 </td>
287 </tr>
289 <!--
290 <tr>
291 <td valign='top' width='1%' nowrap>&nbsp;</td>
292 <td>
293 &nbsp;<br><b>Other data:</b>
294 </td>
295 </tr>
298 <tr>
299 <td valign='top' nowrap><b><?php xl('CMS ID','e');?>:</b></td>
300 <td>
301 <input type='text' size='20' name='form_cms_id' maxlength='15'
302 class='search' title='Identifier assigned by CMS' />
303 </td>
304 </tr>
306 <tr>
307 <td valign='top' nowrap><b><?php xl('Payer Type','e');?>:</b></td>
308 <td>
309 <select name='form_freeb_type'>
310 <?php
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";
317 </select>
318 </td>
319 </tr>
321 <tr>
322 <td valign='top' nowrap><b><?php xl('X12 Partner','e');?>:</b></td>
323 <td>
324 <select name='form_partner' title='Default X12 Partner'>
325 <option value=""><?php xl('None','e','-- ',' --'); ?></option>
326 <?php
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";
333 </select>
334 </td>
335 </tr>
337 </table>
339 <p>&nbsp;<br>
340 <input type='button' value='<?php xl('Search','e'); ?>' class='search' onclick='dosearch()' />
341 &nbsp;
342 <input type='submit' value='<?php xl('Save as New','e'); ?>' name='form_save' onmousedown='save_clicked=true' />
343 &nbsp;
344 <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='window.close()' />
345 </p>
347 </center>
348 </form>
349 </body>
350 </html>