Moving towards HTML5 and CSS3 compatibility. revision 2.
[openemr.git] / contrib / forms / scanned_notes / new.php
bloba0aeba62b3973d25f412fcc5a227f2b3f8f1d1af
1 <?php
2 /**
3 * Encounter form for entering clinical data as a scanned document.
5 * Copyright (C) 2006-2013 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 // NOTE: HTML escaping still needs to be done for this script.
24 $sanitize_all_escapes = true;
25 $fake_register_globals = false;
27 require_once("../../globals.php");
28 require_once("$srcdir/api.inc");
29 require_once("$srcdir/forms.inc");
30 require_once("$srcdir/acl.inc");
32 $row = array();
34 if (! $encounter) { // comes from globals.php
35 die("Internal error: we do not seem to be in an encounter!");
38 $formid = $_GET['id'];
39 $imagedir = $GLOBALS['OE_SITE_DIR'] . "/documents/$pid/encounters";
41 // If Save was clicked, save the info.
43 if ($_POST['bn_save']) {
45 // If updating an existing form...
47 if ($formid) {
48 $query = "UPDATE form_scanned_notes SET notes = ? WHERE id = ?";
49 sqlStatement($query, array($_POST['form_notes'], $formid));
52 // If adding a new form...
54 else {
55 $query = "INSERT INTO form_scanned_notes (notes) VALUES (?)";
56 $formid = sqlInsert($query, array($_POST['form_notes']));
57 addForm($encounter, "Scanned Notes", $formid, "scanned_notes", $pid, $userauthorized);
60 $imagepath = "$imagedir/${encounter}_$formid.jpg";
62 // Upload new or replacement document.
63 // Always convert it to jpeg.
64 if ($_FILES['form_image']['size']) {
65 // If the patient's encounter image directory does not yet exist, create it.
66 if (! is_dir($imagedir)) {
67 $tmp0 = exec("mkdir -p '$imagedir'", $tmp1, $tmp2);
68 if ($tmp2) die("mkdir returned $tmp2: $tmp0");
69 exec("touch '$imagedir/index.html'");
71 // Remove any previous image files for this encounter and form ID.
72 for ($i = -1; true; ++$i) {
73 $suffix = ($i < 0) ? "" : "-$i";
74 $path = "$imagedir/${encounter}_$formid$suffix.jpg";
75 if (is_file($path)) {
76 unlink($path);
78 else {
79 if ($i >= 0) break;
82 $tmp_name = $_FILES['form_image']['tmp_name'];
83 // default density is 72 dpi, we change to 96. And -append was removed
84 // to create a separate image file for each page.
85 $cmd = "convert -density 96 '$tmp_name' '$imagepath'";
86 $tmp0 = exec($cmd, $tmp1, $tmp2);
87 if ($tmp2) die("\"$cmd\" returned $tmp2: $tmp0");
90 // formHeader("Redirecting....");
91 // formJump();
92 // formFooter();
93 // exit;
96 $imagepath = "$imagedir/${encounter}_$formid.jpg";
97 $imageurl = "$web_root/sites/" . $_SESSION['site_id'] .
98 "/documents/$pid/encounters/${encounter}_$formid.jpg";
100 if ($formid) {
101 $row = sqlQuery("SELECT * FROM form_scanned_notes WHERE " .
102 "id = ? AND activity = '1'",
103 array($formid));
104 $formrow = sqlQuery("SELECT id FROM forms WHERE " .
105 "form_id = ? AND formdir = 'scanned_notes'",
106 array($formid));
109 <html>
110 <head>
111 <?php html_header_show();?>
112 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
113 <style type="text/css">
114 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
115 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
116 </style>
117 <script type="text/javascript" src="../../../library/dialog.js"></script>
119 <script language='JavaScript'>
121 function newEvt() {
122 dlgopen('../../main/calendar/add_edit_event.php?patientid=<?php echo $pid ?>',
123 '_blank', 550, 270);
124 return false;
127 // Process click on Delete button.
128 function deleteme() {
129 dlgopen('../../patient_file/deleter.php?formid=<?php echo $formrow['id'] ?>', '_blank', 500, 450);
130 return false;
133 // Called by the deleteme.php window on a successful delete.
134 function imdeleted() {
135 top.restoreSession();
136 location = '<?php echo $GLOBALS['form_exit_url']; ?>';
139 </script>
141 </head>
143 <body class="body_top">
145 <form method="post" enctype="multipart/form-data"
146 action="<?php echo $rootdir ?>/forms/scanned_notes/new.php?id=<?php echo $formid ?>"
147 onsubmit="return top.restoreSession()">
149 <center>
152 <table border='1' width='95%'>
154 <tr bgcolor='#dddddd' class='dehead'>
155 <td colspan='2' align='center'>Scanned Encounter Notes</td>
156 </tr>
158 <tr>
159 <td width='5%' class='dehead' nowrap>&nbsp;Comments&nbsp;</td>
160 <td width='95%' class='detail' nowrap>
161 <textarea name='form_notes' rows='4' style='width:100%'><?php echo $row['notes'] ?></textarea>
162 </td>
163 </tr>
165 <tr>
166 <td class='dehead' nowrap>&nbsp;Document&nbsp;</td>
167 <td class='detail' nowrap>
168 <?php
169 if ($formid && is_file($imagepath)) {
170 echo " <img src='$imageurl' />\n";
173 <p>&nbsp;
174 <?php xl('Upload this file:','e') ?>
175 <input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
176 <input name="form_image" type="file" />
177 <br />&nbsp;</p>
178 </td>
179 </tr>
181 </table>
184 <input type='submit' name='bn_save' value='Save' />
185 &nbsp;
186 <input type='button' value='Add Appointment' onclick='newEvt()' />
187 &nbsp;
188 <input type='button' value='Back' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
189 <?php if ($formrow['id'] && acl_check('admin', 'super')) { ?>
190 &nbsp;
191 <input type='button' value='Delete' onclick='deleteme()' style='color:red' />
192 <?php } ?>
193 </p>
195 </center>
197 </form>
198 </body>
199 </html>