2 // ------------------------------------------------------------------------ //
3 // Garden State Health Systems //
4 // Copyright (c) 2010 gshsys.com //
5 // <http://www.gshsys.com/> //
6 // ------------------------------------------------------------------------ //
7 // This program is free software; you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation; either version 2 of the License, or //
10 // (at your option) any later version. //
12 // You may not change or alter any portion of this comment or credits //
13 // of supporting developers from this source code or any supporting //
14 // source code which is considered copyrighted (c) material of the //
15 // original comment or credit authors. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details. //
22 // You should have received a copy of the GNU General Public License //
23 // along with this program; if not, write to the Free Software //
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
25 // ------------------------------------------------------------------------ //
27 if($_POST['ccrAction'] == 'generate'){
28 if(isset($_POST['show_date'])){
30 $start = $_POST['Start'];
31 $start = $start." 00:00:00";
33 $end = $end." 23:59:59";
37 function getHeaderData() {
39 // Reserved for future use
43 function getMedicationData() {
44 global $pid,$set,$start,$end;
47 SELECT prescriptions.date_added ,
48 prescriptions.patient_id,
49 prescriptions.start_date,
50 prescriptions.quantity,
51 prescriptions.interval,
54 prescriptions.medication,
55 IF(prescriptions.active=1,'Active','Prior History No Longer Active') AS active,
56 prescriptions.provider_id,
58 IFNULL(prescriptions.refills,0) AS refills,
62 LEFT JOIN list_options AS lo
63 ON lo.list_id = 'drug_units' AND prescriptions.unit = lo.option_id
64 LEFT JOIN list_options AS lo2
65 ON lo2.list_id = 'drug_form' AND prescriptions.form = lo2.option_id
66 WHERE prescriptions.patient_id = ?
67 AND prescriptions.date_added BETWEEN ? AND ?
70 DATE(DATE) AS date_added,
72 begdate AS start_date,
78 IF((enddate = '0000-00-00' OR enddate >= CURDATE()),'Active','Prior History No Longer Active') AS active,
86 WHERE `type` = 'medication'
88 AND `date` BETWEEN ? AND ?";
89 $result = sqlStatement($sql, array($pid,$start,$end,$pid,$start,$end) );
92 SELECT prescriptions.date_added ,
93 prescriptions.patient_id,
94 prescriptions.start_date,
95 prescriptions.quantity,
96 prescriptions.interval,
99 prescriptions.medication,
100 IF(prescriptions.active=1,'Active','Prior History No Longer Active') AS active,
101 prescriptions.provider_id,
103 IFNULL(prescriptions.refills,0) AS refills,
107 LEFT JOIN list_options AS lo
108 ON lo.list_id = 'drug_units' AND prescriptions.unit = lo.option_id
109 LEFT JOIN list_options AS lo2
110 ON lo2.list_id = 'drug_form' AND prescriptions.form = lo2.option_id
111 WHERE prescriptions.patient_id = ?
114 DATE(DATE) AS date_added,
116 begdate AS start_date,
122 IF((enddate = '0000-00-00' OR enddate >= CURDATE()),'Active','Prior History No Longer Active') AS active,
130 WHERE `type` = 'medication'
132 $result = sqlStatement($sql, array($pid,$pid) );
137 function getImmunizationData() {
138 global $pid,$set,$start,$end;
141 immunizations.administered_date,
142 immunizations.patient_id,
143 immunizations.vis_date,
145 immunizations.immunization_id,
146 immunizations.manufacturer,
147 codes.code_text AS title
149 LEFT JOIN codes ON immunizations.cvx_code = codes.code
150 LEFT JOIN code_types ON codes.code_type = code_types.ct_id
151 WHERE immunizations.patient_id = ? AND code_types.ct_key = 'CVX'
152 AND create_date BETWEEN ? AND ?" ;
153 $result = sqlStatement($sql, array($pid,$start,$end) );
156 immunizations.administered_date,
157 immunizations.patient_id,
158 immunizations.vis_date,
160 immunizations.immunization_id,
161 immunizations.manufacturer,
162 codes.code_text AS title
164 LEFT JOIN codes ON immunizations.cvx_code = codes.code
165 LEFT JOIN code_types ON codes.code_type = code_types.ct_id
166 WHERE immunizations.patient_id = ? AND code_types.ct_key = 'CVX'";
167 $result = sqlStatement($sql, array($pid) );
173 function getProcedureData() {
175 global $pid,$set,$start,$end;
179 lists.title as proc_title,
180 lists.date as `date`,
181 list_options.title as outcome,
184 lists.type as `type`,
185 lists.diagnosis as `code`,
186 IF(SUBSTRING(lists.diagnosis,1,LOCATE(':',lists.diagnosis)-1) = 'ICD9','ICD9-CM',SUBSTRING(lists.diagnosis,1,LOCATE(':',lists.diagnosis)-1)) AS coding
189 LEFT JOIN issue_encounter
190 ON issue_encounter.list_id = lists.id
191 LEFT JOIN form_encounter
192 ON form_encounter.encounter = issue_encounter.encounter
194 ON form_encounter.facility_id = facility.id
196 ON form_encounter.provider_id = users.id
197 LEFT JOIN list_options
198 ON lists.outcome = list_options.option_id
199 AND list_options.list_id = 'outcome'
200 WHERE lists.type = 'surgery'
202 AND lists.date BETWEEN ? AND ?
205 pt.name as proc_title,
208 ptt.laterality as laterality,
209 ptt.body_site as body_site,
210 'Lab Order' as `type`,
211 ptt.standard_code as `code`,
212 IF(SUBSTRING(ptt.standard_code,1,LOCATE(':',ptt.standard_code)-1) = 'ICD9','ICD9-CM',SUBSTRING(ptt.standard_code,1,LOCATE(':',ptt.standard_code)-1)) AS coding
214 procedure_result AS prs
215 LEFT JOIN procedure_report AS prp
216 ON prs.procedure_report_id = prp.procedure_report_id
217 LEFT JOIN procedure_order AS po
218 ON prp.procedure_order_id = po.procedure_order_id
219 LEFT JOIN procedure_type AS pt
220 ON prs.procedure_type_id = pt.procedure_type_id
221 LEFT JOIN procedure_type AS ptt
222 ON pt.parent = ptt.procedure_type_id
223 AND ptt.procedure_type = 'ord'
224 LEFT JOIN list_options AS lo
225 ON lo.list_id = 'proc_unit'
226 AND pt.units = lo.option_id
227 WHERE po.patient_id = ?
228 AND prs.date BETWEEN ? AND ?";
230 $result = sqlStatement($sql, array($pid,$start,$end,$pid,$start,$end) );
234 lists.title as proc_title,
235 lists.date as `date`,
236 list_options.title as outcome,
239 lists.type as `type`,
240 lists.diagnosis as `code`,
241 IF(SUBSTRING(lists.diagnosis,1,LOCATE(':',lists.diagnosis)-1) = 'ICD9','ICD9-CM',SUBSTRING(lists.diagnosis,1,LOCATE(':',lists.diagnosis)-1)) AS coding
244 LEFT JOIN issue_encounter
245 ON issue_encounter.list_id = lists.id
246 LEFT JOIN form_encounter
247 ON form_encounter.encounter = issue_encounter.encounter
249 ON form_encounter.facility_id = facility.id
251 ON form_encounter.provider_id = users.id
252 LEFT JOIN list_options
253 ON lists.outcome = list_options.option_id
254 AND list_options.list_id = 'outcome'
255 WHERE lists.type = 'surgery'
259 pt.name as proc_title,
262 ptt.laterality as laterality,
263 ptt.body_site as body_site,
264 'Lab Order' as `type`,
265 ptt.standard_code as `code`,
266 IF(SUBSTRING(ptt.standard_code,1,LOCATE(':',ptt.standard_code)-1) = 'ICD9','ICD9-CM',SUBSTRING(ptt.standard_code,1,LOCATE(':',ptt.standard_code)-1)) AS coding
268 procedure_result AS prs
269 LEFT JOIN procedure_report AS prp
270 ON prs.procedure_report_id = prp.procedure_report_id
271 LEFT JOIN procedure_order AS po
272 ON prp.procedure_order_id = po.procedure_order_id
273 LEFT JOIN procedure_type AS pt
274 ON prs.procedure_type_id = pt.procedure_type_id
275 LEFT JOIN procedure_type AS ptt
276 ON pt.parent = ptt.procedure_type_id
277 AND ptt.procedure_type = 'ord'
278 LEFT JOIN list_options AS lo
279 ON lo.list_id = 'proc_unit'
280 AND pt.units = lo.option_id
281 WHERE po.patient_id = ? ";
283 $result = sqlStatement($sql, array($pid,$pid) );
289 function getProblemData() {
291 global $pid,$set,$start,$end;
294 SELECT fe.encounter, fe.reason, fe.provider_id, u.title, u.fname, u.lname,
295 fe.facility_id, f.street, f.city, f.state, ie.list_id, l.pid, l.title AS prob_title, l.diagnosis,
296 l.outcome, l.groupname, l.begdate, l.enddate, l.type, l.comments , l.date, cd.code_text
298 LEFT JOIN issue_encounter AS ie ON ie.list_id = l.id
299 LEFT JOIN form_encounter AS fe ON fe.encounter = ie.encounter
300 LEFT JOIN facility AS f ON fe.facility_id = f.id
301 LEFT JOIN users AS u ON fe.provider_id = u.id
302 LEFT JOIN codes AS cd ON cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
303 LEFT JOIN code_types AS ct ON ct.ct_id = cd.code_type
304 WHERE l.type = 'medical_problem' AND l.pid=? AND ct.ct_key = SUBSTRING(l.diagnosis, 1, LOCATE(':',l.diagnosis)-1)
305 AND l.date BETWEEN ? AND ?";
306 $result = sqlStatement($sql, array($pid,$start,$end) );
309 SELECT fe.encounter, fe.reason, fe.provider_id, u.title, u.fname, u.lname,
310 fe.facility_id, f.street, f.city, f.state, ie.list_id, l.pid, l.title AS prob_title, l.diagnosis,
311 l.outcome, l.groupname, l.begdate, l.enddate, l.type, l.comments , l.date, cd.code_text
313 LEFT JOIN issue_encounter AS ie ON ie.list_id = l.id
314 LEFT JOIN form_encounter AS fe ON fe.encounter = ie.encounter
315 LEFT JOIN facility AS f ON fe.facility_id = f.id
316 LEFT JOIN users AS u ON fe.provider_id = u.id
317 LEFT JOIN codes AS cd ON cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
318 LEFT JOIN code_types AS ct ON ct.ct_id = cd.code_type
319 WHERE l.type = 'medical_problem' AND l.pid=? AND ct.ct_key = SUBSTRING(l.diagnosis, 1, LOCATE(':',l.diagnosis)-1)";
320 $result = sqlStatement($sql, array($pid) );
326 function getAlertData() {
328 global $pid,$set,$start,$end;
331 select fe.reason, fe.provider_id, fe.facility_id, fe.encounter,
332 ie.list_id, l.pid, l.title as alert_title, l.outcome,
333 l.groupname, l.begdate, l.enddate, l.type, l.diagnosis, l.date ,
334 l.reaction , l.comments ,
335 f.street, f.city, f.state, u.title, u.fname, u.lname, cd.code_text
337 left join issue_encounter as ie
339 left join form_encounter as fe
340 on fe.encounter = ie.encounter
341 left join facility as f
342 on fe.facility_id = f.id
344 on fe.provider_id = u.id
345 left join codes as cd
346 on cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
347 where l.type = 'allergy' and l.pid=?
348 AND l.date BETWEEN ? AND ?";
350 $result = sqlStatement($sql, array($pid,$start,$end) );
353 select fe.reason, fe.provider_id, fe.facility_id, fe.encounter,
354 ie.list_id, l.pid, l.title as alert_title, l.outcome,
355 l.groupname, l.begdate, l.enddate, l.type, l.diagnosis, l.date ,
356 l.reaction , l.comments ,
357 f.street, f.city, f.state, u.title, u.fname, u.lname, cd.code_text
359 left join issue_encounter as ie
361 left join form_encounter as fe
362 on fe.encounter = ie.encounter
363 left join facility as f
364 on fe.facility_id = f.id
366 on fe.provider_id = u.id
367 left join codes as cd
368 on cd.code = SUBSTRING(l.diagnosis, LOCATE(':',l.diagnosis)+1)
369 where l.type = 'allergy' and l.pid=?";
371 $result = sqlStatement($sql, array($pid) );
377 function getResultData() {
379 global $pid,$set,$start,$end;
383 prs.procedure_result_id as `pid`,
385 pt.procedure_type_id as `type`,
387 concat_ws(' ',prs.result,lo.title) as `result`,
388 prs.range as `range`,
389 prs.abnormal as `abnormal`,
390 prs.comments as `comments`,
393 procedure_result AS prs
394 LEFT JOIN procedure_report AS prp
395 ON prs.procedure_report_id = prp.procedure_report_id
396 LEFT JOIN procedure_order AS po
397 ON prp.procedure_order_id = po.procedure_order_id
398 LEFT JOIN procedure_type AS pt
399 ON prs.procedure_type_id = pt.procedure_type_id
400 LEFT JOIN procedure_type AS ptt
401 ON pt.parent = ptt.procedure_type_id
402 AND ptt.procedure_type = 'ord'
403 LEFT JOIN list_options AS lo
404 ON lo.list_id = 'proc_unit' AND pt.units = lo.option_id
405 WHERE po.patient_id=?
406 AND prs.date BETWEEN ? AND ?";
408 $result = sqlStatement($sql, array($pid,$start,$end) );
412 prs.procedure_result_id as `pid`,
414 pt.procedure_type_id as `type`,
416 concat_ws(' ',prs.result,lo.title) as `result`,
417 prs.range as `range`,
418 prs.abnormal as `abnormal`,
419 prs.comments as `comments`,
422 procedure_result AS prs
423 LEFT JOIN procedure_report AS prp
424 ON prs.procedure_report_id = prp.procedure_report_id
425 LEFT JOIN procedure_order AS po
426 ON prp.procedure_order_id = po.procedure_order_id
427 LEFT JOIN procedure_type AS pt
428 ON prs.procedure_type_id = pt.procedure_type_id
429 LEFT JOIN procedure_type AS ptt
430 ON pt.parent = ptt.procedure_type_id
431 AND ptt.procedure_type = 'ord'
432 LEFT JOIN list_options AS lo
433 ON lo.list_id = 'proc_unit' AND pt.units = lo.option_id
434 WHERE po.patient_id=?";
436 $result = sqlStatement($sql, array($pid) );
442 function getActorData() {
446 select fname, lname, DOB, sex, pid, street, city, state, postal_code, phone_contact
450 $result[0] = sqlStatement($sql, array($pid) );
453 SELECT * FROM users AS u LEFT JOIN facility AS f ON u.facility_id = f.id WHERE u.id=?";
455 $result[1] = sqlStatement($sql2, array($_SESSION['authUserID']) );
462 LEFT JOIN procedure_order AS po
463 ON po.procedure_type_id = pt.procedure_type_id
465 ON f.form_id = po.procedure_order_id
466 LEFT JOIN list_options AS lo
467 ON lo.title = f.form_name
471 AND lo.list_id = 'proc_type'
472 AND lo.option_id = 'ord'
475 $result[2] = sqlStatement($sql3, array($pid) );
481 function getReportFilename() {
485 select fname, lname, pid
489 $result = sqlQuery($sql, array($pid) );
490 $result_filename = $result['lname']."-".$result['fname']."-".$result['pid']."-".date("mdY",time());
492 return $result_filename;