Portal Updates for Usability study, UI/UX and bug fixes. (#7556)
[openemr.git] / interface / practice / ins_list.php
blobecea8b541c0927034de791dab63197810278a307
1 <?php
3 /**
4 * The purpose of this module is to show a list of insurance
5 * companies that match the passed-in search strings, and to allow
6 * one of them to be selected.
8 * @package OpenEMR
9 * @link https://www.open-emr.org
10 * @author Rod Roark <rod@sunsetsystems.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @author Stephen Waite <stephen.waite@cmsvt.com>
13 * @author Stephen Nielson <snielson@discoverandchange.com>
14 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
15 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
16 * @copyright Copyright (c) 2021 Stephen Waite <stephen.waite@cmsvt.com>
17 * @copyright Copyright (c) 2024 Care Management Solutions, Inc. <stephen.waite@cmsvt.com>
18 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 require_once("../globals.php");
23 use OpenEMR\Common\Csrf\CsrfUtils;
24 use OpenEMR\Core\Header;
26 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
27 CsrfUtils::csrfNotVerified();
31 // Putting a message here will cause a popup window to display it.
32 $info_msg = "";
34 function addwhere($where, $colname, $value)
36 if ($value) {
37 $where .= " AND ";
38 $where .= "$colname LIKE '%" . add_escape_custom($value) . "%'";
41 return $where;
44 // The following code builds the appropriate SQL query from the
45 // search parameters passed by our opener (ins_search.php).
47 $where = '';
48 $where = addwhere($where, 'i.name', $_GET['form_name']);
49 $where = addwhere($where, 'i.attn', $_GET['form_attn']);
50 $where = addwhere($where, 'i.cms_id', $_GET['form_cms_id']);
51 $where = addwhere($where, 'a.line1', $_GET['form_addr1']);
52 $where = addwhere($where, 'a.line2', $_GET['form_addr2']);
53 $where = addwhere($where, 'a.city', $_GET['form_city']);
54 $where = addwhere($where, 'a.state', $_GET['form_state']);
55 $where = addwhere($where, 'a.zip', $_GET['form_zip']);
57 $phone_parts = array();
58 $area_code = null;
59 $prefix = null;
60 $digits = null;
62 // Search by area code if there is one.
63 if (
64 preg_match(
65 "/(\d\d\d)/",
66 $_GET['form_phone'],
67 $phone_parts
69 ) {
70 $area_code = $phone_parts[1];
71 $where = addwhere($where, 'p.area_code', $area_code);
74 // If there is also an exchange, search for that too.
75 if (
76 preg_match(
77 "/\d\d\d\D*(\d\d\d)/",
78 $_GET['form_phone'],
79 $phone_parts
81 ) {
82 $prefix = $phone_parts[1];
83 $where = addwhere($where, 'p.prefix', $prefix);
86 // If the last 4 phone number digits are given, search for that too.
87 if (
88 preg_match(
89 "/\d\d\d\D*\d\d\d\D*(\d\d\d\d)/",
90 $_GET['form_phone'],
91 $phone_parts
93 ) {
94 $digits = $phone_parts[1];
95 $where = addwhere($where, 'p.number', $digits);
98 $query = "SELECT " .
99 "i.id, i.name, i.attn, " .
100 "a.line1, a.line2, a.city, a.state, a.zip, " .
101 "p.area_code, p.prefix, p.number " .
102 "FROM insurance_companies i " .
103 "LEFT JOIN addresses a ON a.foreign_id = i.id " .
104 "LEFT JOIN phone_numbers p ON p.foreign_id = i.id WHERE 1=1 ";
106 $query .= $where . " ORDER BY i.name, a.zip";
107 $res = sqlStatement($query);
109 <html>
110 <head>
111 <title><?php echo xlt('List Insurance Companies');?></title>
112 <?php Header::setupHeader(); ?>
114 <style>
115 td {
116 font-size: 0.8125rem;
118 </style>
120 <script>
122 // This is invoked when an insurance company name is clicked.
123 function setins(ins_id, ins_name) {
124 if (!window.opener) {
125 return; // nothing to do here as somehow we got here without the opener
127 let postMessage = {
128 action: 'insurance-search-set-insurance'
129 ,insuranceId: ins_id
130 ,insuranceName: ins_name
132 // fire off a message so we can decouple things so we don't have to have a specific function
133 // name in the global scope of the opener
134 opener.postMessage(postMessage, window.location.origin);
135 if (opener.closed) {
136 alert('The target form was closed; I cannot apply your selection.');
138 else if (opener.set_insurance) {
139 opener.set_insurance(ins_id, ins_name);
140 dlgclose();
141 } else {
142 // if we don't have a set_insurance function then we will just close the window as the opener is
143 // using post message to receive events.
144 dlgclose();
146 return false;
149 </script>
151 </head>
153 <body class="body_top">
154 <form method='post' name='theform'>
155 <center>
157 <table class="table table-sm border-0 w-100">
158 <tr>
159 <td class='font-weight-bold'><?php echo xlt('Name');?>&nbsp;</td>
160 <td class='font-weight-bold'><?php echo xlt('Attn');?>&nbsp;</td>
161 <td class='font-weight-bold'><?php echo xlt('Address');?>&nbsp;</td>
162 <td class='font-weight-bold'>&nbsp;&nbsp;</td>
163 <td class='font-weight-bold'><?php echo xlt('City');?>&nbsp;</td>
164 <td class='font-weight-bold'><?php echo xlt('State');?>&nbsp;</td>
165 <td class='font-weight-bold'><?php echo xlt('Zip');?>&nbsp;</td>
166 <td class='font-weight-bold'><?php echo xlt('Phone');?></td>
167 </tr>
169 <?php
170 if (empty($res->_numOfRows)) {
171 echo " <td>" . xlt('No matches found.') . "</td>";
173 while ($row = sqlFetchArray($res)) {
174 $anchor = "<a href=\"\" onclick=\"return setins(" .
175 attr_js($row['id']) . "," . attr_js($row['name']) . ")\">";
176 $phone = '&nbsp';
177 if ($row['number'] ?? null) {
178 $phone = text($row['area_code']) . '-' . text($row['prefix']) . '-' . text($row['number']);
181 echo " <tr>\n";
182 echo " <td valign='top'>$anchor" . text($row['name']) . "</a>&nbsp;</td>\n";
183 echo " <td valign='top'>" . text($row['attn']) . "&nbsp;</td>\n";
184 echo " <td valign='top'>" . text($row['line1']) . "&nbsp;</td>\n";
185 echo " <td valign='top'>" . text($row['line2']) . "&nbsp;</td>\n";
186 echo " <td valign='top'>" . text($row['city']) . "&nbsp;</td>\n";
187 echo " <td valign='top'>" . text($row['state']) . "&nbsp;</td>\n";
188 echo " <td valign='top'>" . text($row['zip']) . "&nbsp;</td>\n";
189 echo " <td valign='top'>" . $phone . "</td>\n";
191 echo " </tr>\n";
193 </table>
195 </center>
196 </form>
197 </body>
198 </html>