Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / cmsportal / insurance_form.php
blob5df35c5a54bea2c5a65f8df4e443432acf15dc9a
1 <?php
2 /**
3 * Insurance form posting for the WordPress Patient Portal.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2014 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
17 require_once("$srcdir/options.inc.php");
18 require_once("portal.inc.php");
20 // Consider this a step towards converting the insurance form to layout-based.
21 // Faking it here makes things easier.
22 // Also note that some fields like SSN and most of the subscriber employer
23 // items have been omitted because they are not relevant for claims.
25 $insurance_layout = array(
26 array('field_id' => 'type',
27 'title' => 'Type',
28 'uor' => '2',
29 'data_type' => '1',
30 'list_id' => 'insurance_types',
31 'edit_options' => '',
33 array('field_id' => 'date',
34 'title' => 'Effective Date',
35 'uor' => '2',
36 'data_type' => '4', // Text-date
37 'list_id' => '',
38 'edit_options' => '',
40 array('field_id' => 'provider',
41 'title' => 'Provider',
42 'uor' => '2',
43 'data_type' => '16', // Insurance Providers
44 'list_id' => '',
45 'edit_options' => '',
47 array('field_id' => 'plan_name',
48 'title' => 'Plan Name',
49 'uor' => '1',
50 'data_type' => '2', // Text
51 'list_id' => '',
52 'edit_options' => '',
54 array('field_id' => 'policy_number',
55 'title' => 'Policy Number',
56 'uor' => '1',
57 'data_type' => '2', // Text
58 'list_id' => '',
59 'edit_options' => '',
61 array('field_id' => 'group_number',
62 'title' => 'Group Number',
63 'uor' => '1',
64 'data_type' => '2', // Text
65 'list_id' => '',
66 'edit_options' => '',
68 array('field_id' => 'subscriber_employer',
69 'title' => 'Group Name',
70 'uor' => '1',
71 'data_type' => '2', // Text
72 'list_id' => '',
73 'edit_options' => '',
75 array('field_id' => 'subscriber_lname',
76 'title' => 'Subscriber Last Name',
77 'uor' => '2',
78 'data_type' => '2', // Text
79 'list_id' => '',
80 'edit_options' => '',
82 array('field_id' => 'subscriber_fname',
83 'title' => 'Subscriber First Name',
84 'uor' => '1',
85 'data_type' => '2', // Text
86 'list_id' => '',
87 'edit_options' => '',
89 array('field_id' => 'subscriber_mname',
90 'title' => 'Subscriber Middle Name',
91 'uor' => '1',
92 'data_type' => '2', // Text
93 'list_id' => '',
94 'edit_options' => '',
96 array('field_id' => 'subscriber_DOB',
97 'title' => 'Subscriber DOB',
98 'uor' => '2',
99 'data_type' => '4', // Text-date
100 'list_id' => '',
101 'edit_options' => '',
103 array('field_id' => 'subscriber_sex',
104 'title' => 'Subscriber Sex',
105 'uor' => '2',
106 'data_type' => '1', // List
107 'list_id' => 'sex',
108 'edit_options' => '',
110 array('field_id' => 'subscriber_relationship',
111 'title' => 'Subscriber Relationship',
112 'uor' => '2',
113 'data_type' => '1', // List
114 'list_id' => 'sub_relation',
115 'edit_options' => '',
117 array('field_id' => 'subscriber_street',
118 'title' => 'Subscriber Street',
119 'uor' => '1',
120 'data_type' => '2', // Text
121 'list_id' => '',
122 'edit_options' => '',
124 array('field_id' => 'subscriber_city',
125 'title' => 'Subscriber City',
126 'uor' => '1',
127 'data_type' => '2', // Text
128 'list_id' => '',
129 'edit_options' => '',
131 array('field_id' => 'subscriber_state',
132 'title' => 'Subscriber State',
133 'uor' => '1',
134 'data_type' => '1', // List
135 'list_id' => 'state',
136 'edit_options' => '',
138 array('field_id' => 'subscriber_postal_code',
139 'title' => 'Subscriber Zip',
140 'uor' => '1',
141 'data_type' => '2', // Text
142 'list_id' => '',
143 'edit_options' => '',
145 array('field_id' => 'subscriber_phone',
146 'title' => 'Subscriber Phone',
147 'uor' => '1',
148 'data_type' => '2', // Text
149 'list_id' => '',
150 'edit_options' => '',
154 $postid = intval($_REQUEST['postid']);
156 if ($_POST['bn_save']) {
157 $newdata = array();
158 $ptid = intval($_POST['ptid']);
159 foreach ($insurance_layout as $frow) {
160 $data_type = $frow['data_type'];
161 $field_id = $frow['field_id'];
162 $newdata[$field_id] = get_layout_form_value($frow);
165 newInsuranceData(
166 $ptid,
167 $newdata['type'],
168 $newdata['provider'],
169 $newdata['policy_number'],
170 $newdata['group_number'],
171 $newdata['plan_name'],
172 $newdata['subscriber_lname'],
173 $newdata['subscriber_mname'],
174 $newdata['subscriber_fname'],
175 $newdata['subscriber_relationship'],
176 '', // subscriber_ss
177 $newdata['subscriber_DOB'],
178 $newdata['subscriber_street'],
179 $newdata['subscriber_postal_code'],
180 $newdata['subscriber_city'],
181 $newdata['subscriber_state'],
182 '', // subscriber_country
183 $newdata['subscriber_phone'],
184 $newdata['subscriber_employer'],
185 '', // subscriber_employer_street
186 '', // subscriber_employer_city
187 '', // subscriber_employer_postal_code
188 '', // subscriber_employer_state
189 '', // subscriber_employer_country
190 '', // copay
191 $newdata['subscriber_sex'],
192 $newdata['date'],
193 'TRUE', // accept_assignment
194 '' // policy_type
196 // Finally, delete the request from the portal.
197 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
198 if ($result['errmsg']) {
199 die(text($result['errmsg']));
202 echo "<html><body><script language='JavaScript'>\n";
203 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
204 echo "document.location.href = 'list_requests.php';\n";
205 echo "</script></body></html>\n";
206 exit();
209 // Get the portal request data.
210 if (!$postid) {
211 die(xlt('Request ID is missing!'));
214 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
215 if ($result['errmsg']) {
216 die(text($result['errmsg']));
219 // Look up the patient in OpenEMR.
220 $ptid = lookup_openemr_patient($result['post']['user']);
222 <html>
223 <head>
224 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
225 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
227 <style>
229 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
230 tr.detail { font-size:10pt; background-color:#ddddff; }
231 td input { background-color:transparent; }
233 </style>
235 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
236 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-7-2/jquery.min.js"></script>
237 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
239 <script language="JavaScript">
241 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
243 function myRestoreSession() {
244 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
245 return true;
248 // This capitalizes the first letter of each word in the passed input
249 // element. It also strips out extraneous spaces.
250 // Copied from demographics_full.php.
251 function capitalizeMe(elem) {
252 var a = elem.value.split(' ');
253 var s = '';
254 for(var i = 0; i < a.length; ++i) {
255 if (a[i].length > 0) {
256 if (s.length > 0) s += ' ';
257 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
260 elem.value = s;
263 function validate() {
264 var f = document.forms[0];
265 // TBD
266 return true;
269 $(function() {
270 $('.datepicker').datetimepicker({
271 <?php $datetimepicker_timepicker = false; ?>
272 <?php $datetimepicker_showseconds = false; ?>
273 <?php $datetimepicker_formatInput = true; ?>
274 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
275 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
277 $('.datetimepicker').datetimepicker({
278 <?php $datetimepicker_timepicker = true; ?>
279 <?php $datetimepicker_showseconds = false; ?>
280 <?php $datetimepicker_formatInput = true; ?>
281 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
282 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
286 </script>
287 </head>
289 <body class="body_top">
290 <center>
292 <form method='post' action='insurance_form.php' onsubmit='return validate()'>
294 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
295 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
297 <table width='100%' cellpadding='1' cellspacing='2'>
298 <tr class='head'>
299 <th align='left'><?php echo xlt('Field'); ?></th>
300 <th align='left'><?php echo xlt('Current Value'); ?></th>
301 <th align='left'><?php echo xlt('New Value'); ?></th>
302 </tr>
304 <?php
305 $insrow = getInsuranceData($pid, $result['fields']['type']);
307 foreach ($insurance_layout as $lorow) {
308 $data_type = $lorow['data_type'];
309 $field_id = $lorow['field_id'];
311 $list_id = $lorow['list_id'];
312 $field_title = $lorow['title'];
314 $currvalue = '';
315 if (isset($insrow[$field_id])) {
316 $currvalue = $insrow[$field_id];
319 $newvalue = '';
320 if (isset($result['fields'][$field_id])) {
321 $newvalue = trim($result['fields'][$field_id]);
324 // Translate $newvalue for certain field types including lists.
325 if ($newvalue !== '') {
326 if ($list_id) {
327 $tmp = sqlQuery(
328 "SELECT option_id FROM list_options WHERE " .
329 "list_id = ? AND title = ? AND activity = 1 ORDER BY option_id LIMIT 1",
330 array($list_id, $newvalue)
332 if (isset($tmp['option_id'])) {
333 $newvalue = $tmp['option_id'];
337 // Some data types like insurance provider are pretty hopeless, so let the display
338 // logic generate a "Fix me" message and the user can translate it.
341 echo " <tr class='detail'>\n";
342 echo " <td class='bold'>" . text($field_title) . "</td>\n";
343 echo " <td>";
344 echo generate_display_field($lorow, $currvalue);
345 echo "</td>\n";
346 echo " <td>";
347 generate_form_field($lorow, $newvalue);
348 echo "</td>\n";
349 echo " </tr>\n";
353 </table>
356 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
357 &nbsp;
358 <input type='button' value='<?php echo xla('Back'); ?>' onclick="window.history.back()" />
359 <!-- Was: onclick="myRestoreSession();location='list_requests.php'" -->
360 </p>
362 </form>
364 <script language="JavaScript">
366 // Fix inconsistently formatted phone numbers from the database.
367 var f = document.forms[0];
368 if (f.form_phone) phonekeyup(f.form_phone, mypcc);
370 // This is a by-product of generate_form_field().
371 <?php echo $date_init; ?>
373 </script>
375 <!-- include support for the list-add selectbox feature -->
376 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
378 </center>
379 </body>
380 </html>