4 * Functions for documents.
6 * Copyright (C) 2013 Brady Miller <brady.g.miller@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @author Brady Miller <brady.g.miller@gmail.com>
21 * @link https://www.open-emr.org
24 require_once($GLOBALS['fileroot'] . "/controllers/C_Document.class.php");
27 * Function to add a document via the C_Document class.
29 * @param string $name Name of the document
30 * @param string $type Mime type of file
31 * @param string $tmp_name Temporary file name
32 * @param string $error Errors in file upload
33 * @param string $size Size of file
34 * @param int $owner Owner/user/service that imported the file
35 * @param string $patient_id_or_simple_directory Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
36 * @param int $category_id Document category id
37 * @param string $higher_level_path Can set a higher level path here (and then place the path depth in $path_depth)
38 * @param int $path_depth Path depth when using the $higher_level_path feature
39 * @param boolean $skip_acl_check This needs to be set to true for when uploading via services that piggyback on any user (ie. the background services) or uses cron/cli
40 * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
42 function addNewDocument(
49 $patient_id_or_simple_directory = "00",
51 $higher_level_path = '',
53 $skip_acl_check = false
57 $owner = $_SESSION['authUserID'];
60 // Build the $_FILES array
61 $TEMP_FILES = array();
62 $TEMP_FILES['file']['name'][0] = $name;
63 $TEMP_FILES['file']['type'][0] = $type;
64 $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
65 $TEMP_FILES['file']['error'][0] = $error;
66 $TEMP_FILES['file']['size'][0] = $size;
67 $_FILES = $TEMP_FILES;
69 // Build the parameters
70 $_GET['higher_level_path'] = $higher_level_path;
71 $_GET['patient_id'] = $patient_id_or_simple_directory;
72 $_POST['destination'] = '';
73 $_POST['submit'] = 'Upload';
74 $_POST['path_depth'] = $path_depth;
75 $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ?
$patient_id_or_simple_directory : "00";
76 $_POST['category_id'] = $category_id;
77 $_POST['process'] = 'true';
79 // Add the Document and return the newly added document id
80 $cd = new C_Document();
81 $cd->manual_set_owner
= $owner;
82 if ($skip_acl_check) {
85 $cd->upload_action_process();
86 $v = $cd->getTemplateVars("file");
87 if (!isset($v) ||
!$v) {
91 return array("doc_id" => $v[0]->id
, "url" => $v[0]->url
, "name" => $v[0]->name
);
95 * Function to return the category id of a category title.
97 * @param string $category_title category title
98 * @return int/boolean category id (returns false if the category title does not exist)
100 function document_category_to_id($category_title)
102 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
111 * Function used in the documents request for patient portal..
113 * @param string $imagetype Image type
114 * @return string File extension Image type (returns false if the Image type does not exist)
116 function get_extension($imagetype)
118 if (empty($imagetype)) {
122 switch ($imagetype) {
123 case 'application/andrew-inset':
125 case 'application/mac-binhex40':
127 case 'application/mac-compactpro':
129 case 'application/msword':
131 case 'application/octet-stream':
133 case 'application/octet-stream':
135 case 'application/octet-stream':
137 case 'application/octet-stream':
139 case 'application/octet-stream':
141 case 'application/octet-stream':
143 case 'application/octet-stream':
145 case 'application/octet-stream':
147 case 'application/oda':
149 case 'application/pdf':
151 case 'application/postscript':
153 case 'application/postscript':
155 case 'application/postscript':
157 case 'application/smil':
159 case 'application/smil':
161 case 'application/vnd.wap.wbxml':
163 case 'application/vnd.wap.wmlc':
165 case 'application/vnd.wap.wmlscriptc':
167 case 'application/x-bcpio':
169 case 'application/x-cdlink':
171 case 'application/x-chess-pgn':
173 case 'application/x-cpio':
175 case 'application/x-csh':
177 case 'application/x-director':
179 case 'application/x-director':
181 case 'application/x-director':
183 case 'application/x-dvi':
185 case 'application/x-futuresplash':
187 case 'application/x-gtar':
189 case 'application/x-hdf':
191 case 'application/x-javascript':
193 case 'application/x-koan':
195 case 'application/x-koan':
197 case 'application/x-koan':
199 case 'application/x-koan':
201 case 'application/x-latex':
203 case 'application/x-netcdf':
205 case 'application/x-netcdf':
207 case 'application/x-sh':
209 case 'application/x-shar':
211 case 'application/x-shockwave-flash':
213 case 'application/x-stuffit':
215 case 'application/x-sv4cpio':
217 case 'application/x-sv4crc':
219 case 'application/x-tar':
221 case 'application/x-tcl':
223 case 'application/x-tex':
225 case 'application/x-texinfo':
227 case 'application/x-texinfo':
229 case 'application/x-troff':
231 case 'application/x-troff':
233 case 'application/x-troff':
235 case 'application/x-troff-man':
237 case 'application/x-troff-me':
239 case 'application/x-troff-ms':
241 case 'application/x-ustar':
243 case 'application/x-wais-source':
245 case 'application/xhtml+xml':
247 case 'application/xhtml+xml':
249 case 'application/zip':
273 case 'audio/x-mpegurl':
275 case 'audio/x-pn-realaudio':
277 case 'audio/x-pn-realaudio':
279 case 'audio/x-pn-realaudio-plugin':
281 case 'audio/x-realaudio':
285 case 'chemical/x-pdb':
287 case 'chemical/x-xyz':
307 case 'image/vnd.djvu':
309 case 'image/vnd.djvu':
311 case 'image/vnd.wap.wbmp':
313 case 'image/x-cmu-raster':
315 case 'image/x-portable-anymap':
317 case 'image/x-portable-bitmap':
319 case 'image/x-portable-graymap':
321 case 'image/x-portable-pixmap':
325 case 'image/x-xbitmap':
327 case 'image/x-xpixmap':
329 case 'image/x-windowdump':
355 case 'text/richtext':
363 case 'text/tab-seperated-values':
365 case 'text/vnd.wap.wml':
367 case 'text/vnd.wap.wmlscript':
369 case 'text/x-setext':
381 case 'video/quicktime':
383 case 'video/quicktime':
385 case 'video/vnd.mpegurl':
387 case 'video/x-msvideo':
389 case 'video/x-sgi-movie':
391 case 'x-conference-xcooltalk':