migrated ubiquitous libraries to composer autoloader (#421)
[openemr.git] / interface / cmsportal / history_form.php
blob7cdc08dde5ef7c0219671cd48c24585cb23b3f47
1 <?php
2 /**
3 * Patient history posting for the WordPress Patient Portal.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
22 $sanitize_all_escapes = true;
23 $fake_register_globals = false;
25 require_once("../globals.php");
26 require_once("$srcdir/patient.inc");
27 require_once("$srcdir/options.inc.php");
28 require_once("portal.inc.php");
30 $postid = intval($_REQUEST['postid']);
31 $ptid = intval($_REQUEST['ptid' ]);
33 if ($_POST['bn_save']) {
34 $newdata = array();
35 $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
36 "form_id = 'HIS' AND field_id != '' AND uor > 0 " .
37 "ORDER BY group_name, seq");
38 while ($frow = sqlFetchArray($fres)) {
39 $data_type = $frow['data_type'];
40 $field_id = $frow['field_id'];
41 if (isset($_POST["form_$field_id"])) {
42 $newdata[$field_id] = get_layout_form_value($frow);
45 updateHistoryData($ptid, $newdata);
46 // Finally, delete the request from the portal.
47 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
48 if ($result['errmsg']) {
49 die(text($result['errmsg']));
51 echo "<html><body><script language='JavaScript'>\n";
52 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
53 echo "document.location.href = 'list_requests.php';\n";
54 echo "</script></body></html>\n";
55 exit();
58 // Get the portal request data.
59 if (!$postid) die(xlt('Request ID is missing!'));
60 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
61 if ($result['errmsg']) {
62 die(text($result['errmsg']));
65 // Look up the patient in OpenEMR.
66 $ptid = lookup_openemr_patient($result['post']['user']);
68 // Get patient's current history data in OpenEMR.
69 $hyrow = getHistoryData($ptid, "*");
71 <html>
72 <head>
73 <?php html_header_show(); ?>
74 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
76 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
77 <style>
79 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
80 tr.detail { font-size:10pt; background-color:#ddddff; }
81 td input { background-color:transparent; }
83 </style>
85 <script type="text/javascript" src="../../library/textformat.js"></script>
86 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
87 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
88 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
89 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script>
91 <script language="JavaScript">
93 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
95 function myRestoreSession() {
96 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
97 return true;
100 // This capitalizes the first letter of each word in the passed input
101 // element. It also strips out extraneous spaces.
102 // Copied from demographics_full.php.
103 function capitalizeMe(elem) {
104 var a = elem.value.split(' ');
105 var s = '';
106 for(var i = 0; i < a.length; ++i) {
107 if (a[i].length > 0) {
108 if (s.length > 0) s += ' ';
109 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
112 elem.value = s;
115 function validate() {
116 var f = document.forms[0];
117 // TBD
118 return true;
121 </script>
122 </head>
124 <body class="body_top">
125 <center>
127 <form method='post' action='history_form.php' onsubmit='return validate()'>
129 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
130 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
132 <table width='100%' cellpadding='1' cellspacing='2'>
133 <tr class='head'>
134 <th align='left'><?php echo xlt('Field' ); ?></th>
135 <th align='left'><?php echo xlt('Current Value'); ?></th>
136 <th align='left'><?php echo xlt('New Value' ); ?></th>
137 </tr>
139 <?php
140 $lores = sqlStatement("SELECT * FROM layout_options " .
141 "WHERE form_id = ? AND uor > 0 ORDER BY group_name, seq",
142 array('HIS'));
144 while ($lorow = sqlFetchArray($lores)) {
145 $data_type = $lorow['data_type'];
146 $field_id = $lorow['field_id'];
147 // Check for field name match in portal results, case insensitive.
148 $reskey = $field_id;
149 $gotfield = false;
150 foreach ($result['fields'] as $key => $dummy) {
151 // For Exam Results the field ID has a colon and list item ID appended.
152 if (($i = strpos($key, ':')) !== false) {
153 $key = substr($key, 0, $i);
155 if (strcasecmp($key, $field_id) == 0) {
156 $reskey = $key;
157 $gotfield = true;
160 // Generate form fields for items that are either from the WordPress form
161 // or are mandatory.
162 if ($gotfield || $lorow['uor'] > 1) {
163 $list_id = $lorow['list_id'];
164 $field_title = $lorow['title'];
165 if ($field_title === '') $field_title = '(' . $field_id . ')';
167 $currvalue = '';
168 if (isset($hyrow[$field_id])) $currvalue = $hyrow[$field_id];
170 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
172 echo " <tr class='detail'>\n";
173 echo " <td class='bold'>" . text($field_title) . "</td>\n";
174 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
175 echo " <td>"; generate_form_field($lorow, $newvalue); echo "</td>\n";
176 echo " </tr>\n";
180 echo "</table>\n";
184 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
185 &nbsp;
186 <input type='button' value='<?php echo xla('Back'); ?>'
187 onclick="myRestoreSession();location='list_requests.php'" />
188 </p>
190 </form>
192 <script language="JavaScript">
194 randompass();
196 // This is a by-product of generate_form_field().
197 <?php echo $date_init; ?>
199 </script>
201 <!-- include support for the list-add selectbox feature -->
202 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
204 </center>
205 </body>
206 </html>