adjustments to prior commit
[openemr.git] / interface / cmsportal / history_form.php
blob67e34d684b31013deb983946c3f8dc38a059bff2
1 <?php
2 /**
3 * Patient history 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 $postid = intval($_REQUEST['postid']);
21 $ptid = intval($_REQUEST['ptid' ]);
23 if ($_POST['bn_save']) {
24 $newdata = array();
25 $fres = sqlStatement("SELECT * FROM layout_options WHERE " .
26 "form_id = 'HIS' AND field_id != '' AND uor > 0 " .
27 "ORDER BY group_id, seq");
28 while ($frow = sqlFetchArray($fres)) {
29 $data_type = $frow['data_type'];
30 $field_id = $frow['field_id'];
31 if (isset($_POST["form_$field_id"])) {
32 $newdata[$field_id] = get_layout_form_value($frow);
36 updateHistoryData($ptid, $newdata);
37 // Finally, delete the request from the portal.
38 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
39 if ($result['errmsg']) {
40 die(text($result['errmsg']));
43 echo "<html><body><script language='JavaScript'>\n";
44 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
45 echo "document.location.href = 'list_requests.php';\n";
46 echo "</script></body></html>\n";
47 exit();
50 // Get the portal request data.
51 if (!$postid) {
52 die(xlt('Request ID is missing!'));
55 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
56 if ($result['errmsg']) {
57 die(text($result['errmsg']));
60 // Look up the patient in OpenEMR.
61 $ptid = lookup_openemr_patient($result['post']['user']);
63 // Get patient's current history data in OpenEMR.
64 $hyrow = getHistoryData($ptid, "*");
66 <html>
67 <head>
68 <?php html_header_show(); ?>
69 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
70 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
72 <style>
74 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
75 tr.detail { font-size:10pt; background-color:#ddddff; }
76 td input { background-color:transparent; }
78 </style>
80 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
81 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
82 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
84 <script language="JavaScript">
86 function myRestoreSession() {
87 if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();
88 return true;
91 // This capitalizes the first letter of each word in the passed input
92 // element. It also strips out extraneous spaces.
93 // Copied from demographics_full.php.
94 function capitalizeMe(elem) {
95 var a = elem.value.split(' ');
96 var s = '';
97 for(var i = 0; i < a.length; ++i) {
98 if (a[i].length > 0) {
99 if (s.length > 0) s += ' ';
100 s += a[i].charAt(0).toUpperCase() + a[i].substring(1);
103 elem.value = s;
106 function validate() {
107 var f = document.forms[0];
108 // TBD
109 return true;
112 $(document).ready(function() {
113 $('.datepicker').datetimepicker({
114 <?php $datetimepicker_timepicker = false; ?>
115 <?php $datetimepicker_showseconds = false; ?>
116 <?php $datetimepicker_formatInput = true; ?>
117 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
118 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
120 $('.datetimepicker').datetimepicker({
121 <?php $datetimepicker_timepicker = true; ?>
122 <?php $datetimepicker_showseconds = false; ?>
123 <?php $datetimepicker_formatInput = true; ?>
124 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
125 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
129 </script>
130 </head>
132 <body class="body_top">
133 <center>
135 <form method='post' action='history_form.php' onsubmit='return validate()'>
137 <input type='hidden' name='ptid' value='<?php echo attr($ptid); ?>' />
138 <input type='hidden' name='postid' value='<?php echo attr($postid); ?>' />
140 <table width='100%' cellpadding='1' cellspacing='2'>
141 <tr class='head'>
142 <th align='left'><?php echo xlt('Field'); ?></th>
143 <th align='left'><?php echo xlt('Current Value'); ?></th>
144 <th align='left'><?php echo xlt('New Value'); ?></th>
145 </tr>
147 <?php
148 $lores = sqlStatement(
149 "SELECT * FROM layout_options " .
150 "WHERE form_id = ? AND uor > 0 ORDER BY group_id, seq",
151 array('HIS')
154 while ($lorow = sqlFetchArray($lores)) {
155 $data_type = $lorow['data_type'];
156 $field_id = $lorow['field_id'];
157 // Check for field name match in portal results, case insensitive.
158 $reskey = $field_id;
159 $gotfield = false;
160 foreach ($result['fields'] as $key => $dummy) {
161 // For Exam Results the field ID has a colon and list item ID appended.
162 if (($i = strpos($key, ':')) !== false) {
163 $key = substr($key, 0, $i);
166 if (strcasecmp($key, $field_id) == 0) {
167 $reskey = $key;
168 $gotfield = true;
172 // Generate form fields for items that are either from the WordPress form
173 // or are mandatory.
174 if ($gotfield || $lorow['uor'] > 1) {
175 $list_id = $lorow['list_id'];
176 $field_title = $lorow['title'];
177 if ($field_title === '') {
178 $field_title = '(' . $field_id . ')';
181 $currvalue = '';
182 if (isset($hyrow[$field_id])) {
183 $currvalue = $hyrow[$field_id];
186 $newvalue = cms_field_to_lbf($data_type, $reskey, $result['fields']);
188 echo " <tr class='detail'>\n";
189 echo " <td class='bold'>" . text($field_title) . "</td>\n";
190 echo " <td>" . generate_display_field($lorow, $currvalue) . "</td>\n";
191 echo " <td>";
192 generate_form_field($lorow, $newvalue);
193 echo "</td>\n";
194 echo " </tr>\n";
198 echo "</table>\n";
202 <input type='submit' name='bn_save' value='<?php echo xla('Save and Delete Request'); ?>' />
203 &nbsp;
204 <input type='button' value='<?php echo xla('Back'); ?>'
205 onclick="myRestoreSession();location='list_requests.php'" />
206 </p>
208 </form>
210 <script language="JavaScript">
212 randompass();
214 // This is a by-product of generate_form_field().
215 <?php echo $date_init; ?>
217 </script>
219 <!-- include support for the list-add selectbox feature -->
220 <?php include $GLOBALS['fileroot'] . "/library/options_listadd.inc"; ?>
222 </center>
223 </body>
224 </html>