fix: Update patient_tracker.php (#6595)
[openemr.git] / library / documents.php
blob16e40064fa6997f36a0bf91eb0ded46e58fd95f3
1 <?php
3 /**
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>;.
19 * @package OpenEMR
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");
26 /**
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($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1', $skip_acl_check = false)
45 if (empty($owner)) {
46 $owner = $_SESSION['authUserID'];
49 // Build the $_FILES array
50 $TEMP_FILES = array();
51 $TEMP_FILES['file']['name'][0] = $name;
52 $TEMP_FILES['file']['type'][0] = $type;
53 $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
54 $TEMP_FILES['file']['error'][0] = $error;
55 $TEMP_FILES['file']['size'][0] = $size;
56 $_FILES = $TEMP_FILES;
58 // Build the parameters
59 $_GET['higher_level_path'] = $higher_level_path;
60 $_GET['patient_id'] = $patient_id_or_simple_directory;
61 $_POST['destination'] = '';
62 $_POST['submit'] = 'Upload';
63 $_POST['path_depth'] = $path_depth;
64 $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ? $patient_id_or_simple_directory : "00";
65 $_POST['category_id'] = $category_id;
66 $_POST['process'] = 'true';
68 // Add the Document and return the newly added document id
69 $cd = new C_Document();
70 $cd->manual_set_owner = $owner;
71 if ($skip_acl_check) {
72 $cd->skipAclCheck();
74 $cd->upload_action_process();
75 $v = $cd->getTemplateVars("file");
76 if (!isset($v) || !$v) {
77 return false;
80 return array ("doc_id" => $v[0]->id, "url" => $v[0]->url);
83 /**
84 * Function to return the category id of a category title.
86 * @param string $category_title category title
87 * @return int/boolean category id (returns false if the category title does not exist)
89 function document_category_to_id($category_title)
91 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
92 if ($ret['id']) {
93 return $ret['id'];
94 } else {
95 return false;
99 /**
100 * Function used in the documents request for patient portal..
102 * @param string $imagetype Image type
103 * @return File extension Image type (returns false if the Image type does not exist)
105 function get_extension($imagetype)
107 if (empty($imagetype)) {
108 return false;
111 switch ($imagetype) {
112 case 'application/andrew-inset':
113 return '.ez';
114 case 'application/mac-binhex40':
115 return '.hqx';
116 case 'application/mac-compactpro':
117 return '.cpt';
118 case 'application/msword':
119 return '.doc';
120 case 'application/octet-stream':
121 return '.bin';
122 case 'application/octet-stream':
123 return '.dms';
124 case 'application/octet-stream':
125 return '.lha';
126 case 'application/octet-stream':
127 return '.lzh';
128 case 'application/octet-stream':
129 return '.exe';
130 case 'application/octet-stream':
131 return '.class';
132 case 'application/octet-stream':
133 return '.so';
134 case 'application/octet-stream':
135 return '.dll';
136 case 'application/oda':
137 return '.oda';
138 case 'application/pdf':
139 return '.pdf';
140 case 'application/postscript':
141 return '.ai';
142 case 'application/postscript':
143 return '.eps';
144 case 'application/postscript':
145 return '.ps';
146 case 'application/smil':
147 return '.smi';
148 case 'application/smil':
149 return '.smil';
150 case 'application/vnd.wap.wbxml':
151 return '.wbxml';
152 case 'application/vnd.wap.wmlc':
153 return '.wmlc';
154 case 'application/vnd.wap.wmlscriptc':
155 return '.wmlsc';
156 case 'application/x-bcpio':
157 return '.bcpio';
158 case 'application/x-cdlink':
159 return '.vcd';
160 case 'application/x-chess-pgn':
161 return '.pgn';
162 case 'application/x-cpio':
163 return '.cpio';
164 case 'application/x-csh':
165 return '.csh';
166 case 'application/x-director':
167 return '.dcr';
168 case 'application/x-director':
169 return '.dir';
170 case 'application/x-director':
171 return '.dxr';
172 case 'application/x-dvi':
173 return '.dvi';
174 case 'application/x-futuresplash':
175 return '.spl';
176 case 'application/x-gtar':
177 return '.gtar';
178 case 'application/x-hdf':
179 return '.hdf';
180 case 'application/x-javascript':
181 return '.js';
182 case 'application/x-koan':
183 return '.skp';
184 case 'application/x-koan':
185 return '.skd';
186 case 'application/x-koan':
187 return '.skt';
188 case 'application/x-koan':
189 return '.skm';
190 case 'application/x-latex':
191 return '.latex';
192 case 'application/x-netcdf':
193 return '.nc';
194 case 'application/x-netcdf':
195 return '.cdf';
196 case 'application/x-sh':
197 return '.sh';
198 case 'application/x-shar':
199 return '.shar';
200 case 'application/x-shockwave-flash':
201 return '.swf';
202 case 'application/x-stuffit':
203 return '.sit';
204 case 'application/x-sv4cpio':
205 return '.sv4cpio';
206 case 'application/x-sv4crc':
207 return '.sv4crc';
208 case 'application/x-tar':
209 return '.tar';
210 case 'application/x-tcl':
211 return '.tcl';
212 case 'application/x-tex':
213 return '.tex';
214 case 'application/x-texinfo':
215 return '.texinfo';
216 case 'application/x-texinfo':
217 return '.texi';
218 case 'application/x-troff':
219 return '.t';
220 case 'application/x-troff':
221 return '.tr';
222 case 'application/x-troff':
223 return '.roff';
224 case 'application/x-troff-man':
225 return '.man';
226 case 'application/x-troff-me':
227 return '.me';
228 case 'application/x-troff-ms':
229 return '.ms';
230 case 'application/x-ustar':
231 return '.ustar';
232 case 'application/x-wais-source':
233 return '.src';
234 case 'application/xhtml+xml':
235 return '.xhtml';
236 case 'application/xhtml+xml':
237 return '.xht';
238 case 'application/zip':
239 return '.zip';
240 case 'audio/basic':
241 return '.au';
242 case 'audio/basic':
243 return '.snd';
244 case 'audio/midi':
245 return '.mid';
246 case 'audio/midi':
247 return '.midi';
248 case 'audio/midi':
249 return '.kar';
250 case 'audio/mpeg':
251 return '.mpga';
252 case 'audio/mpeg':
253 return '.mp2';
254 case 'audio/mpeg':
255 return '.mp3';
256 case 'audio/x-aiff':
257 return '.aif';
258 case 'audio/x-aiff':
259 return '.aiff';
260 case 'audio/x-aiff':
261 return '.aifc';
262 case 'audio/x-mpegurl':
263 return '.m3u';
264 case 'audio/x-pn-realaudio':
265 return '.ram';
266 case 'audio/x-pn-realaudio':
267 return '.rm';
268 case 'audio/x-pn-realaudio-plugin':
269 return '.rpm';
270 case 'audio/x-realaudio':
271 return '.ra';
272 case 'audio/x-wav':
273 return '.wav';
274 case 'chemical/x-pdb':
275 return '.pdb';
276 case 'chemical/x-xyz':
277 return '.xyz';
278 case 'image/bmp':
279 return '.bmp';
280 case 'image/gif':
281 return '.gif';
282 case 'image/ief':
283 return '.ief';
284 case 'image/jpeg':
285 return '.jpeg';
286 case 'image/jpeg':
287 return '.jpg';
288 case 'image/jpeg':
289 return '.jpe';
290 case 'image/png':
291 return '.png';
292 case 'image/tiff':
293 return '.tiff';
294 case 'image/tif':
295 return '.tif';
296 case 'image/vnd.djvu':
297 return '.djvu';
298 case 'image/vnd.djvu':
299 return '.djv';
300 case 'image/vnd.wap.wbmp':
301 return '.wbmp';
302 case 'image/x-cmu-raster':
303 return '.ras';
304 case 'image/x-portable-anymap':
305 return '.pnm';
306 case 'image/x-portable-bitmap':
307 return '.pbm';
308 case 'image/x-portable-graymap':
309 return '.pgm';
310 case 'image/x-portable-pixmap':
311 return '.ppm';
312 case 'image/x-rgb':
313 return '.rgb';
314 case 'image/x-xbitmap':
315 return '.xbm';
316 case 'image/x-xpixmap':
317 return '.xpm';
318 case 'image/x-windowdump':
319 return '.xwd';
320 case 'model/iges':
321 return '.igs';
322 case 'model/iges':
323 return '.iges';
324 case 'model/mesh':
325 return '.msh';
326 case 'model/mesh':
327 return '.mesh';
328 case 'model/mesh':
329 return '.silo';
330 case 'model/vrml':
331 return '.wrl';
332 case 'model/vrml':
333 return '.vrml';
334 case 'text/css':
335 return '.css';
336 case 'text/html':
337 return '.html';
338 case 'text/html':
339 return '.htm';
340 case 'text/plain':
341 return '.asc';
342 case 'text/plain':
343 return '.txt';
344 case 'text/richtext':
345 return '.rtx';
346 case 'text/rtf':
347 return '.rtf';
348 case 'text/sgml':
349 return '.sgml';
350 case 'text/sgml':
351 return '.sgm';
352 case 'text/tab-seperated-values':
353 return '.tsv';
354 case 'text/vnd.wap.wml':
355 return '.wml';
356 case 'text/vnd.wap.wmlscript':
357 return '.wmls';
358 case 'text/x-setext':
359 return '.etx';
360 case 'text/xml':
361 return '.xml';
362 case 'text/xml':
363 return '.xsl';
364 case 'video/mpeg':
365 return '.mpeg';
366 case 'video/mpeg':
367 return '.mpg';
368 case 'video/mpeg':
369 return '.mpe';
370 case 'video/quicktime':
371 return '.qt';
372 case 'video/quicktime':
373 return '.mov';
374 case 'video/vnd.mpegurl':
375 return '.mxu';
376 case 'video/x-msvideo':
377 return '.avi';
378 case 'video/x-sgi-movie':
379 return '.movie';
380 case 'x-conference-xcooltalk':
381 return '.ice';
382 default:
383 return "";