More complete support for activity flag in list_options table. (#274)
[openemr.git] / interface / cmsportal / insurance_form.php
blobc4e9e5488bef6466dadb398e16ca7f1a8b74b621
1 <?php
2 /**
3 * Insurance form posting for the WordPress Patient Portal.
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Rod Roark <rod@sunsetsystems.com>
20 $sanitize_all_escapes = true;
21 $fake_register_globals = false;
23 require_once("../globals.php");
24 require_once("$srcdir/patient.inc");
25 require_once("$srcdir/formdata.inc.php");
26 require_once("$srcdir/options.inc.php");
27 require_once("portal.inc.php");
29 // Consider this a step towards converting the insurance form to layout-based.
30 // Faking it here makes things easier.
31 // Also note that some fields like SSN and most of the subscriber employer
32 // items have been omitted because they are not relevant for claims.
34 $insurance_layout = array(
35 array('field_id' => 'type',
36 'title' => 'Type',
37 'uor' => '2',
38 'data_type' => '1',
39 'list_id' => 'insurance_types',
40 'edit_options' => '',
42 array('field_id' => 'date',
43 'title' => 'Effective Date',
44 'uor' => '2',
45 'data_type' => '4', // Text-date
46 'list_id' => '',
47 'edit_options' => '',
49 array('field_id' => 'provider',
50 'title' => 'Provider',
51 'uor' => '2',
52 'data_type' => '16', // Insurance Providers
53 'list_id' => '',
54 'edit_options' => '',
56 array('field_id' => 'plan_name',
57 'title' => 'Plan Name',
58 'uor' => '1',
59 'data_type' => '2', // Text
60 'list_id' => '',
61 'edit_options' => '',
63 array('field_id' => 'policy_number',
64 'title' => 'Policy Number',
65 'uor' => '1',
66 'data_type' => '2', // Text
67 'list_id' => '',
68 'edit_options' => '',
70 array('field_id' => 'group_number',
71 'title' => 'Group Number',
72 'uor' => '1',
73 'data_type' => '2', // Text
74 'list_id' => '',
75 'edit_options' => '',
77 array('field_id' => 'subscriber_employer',
78 'title' => 'Group Name',
79 'uor' => '1',
80 'data_type' => '2', // Text
81 'list_id' => '',
82 'edit_options' => '',
84 array('field_id' => 'subscriber_lname',
85 'title' => 'Subscriber Last Name',
86 'uor' => '2',
87 'data_type' => '2', // Text
88 'list_id' => '',
89 'edit_options' => '',
91 array('field_id' => 'subscriber_fname',
92 'title' => 'Subscriber First Name',
93 'uor' => '1',
94 'data_type' => '2', // Text
95 'list_id' => '',
96 'edit_options' => '',
98 array('field_id' => 'subscriber_mname',
99 'title' => 'Subscriber Middle Name',
100 'uor' => '1',
101 'data_type' => '2', // Text
102 'list_id' => '',
103 'edit_options' => '',
105 array('field_id' => 'subscriber_DOB',
106 'title' => 'Subscriber DOB',
107 'uor' => '2',
108 'data_type' => '4', // Text-date
109 'list_id' => '',
110 'edit_options' => '',
112 array('field_id' => 'subscriber_sex',
113 'title' => 'Subscriber Sex',
114 'uor' => '2',
115 'data_type' => '1', // List
116 'list_id' => 'sex',
117 'edit_options' => '',
119 array('field_id' => 'subscriber_relationship',
120 'title' => 'Subscriber Relationship',
121 'uor' => '2',
122 'data_type' => '1', // List
123 'list_id' => 'sub_relation',
124 'edit_options' => '',
126 array('field_id' => 'subscriber_street',
127 'title' => 'Subscriber Street',
128 'uor' => '1',
129 'data_type' => '2', // Text
130 'list_id' => '',
131 'edit_options' => '',
133 array('field_id' => 'subscriber_city',
134 'title' => 'Subscriber City',
135 'uor' => '1',
136 'data_type' => '2', // Text
137 'list_id' => '',
138 'edit_options' => '',
140 array('field_id' => 'subscriber_state',
141 'title' => 'Subscriber State',
142 'uor' => '1',
143 'data_type' => '1', // List
144 'list_id' => 'state',
145 'edit_options' => '',
147 array('field_id' => 'subscriber_postal_code',
148 'title' => 'Subscriber Zip',
149 'uor' => '1',
150 'data_type' => '2', // Text
151 'list_id' => '',
152 'edit_options' => '',
154 array('field_id' => 'subscriber_phone',
155 'title' => 'Subscriber Phone',
156 'uor' => '1',
157 'data_type' => '2', // Text
158 'list_id' => '',
159 'edit_options' => '',
163 $postid = intval($_REQUEST['postid']);
165 if ($_POST['bn_save']) {
166 $newdata = array();
167 $ptid = intval($_POST['ptid']);
168 foreach ($insurance_layout as $frow) {
169 $data_type = $frow['data_type'];
170 $field_id = $frow['field_id'];
171 // newInsuranceData() does not escape for mysql so we have to do it here.
172 $newdata[$field_id] = add_escape_custom(get_layout_form_value($frow));
174 newInsuranceData(
175 $ptid,
176 $newdata['type'],
177 $newdata['provider'],
178 $newdata['policy_number'],
179 $newdata['group_number'],
180 $newdata['plan_name'],
181 $newdata['subscriber_lname'],
182 $newdata['subscriber_mname'],
183 $newdata['subscriber_fname'],
184 $newdata['subscriber_relationship'],
185 '', // subscriber_ss
186 fixDate($newdata['subscriber_DOB']),
187 $newdata['subscriber_street'],
188 $newdata['subscriber_postal_code'],
189 $newdata['subscriber_city'],
190 $newdata['subscriber_state'],
191 '', // subscriber_country
192 $newdata['subscriber_phone'],
193 $newdata['subscriber_employer'],
194 '', // subscriber_employer_street
195 '', // subscriber_employer_city
196 '', // subscriber_employer_postal_code
197 '', // subscriber_employer_state
198 '', // subscriber_employer_country
199 '', // copay
200 $newdata['subscriber_sex'],
201 fixDate($newdata['date']),
202 'TRUE', // accept_assignment
203 '' // policy_type
205 // Finally, delete the request from the portal.
206 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
207 if ($result['errmsg']) {
208 die(text($result['errmsg']));
210 echo "<html><body><script language='JavaScript'>\n";
211 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
212 echo "document.location.href = 'list_requests.php';\n";
213 echo "</script></body></html>\n";
214 exit();
217 // Get the portal request data.
218 if (!$postid) die(xlt('Request ID is missing!'));
219 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
220 if ($result['errmsg']) {
221 die(text($result['errmsg']));
224 // Look up the patient in OpenEMR.
225 $ptid = lookup_openemr_patient($result['post']['user']);
227 <html>
228 <head>
229 <?php html_header_show(); ?>
230 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
232 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
233 <style>
235 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
236 tr.detail { font-size:10pt; background-color:#ddddff; }
237 td input { background-color:transparent; }
239 </style>
241 <script type="text/javascript" src="../../library/textformat.js"></script>
242 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
243 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
244 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
245 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
247 <script language="JavaScript">
249 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
251 function myRestoreSession() {
252 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
253 return true;
256 // This capitalizes the first letter of each word in the passed input
257 // element. It also strips out extraneous spaces.
258 // Copied from demographics_full.php.
259 function capitalizeMe(elem) {
260 var a = elem.value.split(' ');
261 var s = '';
262 for(var i = 0; i < a.length; ++i) {
263 if (a[i].length > 0) {
264 if (s.length > 0) s += ' ';
265 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
268 elem.value = s;
271 function validate() {
272 var f = document.forms[0];
273 // TBD
274 return true;
277 </script>
278 </head>
280 <body class="body_top">
281 <center>
283 <form method='post' action='insurance_form.php' onsubmit='return validate()'>
285 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
286 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
288 <table width='100%' cellpadding='1' cellspacing='2'>
289 <tr class='head'>
290 <th align='left'><?php echo xlt('Field' ); ?></th>
291 <th align='left'><?php echo xlt('Current Value'); ?></th>
292 <th align='left'><?php echo xlt('New Value' ); ?></th>
293 </tr>
295 <?php
296 $insrow = getInsuranceData($pid, $result['fields']['type']);
298 foreach ($insurance_layout as $lorow) {
299 $data_type = $lorow['data_type'];
300 $field_id = $lorow['field_id'];
302 $list_id = $lorow['list_id'];
303 $field_title = $lorow['title'];
305 $currvalue = '';
306 if (isset($insrow[$field_id])) $currvalue = $insrow[$field_id];
308 $newvalue = '';
309 if (isset($result['fields'][$field_id])) $newvalue = trim($result['fields'][$field_id]);
311 // Translate $newvalue for certain field types including lists.
312 if ($newvalue !== '') {
313 if ($list_id) {
314 $tmp = sqlQuery("SELECT option_id FROM list_options WHERE " .
315 "list_id = ? AND title = ? AND activity = 1 ORDER BY option_id LIMIT 1",
316 array($list_id, $newvalue));
317 if (isset($tmp['option_id'])) $newvalue = $tmp['option_id'];
319 // Some data types like insurance provider are pretty hopeless, so let the display
320 // logic generate a "Fix me" message and the user can translate it.
323 echo " <tr class='detail'>\n";
324 echo " <td class='bold'>" . text($field_title) . "</td>\n";
325 echo " <td>";
326 echo generate_display_field($lorow, $currvalue);
327 echo "</td>\n";
328 echo " <td>";
329 generate_form_field($lorow, $newvalue);
330 echo "</td>\n";
331 echo " </tr>\n";
335 </table>
338 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
339 &nbsp;
340 <input type='button' value='<?php echo xla('Back'); ?>' onclick="window.history.back()" />
341 <!-- Was: onclick="myRestoreSession();location='list_requests.php'" -->
342 </p>
344 </form>
346 <script language="JavaScript">
348 // Fix inconsistently formatted phone numbers from the database.
349 var f = document.forms[0];
350 if (f.form_phone) phonekeyup(f.form_phone, mypcc);
352 // This is a by-product of generate_form_field().
353 <?php echo $date_init; ?>
355 </script>
357 <!-- include support for the list-add selectbox feature -->
358 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
360 </center>
361 </body>
362 </html>