More improved flexibility of code types.
[openemr.git] / interface / reports / clinical_reports.php
blobf0744919ff5b5e6ba3f8b4f8ac0761cd98a3f364
1 <?php
2 // Copyright (C) 2010 OpenEMR Support LLC
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report lists prescriptions and their dispensations according
10 // to various input selection criteria.
12 // Prescription report written by Rod Roark, 2010
13 // Fixed drug name search to work in a broader sense - tony@mi-squared.com, 2010
14 // Added five new reports as per EHR certification requirements for Patient Lists - OpenEMR Support LLC, 2010
16 //SANITIZE ALL ESCAPES
17 $sanitize_all_escapes=true;
20 //STOP FAKE REGISTER GLOBALS
21 $fake_register_globals=false;
23 require_once("../globals.php");
24 require_once("$srcdir/patient.inc");
25 require_once("$srcdir/options.inc.php");
26 require_once("../drugs/drugs.inc.php");
27 require_once("$srcdir/formatting.inc.php");
28 require_once("../../custom/code_types.inc.php");
30 function add_date($givendate,$day=0,$mth=0,$yr=0) {
31 $cd = strtotime($givendate);
32 $newdate = date('Y-m-d', mktime(date('h',$cd),
33 date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
34 date('d',$cd)+$day, date('Y',$cd)+$yr));
35 return $newdate;
38 $type = $_POST["type"];
39 $facility = isset($_POST['facility']) ? $_POST['facility'] : '';
40 $sql_date_from = fixDate($_POST['date_from'], date('Y-01-01'));
41 $sql_date_to = fixDate($_POST['date_to'] , add_date(date('Y-m-d')));
42 $patient_id = trim($_POST["patient_id"]);
43 $age_from = $_POST["age_from"];
44 $age_to = $_POST["age_to"];
45 $sql_gender = $_POST["gender"];
46 $sql_ethnicity = $_POST["ethnicity"];
47 $sql_race=$_POST["race"];
48 $form_drug_name = trim($_POST["form_drug_name"]);
49 $form_diagnosis = trim($_POST["form_diagnosis"]);
50 $form_lab_results = trim($_POST["form_lab_results"]);
51 $form_service_codes = trim($_POST["form_service_codes"]);
53 // Create comma-separated lists of active diagnosis and procedure code types.
54 $ct_diag_list = '';
55 $ct_proc_list = '';
56 foreach ($code_types as $ct_key => $ct_arr) {
57 if (!$ct_arr['active']) continue;
58 if ($ct_arr['diag']) {
59 if ($ct_diag_list) $ct_diag_list .= ',';
60 $ct_diag_list .= urlencode($ct_key);
62 else {
63 if ($ct_proc_list) $ct_proc_list .= ',';
64 $ct_proc_list .= urlencode($ct_key);
68 <html>
69 <head>
70 <?php html_header_show();?>
71 <title>
72 <?php echo htmlspecialchars(xl('Clinical Reports'),ENT_NOQUOTES); ?>
73 </title>
74 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
75 <script type="text/javascript" src="../../library/textformat.js"></script>
76 <script type="text/javascript" src="../../library/dialog.js"></script>
77 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
78 <script language="JavaScript">
80 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
82 function toggle(id) {
83 var tr = document.getElementById(id);
84 if (tr==null) { return; }
85 var bExpand = tr.style.display == '';
86 tr.style.display = (bExpand ? 'none' : '');
88 function changeimage(id, sMinus, sPlus) {
89 var img = document.getElementById(id);
90 if (img!=null) {
91 var bExpand = img.src.indexOf(sPlus) >= 0;
92 if (!bExpand)
93 img.src = "../pic/blue-up-arrow.gif";
94 else
95 img.src = "../pic/blue-down-arrow.gif";
98 function Toggle_trGrpHeader2(t_id,i_id) {
99 var img=i_id;
100 changeimage(img, 'blue-down-arrow.gif', 'blue-up-arrow.gif');
101 var id1=t_id;
102 toggle(id1);
104 // This is for callback by the find-code popup.
105 // Appends to or erases the current list of diagnoses.
106 function set_related(codetype, code, selector, codedesc) {
107 var f = document.forms[0][current_sel_name];
108 var s = f.value;
109 if (code) {
110 if (s.length > 0) s += ';';
111 s += codetype + ':' + code;
112 } else {
113 s = '';
115 f.value = s;
118 //This invokes the find-code popup.
119 function sel_diagnosis(e) {
120 current_sel_name = e.name;
121 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo $ct_diag_list; ?>', '_blank', 500, 400);
124 //This invokes the find-code popup.
125 function sel_procedure(e) {
126 current_sel_name = e.name;
127 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo $ct_proc_list; ?>', '_blank', 500, 400);
129 </script>
130 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
131 <style type="text/css">
132 /* specifically include & exclude from printing */
133 @media print {
134 #report_parameters {
135 visibility: hidden;
136 display: none;
138 #report_parameters_daterange {
139 visibility: visible;
140 display: inline;
142 #report_results table {
143 margin-top: 0px;
147 /* specifically exclude some from the screen */
148 @media screen {
149 #report_parameters_daterange {
150 visibility: hidden;
151 display: none;
154 .optional_area_service_codes {
155 <?php
156 if($type != 'Service Codes' || $type == '')
159 display: none;
160 <?php
164 </style>
165 <script language="javascript" type="text/javascript">
166 function checkType() {
167 if($('#type').val() == 'Service Codes')
169 $('.optional_area_service_codes').css("display", "inline");
171 else
173 $('.optional_area_service_codes').css("display", "none");
177 function submitForm() {
178 var d_from = new String($('#date_from').val());
179 var d_to = new String($('#date_to').val());
181 var d_from_arr = d_from.split('-');
182 var d_to_arr = d_to.split('-');
184 var dt_from = new Date(d_from_arr[0], d_from_arr[1], d_from_arr[2]);
185 var dt_to = new Date(d_to_arr[0], d_to_arr[1], d_to_arr[2]);
187 var mili_from = dt_from.getTime();
188 var mili_to = dt_to.getTime();
189 var diff = mili_to - mili_from;
191 $('#date_error').css("display", "none");
193 if(diff < 0) //negative
195 $('#date_error').css("display", "inline");
197 else
199 $("#form_refresh").attr("value","true");
200 $("#theform").submit();
204 $(document).ready(function() {
205 $(".numeric_only").keydown(function(event) {
206 //alert(event.keyCode);
207 // Allow only backspace and delete
208 if ( event.keyCode == 46 || event.keyCode == 8 ) {
209 // let it happen, don't do anything
211 else {
212 if(!((event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 48 && event.keyCode <= 57)))
214 event.preventDefault();
219 </script>
220 </head>
221 <body class="body_top">
222 <!-- Required for the popup date selectors -->
223 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
224 <span class='title'>
225 <?php echo htmlspecialchars(xl('Report - Clinical'),ENT_NOQUOTES); ?>
226 </span>
227 <!-- Search can be done using age range, gender, and ethnicity filters.
228 Search options include diagnosis, procedure, prescription, medical history, and lab results.
230 <div id="report_parameters_daterange"> <?php echo htmlspecialchars(date("d F Y", strtotime($sql_date_from)),ENT_NOQUOTES) .
231 " &nbsp; to &nbsp; ". htmlspecialchars(date("d F Y", strtotime($sql_date_to)),ENT_NOQUOTES); ?> </div>
232 <form name='theform' id='theform' method='post' action='clinical_reports.php'>
233 <div id="report_parameters">
234 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
235 <table>
236 <tr>
237 <td width='740px'><div style='float:left'>
238 <table class='text'>
239 <tr>
240 <td class='label' width="100"><?php echo htmlspecialchars(xl('Facility'),ENT_NOQUOTES); ?>: </td>
241 <td width="250"> <?php dropdown_facility($facility,'facility',false); ?> </td>
242 <td class='label' width="100"><?php echo htmlspecialchars(xl('From'),ENT_NOQUOTES); ?>: </td>
243 <td><input type='text' name='date_from' id="date_from" size='10' value='<?php echo htmlspecialchars($sql_date_from,ENT_QUOTES); ?>' onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' id='img_from_date' border='0' alt='[?]' style='cursor:pointer' title='<?php echo htmlspecialchars(xl('Click here to choose a date'),ENT_QUOTES); ?>'></td>
244 </tr>
245 <tr>
246 <td class='label'><?php echo htmlspecialchars(xl('Patient ID'),ENT_NOQUOTES); ?>:</td>
247 <td><input name='patient_id' class="numeric_only" type='text' id="patient_id" title='<?php echo htmlspecialchars(xl('Optional numeric patient ID'),ENT_QUOTES); ?>' value='<?php echo htmlspecialchars($patient_id,ENT_QUOTES); ?>' size='10' maxlength='20' /></td>
248 <td class='label'><?php echo htmlspecialchars(xl('To'),ENT_NOQUOTES); ?>: </td>
249 <td><input type='text' name='date_to' id="date_to" size='10' value='<?php echo htmlspecialchars($sql_date_to,ENT_QUOTES); ?>' onKeyUp='datekeyup(this,mypcc)' onBlur='dateblur(this,mypcc)' title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' id='img_to_date' border='0' alt='[?]' style='cursor:pointer' title='<?php echo htmlspecialchars(xl('Click here to choose a date'),ENT_QUOTES); ?>'></td>
250 </tr>
251 <tr>
252 <td class='label'><?php echo htmlspecialchars(xl('Age Range'),ENT_NOQUOTES); ?>:</td>
253 <td><?php echo htmlspecialchars(xl('From'),ENT_NOQUOTES); ?>
254 <input name='age_from' class="numeric_only" type='text' id="age_from" value="<?php echo htmlspecialchars($age_from,ENT_QUOTES); ?>" size='3' maxlength='3' /> <?php echo htmlspecialchars(xl('To'),ENT_NOQUOTES); ?>
255 <input name='age_to' class="numeric_only" type='text' id="age_to" value="<?php echo htmlspecialchars($age_to,ENT_QUOTES); ?>" size='3' maxlength='3' /></td>
256 <td class='label'><?php echo htmlspecialchars(xl('Problem DX'),ENT_NOQUOTES); ?>:</td>
257 <td><input type='text' name='form_diagnosis' size='10' maxlength='250' value='<?php echo htmlspecialchars($form_diagnosis,ENT_QUOTES); ?>' onclick='sel_diagnosis(this)' title='<?php echo htmlspecialchars(xl('Click to select or change diagnoses'),ENT_QUOTES); ?>' readonly /></td>
258 <td>&nbsp;</td>
259 <!-- Visolve -->
260 </tr>
261 <tr>
262 <td class='label'><?php echo htmlspecialchars(xl('Gender'),ENT_NOQUOTES); ?>:</td>
263 <td><?php echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?></td>
264 <td class='label'><?php echo htmlspecialchars(xl('Drug'),ENT_NOQUOTES); ?>:</td>
265 <td><input type='text' name='form_drug_name' size='10' maxlength='250' value='<?php echo htmlspecialchars($form_drug_name,ENT_QUOTES); ?>' title='<?php echo htmlspecialchars(xl('Optional drug name, use % as a wildcard'),ENT_QUOTES); ?>' /></td>
267 </tr>
268 <tr>
269 <td class='label'><?php echo htmlspecialchars(xl('Race'),ENT_NOQUOTES); ?>:</td>
270 <td><?php echo generate_select_list('race', 'race', $sql_race, 'Select Race', 'Unassigned', '', ''); ?></td>
271 <td class='label'><?php echo htmlspecialchars(xl('Ethnicity'),ENT_NOQUOTES); ?>:</td>
272 <td><?php echo generate_select_list('ethnicity', 'ethnicity', $sql_ethnicity, 'Select Ethnicity', 'Unassigned', '', ''); ?></td>
274 </tr>
275 <tr>
276 <td class='label' width='100'><?php echo htmlspecialchars(xl('Lab Result'),ENT_NOQUOTES); ?>:</td>
277 <td width='100'><input type='text' name='form_lab_results' size='13' maxlength='250' value='<?php echo htmlspecialchars($form_lab_results,ENT_QUOTES); ?>' title='<?php echo htmlspecialchars(xl('Result, use % as a wildcard'),ENT_QUOTES); ?>' /></td>
279 <td class='label' width='100'><?php echo htmlspecialchars(xl('Option'),ENT_NOQUOTES); ?>:</td>
280 <td><select name="type" id="type" onChange="checkType();">
281 <option> <?php echo htmlspecialchars(xl('Select'),ENT_NOQUOTES); ?></option>
282 <option value="Procedure" <?php if($type == 'Procedure') { echo "selected"; } ?>><?php echo htmlspecialchars(xl('Procedure'),ENT_NOQUOTES); ?></option>
283 <option value="Medical History" <?php if($type == 'Medical History') { echo "selected"; } ?>><?php echo htmlspecialchars(xl('Medical History'),ENT_NOQUOTES); ?></option>
285 <option value="Service Codes" <?php if($type == 'Service Codes') { echo "selected"; } ?>><?php echo htmlspecialchars(xl('Service Codes'),ENT_NOQUOTES); ?></option>
286 </select></td>
287 <td> &nbsp;</td>
288 </tr>
289 </table>
290 <table>
291 <tr class="optional_area_service_codes">
292 <td width='100'>&nbsp;</td>
293 <td width='100'>&nbsp;</td>
294 <td width='195'>&nbsp;</td>
295 <td class='label' width='76'><?php echo htmlspecialchars(xl('Code'),ENT_NOQUOTES); ?>:</td>
296 <td> <input type='text' name='form_service_codes' size='10' maxlength='250' value='<?php echo htmlspecialchars($form_service_codes,ENT_QUOTES); ?>' onclick='sel_procedure(this)' title='<?php echo htmlspecialchars(xl('Click to select or change service codes'),ENT_QUOTES); ?>' readonly />&nbsp;</td>
297 </tr>
298 </table>
299 <table class='text'>
300 <tr>
301 <!-- Sort by Start -->
302 <td class='label' width='63'><?php echo htmlspecialchars(xl('Sort By'),ENT_NOQUOTES); ?>:</td>
303 <td>
304 <input type='checkbox' name='form_pt_name'<?php if ($_POST['form_pt_name'] == true) echo ' checked'; ?>>
305 <?php echo htmlspecialchars(xl('Patient Name'),ENT_NOQUOTES); ?>&nbsp;
307 <input type='checkbox' name='form_pt_age'<?php if ($_POST['form_pt_age'] == true) echo ' checked'; ?>>
308 <?php echo htmlspecialchars(xl('Age'),ENT_NOQUOTES); ?>&nbsp;
310 <input type='checkbox' name='form_diagnosis_code'<?php if ($_POST['form_diagnosis_code'] == true) echo ' checked'; ?>>
311 <?php echo htmlspecialchars(xl('Diagnosis Code'),ENT_NOQUOTES); ?>&nbsp;
313 <input type='checkbox' name='form_diagnosis_tit'<?php if ($_POST['form_diagnosis_tit'] == true) echo ' checked'; ?>>
314 <?php echo htmlspecialchars(xl('Diagnosis Title'),ENT_NOQUOTES); ?>&nbsp;
316 <input type='checkbox' name='form_drug'<?php if ($_POST['form_drug'] == true) echo ' checked'; ?>>
317 <?php echo htmlspecialchars(xl('Drug'),ENT_NOQUOTES); ?>&nbsp;
319 <input type='checkbox' name='ndc_no'<?php if ($_POST['ndc_no'] == true) echo ' checked'; ?>>
320 <?php echo htmlspecialchars(xl('NDC Number'),ENT_NOQUOTES); ?>&nbsp;
321 <input type='checkbox' name='lab_results'<?php if ($_POST['lab_results'] == true) echo ' checked'; ?>>
322 <?php echo htmlspecialchars(xl('Lab Results'),ENT_NOQUOTES); ?>&nbsp;
323 </td>
324 </tr>
325 <!-- Sort by ends -->
326 </tr>
327 <tr>
328 <td colspan=3><span id="date_error" style="color: #F00; font-siz: 11px; display: none;"><?php echo htmlspecialchars(xl('From Date Cannot be Greater than To Date.'),ENT_NOQUOTES); ?></span>&nbsp;</td>
329 </tr>
330 </table>
331 </div></td>
332 <td height="100%" valign='middle' width="175"><table style='border-left:1px solid; width:100%; height:100%'>
333 <tr>
334 <td><div style='margin-left:15px'> <a href='#' class='css_button' onclick='submitForm();'> <span>
335 <?php echo htmlspecialchars(xl('Submit'),ENT_NOQUOTES); ?>
336 </span> </a>
337 <?php if ($_POST['form_refresh']) { ?>
338 <a href='#' class='css_button' onclick='window.print()'> <span>
339 <?php echo htmlspecialchars(xl('Print'),ENT_NOQUOTES); ?>
340 </span> </a>
341 <?php } ?>
342 </div></td>
343 </tr>
344 </table></td>
345 </tr>
346 </table>
347 </div>
348 <!-- end of parameters -->
349 <?php
350 // SQL scripts for the various searches
351 $sqlBindArray = array();
352 if ($_POST['form_refresh'])
354 $sqlstmt = "select
355 concat(pd.fname, ' ', pd.lname) AS patient_name,
356 pd.pid AS patient_id,
357 DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 AS patient_age,
358 pd.sex AS patient_sex,
359 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
360 concat(u.fname, ' ', u.lname) AS users_provider";
361 if(strlen($form_diagnosis) > 0) {
362 $sqlstmt=$sqlstmt.",li.date AS lists_date,
363 li.diagnosis AS lists_diagnosis,
364 li.title AS lists_title";
366 if(strlen($form_drug_name) > 0) {
368 $sqlstmt=$sqlstmt.",r.id as id, r.date_modified AS prescriptions_date_modified, r.dosage as dosage, r.route as route, r.interval as hinterval, r.refills as refills, r.drug as drug,
369 r.form as hform, r.size as size, r.unit as hunit, d.name as name, d.ndc_number as ndc_number,r.quantity as quantity";
371 if(strlen($form_lab_results) > 0) {
373 $sqlstmt = $sqlstmt.",pr.date AS procedure_result_date,
374 pr.facility AS procedure_result_facility,
375 pr.units AS procedure_result_units,
376 pr.result AS procedure_result_result,
377 pr.range AS procedure_result_range,
378 pr.abnormal AS procedure_result_abnormal,
379 pr.comments AS procedure_result_comments,
380 pr.document_id AS procedure_result_document_id";
382 if ( $type == 'Procedure') {
383 $sqlstmt = $sqlstmt.",po.date_ordered AS procedure_order_date_ordered,
384 pt.standard_code AS procedure_type_standard_code,
385 pt.name as procedure_name,
386 po.order_priority AS procedure_order_order_priority,
387 po.order_status AS procedure_order_order_status,
388 po.encounter_id AS procedure_order_encounter,
389 po.patient_instructions AS procedure_order_patient_instructions,
390 po.activity AS procedure_order_activity,
391 po.control_id AS procedure_order_control_id ";
393 if ( $type == 'Medical History') {
394 $sqlstmt = $sqlstmt.",hd.date AS history_data_date,
395 hd.tobacco AS history_data_tobacco,
396 hd.alcohol AS history_data_alcohol,
397 hd.recreational_drugs AS history_data_recreational_drugs ";
399 if($type == 'Service Codes') {
400 $sqlstmt .= ", c.code as code,
401 c.code_text as code_text,
402 fe.encounter as encounter,
403 b.date as date";
404 $mh_stmt = $mh_stmt.",code,code_text,encounter,date";
406 //from
407 $sqlstmt=$sqlstmt." from patient_data as pd left outer join users as u on u.id = pd.providerid
408 left outer join facility as f on f.id = u.facility_id";
410 if(strlen($form_diagnosis) > 0 ){
411 $sqlstmt = $sqlstmt." left outer join lists as li on li.pid = pd.pid ";
413 if ( $type == 'Procedure' ||( strlen($form_lab_results)!=0) ) {
414 $sqlstmt = $sqlstmt." left outer join procedure_order as po on po.patient_id = pd.pid
415 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
416 left outer join procedure_type as pt on pt.procedure_type_id = po.procedure_type_id ";
418 if (strlen($form_lab_results)!=0 ) {
419 $sqlstmt = $sqlstmt." left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id
420 and pr.procedure_type_id = po.procedure_type_id ";
422 if(strlen($form_drug_name)!=0) {
423 $sqlstmt=$sqlstmt." left outer join prescriptions AS r on r.patient_id=pd.pid
424 LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id";
426 if ( $type == 'Medical History') {
427 $sqlstmt = $sqlstmt." left outer join history_data as hd on hd.pid = pd.pid
428 and (isnull(hd.tobacco) = 0
429 or isnull(hd.alcohol) = 0
430 or isnull(hd.recreational_drugs) = 0)";
432 if($type == 'Service Codes') {
433 $sqlstmt = $sqlstmt." left outer join billing as b on b.pid = pd.pid
434 left outer join form_encounter as fe on fe.encounter = b.encounter and b.code_type = 'CPT4'
435 left outer join codes as c on c.code = b.code ";
437 //where
438 $whr_stmt="where 1=1";
439 if(strlen($form_diagnosis) > 0 ) {
440 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
441 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
443 if(strlen($form_lab_results)!=0 ) {
444 $whr_stmt=$whr_stmt." AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND pr.date <= ?";
445 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
447 if(strlen($form_drug_name)!=0) {
448 $whr_stmt=$whr_stmt." AND r.date_modified >= ? AND r.date_modified < DATE_ADD(?, INTERVAL 1 DAY) AND r.date_modified <= ?";
449 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
451 if($type == 'Medical History') {
452 $whr_stmt=$whr_stmt." AND hd.date >= ? AND hd.date < DATE_ADD(?, INTERVAL 1 DAY) AND hd.date <= ?";
453 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
455 if($type == 'Procedure') {
456 $whr_stmt=$whr_stmt." AND po.date_ordered >= ? AND po.date_ordered < DATE_ADD(?, INTERVAL 1 DAY) AND po.date_ordered <= ?";
457 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
459 if($type == "Service Codes") {
460 $whr_stmt=$whr_stmt." AND b.date >= ? AND b.date < DATE_ADD(?, INTERVAL 1 DAY) AND b.date <= ?";
461 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
463 if(strlen($form_lab_results) != 0) {
464 $whr_stmt= $whr_stmt." AND (pr.result LIKE ?) ";
465 array_push($sqlBindArray, $form_lab_results);
467 if(strlen($form_drug_name) > 0) {
468 $whr_stmt .= " AND (
469 d.name LIKE ?
470 OR r.drug LIKE ?
471 ) ";
472 array_push($sqlBindArray, $form_drug_name, $form_drug_name);
474 if($type == 'Service Codes') {
475 if(strlen($form_service_codes) != 0) {
476 $whr_stmt = $whr_stmt." AND (b.code = ?) ";
477 $service_code = explode(":",$form_service_codes);
478 array_push($sqlBindArray, $service_code[1]);
481 if(strlen($patient_id) != 0) {
482 $whr_stmt = $whr_stmt." and pd.pid = ?";
483 array_push($sqlBindArray, $patient_id);
486 if(strlen($age_from) != 0) {
487 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
488 array_push($sqlBindArray, $age_from);
490 if(strlen($age_to) != 0) {
491 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
492 array_push($sqlBindArray, $age_to);
494 if(strlen($sql_gender) != 0) {
495 $whr_stmt = $whr_stmt." and pd.sex = ?";
496 array_push($sqlBindArray, $sql_gender);
498 if(strlen($sql_ethnicity) != 0) {
499 $whr_stmt = $whr_stmt." and pd.ethnicity = ?";
500 array_push($sqlBindArray, $sql_ethnicity);
502 if(strlen($sql_race) != 0) {
503 $whr_stmt = $whr_stmt." and pd.race = ?";
504 array_push($sqlBindArray, $sql_race);
506 if($facility != '') {
507 $whr_stmt = $whr_stmt." and f.id = ? ";
508 array_push($sqlBindArray, $facility);
510 if(strlen($form_diagnosis) > 0) {
511 $whr_stmt = $whr_stmt." AND (li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis = ?) ";
512 array_push($sqlBindArray, $form_diagnosis.";%", '%;'.$form_diagnosis.';%', '%;'.$form_diagnosis, $form_diagnosis);
514 // order by
515 $odrstmt = $odrstmt."ORDER BY patient_id";
516 if ($_POST['form_pt_name'] == true){
517 $odrstmt=$odrstmt.",patient_name";
519 if ($_POST['form_pt_age'] == true) {
520 $odrstmt=$odrstmt.",patient_age";
522 if (($_POST['form_diagnosis_code'] == true) && (strlen($form_diagnosis) > 0)){
523 $odrstmt=$odrstmt.",lists_diagnosis";
525 if (($_POST['form_diagnosis_tit'] == true) && (strlen($form_diagnosis) > 0)){
526 $odrstmt=$odrstmt.",lists_title";
528 if (($_POST['form_drug'] == true)&& (strlen($form_drug_name) > 0)){
529 $odrstmt=$odrstmt.",r.drug";
531 if (($_POST['ndc_no'] == true) && (strlen($form_drug_name) > 0)) {
532 $odrstmt=$odrstmt.",d.ndc_number";
534 if (($_POST['lab_results'] == true) && (strlen($form_lab_results) > 0)) {
535 $odrstmt=$odrstmt.",procedure_result_result";
539 if($type == 'Medical History') {
540 $sqlstmt="select * from (".$sqlstmt." ".$whr_stmt." ".$odrstmt.",history_data_date desc) a group by patient_id";
542 else
543 $sqlstmt=$sqlstmt." ".$whr_stmt." ".$odrstmt;
545 $result = sqlStatement($sqlstmt,$sqlBindArray);
547 $row_id = 1.1;//given to each row to identify and toggle
548 $img_id = 1.2;
549 $k=1.3;
551 if(sqlNumRows($result) > 0)
554 <br>
555 <div id = "report_results">
556 <?php while ($row = sqlFetchArray($result)) { ?>
557 <table width=90% align="center" cellpadding="5" cellspacing="0" style="font-family:tahoma;color:black;" border="0">
558 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
559 <td><b><?php echo htmlspecialchars(xl('Summary of'),ENT_NOQUOTES); echo " "; ?> <?php echo htmlspecialchars($row['patient_name'],ENT_NOQUOTES); ?></b></td>
560 <td>&nbsp;</td>
561 <td>&nbsp;</td>
562 <td align="center">
563 <span onclick="javascript:Toggle_trGrpHeader2(<?php echo $row_id; ?>,<?php echo $img_id; ?>);"><img src="../pic/blue-down-arrow.gif" id="<?php echo $img_id; $img_id++; ?>" title="<?php echo htmlspecialchars( xl('Click here to view patient details'), ENT_QUOTES); ?>" /></span>
564 </td></tr>
565 <table width="100%" align="center" id = "<?php echo $row_id; $row_id++;?>" class="border1" style="display:none; font-size:13px;" cellpadding=5>
566 <tr bgcolor="#C3FDB8" align="left">
567 <td><b><?php echo htmlspecialchars(xl('Patient Name'),ENT_NOQUOTES); ?></b></td>
568 <td><b><?php echo htmlspecialchars(xl('PID'),ENT_NOQUOTES);?></b></td>
569 <td><b><?php echo htmlspecialchars(xl('Age'),ENT_NOQUOTES);?></b></td>
570 <td><b><?php echo htmlspecialchars(xl('Gender'),ENT_NOQUOTES); ?></b></td>
571 <td><b><?php echo htmlspecialchars(xl('Race'),ENT_NOQUOTES);?></b></td>
572 <td><b><?php echo htmlspecialchars(xl('Ethnicity'),ENT_NOQUOTES);?></b></td>
573 <td colspan=5><b><?php echo htmlspecialchars(xl('Provider'),ENT_NOQUOTES);?></b></td>
574 </tr>
575 <tr bgcolor="#FFFFFF">
576 <td><?php echo htmlspecialchars($row['patient_name'],ENT_NOQUOTES); ?>&nbsp;</td>
577 <td> <?php echo htmlspecialchars($row['patient_id'],ENT_NOQUOTES); ?>&nbsp;</td>
578 <td> <?php echo htmlspecialchars($row['patient_age'],ENT_NOQUOTES); ?>&nbsp;</td>
579 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'sex'), $row['patient_sex']),ENT_NOQUOTES); ?>&nbsp;</td>
580 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'race'), $row['patient_race']),ENT_NOQUOTES); ?>&nbsp;</td>
581 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ethnicity'), $row['patient_ethinic']),ENT_NOQUOTES); ?>&nbsp;</td>
582 <td colspan=5> <?php echo htmlspecialchars($row['users_provider'],ENT_NOQUOTES); ?>&nbsp;</td>
583 </tr>
584 <!-- Diagnosis Report Start-->
585 <?php
586 if(strlen($form_diagnosis) > 0)
589 <tr bgcolor="#C3FDB8" align= "left">
590 <td colspan=12><b><?php echo "#"; echo htmlspecialchars(xl('Diagnosis Report'),ENT_NOQUOTES);?></b></td>
591 </tr>
592 <tr bgcolor="#C3FDB8" align= "left">
593 <td><b><?php echo htmlspecialchars(xl('Diagnosis Date'),ENT_NOQUOTES);?></b></td>
594 <td><b><?php echo htmlspecialchars(xl('Diagnosis'),ENT_NOQUOTES);?></b></td>
595 <td colspan=9><b><?php echo htmlspecialchars(xl('Diagnosis Name'),ENT_NOQUOTES);?></b></td>
596 </tr>
597 <tr bgcolor="#FFFFFF">
598 <td><?php echo htmlspecialchars($row['lists_date'],ENT_NOQUOTES); ?>&nbsp;</td>
599 <td><?php echo htmlspecialchars($row['lists_diagnosis'],ENT_NOQUOTES); ?>&nbsp;</td>
600 <td colspan=9><?php echo htmlspecialchars($row['lists_title'],ENT_NOQUOTES); ?>&nbsp;</td>
601 </tr>
602 <?php } ?>
603 <!-- Diagnosis Report End-->
605 <!-- Prescription Report Start-->
606 <?php
607 if(strlen($form_drug_name) > 0)
610 <tr bgcolor="#C3FDB8" align= "left">
611 <td colspan=12><b><?php echo "#"; echo htmlspecialchars(xl('Prescription Report'),ENT_NOQUOTES);?><b></td></tr>
612 <tr bgcolor="#C3FDB8" align= "left">
613 <td><b><?php echo htmlspecialchars(xl('Date'),ENT_NOQUOTES); ?></b></td>
614 <td><b><?php echo htmlspecialchars(xl('Drug Name'),ENT_NOQUOTES);?></b></td>
615 <td><b><?php echo htmlspecialchars(xl('Route'),ENT_NOQUOTES);?></b></td>
616 <td><b><?php echo htmlspecialchars(xl('Dosage'),ENT_NOQUOTES);?></b></td>
617 <td><b><?php echo htmlspecialchars(xl('Form'),ENT_NOQUOTES);?></b></td>
618 <td><b><?php echo htmlspecialchars(xl('Interval'),ENT_NOQUOTES);?></b></td>
619 <td><b><?php echo htmlspecialchars(xl('Size'),ENT_NOQUOTES);?></b></td>
620 <td><b><?php echo htmlspecialchars(xl('Unit'),ENT_NOQUOTES);?></b></td>
621 <td><b><?php echo htmlspecialchars(xl('ReFill'),ENT_NOQUOTES);?></b></td>
622 <td><b><?php echo htmlspecialchars(xl('Quantity'),ENT_NOQUOTES);?></b></td>
623 <td><b><?php echo htmlspecialchars(xl('NDC'),ENT_NOQUOTES);?></b></td>
624 </tr>
625 <tr bgcolor="#FFFFFF" align="">
626 <?php
627 $rx_route = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']) ;
628 $rx_form = generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['hform']) ;
629 $rx_interval = generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['hinterval']) ;
630 $rx_units = generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['hunit']);
632 <td> <?php echo htmlspecialchars(oeFormatShortDate($row['prescriptions_date_modified']),ENT_NOQUOTES); ?>&nbsp;</td>
633 <td><?php echo htmlspecialchars($row['drug'],ENT_NOQUOTES); ?></td>
634 <td><?php echo htmlspecialchars($rx_route,ENT_NOQUOTES); ?></td>
635 <td><?php echo htmlspecialchars($row['dosage'],ENT_NOQUOTES); ?></td>
636 <td><?php echo htmlspecialchars($rx_form,ENT_NOQUOTES); ?></td>
637 <td><?php echo htmlspecialchars($rx_interval,ENT_NOQUOTES); ?></td>
638 <td><?php echo htmlspecialchars($row['size'],ENT_NOQUOTES); ?></td>
639 <td><?php echo htmlspecialchars($rx_units,ENT_NOQUOTES); ?></td>
640 <td><?php echo htmlspecialchars($row['refills'],ENT_NOQUOTES); ?></td>
641 <td><?php echo htmlspecialchars($row['quantity'],ENT_NOQUOTES); ?></td>
642 <td><?php echo htmlspecialchars($row['ndc_number'],ENT_NOQUOTES); ?></td>
643 </tr>
644 <?php } ?>
645 <!-- Prescription Report End-->
647 <!-- Lab Results Report Start-->
648 <?php
649 if(strlen($form_lab_results) > 0)
652 <tr bgcolor="#C3FDB8" align= "left">
653 <td colspan=12><b><?php echo "#"; echo htmlspecialchars(xl('Lab Results Report'),ENT_NOQUOTES);?><b></td></tr>
654 <tr bgcolor="#C3FDB8" align= "left">
655 <td><b><?php echo htmlspecialchars(xl('Date'),ENT_NOQUOTES); ?></b></td>
656 <td><b><?php echo htmlspecialchars(xl('Facility'),ENT_NOQUOTES);?></b></td>
657 <td><b><?php echo htmlspecialchars(xl('Unit'),ENT_NOQUOTES);?></b></td>
658 <td><b><?php echo htmlspecialchars(xl('Result'),ENT_NOQUOTES);?></b></td>
659 <td><b><?php echo htmlspecialchars(xl('Range'),ENT_NOQUOTES);?></b></td>
660 <td><b><?php echo htmlspecialchars(xl('Abnormal'),ENT_NOQUOTES);?></b></td>
661 <td><b><?php echo htmlspecialchars(xl('Comments'),ENT_NOQUOTES);?></b></td>
662 <td colspan=4><b><?php echo htmlspecialchars(xl('Document ID'),ENT_NOQUOTES);?></b></td>
663 </tr>
664 <tr bgcolor="#FFFFFF">
665 <td> <?php echo htmlspecialchars(oeFormatShortDate($row['procedure_result_date']),ENT_NOQUOTES); ?>&nbsp;</td>
666 <td> <?php echo htmlspecialchars($row['procedure_result_facility'],ENT_NOQUOTES); ?>&nbsp;</td>
667 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$row['procedure_result_units']),ENT_NOQUOTES); ?>&nbsp;</td>
668 <td> <?php echo htmlspecialchars($row['procedure_result_result'],ENT_NOQUOTES); ?>&nbsp;</td>
669 <td> <?php echo htmlspecialchars($row['procedure_result_range'],ENT_NOQUOTES); ?>&nbsp;</td>
670 <td> <?php echo htmlspecialchars($row['procedure_result_abnormal'],ENT_NOQUOTES); ?>&nbsp;</td>
671 <td> <?php echo htmlspecialchars($row['procedure_result_comments'],ENT_NOQUOTES); ?>&nbsp;</td>
672 <td colspan=4> <?php echo htmlspecialchars($row['procedure_result_document_id'],ENT_NOQUOTES); ?>&nbsp;</td>
673 </tr>
674 <?php } ?>
675 <!-- Lab Results End-->
677 <!-- Procedures Report Start-->
678 <?php
679 if ( $type == 'Procedure')
682 <tr bgcolor="#C3FDB8" align= "left">
683 <td colspan=12><b><?php echo "#"; echo htmlspecialchars(xl('Procedure Report'),ENT_NOQUOTES);?><b></td></tr>
684 <tr bgcolor="#C3FDB8" align= "left">
685 <td><b><?php echo htmlspecialchars(xl('Date'),ENT_NOQUOTES); ?></b></td>
686 <td><b><?php echo htmlspecialchars(xl('Standard Name'),ENT_NOQUOTES);?></b></td>
687 <td><b><?php echo htmlspecialchars(xl('Procedure'),ENT_NOQUOTES); ?></b></td>
688 <td><b><?php echo htmlspecialchars(xl('Encounter'),ENT_NOQUOTES);?></b></td>
689 <td><b><?php echo htmlspecialchars(xl('Priority'),ENT_NOQUOTES);?></b></td>
690 <td><b><?php echo htmlspecialchars(xl('Status'),ENT_NOQUOTES);?></b></td>
691 <td><b><?php echo htmlspecialchars(xl('Instruction'),ENT_NOQUOTES);?></b></td>
692 <td><b><?php echo htmlspecialchars(xl('Activity'),ENT_NOQUOTES);?></b></td>
693 <td colspan=3><b><?php echo htmlspecialchars(xl('Control ID'),ENT_NOQUOTES);?></b></td>
694 </tr>
695 <tr bgcolor="#FFFFFF">
696 <?php
697 $procedure_type_standard_code_arr = explode(':', $row['procedure_type_standard_code']);
698 $procedure_type_standard_code = $procedure_type_standard_code_arr[1];
700 <!-- Procedure -->
701 <td> <?php echo htmlspecialchars(oeFormatShortDate($row['procedure_order_date_ordered']),ENT_NOQUOTES); ?>&nbsp;</td>
702 <td> <?php echo htmlspecialchars($procedure_type_standard_code,ENT_NOQUOTES); ?>&nbsp;</td>
703 <td> <?php echo htmlspecialchars($row['procedure_name'],ENT_NOQUOTES); ?>&nbsp;</td>
704 <td> <?php echo htmlspecialchars($row['procedure_order_encounter'],ENT_NOQUOTES); ?>&nbsp;</td>
705 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ord_priority'),$row['procedure_order_order_priority']),ENT_NOQUOTES); ?>&nbsp;</td>
706 <td> <?php echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ord_status'),$row['procedure_order_order_status']),ENT_NOQUOTES); ?>&nbsp;</td>
707 <td> <?php echo htmlspecialchars($row['procedure_order_patient_instructions'],ENT_NOQUOTES); ?>&nbsp;</td>
708 <td> <?php echo htmlspecialchars($row['procedure_order_activity'],ENT_NOQUOTES); ?>&nbsp;</td>
709 <td colspan=3> <?php echo htmlspecialchars($row['procedure_order_control_id'],ENT_NOQUOTES); ?>&nbsp;</td>
711 </tr>
712 <?php } ?>
713 <!-- Procedure Report End-->
715 <!-- Medical History Report Start-->
716 <?php
717 if ( $type == 'Medical History')
720 <tr bgcolor="#C3FDB8" align= "left">
721 <td colspan=12><b><?php echo "#"; echo htmlspecialchars(xl('Medical History'),ENT_NOQUOTES);?><b></td></tr>
722 <tr bgcolor="#C3FDB8" align= "left">
723 <td><b><?php echo htmlspecialchars(xl('History Date'),ENT_NOQUOTES); ?></b></td>
724 <td><b><?php echo htmlspecialchars(xl('Tobacco'),ENT_NOQUOTES);?></b></td>
725 <td><b><?php echo htmlspecialchars(xl('Alcohol'),ENT_NOQUOTES);?></b></td>
726 <td colspan=8><b><?php echo htmlspecialchars(xl('Recreational Drugs'),ENT_NOQUOTES);?></b></td>
727 </tr>
728 <tr bgcolor="#FFFFFF">
729 <?php
730 $tmp_t = explode('|', $row['history_data_tobacco']);
731 $tmp_a = explode('|', $row['history_data_alcohol']);
732 $tmp_d = explode('|', $row['history_data_recreational_drugs']);
733 $his_tobac = generate_display_field(array('data_type'=>'1','list_id'=>'smoking_status'), $tmp_t[3]) ;
735 <td> <?php echo htmlspecialchars(oeFormatShortDate($row['history_data_date']),ENT_NOQUOTES); ?>&nbsp;</td>
736 <td> <?php echo htmlspecialchars($his_tobac,ENT_NOQUOTES); ?>&nbsp;</td>
737 <?php
738 if ($tmp_a[1] == "currentalcohol") $res = xl('Current Alcohol');
739 if ($tmp_a[1] == "quitalcohol") $res = xl('Quit Alcohol');
740 if ($tmp_a[1] == "neveralcohol") $res = xl('Never Alcohol');
741 if ($tmp_a[1] == "not_applicablealcohol") $res = xl('N/A');
743 <td> <?php echo htmlspecialchars($res,ENT_NOQUOTES); ?>&nbsp;</td>
744 <?php
745 if ($tmp_d[1] == "currentrecreational_drugs") $resd = xl('Current Recreational Drugs');
746 if ($tmp_d[1] == "quitrecreational_drugs") $resd = xl('Quit');
747 if ($tmp_d[1] == "neverrecreational_drugs") $resd = xl('Never');
748 if ($tmp_d[1] == "not_applicablerecreational_drugs") $resd = xl('N/A');
750 <td colspan=8> <?php echo htmlspecialchars($resd,ENT_NOQUOTES); ?>&nbsp;</td>
751 </tr>
752 <?php } ?>
753 <!-- Medical History Report End-->
755 <!-- Service Codes Report Start-->
756 <?php
757 if ( $type == 'Service Codes') {
759 <tr bgcolor="#C3FDB8" align= "left">
760 <td colspan=11><b><?php echo "#"; echo htmlspecialchars(xl('Service Codes'),ENT_NOQUOTES);?><b></td></tr>
761 <tr bgcolor="#C3FDB8" align= "left">
762 <td><b><?php echo htmlspecialchars(xl('Date'),ENT_NOQUOTES); ?></b></td>
763 <td><b><?php echo htmlspecialchars(xl('Code'),ENT_NOQUOTES);?></b></td>
764 <td><b><?php echo htmlspecialchars(xl('Encounter ID'),ENT_NOQUOTES);?></b></td>
765 <td colspan=8><b><?php echo htmlspecialchars(xl('Code Text'),ENT_NOQUOTES);?></b></td></tr>
766 <tr bgcolor="#FFFFFF">
767 <td><?php echo htmlspecialchars(oeFormatShortDate($row['date']),ENT_NOQUOTES); ?>&nbsp;</td>
768 <td><?php echo htmlspecialchars($row['code'],ENT_NOQUOTES); ?>&nbsp;</td>
769 <td><?php echo htmlspecialchars($row['encounter'],ENT_NOQUOTES); ?>&nbsp;</td>
770 <td colspan=8><?php echo htmlspecialchars($row['code_text'],ENT_NOQUOTES); ?>&nbsp;</td>
771 </tr>
772 <?php } ?>
773 <!-- Service Codes Report End-->
774 </table>
775 <?php } //while loop end ?>
776 </table> <!-- Main table ends -->
777 <?php
778 } //End if $result
779 } //End if form_refresh
780 else
782 ?><div class='text'> <?php echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'),ENT_NOQUOTES); ?> </div><?php
785 </form>
786 </body>
788 <!-- stuff for the popup calendar -->
789 <style type="text/css">
790 @import url(../../library/dynarch_calendar.css);
791 </style>
792 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
793 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
794 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
795 <script language="Javascript">
796 Calendar.setup({inputField:"date_from", ifFormat:"%Y-%m-%d", button:"img_from_date"});
797 Calendar.setup({inputField:"date_to", ifFormat:"%Y-%m-%d", button:"img_to_date"});
798 </script>
799 </html>