migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / cmsportal / insurance_form.php
blobd662458ed96b90e091fefbaf2ceaad3ef7e96b7a
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/options.inc.php");
26 require_once("portal.inc.php");
28 // Consider this a step towards converting the insurance form to layout-based.
29 // Faking it here makes things easier.
30 // Also note that some fields like SSN and most of the subscriber employer
31 // items have been omitted because they are not relevant for claims.
33 $insurance_layout = array(
34 array('field_id' => 'type',
35 'title' => 'Type',
36 'uor' => '2',
37 'data_type' => '1',
38 'list_id' => 'insurance_types',
39 'edit_options' => '',
41 array('field_id' => 'date',
42 'title' => 'Effective Date',
43 'uor' => '2',
44 'data_type' => '4', // Text-date
45 'list_id' => '',
46 'edit_options' => '',
48 array('field_id' => 'provider',
49 'title' => 'Provider',
50 'uor' => '2',
51 'data_type' => '16', // Insurance Providers
52 'list_id' => '',
53 'edit_options' => '',
55 array('field_id' => 'plan_name',
56 'title' => 'Plan Name',
57 'uor' => '1',
58 'data_type' => '2', // Text
59 'list_id' => '',
60 'edit_options' => '',
62 array('field_id' => 'policy_number',
63 'title' => 'Policy Number',
64 'uor' => '1',
65 'data_type' => '2', // Text
66 'list_id' => '',
67 'edit_options' => '',
69 array('field_id' => 'group_number',
70 'title' => 'Group Number',
71 'uor' => '1',
72 'data_type' => '2', // Text
73 'list_id' => '',
74 'edit_options' => '',
76 array('field_id' => 'subscriber_employer',
77 'title' => 'Group Name',
78 'uor' => '1',
79 'data_type' => '2', // Text
80 'list_id' => '',
81 'edit_options' => '',
83 array('field_id' => 'subscriber_lname',
84 'title' => 'Subscriber Last Name',
85 'uor' => '2',
86 'data_type' => '2', // Text
87 'list_id' => '',
88 'edit_options' => '',
90 array('field_id' => 'subscriber_fname',
91 'title' => 'Subscriber First Name',
92 'uor' => '1',
93 'data_type' => '2', // Text
94 'list_id' => '',
95 'edit_options' => '',
97 array('field_id' => 'subscriber_mname',
98 'title' => 'Subscriber Middle Name',
99 'uor' => '1',
100 'data_type' => '2', // Text
101 'list_id' => '',
102 'edit_options' => '',
104 array('field_id' => 'subscriber_DOB',
105 'title' => 'Subscriber DOB',
106 'uor' => '2',
107 'data_type' => '4', // Text-date
108 'list_id' => '',
109 'edit_options' => '',
111 array('field_id' => 'subscriber_sex',
112 'title' => 'Subscriber Sex',
113 'uor' => '2',
114 'data_type' => '1', // List
115 'list_id' => 'sex',
116 'edit_options' => '',
118 array('field_id' => 'subscriber_relationship',
119 'title' => 'Subscriber Relationship',
120 'uor' => '2',
121 'data_type' => '1', // List
122 'list_id' => 'sub_relation',
123 'edit_options' => '',
125 array('field_id' => 'subscriber_street',
126 'title' => 'Subscriber Street',
127 'uor' => '1',
128 'data_type' => '2', // Text
129 'list_id' => '',
130 'edit_options' => '',
132 array('field_id' => 'subscriber_city',
133 'title' => 'Subscriber City',
134 'uor' => '1',
135 'data_type' => '2', // Text
136 'list_id' => '',
137 'edit_options' => '',
139 array('field_id' => 'subscriber_state',
140 'title' => 'Subscriber State',
141 'uor' => '1',
142 'data_type' => '1', // List
143 'list_id' => 'state',
144 'edit_options' => '',
146 array('field_id' => 'subscriber_postal_code',
147 'title' => 'Subscriber Zip',
148 'uor' => '1',
149 'data_type' => '2', // Text
150 'list_id' => '',
151 'edit_options' => '',
153 array('field_id' => 'subscriber_phone',
154 'title' => 'Subscriber Phone',
155 'uor' => '1',
156 'data_type' => '2', // Text
157 'list_id' => '',
158 'edit_options' => '',
162 $postid = intval($_REQUEST['postid']);
164 if ($_POST['bn_save']) {
165 $newdata = array();
166 $ptid = intval($_POST['ptid']);
167 foreach ($insurance_layout as $frow) {
168 $data_type = $frow['data_type'];
169 $field_id = $frow['field_id'];
170 // newInsuranceData() does not escape for mysql so we have to do it here.
171 $newdata[$field_id] = add_escape_custom(get_layout_form_value($frow));
173 newInsuranceData(
174 $ptid,
175 $newdata['type'],
176 $newdata['provider'],
177 $newdata['policy_number'],
178 $newdata['group_number'],
179 $newdata['plan_name'],
180 $newdata['subscriber_lname'],
181 $newdata['subscriber_mname'],
182 $newdata['subscriber_fname'],
183 $newdata['subscriber_relationship'],
184 '', // subscriber_ss
185 fixDate($newdata['subscriber_DOB']),
186 $newdata['subscriber_street'],
187 $newdata['subscriber_postal_code'],
188 $newdata['subscriber_city'],
189 $newdata['subscriber_state'],
190 '', // subscriber_country
191 $newdata['subscriber_phone'],
192 $newdata['subscriber_employer'],
193 '', // subscriber_employer_street
194 '', // subscriber_employer_city
195 '', // subscriber_employer_postal_code
196 '', // subscriber_employer_state
197 '', // subscriber_employer_country
198 '', // copay
199 $newdata['subscriber_sex'],
200 fixDate($newdata['date']),
201 'TRUE', // accept_assignment
202 '' // policy_type
204 // Finally, delete the request from the portal.
205 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
206 if ($result['errmsg']) {
207 die(text($result['errmsg']));
209 echo "<html><body><script language='JavaScript'>\n";
210 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
211 echo "document.location.href = 'list_requests.php';\n";
212 echo "</script></body></html>\n";
213 exit();
216 // Get the portal request data.
217 if (!$postid) die(xlt('Request ID is missing!'));
218 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
219 if ($result['errmsg']) {
220 die(text($result['errmsg']));
223 // Look up the patient in OpenEMR.
224 $ptid = lookup_openemr_patient($result['post']['user']);
226 <html>
227 <head>
228 <?php html_header_show(); ?>
229 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
231 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
232 <style>
234 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
235 tr.detail { font-size:10pt; background-color:#ddddff; }
236 td input { background-color:transparent; }
238 </style>
240 <script type="text/javascript" src="../../library/textformat.js"></script>
241 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
242 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
243 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
244 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
246 <script language="JavaScript">
248 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
250 function myRestoreSession() {
251 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
252 return true;
255 // This capitalizes the first letter of each word in the passed input
256 // element. It also strips out extraneous spaces.
257 // Copied from demographics_full.php.
258 function capitalizeMe(elem) {
259 var a = elem.value.split(' ');
260 var s = '';
261 for(var i = 0; i < a.length; ++i) {
262 if (a[i].length > 0) {
263 if (s.length > 0) s += ' ';
264 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
267 elem.value = s;
270 function validate() {
271 var f = document.forms[0];
272 // TBD
273 return true;
276 </script>
277 </head>
279 <body class="body_top">
280 <center>
282 <form method='post' action='insurance_form.php' onsubmit='return validate()'>
284 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
285 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
287 <table width='100%' cellpadding='1' cellspacing='2'>
288 <tr class='head'>
289 <th align='left'><?php echo xlt('Field' ); ?></th>
290 <th align='left'><?php echo xlt('Current Value'); ?></th>
291 <th align='left'><?php echo xlt('New Value' ); ?></th>
292 </tr>
294 <?php
295 $insrow = getInsuranceData($pid, $result['fields']['type']);
297 foreach ($insurance_layout as $lorow) {
298 $data_type = $lorow['data_type'];
299 $field_id = $lorow['field_id'];
301 $list_id = $lorow['list_id'];
302 $field_title = $lorow['title'];
304 $currvalue = '';
305 if (isset($insrow[$field_id])) $currvalue = $insrow[$field_id];
307 $newvalue = '';
308 if (isset($result['fields'][$field_id])) $newvalue = trim($result['fields'][$field_id]);
310 // Translate $newvalue for certain field types including lists.
311 if ($newvalue !== '') {
312 if ($list_id) {
313 $tmp = sqlQuery("SELECT option_id FROM list_options WHERE " .
314 "list_id = ? AND title = ? AND activity = 1 ORDER BY option_id LIMIT 1",
315 array($list_id, $newvalue));
316 if (isset($tmp['option_id'])) $newvalue = $tmp['option_id'];
318 // Some data types like insurance provider are pretty hopeless, so let the display
319 // logic generate a "Fix me" message and the user can translate it.
322 echo " <tr class='detail'>\n";
323 echo " <td class='bold'>" . text($field_title) . "</td>\n";
324 echo " <td>";
325 echo generate_display_field($lorow, $currvalue);
326 echo "</td>\n";
327 echo " <td>";
328 generate_form_field($lorow, $newvalue);
329 echo "</td>\n";
330 echo " </tr>\n";
334 </table>
337 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
338 &nbsp;
339 <input type='button' value='<?php echo xla('Back'); ?>' onclick="window.history.back()" />
340 <!-- Was: onclick="myRestoreSession();location='list_requests.php'" -->
341 </p>
343 </form>
345 <script language="JavaScript">
347 // Fix inconsistently formatted phone numbers from the database.
348 var f = document.forms[0];
349 if (f.form_phone) phonekeyup(f.form_phone, mypcc);
351 // This is a by-product of generate_form_field().
352 <?php echo $date_init; ?>
354 </script>
356 <!-- include support for the list-add selectbox feature -->
357 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
359 </center>
360 </body>
361 </html>