PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/interface/practice/ins_search.php

https://github.com/md-tech/openemr
PHP | 374 lines | 283 code | 54 blank | 37 comment | 16 complexity | ff459c05a121c29e4788812882161aea MD5 | raw file
  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.
  8. // This module is used to find and add insurance companies.
  9. // It is opened as a popup window. The opener may have a
  10. // JavaScript function named set_insurance(id, name), in which
  11. // case selecting or adding an insurance company will cause the
  12. // function to be called passing the ID and name of that company.
  13. // When used for searching, this module will in turn open another
  14. // popup window ins_list.php, which lists the matched results and
  15. // permits selection of one of them via the same set_insurance()
  16. // function.
  17. include_once("../globals.php");
  18. include_once("$srcdir/acl.inc");
  19. // Putting a message here will cause a popup window to display it.
  20. $info_msg = "";
  21. // This is copied from InsuranceCompany.class.php. It should
  22. // really be in a SQL table.
  23. $freeb_type_array = array(''
  24. , xl('Other HCFA')
  25. , xl('Medicare Part B')
  26. , xl('Medicaid')
  27. , xl('ChampUSVA')
  28. , xl('ChampUS')
  29. , xl('Blue Cross Blue Shield')
  30. , xl('FECA')
  31. , xl('Self Pay')
  32. , xl('Central Certification')
  33. , xl('Other Non-Federal Programs')
  34. , xl('Preferred Provider Organization (PPO)')
  35. , xl('Point of Service (POS)')
  36. , xl('Exclusive Provider Organization (EPO)')
  37. , xl('Indemnity Insurance')
  38. , xl('Health Maintenance Organization (HMO) Medicare Risk')
  39. , xl('Automobile Medical')
  40. , xl('Commercial Insurance Co.')
  41. , xl('Disability')
  42. , xl('Health Maintenance Organization')
  43. , xl('Liability')
  44. , xl('Liability Medical')
  45. , xl('Other Federal Program')
  46. , xl('Title V')
  47. , xl('Veterans Administration Plan')
  48. , xl('Workers Compensation Health Plan')
  49. , xl('Mutually Defined')
  50. );
  51. ?>
  52. <html>
  53. <head>
  54. <title><?php xl('Insurance Company Search/Add','e');?></title>
  55. <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
  56. <style>
  57. td { font-size:10pt; }
  58. .search { background-color:#aaffaa }
  59. #form_entry {
  60. display:block;
  61. }
  62. #form_list {
  63. display:none;
  64. }
  65. </style>
  66. <script type="text/javascript" src="../../library/topdialog.js"></script>
  67. <script type="text/javascript" src="../../library/dialog.js"></script>
  68. <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
  69. <script language="JavaScript">
  70. var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
  71. <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
  72. function doescape(value) {
  73. return encodeURIComponent(value);
  74. }
  75. // This is invoked when our Search button is clicked.
  76. function dosearch() {
  77. $("#form_entry").hide();
  78. var f = document.forms[0];
  79. var search_list = 'ins_list.php' +
  80. '?form_name=' + doescape(f.form_name.value ) +
  81. '&form_attn=' + doescape(f.form_attn.value ) +
  82. '&form_addr1=' + doescape(f.form_addr1.value ) +
  83. '&form_addr2=' + doescape(f.form_addr2.value ) +
  84. '&form_city=' + doescape(f.form_city.value ) +
  85. '&form_state=' + doescape(f.form_state.value ) +
  86. '&form_zip=' + doescape(f.form_zip.value ) +
  87. '&form_phone=' + doescape(f.form_phone.value ) +
  88. '&form_cms_id=' + doescape(f.form_cms_id.value);
  89. top.restoreSession();
  90. $("#form_list").load( search_list ).show();
  91. return false;
  92. }
  93. // The ins_list.php window calls this to set the selected insurance.
  94. function set_insurance(ins_id, ins_name) {
  95. if (opener.closed || ! opener.set_insurance)
  96. alert('The target form was closed; I cannot apply your selection.');
  97. else
  98. opener.set_insurance(ins_id, ins_name);
  99. parent.$.fn.fancybox.close();
  100. parent.location.reload();
  101. top.restoreSession();
  102. }
  103. // This is set to true on a mousedown of the Save button. The
  104. // reason is so we can distinguish between clicking on the Save
  105. // button vs. hitting the Enter key, as we prefer the "default"
  106. // action to be search and not save.
  107. var save_clicked = false;
  108. // Onsubmit handler.
  109. function validate(f) {
  110. // If save was not clicked then default to searching.
  111. if (! save_clicked) return dosearch();
  112. save_clicked = false;
  113. msg = '';
  114. if (! f.form_name.value.length ) msg += 'Company name is missing. ';
  115. if (! f.form_addr1.value.length) msg += 'Address is missing. ';
  116. if (! f.form_city.value.length ) msg += 'City is missing. ';
  117. if (! f.form_state.value.length) msg += 'State is missing. ';
  118. if (! f.form_zip.value.length ) msg += 'Zip is missing.';
  119. if (msg) {
  120. alert(msg);
  121. return false;
  122. }
  123. top.restoreSession();
  124. return true;
  125. }
  126. </script>
  127. </head>
  128. <body class="body_top" onunload='imclosing()'>
  129. <?php
  130. // If we are saving, then save and close the window.
  131. //
  132. if ($_POST['form_save']) {
  133. $ins_id = '';
  134. $ins_name = $_POST['form_name'];
  135. if ($ins_id) {
  136. // sql for updating could go here if this script is enhanced to support
  137. // editing of existing insurance companies.
  138. } else {
  139. $ins_id = generate_id();
  140. sqlInsert("INSERT INTO insurance_companies ( " .
  141. "id, name, attn, cms_id, freeb_type, x12_receiver_id, x12_default_partner_id " .
  142. ") VALUES ( " .
  143. $ins_id . ", " .
  144. "'" . $ins_name . "', " .
  145. "'" . $_POST['form_attn'] . "', " .
  146. "'" . $_POST['form_cms_id'] . "', " .
  147. "'" . $_POST['form_freeb_type'] . "', " .
  148. "'" . $_POST['form_partner'] . "', " .
  149. "'" . $_POST['form_partner'] . "' " .
  150. ")");
  151. sqlInsert("INSERT INTO addresses ( " .
  152. "id, line1, line2, city, state, zip, country, foreign_id " .
  153. ") VALUES ( " .
  154. generate_id() . ", " .
  155. "'" . $_POST['form_addr1'] . "', " .
  156. "'" . $_POST['form_addr2'] . "', " .
  157. "'" . $_POST['form_city'] . "', " .
  158. "'" . $_POST['form_state'] . "', " .
  159. "'" . $_POST['form_zip'] . "', " .
  160. "'" . $_POST['form_country'] . "', " .
  161. $ins_id . " " .
  162. ")");
  163. $phone_parts = array();
  164. preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/", $_POST['form_phone'],
  165. $phone_parts);
  166. sqlInsert("INSERT INTO phone_numbers ( " .
  167. "id, country_code, area_code, prefix, number, type, foreign_id " .
  168. ") VALUES ( " .
  169. generate_id() . ", " .
  170. "'+1'" . ", " .
  171. "'" . $phone_parts[1] . "', " .
  172. "'" . $phone_parts[2] . "', " .
  173. "'" . $phone_parts[3] . "', " .
  174. "'2'" . ", " .
  175. $ins_id . " " .
  176. ")");
  177. }
  178. // Close this window and tell our opener to select the new company.
  179. //
  180. echo "<script language='JavaScript'>\n";
  181. if ($info_msg) echo " alert('$info_msg');\n";
  182. echo " parent.$.fn.fancybox.close();\n";
  183. echo " top.restoreSession();\n";
  184. echo " if (parent.set_insurance) parent.set_insurance($ins_id,'$ins_name');\n";
  185. echo "</script></body></html>\n";
  186. exit();
  187. }
  188. // Query x12_partners.
  189. $xres = sqlStatement(
  190. "SELECT id, name FROM x12_partners ORDER BY name"
  191. );
  192. ?>
  193. <div id="form_entry">
  194. <form method='post' name='theform' action='ins_search.php'
  195. onsubmit='return validate(this)'>
  196. <center>
  197. <p>
  198. <table border='0' width='100%'>
  199. <!--
  200. <tr>
  201. <td valign='top' width='1%' nowrap>&nbsp;</td>
  202. <td>
  203. Note: Green fields are searchable.
  204. </td>
  205. </tr>
  206. -->
  207. <tr>
  208. <td valign='top' width='1%' nowrap><b><?php xl('Name','e');?>:</b></td>
  209. <td>
  210. <input type='text' size='20' name='form_name' maxlength='35'
  211. class='search' style='width:100%' title=<?php xl('Name of insurance company','e');?> />
  212. </td>
  213. </tr>
  214. <tr>
  215. <td valign='top' nowrap><b><?php xl('Attention','e');?>:</b></td>
  216. <td>
  217. <input type='text' size='20' name='form_attn' maxlength='35'
  218. class='search' style='width:100%' title=".xl('Contact name')." />
  219. </td>
  220. </tr>
  221. <tr>
  222. <td valign='top' nowrap><b><?php xl('Address1','e');?>:</b></td>
  223. <td>
  224. <input type='text' size='20' name='form_addr1' maxlength='35'
  225. class='search' style='width:100%' title='First address line' />
  226. </td>
  227. </tr>
  228. <tr>
  229. <td valign='top' nowrap><b><?php xl('Address2','e');?>:</b></td>
  230. <td>
  231. <input type='text' size='20' name='form_addr2' maxlength='35'
  232. class='search' style='width:100%' title='Second address line, if any' />
  233. </td>
  234. </tr>
  235. <tr>
  236. <td valign='top' nowrap><b><?php xl('City/State','e');?>:</b></td>
  237. <td>
  238. <input type='text' size='20' name='form_city' maxlength='25'
  239. class='search' title='City name' />
  240. &nbsp;
  241. <input type='text' size='3' name='form_state' maxlength='35'
  242. class='search' title='State or locality' />
  243. </td>
  244. </tr>
  245. <tr>
  246. <td valign='top' nowrap><b><?php xl('Zip/Country:','e'); ?></b></td>
  247. <td>
  248. <input type='text' size='20' name='form_zip' maxlength='10'
  249. class='search' title='Postal code' />
  250. &nbsp;
  251. <input type='text' size='20' name='form_country' value='USA' maxlength='35'
  252. title='Country name' />
  253. </td>
  254. </tr>
  255. <tr>
  256. <td valign='top' nowrap><b><?php xl('Phone','e');?>:</b></td>
  257. <td>
  258. <input type='text' size='20' name='form_phone' maxlength='20'
  259. class='search' title='Telephone number' />
  260. </td>
  261. </tr>
  262. <!--
  263. <tr>
  264. <td valign='top' width='1%' nowrap>&nbsp;</td>
  265. <td>
  266. &nbsp;<br><b>Other data:</b>
  267. </td>
  268. </tr>
  269. -->
  270. <tr>
  271. <td valign='top' nowrap><b><?php xl('CMS ID','e');?>:</b></td>
  272. <td>
  273. <input type='text' size='20' name='form_cms_id' maxlength='15'
  274. class='search' title='Identifier assigned by CMS' />
  275. </td>
  276. </tr>
  277. <tr>
  278. <td valign='top' nowrap><b><?php xl('Payer Type','e');?>:</b></td>
  279. <td>
  280. <select name='form_freeb_type'>
  281. <?php
  282. for ($i = 1; $i < count($freeb_type_array); ++$i) {
  283. echo " <option value='$i'";
  284. // if ($i == $row['freeb_type']) echo " selected";
  285. echo ">" . $freeb_type_array[$i] . "\n";
  286. }
  287. ?>
  288. </select>
  289. </td>
  290. </tr>
  291. <tr>
  292. <td valign='top' nowrap><b><?php xl('X12 Partner','e');?>:</b></td>
  293. <td>
  294. <select name='form_partner' title='Default X12 Partner'>
  295. <option value=""><?php xl('None','e','-- ',' --'); ?></option>
  296. <?php
  297. while ($xrow = sqlFetchArray($xres)) {
  298. echo " <option value='" . $xrow['id'] . "'";
  299. // if ($xrow['id'] == $row['x12_default_partner_id']) echo " selected";
  300. echo ">" . $xrow['name'] . "</option>\n";
  301. }
  302. ?>
  303. </select>
  304. </td>
  305. </tr>
  306. </table>
  307. <p>&nbsp;<br>
  308. <input type='button' value='<?php xl('Search','e'); ?>' class='search' onclick='dosearch()' />
  309. &nbsp;
  310. <input type='submit' value='<?php xl('Save as New','e'); ?>' name='form_save' onmousedown='save_clicked=true' />
  311. &nbsp;
  312. <input type='button' value='<?php xl('Cancel','e'); ?>' onclick='parent.$.fn.fancybox.close();'/>
  313. </p>
  314. </center>
  315. </form>
  316. </div>
  317. <div id="form_list">
  318. </div>
  319. </body>
  320. </html>