added popup insurance search/add
[openemr.git] / interface / practice / ins_list.php
blobc34cdc39f452e870ef4d0c39f8d62fc65cff82e9
1 <?
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 // The purpose of this module is to show a list of insurance
10 // companies that match the passed-in search strings, and to allow
11 // one of them to be selected.
13 include_once("../globals.php");
15 // Putting a message here will cause a popup window to display it.
16 $info_msg = "";
18 function addwhere($where, $colname, $value) {
19 if ($value) {
20 $where .= " AND ";
21 $where .= "$colname LIKE '%$value%'";
23 return $where;
26 // The following code builds the appropriate SQL query from the
27 // search parameters passed by our opener (ins_search.php).
29 $where = '';
30 $where = addwhere($where, 'i.name' , $_REQUEST['form_name'] );
31 $where = addwhere($where, 'i.attn' , $_REQUEST['form_attn'] );
32 $where = addwhere($where, 'i.cms_id', $_REQUEST['form_cms_id']);
33 $where = addwhere($where, 'a.line1' , $_REQUEST['form_addr1'] );
34 $where = addwhere($where, 'a.line2' , $_REQUEST['form_addr2'] );
35 $where = addwhere($where, 'a.city' , $_REQUEST['form_city'] );
36 $where = addwhere($where, 'a.state' , $_REQUEST['form_state'] );
37 $where = addwhere($where, 'a.zip' , $_REQUEST['form_zip'] );
39 $phone_parts = array();
41 // Search by area code if there is one.
42 if (preg_match("/(\d\d\d)/",
43 $_REQUEST['form_phone'], $phone_parts))
44 $where = addwhere($where, 'p.area_code', $phone_parts[1]);
46 // If there is also an exchange, search for that too.
47 if (preg_match("/\d\d\d\D*(\d\d\d)/",
48 $_REQUEST['form_phone'], $phone_parts))
49 $where = addwhere($where, 'p.prefix', $phone_parts[1]);
51 // If the last 4 phone number digits are given, search for that too.
52 if (preg_match("/\d\d\d\D*\d\d\d\D*(\d\d\d\d)/",
53 $_REQUEST['form_phone'], $phone_parts))
54 $where = addwhere($where, 'p.number', $phone_parts[1]);
56 $query = "SELECT " .
57 "i.id, i.name, i.attn, " .
58 "a.line1, a.line2, a.city, a.state, a.zip, " .
59 "p.area_code, p.prefix, p.number " .
60 "FROM insurance_companies AS i, addresses AS a, phone_numbers AS p " .
61 "WHERE a.foreign_id = i.id AND p.foreign_id = i.id$where " .
62 "ORDER BY i.name, a.zip";
63 $res = sqlStatement($query);
65 <html>
66 <head>
67 <title>List Insurance Companies</title>
68 <link rel=stylesheet href='<? echo $css_header ?>' type='text/css'>
70 <style>
71 td { font-size:10pt; }
72 </style>
74 <script language="JavaScript">
76 // This is invoked when an insurance company name is clicked.
77 function setins(ins_id, ins_name) {
78 if (opener.closed || ! opener.set_insurance)
79 alert('The parent window was closed; I cannot apply your selection.');
80 else
81 opener.set_insurance(ins_id, ins_name);
82 window.close();
83 return false;
86 </script>
88 </head>
90 <body <?echo $top_bg_line;?>>
91 <form method='post' name='theform'>
92 <center>
94 <table border='0' width='100%'>
95 <tr>
96 <td><b>Name</b>&nbsp;</td>
97 <td><b>Attn</b>&nbsp;</td>
98 <td><b>Address</b>&nbsp;</td>
99 <td><b>&nbsp;</b>&nbsp;</td>
100 <td><b>City</b>&nbsp;</td>
101 <td><b>State</b>&nbsp;</td>
102 <td><b>Zip</b>&nbsp;</td>
103 <td><b>Phone</b></td>
104 </tr>
107 while ($row = sqlFetchArray($res)) {
108 $anchor = "<a href=\"\" onclick=\"return setins(" .
109 $row['id'] . ",'" . addslashes($row['name']) . "')\">";
110 $phone = '&nbsp';
111 if ($row['number']) {
112 $phone = $row['area_code'] . '-' . $row['prefix'] . '-' . $row['number'];
114 echo " <tr>\n";
115 echo " <td valign='top'>$anchor" . $row['name'] . "</a>&nbsp;</td>\n";
116 echo " <td valign='top'>" . $row['attn'] . "&nbsp;</td>\n";
117 echo " <td valign='top'>" . $row['line1'] . "&nbsp;</td>\n";
118 echo " <td valign='top'>" . $row['line2'] . "&nbsp;</td>\n";
119 echo " <td valign='top'>" . $row['city'] . "&nbsp;</td>\n";
120 echo " <td valign='top'>" . $row['state'] . "&nbsp;</td>\n";
121 echo " <td valign='top'>" . $row['zip'] . "&nbsp;</td>\n";
122 echo " <td valign='top'>$phone</td>\n";
123 echo " </tr>\n";
126 </table>
128 </center>
129 </form>
130 </body>
131 </html>