Highway to PSR2
[openemr.git] / contrib / forms / scanned_notes / new.php
blob892a789f5cd6dff66922d84301f7a7390b82ebf1
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 require_once("../../globals.php");
25 require_once("$srcdir/api.inc");
26 require_once("$srcdir/forms.inc");
27 require_once("$srcdir/acl.inc");
29 $row = array();
31 if (! $encounter) { // comes from globals.php
32 die("Internal error: we do not seem to be in an encounter!");
35 $formid = $_GET['id'];
36 $imagedir = $GLOBALS['OE_SITE_DIR'] . "/documents/$pid/encounters";
38 // If Save was clicked, save the info.
40 if ($_POST['bn_save']) {
41 // If updating an existing form...
43 if ($formid) {
44 $query = "UPDATE form_scanned_notes SET notes = ? WHERE id = ?";
45 sqlStatement($query, array($_POST['form_notes'], $formid));
46 } // If adding a new form...
48 else {
49 $query = "INSERT INTO form_scanned_notes (notes) VALUES (?)";
50 $formid = sqlInsert($query, array($_POST['form_notes']));
51 addForm($encounter, "Scanned Notes", $formid, "scanned_notes", $pid, $userauthorized);
54 $imagepath = "$imagedir/${encounter}_$formid.jpg";
56 // Upload new or replacement document.
57 // Always convert it to jpeg.
58 if ($_FILES['form_image']['size']) {
59 // If the patient's encounter image directory does not yet exist, create it.
60 if (! is_dir($imagedir)) {
61 $tmp0 = exec("mkdir -p '$imagedir'", $tmp1, $tmp2);
62 if ($tmp2) {
63 die("mkdir returned $tmp2: $tmp0");
66 exec("touch '$imagedir/index.html'");
69 // Remove any previous image files for this encounter and form ID.
70 for ($i = -1; true; ++$i) {
71 $suffix = ($i < 0) ? "" : "-$i";
72 $path = "$imagedir/${encounter}_$formid$suffix.jpg";
73 if (is_file($path)) {
74 unlink($path);
75 } else {
76 if ($i >= 0) {
77 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) {
88 die("\"$cmd\" returned $tmp2: $tmp0");
92 // formHeader("Redirecting....");
93 // formJump();
94 // formFooter();
95 // exit;
98 $imagepath = "$imagedir/${encounter}_$formid.jpg";
99 $imageurl = "$web_root/sites/" . $_SESSION['site_id'] .
100 "/documents/$pid/encounters/${encounter}_$formid.jpg";
102 if ($formid) {
103 $row = sqlQuery(
104 "SELECT * FROM form_scanned_notes WHERE " .
105 "id = ? AND activity = '1'",
106 array($formid)
108 $formrow = sqlQuery(
109 "SELECT id FROM forms WHERE " .
110 "form_id = ? AND formdir = 'scanned_notes'",
111 array($formid)
115 <html>
116 <head>
117 <?php html_header_show();?>
118 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
119 <style type="text/css">
120 .dehead { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
121 .detail { color:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
122 </style>
123 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
125 <script language='JavaScript'>
127 function newEvt() {
128 dlgopen('../../main/calendar/add_edit_event.php?patientid=<?php echo $pid ?>',
129 '_blank', 775, 500);
130 return false;
133 // Process click on Delete button.
134 function deleteme() {
135 dlgopen('../../patient_file/deleter.php?formid=<?php echo $formrow['id'] ?>', '_blank', 500, 450);
136 return false;
139 // Called by the deleteme.php window on a successful delete.
140 function imdeleted() {
141 top.restoreSession();
142 location = '<?php echo $GLOBALS['form_exit_url']; ?>';
145 </script>
147 </head>
149 <body class="body_top">
151 <form method="post" enctype="multipart/form-data"
152 action="<?php echo $rootdir ?>/forms/scanned_notes/new.php?id=<?php echo $formid ?>"
153 onsubmit="return top.restoreSession()">
155 <center>
158 <table border='1' width='95%'>
160 <tr bgcolor='#dddddd' class='dehead'>
161 <td colspan='2' align='center'>Scanned Encounter Notes</td>
162 </tr>
164 <tr>
165 <td width='5%' class='dehead' nowrap>&nbsp;Comments&nbsp;</td>
166 <td width='95%' class='detail' nowrap>
167 <textarea name='form_notes' rows='4' style='width:100%'><?php echo $row['notes'] ?></textarea>
168 </td>
169 </tr>
171 <tr>
172 <td class='dehead' nowrap>&nbsp;Document&nbsp;</td>
173 <td class='detail' nowrap>
174 <?php
175 if ($formid && is_file($imagepath)) {
176 echo " <img src='$imageurl' />\n";
179 <p>&nbsp;
180 <?php xl('Upload this file:', 'e') ?>
181 <input type="hidden" name="MAX_FILE_SIZE" value="12000000" />
182 <input name="form_image" type="file" />
183 <br />&nbsp;</p>
184 </td>
185 </tr>
187 </table>
190 <input type='submit' name='bn_save' value='Save' />
191 &nbsp;
192 <input type='button' value='Add Appointment' onclick='newEvt()' />
193 &nbsp;
194 <input type='button' value='Back' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url']; ?>'" />
195 <?php if ($formrow['id'] && acl_check('admin', 'super')) { ?>
196 &nbsp;
197 <input type='button' value='Delete' onclick='deleteme()' style='color:red' />
198 <?php } ?>
199 </p>
201 </center>
203 </form>
204 </body>
205 </html>