added popup insurance search/add
[openemr.git] / interface / practice / ins_search.php
blobc55d8c6179d80fef84448477b690e6a8b94a2d10
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 ,'Other HCFA'
30 ,'Medicare Part B'
31 ,'Medicaid'
32 ,'ChampUSVA'
33 ,'ChampUS'
34 ,'Blue Cross Blue Shield'
35 ,'FECA'
36 ,'Self Pay'
37 ,'Central Certification'
38 ,'Other Non-Federal Programs'
39 ,'Preferred Provider Organization (PPO)'
40 ,'Point of Service (POS)'
41 ,'Exclusive Provider Organization (EPO)'
42 ,'Indemnity Insurance'
43 ,'Health Maintenance Organization (HMO) Medicare Risk'
44 ,'Automobile Medical'
45 ,'Commercial Insurance Co.'
46 ,'Disability'
47 ,'Health Maintenance Organization'
48 ,'Liability'
49 ,'Liability Medical'
50 ,'Other Federal Program'
51 ,'Title V'
52 ,'Veterans Administration Plan'
53 ,'Workers Compensation Health Plan'
54 ,'Mutually Defined'
58 <html>
59 <head>
60 <title>Insurance Company Search/Add</title>
61 <link rel=stylesheet href='<? 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 = '<? echo $GLOBALS['phone_country_code'] ?>';
75 function doescape(value) {
76 return escape(value);
79 // This is invoked when our Search button is clicked.
80 function dosearch() {
81 var f = document.forms[0];
82 dlgopen('ins_list.php' +
83 '?form_name=' + doescape(f.form_name.value ) +
84 '&form_attn=' + doescape(f.form_attn.value ) +
85 '&form_addr1=' + doescape(f.form_addr1.value ) +
86 '&form_addr2=' + doescape(f.form_addr2.value ) +
87 '&form_city=' + doescape(f.form_city.value ) +
88 '&form_state=' + doescape(f.form_state.value ) +
89 '&form_zip=' + doescape(f.form_zip.value ) +
90 '&form_phone=' + doescape(f.form_phone.value ) +
91 '&form_cms_id=' + doescape(f.form_cms_id.value) +
92 '', '_blank', 780, 500);
94 return false;
97 // The ins_list.php window calls this to set the selected insurance.
98 function set_insurance(ins_id, ins_name) {
99 if (opener.closed || ! opener.set_insurance)
100 alert('The target form was closed; I cannot apply your selection.');
101 else
102 opener.set_insurance(ins_id, ins_name);
103 window.close();
106 // This is set to true on a mousedown of the Save button. The
107 // reason is so we can distinguish between clicking on the Save
108 // button vs. hitting the Enter key, as we prefer the "default"
109 // action to be search and not save.
110 var save_clicked = false;
112 // Onsubmit handler.
113 function validate(f) {
114 // If save was not clicked then default to searching.
115 if (! save_clicked) return dosearch();
116 save_clicked = false;
118 msg = '';
119 if (! f.form_name.value.length ) msg += 'Company name is missing. ';
120 if (! f.form_addr1.value.length) msg += 'Address is missing. ';
121 if (! f.form_city.value.length ) msg += 'City is missing. ';
122 if (! f.form_state.value.length) msg += 'State is missing. ';
123 if (! f.form_zip.value.length ) msg += 'Zip is missing.';
125 if (msg) {
126 alert(msg);
127 return false;
129 return true;
132 </script>
134 </head>
136 <body <?echo $top_bg_line;?> onunload='imclosing()'>
137 <?php
138 // If we are saving, then save and close the window.
140 if ($_POST['form_save']) {
141 $ins_id = '';
142 $ins_name = $_POST['form_name'];
144 if ($ins_id) {
145 // sql for updating could go here if this script is enhanced to support
146 // editing of existing insurance companies.
147 } else {
148 $ins_id = generate_id();
150 sqlInsert("INSERT INTO insurance_companies ( " .
151 "id, name, attn, cms_id, freeb_type, x12_receiver_id, x12_default_partner_id " .
152 ") VALUES ( " .
153 $ins_id . ", " .
154 "'" . $ins_name . "', " .
155 "'" . $_POST['form_attn'] . "', " .
156 "'" . $_POST['form_cms_id'] . "', " .
157 "'" . $_POST['form_freeb_type'] . "', " .
158 "'" . $_POST['form_partner'] . "', " .
159 "'" . $_POST['form_partner'] . "' " .
160 ")");
162 sqlInsert("INSERT INTO addresses ( " .
163 "id, line1, line2, city, state, zip, country, foreign_id " .
164 ") VALUES ( " .
165 generate_id() . ", " .
166 "'" . $_POST['form_addr1'] . "', " .
167 "'" . $_POST['form_addr2'] . "', " .
168 "'" . $_POST['form_city'] . "', " .
169 "'" . $_POST['form_state'] . "', " .
170 "'" . $_POST['form_zip'] . "', " .
171 "'" . $_POST['form_country'] . "', " .
172 $ins_id . " " .
173 ")");
175 $phone_parts = array();
176 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
177 $phone_parts);
179 sqlInsert("INSERT INTO phone_numbers ( " .
180 "id, country_code, area_code, prefix, number, type, foreign_id " .
181 ") VALUES ( " .
182 generate_id() . ", " .
183 "'+1'" . ", " .
184 "'" . $phone_parts[1] . "', " .
185 "'" . $phone_parts[2] . "', " .
186 "'" . $phone_parts[3] . "', " .
187 "'2'" . ", " .
188 $ins_id . " " .
189 ")");
192 // Close this window and tell our opener to select the new company.
194 echo "<script language='JavaScript'>\n";
195 if ($info_msg) echo " alert('$info_msg');\n";
196 echo " window.close();\n";
197 echo " if (opener.set_insurance) opener.set_insurance($ins_id,'$ins_name');\n";
198 echo "</script></body></html>\n";
199 exit();
202 // Query x12_partners.
203 $xres = sqlStatement(
204 "SELECT id, name FROM x12_partners ORDER BY name"
207 <form method='post' name='theform' action='ins_search.php'
208 onsubmit='return validate(this)'>
209 <center>
212 <table border='0' width='100%'>
214 <!--
215 <tr>
216 <td valign='top' width='1%' nowrap>&nbsp;</td>
217 <td>
218 Note: Green fields are searchable.
219 </td>
220 </tr>
223 <tr>
224 <td valign='top' width='1%' nowrap><b>Name:</b></td>
225 <td>
226 <input type='text' size='20' name='form_name' maxlength='35'
227 class='search' style='width:100%' title='Name of insurance company' />
228 </td>
229 </tr>
231 <tr>
232 <td valign='top' nowrap><b>Attention:</b></td>
233 <td>
234 <input type='text' size='20' name='form_attn' maxlength='35'
235 class='search' style='width:100%' title='Contact name' />
236 </td>
237 </tr>
239 <tr>
240 <td valign='top' nowrap><b>Address1:</b></td>
241 <td>
242 <input type='text' size='20' name='form_addr1' maxlength='35'
243 class='search' style='width:100%' title='First address line' />
244 </td>
245 </tr>
247 <tr>
248 <td valign='top' nowrap><b>Address2:</b></td>
249 <td>
250 <input type='text' size='20' name='form_addr2' maxlength='35'
251 class='search' style='width:100%' title='Second address line, if any' />
252 </td>
253 </tr>
255 <tr>
256 <td valign='top' nowrap><b>City/State:</b></td>
257 <td>
258 <input type='text' size='20' name='form_city' maxlength='25'
259 class='search' title='City name' />
260 &nbsp;
261 <input type='text' size='3' name='form_state' maxlength='35'
262 class='search' title='State or locality' />
263 </td>
264 </tr>
266 <tr>
267 <td valign='top' nowrap><b>Zip/Country:</b></td>
268 <td>
269 <input type='text' size='20' name='form_zip' maxlength='10'
270 class='search' title='Postal code' />
271 &nbsp;
272 <input type='text' size='20' name='form_country' value='USA' maxlength='35'
273 title='Country name' />
274 </td>
275 </tr>
277 <tr>
278 <td valign='top' nowrap><b>Phone:</b></td>
279 <td>
280 <input type='text' size='20' name='form_phone' maxlength='20'
281 class='search' title='Telephone number' />
282 </td>
283 </tr>
285 <!--
286 <tr>
287 <td valign='top' width='1%' nowrap>&nbsp;</td>
288 <td>
289 &nbsp;<br><b>Other data:</b>
290 </td>
291 </tr>
294 <tr>
295 <td valign='top' nowrap><b>CMS ID:</b></td>
296 <td>
297 <input type='text' size='20' name='form_cms_id' maxlength='15'
298 class='search' title='Identifier assigned by CMS' />
299 </td>
300 </tr>
302 <tr>
303 <td valign='top' nowrap><b>Payer Type:</b></td>
304 <td>
305 <select name='form_freeb_type'>
306 <?php
307 for ($i = 1; $i < count($freeb_type_array); ++$i) {
308 echo " <option value='$i'";
309 // if ($i == $row['freeb_type']) echo " selected";
310 echo ">" . $freeb_type_array[$i] . "\n";
313 </select>
314 </td>
315 </tr>
317 <tr>
318 <td valign='top' nowrap><b>X12 Partner:</b></td>
319 <td>
320 <select name='form_partner' title='Default X12 Partner'>
321 <option value="">-- None --</option>
322 <?php
323 while ($xrow = sqlFetchArray($xres)) {
324 echo " <option value='" . $xrow['id'] . "'";
325 // if ($xrow['id'] == $row['x12_default_partner_id']) echo " selected";
326 echo ">" . $xrow['name'] . "</option>\n";
329 </select>
330 </td>
331 </tr>
333 </table>
335 <p>&nbsp;<br>
336 <input type='button' value='Search' class='search' onclick='dosearch()' />
337 &nbsp;
338 <input type='submit' value='Save as New' name='form_save' onmousedown='save_clicked=true' />
339 &nbsp;
340 <input type='button' value='Cancel' onclick='window.close()' />
341 </p>
343 </center>
344 </form>
345 </body>
346 </html>