added physical_exam encounter form
[openemr.git] / interface / forms / physical_exam / view.php
blob1bbc3a47f2402ea6896976610f4b0ccfbc26cda4
1 <?php
2 //////////////////////////////////////////////////////////////////////
3 // ------------------ DO NOT MODIFY VIEW.PHP !!! ---------------------
4 // View.php is an exact duplicate of new.php. If you wish to make
5 // any changes, then change new.php and either (recommended) make
6 // view.php a symbolic link to new.php, or copy new.php to view.php.
7 //
8 // And if you check in a change to either module, be sure to check
9 // in the other (identical) module also.
11 // This nonsense can go away when we move to subversion.
12 //////////////////////////////////////////////////////////////////////
14 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
16 // This program is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU General Public License
18 // as published by the Free Software Foundation; either version 2
19 // of the License, or (at your option) any later version.
21 include_once("../../globals.php");
22 include_once("$srcdir/api.inc");
23 include_once("$srcdir/forms.inc");
24 include_once("lines.php");
26 if (! $encounter) { // comes from globals.php
27 die("Internal error: we do not seem to be in an encounter!");
30 function showExamLine($line_id, $description, &$linedbrow, $sysnamedisp) {
31 $dres = sqlStatement("SELECT * FROM form_physical_exam_diagnoses " .
32 "WHERE line_id = '$line_id' ORDER BY ordering, diagnosis");
34 echo " <tr>\n";
35 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
36 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
37 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][abn]' " .
38 "value='1'" . ($linedbrow['abn'] ? " checked" : "") . " /></td>\n";
39 echo " <td nowrap>$sysnamedisp</td>\n";
40 echo " <td nowrap>$description</td>\n";
42 echo " <td><select name='form_obs[$line_id][diagnosis]' onchange='seldiag(this, \"$line_id\")' style='width:100%'>\n";
43 echo " <option value=''></option>\n";
44 $diagnosis = $linedbrow['diagnosis'];
45 while ($drow = sqlFetchArray($dres)) {
46 $sel = '';
47 $diag = $drow['diagnosis'];
48 if ($diagnosis && $diag == $diagnosis) {
49 $sel = 'selected';
50 $diagnosis = '';
52 echo " <option value='$diag' $sel>$diag</option>\n";
54 // If the diagnosis was not in the standard list then it must have been
55 // there before and then removed. In that case show it in parentheses.
56 if ($diagnosis) {
57 echo " <option value='$diagnosis' selected>($diagnosis)</option>\n";
59 echo " <option value='*'>-- Edit --</option>\n";
60 echo " </select></td>\n";
62 echo " <td><input type='text' name='form_obs[$line_id][comments]' " .
63 "size='20' maxlength='250' style='width:100%' " .
64 "value='" . htmlentities($linedbrow['comments']) . "' /></td>\n";
65 echo " </tr>\n";
68 function showTreatmentLine($line_id, $description, &$linedbrow) {
69 echo " <tr>\n";
70 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
71 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
72 echo " <td></td>\n";
73 echo " <td colspan='2' nowrap>$description</td>\n";
74 echo " <td colspan='2'><input type='text' name='form_obs[$line_id][comments]' " .
75 "size='20' maxlength='250' style='width:100%' " .
76 "value='" . htmlentities($linedbrow['comments']) . "' /></td>\n";
77 echo " </tr>\n";
80 $formid = $_GET['id'];
82 // If Save was clicked, save the info.
84 if ($_POST['bn_save']) {
86 // We are to update/insert multiple table rows for the form.
87 // Each has 2 checkboxes, a dropdown and a text input field.
88 // Skip rows that have no entries.
89 // There are also 3 special rows with just one checkbox and a text
90 // input field. Maybe also a diagnosis line, not clear.
92 if ($formid) {
93 $query = "DELETE FROM form_physical_exam WHERE forms_id = '$formid'";
94 sqlStatement($query);
96 else {
97 $formid = addForm($encounter, "Physical Exam", 0, "physical_exam", $pid, $userauthorized);
98 $query = "UPDATE forms SET form_id = id WHERE id = '$formid' AND form_id = 0";
99 sqlStatement($query);
102 $form_obs = $_POST['form_obs'];
103 foreach ($form_obs as $line_id => $line_array) {
104 $wnl = $line_array['wnl'] ? '1' : '0';
105 $abn = $line_array['abn'] ? '1' : '0';
106 $diagnosis = $line_array['diagnosis'] ? $line_array['diagnosis'] : '';
107 $comments = $line_array['comments'] ? $line_array['comments'] : '';
108 if ($wnl || $abn || $diagnosis || $comments) {
109 $query = "INSERT INTO form_physical_exam ( " .
110 "forms_id, line_id, wnl, abn, diagnosis, comments " .
111 ") VALUES ( " .
112 "'$formid', '$line_id', '$wnl', '$abn', '$diagnosis', '$comments' " .
113 ")";
114 sqlInsert($query);
118 if (! $_POST['form_refresh']) {
119 formHeader("Redirecting....");
120 formJump();
121 formFooter();
122 exit;
126 // Load all existing rows for this form as a hash keyed on line_id.
128 $rows = array();
129 if ($formid) {
130 $res = sqlStatement("SELECT * FROM form_physical_exam WHERE forms_id = '$formid'");
131 while ($row = sqlFetchArray($res)) {
132 $rows[$row['line_id']] = $row;
136 <html>
137 <head>
138 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
139 <script type="text/javascript" src="../../../library/dialog.js"></script>
140 <script language="JavaScript">
142 function seldiag(selobj, line_id) {
143 var i = selobj.selectedIndex;
144 var opt = selobj.options[i];
145 if (opt.value == '*') {
146 selobj.selectedIndex = 0;
147 dlgopen('../../forms/physical_exam/edit_diagnoses.php?lineid=' + line_id, '_blank', 500, 400);
151 function refreshme() {
152 var f = document.forms[0];
153 f.form_refresh.value = '1';
154 f.submit();
157 </script>
158 </head>
160 <body <?echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2"
161 bottommargin="0" marginwidth="2" marginheight="0">
162 <form method="post" action="<? echo $rootdir ?>/forms/physical_exam/new.php?id=<? echo $formid ?>">
164 <center>
167 <table border='0' width='98%'>
169 <tr>
170 <td align='center' width='1%' nowrap><b>WNL</b></td>
171 <td align='center' width='1%' nowrap><b>ABN1</b></td>
172 <td align='left' width='1%' nowrap><b>System</b></td>
173 <td align='left' width='1%' nowrap><b>Specific</b></td>
174 <td align='left' width='1%' nowrap><b>Diagnosis</b></td>
175 <td align='left' width='95%' nowrap><b>Comments</b></td>
176 </tr>
178 <?php
179 foreach ($pelines as $sysname => $sysarray) {
180 if ($sysname == '*') {
181 // TBD: Show any remaining entries in $rows (should not be any).
182 echo " <tr><td colspan='6'>\n";
183 echo " &nbsp;<br><b>Treatment:</b>\n";
184 echo " </td></tr>\n";
186 $sysnamedisp = $sysname;
187 foreach ($sysarray as $line_id => $description) {
188 if ($sysname != '*') {
189 showExamLine($line_id, $description, $rows[$line_id], $sysnamedisp);
190 } else {
191 showTreatmentLine($line_id, $description, $rows[$line_id]);
193 $sysnamedisp = '';
194 // TBD: Delete $rows[$line_id] if it exists.
195 } // end of line
196 } // end of system name
199 </table>
202 <input type='hidden' name='form_refresh' value='' />
203 <input type='submit' name='bn_save' value='Save' />
204 &nbsp;
205 <input type='button' value='Cancel' onclick="location='<? echo "$rootdir/patient_file/encounter/patient_encounter.php" ?>'" />
206 </p>
208 </center>
210 </form>
211 <?php
212 // TBD: If $alertmsg, display it with a JavaScript alert().
214 </body>
215 </html>