minor changes to prior commit
[openemr.git] / interface / cmsportal / insurance_form.php
blobcd6cf744e46c899290cc4945bf04ee05c01d3c76
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 <?php html_header_show(); ?>
225 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
226 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
228 <style>
230 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
231 tr.detail { font-size:10pt; background-color:#ddddff; }
232 td input { background-color:transparent; }
234 </style>
236 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
237 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-7-2/jquery.min.js"></script>
238 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
240 <script language="JavaScript">
242 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
244 function myRestoreSession() {
245 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
246 return true;
249 // This capitalizes the first letter of each word in the passed input
250 // element. It also strips out extraneous spaces.
251 // Copied from demographics_full.php.
252 function capitalizeMe(elem) {
253 var a = elem.value.split(' ');
254 var s = '';
255 for(var i = 0; i < a.length; ++i) {
256 if (a[i].length > 0) {
257 if (s.length > 0) s += ' ';
258 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
261 elem.value = s;
264 function validate() {
265 var f = document.forms[0];
266 // TBD
267 return true;
270 $(document).ready(function() {
271 $('.datepicker').datetimepicker({
272 <?php $datetimepicker_timepicker = false; ?>
273 <?php $datetimepicker_showseconds = false; ?>
274 <?php $datetimepicker_formatInput = true; ?>
275 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
276 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
278 $('.datetimepicker').datetimepicker({
279 <?php $datetimepicker_timepicker = true; ?>
280 <?php $datetimepicker_showseconds = false; ?>
281 <?php $datetimepicker_formatInput = true; ?>
282 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
283 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
287 </script>
288 </head>
290 <body class="body_top">
291 <center>
293 <form method='post' action='insurance_form.php' onsubmit='return validate()'>
295 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
296 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
298 <table width='100%' cellpadding='1' cellspacing='2'>
299 <tr class='head'>
300 <th align='left'><?php echo xlt('Field'); ?></th>
301 <th align='left'><?php echo xlt('Current Value'); ?></th>
302 <th align='left'><?php echo xlt('New Value'); ?></th>
303 </tr>
305 <?php
306 $insrow = getInsuranceData($pid, $result['fields']['type']);
308 foreach ($insurance_layout as $lorow) {
309 $data_type = $lorow['data_type'];
310 $field_id = $lorow['field_id'];
312 $list_id = $lorow['list_id'];
313 $field_title = $lorow['title'];
315 $currvalue = '';
316 if (isset($insrow[$field_id])) {
317 $currvalue = $insrow[$field_id];
320 $newvalue = '';
321 if (isset($result['fields'][$field_id])) {
322 $newvalue = trim($result['fields'][$field_id]);
325 // Translate $newvalue for certain field types including lists.
326 if ($newvalue !== '') {
327 if ($list_id) {
328 $tmp = sqlQuery(
329 "SELECT option_id FROM list_options WHERE " .
330 "list_id = ? AND title = ? AND activity = 1 ORDER BY option_id LIMIT 1",
331 array($list_id, $newvalue)
333 if (isset($tmp['option_id'])) {
334 $newvalue = $tmp['option_id'];
338 // Some data types like insurance provider are pretty hopeless, so let the display
339 // logic generate a "Fix me" message and the user can translate it.
342 echo " <tr class='detail'>\n";
343 echo " <td class='bold'>" . text($field_title) . "</td>\n";
344 echo " <td>";
345 echo generate_display_field($lorow, $currvalue);
346 echo "</td>\n";
347 echo " <td>";
348 generate_form_field($lorow, $newvalue);
349 echo "</td>\n";
350 echo " </tr>\n";
354 </table>
357 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
358 &nbsp;
359 <input type='button' value='<?php echo xla('Back'); ?>' onclick="window.history.back()" />
360 <!-- Was: onclick="myRestoreSession();location='list_requests.php'" -->
361 </p>
363 </form>
365 <script language="JavaScript">
367 // Fix inconsistently formatted phone numbers from the database.
368 var f = document.forms[0];
369 if (f.form_phone) phonekeyup(f.form_phone, mypcc);
371 // This is a by-product of generate_form_field().
372 <?php echo $date_init; ?>
374 </script>
376 <!-- include support for the list-add selectbox feature -->
377 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
379 </center>
380 </body>
381 </html>