fix for escaping in the code search popup
[openemr.git] / interface / forms / physical_exam / new.php
blob20f350aef3dd25dabc51a29d26e55bed8ec2e909
1 <?php
2 // Copyright (C) 2006, 2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 include_once("../../globals.php");
10 include_once("$srcdir/api.inc");
11 include_once("$srcdir/forms.inc");
12 include_once("lines.php");
14 if (! $encounter) { // comes from globals.php
15 die("Internal error: we do not seem to be in an encounter!");
18 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
20 function showExamLine($line_id, $description, &$linedbrow, $sysnamedisp) {
21 $dres = sqlStatement("SELECT * FROM form_physical_exam_diagnoses " .
22 "WHERE line_id = '$line_id' ORDER BY ordering, diagnosis");
24 echo " <tr>\n";
25 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
26 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
27 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][abn]' " .
28 "value='1'" . ($linedbrow['abn'] ? " checked" : "") . " /></td>\n";
29 echo " <td nowrap>$sysnamedisp</td>\n";
30 echo " <td nowrap>$description</td>\n";
32 echo " <td><select name='form_obs[$line_id][diagnosis]' onchange='seldiag(this, \"$line_id\")' style='width:100%'>\n";
33 echo " <option value=''></option>\n";
34 $diagnosis = $linedbrow['diagnosis'];
35 while ($drow = sqlFetchArray($dres)) {
36 $sel = '';
37 $diag = $drow['diagnosis'];
38 if ($diagnosis && $diag == $diagnosis) {
39 $sel = 'selected';
40 $diagnosis = '';
42 echo " <option value='$diag' $sel>$diag</option>\n";
44 // If the diagnosis was not in the standard list then it must have been
45 // there before and then removed. In that case show it in parentheses.
46 if ($diagnosis) {
47 echo " <option value='$diagnosis' selected>($diagnosis)</option>\n";
49 echo " <option value='*'>-- Edit --</option>\n";
50 echo " </select></td>\n";
52 echo " <td><input type='text' name='form_obs[$line_id][comments]' " .
53 "size='20' maxlength='250' style='width:100%' " .
54 "value='" . htmlentities($linedbrow['comments']) . "' /></td>\n";
55 echo " </tr>\n";
58 function showTreatmentLine($line_id, $description, &$linedbrow) {
59 echo " <tr>\n";
60 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
61 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
62 echo " <td></td>\n";
63 echo " <td colspan='2' nowrap>$description</td>\n";
64 echo " <td colspan='2'><input type='text' name='form_obs[$line_id][comments]' " .
65 "size='20' maxlength='250' style='width:100%' " .
66 "value='" . htmlentities($linedbrow['comments']) . "' /></td>\n";
67 echo " </tr>\n";
70 $formid = $_GET['id'];
72 // If Save was clicked, save the info.
74 if ($_POST['bn_save']) {
76 // We are to update/insert multiple table rows for the form.
77 // Each has 2 checkboxes, a dropdown and a text input field.
78 // Skip rows that have no entries.
79 // There are also 3 special rows with just one checkbox and a text
80 // input field. Maybe also a diagnosis line, not clear.
82 if ($formid) {
83 $query = "DELETE FROM form_physical_exam WHERE forms_id = '$formid'";
84 sqlStatement($query);
86 else {
87 $formid = addForm($encounter, "Physical Exam", 0, "physical_exam", $pid, $userauthorized);
88 $query = "UPDATE forms SET form_id = id WHERE id = '$formid' AND form_id = 0";
89 sqlStatement($query);
92 $form_obs = $_POST['form_obs'];
93 foreach ($form_obs as $line_id => $line_array) {
94 $wnl = $line_array['wnl'] ? '1' : '0';
95 $abn = $line_array['abn'] ? '1' : '0';
96 $diagnosis = $line_array['diagnosis'] ? $line_array['diagnosis'] : '';
97 $comments = $line_array['comments'] ? $line_array['comments'] : '';
98 if ($wnl || $abn || $diagnosis || $comments) {
99 $query = "INSERT INTO form_physical_exam ( " .
100 "forms_id, line_id, wnl, abn, diagnosis, comments " .
101 ") VALUES ( " .
102 "'$formid', '$line_id', '$wnl', '$abn', '$diagnosis', '$comments' " .
103 ")";
104 sqlInsert($query);
108 if (! $_POST['form_refresh']) {
109 formHeader("Redirecting....");
110 formJump();
111 formFooter();
112 exit;
116 // Load all existing rows for this form as a hash keyed on line_id.
118 $rows = array();
119 if ($formid) {
120 $res = sqlStatement("SELECT * FROM form_physical_exam WHERE forms_id = '$formid'");
121 while ($row = sqlFetchArray($res)) {
122 $rows[$row['line_id']] = $row;
126 <html>
127 <head>
128 <?php html_header_show();?>
129 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
130 <script type="text/javascript" src="../../../library/dialog.js"></script>
131 <script language="JavaScript">
133 function seldiag(selobj, line_id) {
134 var i = selobj.selectedIndex;
135 var opt = selobj.options[i];
136 if (opt.value == '*') {
137 selobj.selectedIndex = 0;
138 dlgopen('../../forms/physical_exam/edit_diagnoses.php?lineid=' + line_id, '_blank', 500, 400);
142 function refreshme() {
143 top.restoreSession();
144 var f = document.forms[0];
145 f.form_refresh.value = '1';
146 f.submit();
149 </script>
150 </head>
152 <body class="body_top">
153 <form method="post" action="<?php echo $rootdir ?>/forms/physical_exam/new.php?id=<?php echo $formid ?>"
154 onsubmit="return top.restoreSession()">
156 <center>
159 <table border='0' width='98%'>
161 <tr>
162 <td align='center' width='1%' nowrap><b><?php xl('WNL','e'); ?></b></td>
163 <td align='center' width='1%' nowrap><b><?php xl('ABN1','e'); ?></b></td>
164 <td align='left' width='1%' nowrap><b><?php xl('System','e'); ?></b></td>
165 <td align='left' width='1%' nowrap><b><?php xl('Specific','e'); ?></b></td>
166 <td align='left' width='1%' nowrap><b><?php xl('Diagnosis','e'); ?></b></td>
167 <td align='left' width='95%' nowrap><b><?php xl('Comments','e'); ?></b></td>
168 </tr>
170 <?php
171 foreach ($pelines as $sysname => $sysarray) {
172 $sysnamedisp = $sysname;
173 if ($sysname == '*') {
174 // TBD: Show any remaining entries in $rows (should not be any).
175 echo " <tr><td colspan='6'>\n";
176 echo " &nbsp;<br><b>" .xl('Treatment:'). "</b>\n";
177 echo " </td></tr>\n";
179 else {
180 $sysnamedisp = xl($sysname);
182 foreach ($sysarray as $line_id => $description) {
183 if ($sysname != '*') {
184 showExamLine($line_id, $description, $rows[$line_id], $sysnamedisp);
185 } else {
186 showTreatmentLine($line_id, $description, $rows[$line_id]);
188 $sysnamedisp = '';
189 // TBD: Delete $rows[$line_id] if it exists.
190 } // end of line
191 } // end of system name
194 </table>
197 <input type='hidden' name='form_refresh' value='' />
198 <input type='submit' name='bn_save' value='<?php xl('Save','e'); ?>' />
199 &nbsp;
200 <input type='button' value='<?php xl('Cancel','e'); ?>'
201 onclick="top.restoreSession();location='<?php echo "$rootdir/patient_file/encounter/$returnurl" ?>'" />
202 </p>
204 </center>
206 </form>
207 <?php
208 // TBD: If $alertmsg, display it with a JavaScript alert().
210 </body>
211 </html>