3 * Functions for documents.
5 * Copyright (C) 2013 Brady Miller <brady@sparmy.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 3
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 Brady Miller <brady@sparmy.com>
20 * @link http://www.open-emr.org
23 require_once($GLOBALS['fileroot']."/controllers/C_Document.class.php");
26 * Function to add a document via the C_Document class.
28 * @param string $name Name of the document
29 * @param string $type Mime type of file
30 * @param string $tmp_name Temporary file name
31 * @param string $error Errors in file upload
32 * @param string $size Size of file
33 * @param int $owner Owner/user/service that imported the file
34 * @param string $patient_id_or_simple_directory Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
35 * @param int $category_id Document category id
36 * @param string $higher_level_path Can set a higher level path here (and then place the path depth in $path_depth)
37 * @param int $path_depth Path depth when using the $higher_level_path feature
38 * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
40 function addNewDocument($name,$type,$tmp_name,$error,$size,$owner='',$patient_id_or_simple_directory="00",$category_id='1',$higher_level_path='',$path_depth='1') {
43 $owner = $_SESSION['authUserID'];
46 // Build the $_FILES array
47 $TEMP_FILES = array();
48 $TEMP_FILES['file']['name'][0]=$name;
49 $TEMP_FILES['file']['type'][0]=$type;
50 $TEMP_FILES['file']['tmp_name'][0]=$tmp_name;
51 $TEMP_FILES['file']['error'][0]=$error;
52 $TEMP_FILES['file']['size'][0]=$size;
53 $_FILES = $TEMP_FILES;
55 // Build the parameters
56 $_GET['higher_level_path']=$higher_level_path;
57 $_GET['patient_id']=$patient_id_or_simple_directory;
58 $_POST['destination']='';
59 $_POST['submit']='Upload';
60 $_POST['path_depth']=$path_depth;
61 $_POST['patient_id']=(is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory>0) ?
$patient_id_or_simple_directory : "00";
62 $_POST['category_id']=$category_id;
63 $_POST['process']='true';
65 // Add the Document and return the newly added document id
66 $cd = new C_Document();
67 $cd->manual_set_owner
=$owner;
68 $cd->upload_action_process();
69 $v = $cd->get_template_vars("file");
70 if (!isset($v) ||
!$v) return false;
71 return array ("doc_id" => $v[0]->id
, "url" => $v[0]->url
);
75 * Function to return the category id of a category title.
77 * @param string $category_title category title
78 * @return int/boolean category id (returns false if the category title does not exist)
80 function document_category_to_id($category_title) {
81 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title) );
91 * Function used in the documents request for patient portal..
93 * @param string $imagetype Image type
94 * @return File extension Image type (returns false if the Image type does not exist)
96 function get_extension($imagetype) {
97 if(empty($imagetype)) return false;
100 case 'application/andrew-inset': return '.ez';
101 case 'application/mac-binhex40': return '.hqx';
102 case 'application/mac-compactpro': return '.cpt';
103 case 'application/msword': return '.doc';
104 case 'application/octet-stream': return '.bin';
105 case 'application/octet-stream': return '.dms';
106 case 'application/octet-stream': return '.lha';
107 case 'application/octet-stream': return '.lzh';
108 case 'application/octet-stream': return '.exe';
109 case 'application/octet-stream': return '.class';
110 case 'application/octet-stream': return '.so';
111 case 'application/octet-stream': return '.dll';
112 case 'application/oda': return '.oda';
113 case 'application/pdf': return '.pdf';
114 case 'application/postscript': return '.ai';
115 case 'application/postscript': return '.eps';
116 case 'application/postscript': return '.ps';
117 case 'application/smil': return '.smi';
118 case 'application/smil': return '.smil';
119 case 'application/vnd.wap.wbxml': return '.wbxml';
120 case 'application/vnd.wap.wmlc': return '.wmlc';
121 case 'application/vnd.wap.wmlscriptc': return '.wmlsc';
122 case 'application/x-bcpio': return '.bcpio';
123 case 'application/x-cdlink': return '.vcd';
124 case 'application/x-chess-pgn': return '.pgn';
125 case 'application/x-cpio': return '.cpio';
126 case 'application/x-csh': return '.csh';
127 case 'application/x-director': return '.dcr';
128 case 'application/x-director': return '.dir';
129 case 'application/x-director': return '.dxr';
130 case 'application/x-dvi': return '.dvi';
131 case 'application/x-futuresplash': return '.spl';
132 case 'application/x-gtar': return '.gtar';
133 case 'application/x-hdf': return '.hdf';
134 case 'application/x-javascript': return '.js';
135 case 'application/x-koan': return '.skp';
136 case 'application/x-koan': return '.skd';
137 case 'application/x-koan': return '.skt';
138 case 'application/x-koan': return '.skm';
139 case 'application/x-latex': return '.latex';
140 case 'application/x-netcdf': return '.nc';
141 case 'application/x-netcdf': return '.cdf';
142 case 'application/x-sh': return '.sh';
143 case 'application/x-shar': return '.shar';
144 case 'application/x-shockwave-flash': return '.swf';
145 case 'application/x-stuffit': return '.sit';
146 case 'application/x-sv4cpio': return '.sv4cpio';
147 case 'application/x-sv4crc': return '.sv4crc';
148 case 'application/x-tar': return '.tar';
149 case 'application/x-tcl': return '.tcl';
150 case 'application/x-tex': return '.tex';
151 case 'application/x-texinfo': return '.texinfo';
152 case 'application/x-texinfo': return '.texi';
153 case 'application/x-troff': return '.t';
154 case 'application/x-troff': return '.tr';
155 case 'application/x-troff': return '.roff';
156 case 'application/x-troff-man': return '.man';
157 case 'application/x-troff-me': return '.me';
158 case 'application/x-troff-ms': return '.ms';
159 case 'application/x-ustar': return '.ustar';
160 case 'application/x-wais-source': return '.src';
161 case 'application/xhtml+xml': return '.xhtml';
162 case 'application/xhtml+xml': return '.xht';
163 case 'application/zip': return '.zip';
164 case 'audio/basic': return '.au';
165 case 'audio/basic': return '.snd';
166 case 'audio/midi': return '.mid';
167 case 'audio/midi': return '.midi';
168 case 'audio/midi': return '.kar';
169 case 'audio/mpeg': return '.mpga';
170 case 'audio/mpeg': return '.mp2';
171 case 'audio/mpeg': return '.mp3';
172 case 'audio/x-aiff': return '.aif';
173 case 'audio/x-aiff': return '.aiff';
174 case 'audio/x-aiff': return '.aifc';
175 case 'audio/x-mpegurl': return '.m3u';
176 case 'audio/x-pn-realaudio': return '.ram';
177 case 'audio/x-pn-realaudio': return '.rm';
178 case 'audio/x-pn-realaudio-plugin': return '.rpm';
179 case 'audio/x-realaudio': return '.ra';
180 case 'audio/x-wav': return '.wav';
181 case 'chemical/x-pdb': return '.pdb';
182 case 'chemical/x-xyz': return '.xyz';
183 case 'image/bmp': return '.bmp';
184 case 'image/gif': return '.gif';
185 case 'image/ief': return '.ief';
186 case 'image/jpeg': return '.jpeg';
187 case 'image/jpeg': return '.jpg';
188 case 'image/jpeg': return '.jpe';
189 case 'image/png': return '.png';
190 case 'image/tiff': return '.tiff';
191 case 'image/tif': return '.tif';
192 case 'image/vnd.djvu': return '.djvu';
193 case 'image/vnd.djvu': return '.djv';
194 case 'image/vnd.wap.wbmp': return '.wbmp';
195 case 'image/x-cmu-raster': return '.ras';
196 case 'image/x-portable-anymap': return '.pnm';
197 case 'image/x-portable-bitmap': return '.pbm';
198 case 'image/x-portable-graymap': return '.pgm';
199 case 'image/x-portable-pixmap': return '.ppm';
200 case 'image/x-rgb': return '.rgb';
201 case 'image/x-xbitmap': return '.xbm';
202 case 'image/x-xpixmap': return '.xpm';
203 case 'image/x-windowdump': return '.xwd';
204 case 'model/iges': return '.igs';
205 case 'model/iges': return '.iges';
206 case 'model/mesh': return '.msh';
207 case 'model/mesh': return '.mesh';
208 case 'model/mesh': return '.silo';
209 case 'model/vrml': return '.wrl';
210 case 'model/vrml': return '.vrml';
211 case 'text/css': return '.css';
212 case 'text/html': return '.html';
213 case 'text/html': return '.htm';
214 case 'text/plain': return '.asc';
215 case 'text/plain': return '.txt';
216 case 'text/richtext': return '.rtx';
217 case 'text/rtf': return '.rtf';
218 case 'text/sgml': return '.sgml';
219 case 'text/sgml': return '.sgm';
220 case 'text/tab-seperated-values': return '.tsv';
221 case 'text/vnd.wap.wml': return '.wml';
222 case 'text/vnd.wap.wmlscript': return '.wmls';
223 case 'text/x-setext': return '.etx';
224 case 'text/xml': return '.xml';
225 case 'text/xml': return '.xsl';
226 case 'video/mpeg': return '.mpeg';
227 case 'video/mpeg': return '.mpg';
228 case 'video/mpeg': return '.mpe';
229 case 'video/quicktime': return '.qt';
230 case 'video/quicktime': return '.mov';
231 case 'video/vnd.mpegurl': return '.mxu';
232 case 'video/x-msvideo': return '.avi';
233 case 'video/x-sgi-movie': return '.movie';
234 case 'x-conference-xcooltalk': return '.ice';