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>.
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");
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...
48 $query = "UPDATE form_scanned_notes SET notes = ? WHERE id = ?";
49 sqlStatement($query, array($_POST['form_notes'], $formid));
52 // If adding a new form...
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";
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....");
96 $imagepath = "$imagedir/${encounter}_$formid.jpg";
97 $imageurl = "$web_root/sites/" . $_SESSION['site_id'] .
98 "/documents/$pid/encounters/${encounter}_$formid.jpg";
101 $row = sqlQuery("SELECT * FROM form_scanned_notes WHERE " .
102 "id = ? AND activity = '1'",
104 $formrow = sqlQuery("SELECT id FROM forms WHERE " .
105 "form_id = ? AND formdir = 'scanned_notes'",
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 }
117 <script type
="text/javascript" src
="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
119 <script language
='JavaScript'>
122 dlgopen('../../main/calendar/add_edit_event.php?patientid=<?php echo $pid ?>',
127 // Process click on Delete button.
128 function deleteme() {
129 dlgopen('../../patient_file/deleter.php?formid=<?php echo $formrow['id
'] ?>', '_blank', 500, 450);
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
']; ?>';
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()">
152 <table border
='1' width
='95%'>
154 <tr bgcolor
='#dddddd' class='dehead'>
155 <td colspan
='2' align
='center'>Scanned Encounter Notes
</td
>
159 <td width
='5%' class='dehead' nowrap
> 
;Comments
 
;</td
>
160 <td width
='95%' class='detail' nowrap
>
161 <textarea name
='form_notes' rows
='4' style
='width:100%'><?php
echo $row['notes'] ?
></textarea
>
166 <td
class='dehead' nowrap
> 
;Document
 
;</td
>
167 <td
class='detail' nowrap
>
169 if ($formid && is_file($imagepath)) {
170 echo " <img src='$imageurl' />\n";
174 <?php
xl('Upload this file:','e') ?
>
175 <input type
="hidden" name
="MAX_FILE_SIZE" value
="12000000" />
176 <input name
="form_image" type
="file" />
184 <input type
='submit' name
='bn_save' value
='Save' />
186 <input type
='button' value
='Add Appointment' onclick
='newEvt()' />
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')) { ?
>
191 <input type
='button' value
='Delete' onclick
='deleteme()' style
='color:red' />