yet more changes for new frame layout
[openemr.git] / interface / forms / physical_exam / new.php
blobaf8cad2423d58737df032b0b971e90e6421c1cd4
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 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
32 function showExamLine($line_id, $description, &$linedbrow, $sysnamedisp) {
33 $dres = sqlStatement("SELECT * FROM form_physical_exam_diagnoses " .
34 "WHERE line_id = '$line_id' ORDER BY ordering, diagnosis");
36 echo " <tr>\n";
37 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
38 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
39 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][abn]' " .
40 "value='1'" . ($linedbrow['abn'] ? " checked" : "") . " /></td>\n";
41 echo " <td nowrap>$sysnamedisp</td>\n";
42 echo " <td nowrap>$description</td>\n";
44 echo " <td><select name='form_obs[$line_id][diagnosis]' onchange='seldiag(this, \"$line_id\")' style='width:100%'>\n";
45 echo " <option value=''></option>\n";
46 $diagnosis = $linedbrow['diagnosis'];
47 while ($drow = sqlFetchArray($dres)) {
48 $sel = '';
49 $diag = $drow['diagnosis'];
50 if ($diagnosis && $diag == $diagnosis) {
51 $sel = 'selected';
52 $diagnosis = '';
54 echo " <option value='$diag' $sel>$diag</option>\n";
56 // If the diagnosis was not in the standard list then it must have been
57 // there before and then removed. In that case show it in parentheses.
58 if ($diagnosis) {
59 echo " <option value='$diagnosis' selected>($diagnosis)</option>\n";
61 echo " <option value='*'>-- Edit --</option>\n";
62 echo " </select></td>\n";
64 echo " <td><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 function showTreatmentLine($line_id, $description, &$linedbrow) {
71 echo " <tr>\n";
72 echo " <td align='center'><input type='checkbox' name='form_obs[$line_id][wnl]' " .
73 "value='1'" . ($linedbrow['wnl'] ? " checked" : "") . " /></td>\n";
74 echo " <td></td>\n";
75 echo " <td colspan='2' nowrap>$description</td>\n";
76 echo " <td colspan='2'><input type='text' name='form_obs[$line_id][comments]' " .
77 "size='20' maxlength='250' style='width:100%' " .
78 "value='" . htmlentities($linedbrow['comments']) . "' /></td>\n";
79 echo " </tr>\n";
82 $formid = $_GET['id'];
84 // If Save was clicked, save the info.
86 if ($_POST['bn_save']) {
88 // We are to update/insert multiple table rows for the form.
89 // Each has 2 checkboxes, a dropdown and a text input field.
90 // Skip rows that have no entries.
91 // There are also 3 special rows with just one checkbox and a text
92 // input field. Maybe also a diagnosis line, not clear.
94 if ($formid) {
95 $query = "DELETE FROM form_physical_exam WHERE forms_id = '$formid'";
96 sqlStatement($query);
98 else {
99 $formid = addForm($encounter, "Physical Exam", 0, "physical_exam", $pid, $userauthorized);
100 $query = "UPDATE forms SET form_id = id WHERE id = '$formid' AND form_id = 0";
101 sqlStatement($query);
104 $form_obs = $_POST['form_obs'];
105 foreach ($form_obs as $line_id => $line_array) {
106 $wnl = $line_array['wnl'] ? '1' : '0';
107 $abn = $line_array['abn'] ? '1' : '0';
108 $diagnosis = $line_array['diagnosis'] ? $line_array['diagnosis'] : '';
109 $comments = $line_array['comments'] ? $line_array['comments'] : '';
110 if ($wnl || $abn || $diagnosis || $comments) {
111 $query = "INSERT INTO form_physical_exam ( " .
112 "forms_id, line_id, wnl, abn, diagnosis, comments " .
113 ") VALUES ( " .
114 "'$formid', '$line_id', '$wnl', '$abn', '$diagnosis', '$comments' " .
115 ")";
116 sqlInsert($query);
120 if (! $_POST['form_refresh']) {
121 formHeader("Redirecting....");
122 formJump();
123 formFooter();
124 exit;
128 // Load all existing rows for this form as a hash keyed on line_id.
130 $rows = array();
131 if ($formid) {
132 $res = sqlStatement("SELECT * FROM form_physical_exam WHERE forms_id = '$formid'");
133 while ($row = sqlFetchArray($res)) {
134 $rows[$row['line_id']] = $row;
138 <html>
139 <head>
140 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
141 <script type="text/javascript" src="../../../library/dialog.js"></script>
142 <script language="JavaScript">
144 function seldiag(selobj, line_id) {
145 var i = selobj.selectedIndex;
146 var opt = selobj.options[i];
147 if (opt.value == '*') {
148 selobj.selectedIndex = 0;
149 dlgopen('../../forms/physical_exam/edit_diagnoses.php?lineid=' + line_id, '_blank', 500, 400);
153 function refreshme() {
154 var f = document.forms[0];
155 f.form_refresh.value = '1';
156 f.submit();
159 </script>
160 </head>
162 <body <?echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2"
163 bottommargin="0" marginwidth="2" marginheight="0">
164 <form method="post" action="<? echo $rootdir ?>/forms/physical_exam/new.php?id=<? echo $formid ?>">
166 <center>
169 <table border='0' width='98%'>
171 <tr>
172 <td align='center' width='1%' nowrap><b>WNL</b></td>
173 <td align='center' width='1%' nowrap><b>ABN1</b></td>
174 <td align='left' width='1%' nowrap><b>System</b></td>
175 <td align='left' width='1%' nowrap><b>Specific</b></td>
176 <td align='left' width='1%' nowrap><b>Diagnosis</b></td>
177 <td align='left' width='95%' nowrap><b>Comments</b></td>
178 </tr>
180 <?php
181 foreach ($pelines as $sysname => $sysarray) {
182 if ($sysname == '*') {
183 // TBD: Show any remaining entries in $rows (should not be any).
184 echo " <tr><td colspan='6'>\n";
185 echo " &nbsp;<br><b>Treatment:</b>\n";
186 echo " </td></tr>\n";
188 $sysnamedisp = $sysname;
189 foreach ($sysarray as $line_id => $description) {
190 if ($sysname != '*') {
191 showExamLine($line_id, $description, $rows[$line_id], $sysnamedisp);
192 } else {
193 showTreatmentLine($line_id, $description, $rows[$line_id]);
195 $sysnamedisp = '';
196 // TBD: Delete $rows[$line_id] if it exists.
197 } // end of line
198 } // end of system name
201 </table>
204 <input type='hidden' name='form_refresh' value='' />
205 <input type='submit' name='bn_save' value='Save' />
206 &nbsp;
207 <input type='button' value='Cancel' onclick="location='<? echo "$rootdir/patient_file/encounter/$returnurl" ?>'" />
208 </p>
210 </center>
212 </form>
213 <?php
214 // TBD: If $alertmsg, display it with a JavaScript alert().
216 </body>
217 </html>