Fixed bug: https://sourceforge.net/p/openemr/bugs/416/
[openemr.git] / interface / reports / patient_list_creation.php
blobb12711a2be9173a910c5f78345b8a98e4b1bdeff
1 <?php
2 /**
3 * This report lists all the demographics allergies,problems,drugs and lab results
5 * Copyright (C) 2014 Ensoftek, Inc
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>;.
18 * @package OpenEMR
19 * @link http://www.open-emr.org
22 //SANITIZE ALL ESCAPES
23 $sanitize_all_escapes=true;
26 //STOP FAKE REGISTER GLOBALS
27 $fake_register_globals=false;
29 require_once("../globals.php");
30 require_once("$srcdir/patient.inc");
31 require_once("$srcdir/options.inc.php");
32 require_once("../drugs/drugs.inc.php");
33 require_once("$srcdir/formatting.inc.php");
34 require_once("$srcdir/payment_jav.inc.php");
36 $DateFormat=DateFormatRead();
37 $search_options = array("Demographics"=>xl("Demographics"),"Problems"=>xl("Problems"),"Medications"=>xl("Medications"),"Allergies"=>xl("Allergies"),"Lab results"=>xl("Lab Results"),"Communication"=>xl("Communication"));
38 $comarr = array("allow_sms"=>xl("Allow SMS"),"allow_voice"=>xl("Allow Voice Message"),"allow_mail"=>xl("Allow Mail Message"),"allow_email"=>xl("Allow Email"));
39 $_POST['form_details'] = true;
40 function add_date($givendate,$day=0,$mth=0,$yr=0) {
41 $cd = strtotime($givendate);
42 $newdate = date('Y-m-d H:i:s', mktime(date('h',$cd),
43 date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
44 date('d',$cd)+$day, date('Y',$cd)+$yr));
45 return $newdate;
47 if($_POST['date_from'] != "")
48 $sql_date_from = $_POST['date_from'];
49 else
50 $sql_date_from = fixDate($_POST['date_from'], date('Y-01-01 H:i:s'));
52 if($_POST['date_to'] != "")
53 $sql_date_to = $_POST['date_to'];
54 else
55 $sql_date_to = fixDate($_POST['date_to'] , add_date(date('Y-m-d H:i:s')));
57 //echo "<pre>";print_r($_POST);
58 $patient_id = trim($_POST["patient_id"]);
59 $age_from = $_POST["age_from"];
60 $age_to = $_POST["age_to"];
61 $sql_gender = $_POST["gender"];
62 $sql_ethnicity = $_POST["cpms_ethnicity"];
63 $sql_race=$_POST["race"];
64 $form_drug_name = trim($_POST["form_drug_name"]);
65 $form_diagnosis = trim($_POST["form_diagnosis"]);
66 $form_lab_results = trim($_POST["form_lab_results"]);
67 $form_service_codes = trim($_POST["form_service_codes"]);
68 $form_immunization = trim($_POST["form_immunization"]);
69 $communication = trim($_POST["communication"]);
71 <html>
72 <head>
73 <?php html_header_show();?>
74 <title>
75 <?php echo xlt('Patient List Creation'); ?>
76 </title>
77 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
78 <script type="text/javascript" src="../../library/dialog.js"></script>
79 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
80 <script language="JavaScript">
81 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
82 var global_date_format = '%Y-%m-%d';
83 function Form_Validate() {
84 var d = document.forms[0];
85 FromDate = d.date_from.value;
86 ToDate = d.date_to.value;
87 if ( (FromDate.length > 0) && (ToDate.length > 0) ) {
88 if ( FromDate > ToDate ){
89 alert("<?php echo xls('To date must be later than From date!'); ?>");
90 return false;
93 $("#processing").show();
94 return true;
97 </script>
98 <script type="text/javascript" src="../../library/dialog.js"></script>
99 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
100 <link rel="stylesheet" href="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui-1.8.5.custom.css" type="text/css" />
101 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.css" media="screen" />
102 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.4.3.min.js"></script>
103 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui-1.8.5.custom.min.js"></script>
104 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox-1.3.4/jquery.fancybox-1.3.4.patched.js"></script>
105 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
106 <style type="text/css">
107 /* specifically include & exclude from printing */
108 @media print {
109 #report_parameters {
110 visibility: hidden;
111 display: none;
113 #report_parameters_daterange {
114 visibility: visible;
115 display: inline;
117 #report_results table {
118 margin-top: 0px;
120 #report_image {
121 visibility: hidden;
122 display: none;
126 /* specifically exclude some from the screen */
127 @media screen {
128 #report_parameters_daterange {
129 visibility: hidden;
130 display: none;
134 </style>
135 <script language="javascript" type="text/javascript">
137 function submitForm() {
138 var d_from = new String($('#date_from').val());
139 var d_to = new String($('#date_to').val());
141 var d_from_arr = d_from.split('-');
142 var d_to_arr = d_to.split('-');
144 var dt_from = new Date(d_from_arr[0], d_from_arr[1], d_from_arr[2]);
145 var dt_to = new Date(d_to_arr[0], d_to_arr[1], d_to_arr[2]);
147 var mili_from = dt_from.getTime();
148 var mili_to = dt_to.getTime();
149 var diff = mili_to - mili_from;
151 $('#date_error').css("display", "none");
153 if(diff < 0) //negative
155 $('#date_error').css("display", "inline");
157 else
159 $("#form_refresh").attr("value","true");
160 top.restoreSession();
161 $("#theform").submit();
165 //sorting changes
166 function sortingCols(sort_by,sort_order)
168 $("#sortby").val(sort_by);
169 $("#sortorder").val(sort_order);
170 $("#form_refresh").attr("value","true");
171 $("#theform").submit();
174 $(document).ready(function() {
175 $(".numeric_only").keydown(function(event) {
176 //alert(event.keyCode);
177 // Allow only backspace and delete
178 if ( event.keyCode == 46 || event.keyCode == 8 ) {
179 // let it happen, don't do anything
181 else {
182 if(!((event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 48 && event.keyCode <= 57)))
184 event.preventDefault();
188 <?php if($_POST['srch_option'] == "Communication"){ ?>
189 $('#com_pref').show();
190 <?php } ?>
191 });
193 </script>
194 </head>
196 <body class="body_top">
197 <!-- Required for the popup date selectors -->
198 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
199 <span class='title'>
200 <?php echo xlt('Report - Patient List Creation');?>
201 </span>
202 <!-- Search can be done using age range, gender, and ethnicity filters.
203 Search options include diagnosis, procedure, prescription, medical history, and lab results.
206 <div id="report_parameters_daterange">
208 <?php echo "<span style='margin-left:5px;'><b>".xlt('Date Range').":</b>&nbsp;".text(date($sql_date_from, strtotime($sql_date_from))) .
209 " &nbsp; to &nbsp; ". text(date($sql_date_to, strtotime($sql_date_to)))."</span>"; ?>
210 <span style="margin-left:5px; " ><b><?php echo xlt('Option'); ?>:</b>&nbsp;<?php echo text($_POST['srch_option']);
211 if($_POST['srch_option'] == "Communication" && $_POST['communication'] != ""){
212 if(isset($comarr[$_POST['communication']]))
213 echo "(".text($comarr[$_POST['communication']]).")";
214 else
215 echo "(".xlt('All').")";
216 } ?></span>
217 </p>
218 </div>
219 <form name='theform' id='theform' method='post' action='patient_list_creation.php' onSubmit="return Form_Validate();">
220 <div id="report_parameters">
221 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
222 <table>
223 <tr>
224 <td width='900px'><div style='float:left'>
225 <table class='text'>
226 <tr>
227 <td class='label' ><?php echo xlt('From'); ?>: </td>
228 <td><input type='text' name='date_from' id="date_from" size='18' value='<?php echo attr($sql_date_from); ?>' readonly="readonly" title='<?php echo attr($title_tooltip) ?>'> <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 xla('Click here to choose a date'); ?>'></td>
229 <td class='label'><?php echo xlt('To{{range}}'); ?>: </td>
230 <td><input type='text' name='date_to' id="date_to" size='18' value='<?php echo attr($sql_date_to); ?>' readonly="readonly" title='<?php echo attr($title_tooltip) ?>'> <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 xla('Click here to choose a date'); ?>'></td>
231 <td class='label'><?php echo xlt('Option'); ?>: </td>
232 <td class='label'>
233 <select name="srch_option" id="srch_option" onchange="javascript:$('#sortby').val('');$('#sortorder').val('');if(this.value == 'Communication'){ $('#communication').val('');$('#com_pref').show();}else{ $('#communication').val('');$('#com_pref').hide();}">
234 <?php foreach($search_options as $skey => $svalue){ ?>
235 <option <?php if($_POST['srch_option'] == $skey) echo 'selected'; ?> value="<?php echo attr($skey); ?>"><?php echo text($svalue); ?></option>
236 <?php } ?>
237 </select>
238 <?php ?>
239 </td>
241 <td >
242 <span id="com_pref" style="display:none">
243 <select name="communication" id="communication" title="<?php echo xlt('Select Communication Preferences'); ?>">
244 <option> <?php echo xlt('All'); ?></option>
245 <option value="allow_sms" <?php if($communication == "allow_sms"){ echo "selected";}?>><?php echo xlt('Allow SMS'); ?></option>
246 <option value="allow_voice" <?php if($communication == "allow_voice"){ echo "selected";}?>><?php echo xlt('Allow Voice Message'); ?></option>
247 <option value="allow_mail" <?php if($communication == "allow_mail"){ echo "selected";}?>><?php echo xlt('Allow Mail Message'); ?></option>
248 <option value="allow_email" <?php if($communication == "allow_email"){ echo "selected";}?>><?php echo xlt('Allow Email'); ?></option>
249 </select>
250 </span>
251 </td>
253 </tr>
254 <tr>
255 <td class='label'><?php echo xlt('Patient ID'); ?>:</td>
256 <td><input name='patient_id' class="numeric_only" type='text' id="patient_id" title='<?php echo xla('Optional numeric patient ID'); ?>' value='<?php echo attr($patient_id); ?>' size='10' maxlength='20' /></td>
257 <td class='label'><?php echo xlt('Age Range'); ?>:</td>
258 <td><?php echo xlt('From'); ?>
259 <input name='age_from' class="numeric_only" type='text' id="age_from" value="<?php echo attr($age_from); ?>" size='3' maxlength='3' /> <?php echo xlt('To{{range}}'); ?>
260 <input name='age_to' class="numeric_only" type='text' id="age_to" value="<?php echo attr($age_to); ?>" size='3' maxlength='3' /></td>
261 <td class='label'><?php echo xlt('Gender'); ?>:</td>
262 <td colspan="2"><?php echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?></td>
263 </tr>
265 </table>
267 </div></td>
268 <td height="100%" valign='middle' width="175"><table style='border-left:1px solid; width:100%; height:100%'>
269 <tr>
270 <td width="130px"><div style='margin-left:15px'> <a href='#' class='css_button' onclick='submitForm();'> <span>
271 <?php echo xlt('Submit'); ?>
272 </span> </a>
273 </div>
274 </td>
275 <td>
276 <div id='processing' style='display:none;' ><img src='../pic/ajax-loader.gif'/></div>
277 </td>
279 </tr>
280 </table></td>
281 </tr>
282 </table>
283 </div>
284 <!-- end of parameters -->
285 <?php
286 //$sql_date_from=DateTimeToYYYYMMDD($sql_date_from);
287 //$sql_date_to=DateTimeToYYYYMMDD($sql_date_to);
289 // SQL scripts for the various searches
290 $sqlBindArray = array();
291 if ($_POST['form_refresh']){
293 $sqlstmt = "select
294 pd.date as patient_date,
295 concat(pd.lname, ', ', pd.fname) AS patient_name,
296 pd.pid AS patient_id,
297 DATE_FORMAT(FROM_DAYS(DATEDIFF('".date('Y-m-d H:i:s')."',pd.dob)), '%Y')+0 AS patient_age,
298 pd.sex AS patient_sex,
299 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
300 concat(u.lname, ', ', u.fname) AS users_provider";
302 $srch_option = $_POST['srch_option'];
303 switch ($srch_option) {
304 case "Medications":
305 case "Allergies":
306 case "Problems":
307 $sqlstmt=$sqlstmt.",li.date AS lists_date,
308 li.diagnosis AS lists_diagnosis,
309 li.title AS lists_title";
310 break;
311 case "Lab results":
312 $sqlstmt = $sqlstmt.",pr.date AS procedure_result_date,
313 pr.facility AS procedure_result_facility,
314 pr.units AS procedure_result_units,
315 pr.result AS procedure_result_result,
316 pr.range AS procedure_result_range,
317 pr.abnormal AS procedure_result_abnormal,
318 pr.comments AS procedure_result_comments,
319 pr.document_id AS procedure_result_document_id";
320 break;
321 case "Communication":
322 $sqlstmt = $sqlstmt.",REPLACE(REPLACE(concat_ws(',',IF(pd.hipaa_allowemail = 'YES', 'Allow Email','NO'),IF(pd.hipaa_allowsms = 'YES', 'Allow SMS','NO') , IF(pd.hipaa_mail = 'YES', 'Allow Mail Message','NO') , IF(pd.hipaa_voice = 'YES', 'Allow Voice Message','NO') ), ',NO',''), 'NO,','') as communications";
323 break;
326 //from
327 $sqlstmt=$sqlstmt." from patient_data as pd left outer join users as u on u.id = pd.providerid";
328 //JOINS
329 switch ($srch_option) {
330 case "Problems":
331 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND li.type='medical_problem')";
332 break;
333 case "Medications":
334 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='medication')) ";
335 break;
336 case "Allergies":
337 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='allergy')) ";
338 break;
339 case "Lab results":
341 $sqlstmt = $sqlstmt." left outer join procedure_order as po on po.patient_id = pd.pid
342 left outer join procedure_order_code as pc on pc.procedure_order_id = po.procedure_order_id
343 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
344 left outer join procedure_type as pt on pt.procedure_code = pc.procedure_code and pt.lab_id = po.lab_id
345 left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id";
346 break;
349 //WHERE Conditions started
350 $whr_stmt="where 1=1";
351 switch ($srch_option) {
352 case "Medications":
353 case "Allergies":
354 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
355 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
356 break;
357 case "Problems":
358 $whr_stmt = $whr_stmt." AND li.title != '' ";
359 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
360 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
361 break;
362 case "Lab results":
363 $whr_stmt=$whr_stmt." AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND pr.date <= ?";
364 $whr_stmt= $whr_stmt." AND (pr.result != '') ";
365 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
366 break;
367 case "Communication":
368 $whr_stmt .= " AND (pd.hipaa_allowsms = 'YES' OR pd.hipaa_voice = 'YES' OR pd.hipaa_mail = 'YES' OR pd.hipaa_allowemail = 'YES') ";
369 break;
372 if(strlen($patient_id) != 0) {
373 $whr_stmt = $whr_stmt." and pd.pid = ?";
374 array_push($sqlBindArray, $patient_id);
377 if(strlen($age_from) != 0) {
378 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
379 array_push($sqlBindArray, $age_from);
382 if(strlen($age_to) != 0) {
383 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
384 array_push($sqlBindArray, $age_to);
387 if(strlen($sql_gender) != 0) {
388 $whr_stmt = $whr_stmt." and pd.sex = ?";
389 array_push($sqlBindArray, $sql_gender);
392 if($srch_option == "Communication" && strlen($communication) > 0){
393 if($communication == "allow_sms") $whr_stmt .= " AND pd.hipaa_allowsms = 'YES' ";
394 else if($communication == "allow_voice") $whr_stmt .= " AND pd.hipaa_voice = 'YES' ";
395 else if($communication == "allow_mail") $whr_stmt .= " AND pd.hipaa_mail = 'YES' ";
396 else if($communication == "allow_email") $whr_stmt .= " AND pd.hipaa_allowemail = 'YES' ";
399 //Sorting By filter fields
400 $sortby = $_REQUEST['sortby'];
401 $sortorder = $_REQUEST['sortorder'];
403 // This is for sorting the records.
404 switch ($srch_option) {
405 case "Medications":
406 case "Allergies":
407 case "Problems":
408 $sort = array("lists_date","lists_diagnosis","lists_title");
409 if($sortby == "")$sortby = $sort[1];
410 break;
411 case "Lab results":
412 $sort = array("procedure_result_date","procedure_result_facility","procedure_result_units","procedure_result_result","procedure_result_range","procedure_result_abnormal");
413 //$odrstmt = " procedure_result_result";
414 break;
415 case "Communication":
416 //$commsort = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(','))";
417 $sort = array("patient_date","patient_name","patient_id","patient_age","patient_sex","users_provider", "communications");
418 if($sortby == "")$sortby = $sort[6];
419 //$odrstmt = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
420 break;
421 case "Demographics":
422 $sort = array("patient_date","patient_name","patient_id","patient_age","patient_sex","patient_race","patient_ethinic","users_provider");
423 break;
425 if($sortby == "") {
426 $sortby = $sort[0];
428 if($sortorder == "") {
429 $sortorder = "asc";
431 for($i = 0; $i < count($sort); $i++) {
432 $sortlink[$i] = "<a href=\"#\" onclick=\"sortingCols('$sort[$i]','asc');\" ><img src=\"../../images/sortdown.gif\" border=0 alt=\"".xla('Sort Up')."\"></a>";
434 for($i = 0; $i < count($sort); $i++) {
435 if($sortby == $sort[$i]) {
436 switch($sortorder) {
437 case "asc" : $sortlink[$i] = "<a href=\"#\" onclick=\"sortingCols('$sortby','desc');\" ><img src=\"../../images/sortup.gif\" border=0 alt=\"".htmlspecialchars( xl('Sort Up'), ENT_QUOTES)."\"></a>"; break;
438 case "desc" : $sortlink[$i] = "<a href=\"#\" onclick=\"sortingCols('$sortby','asc');\" onclick=\"top.restoreSession()\"><img src=\"../../images/sortdown.gif\" border=0 alt=\"".xla('Sort Down')."\"></a>"; break;
439 } break;
443 switch ($srch_option) {
444 case "Medications":
445 case "Allergies":
446 case "Problems":
447 $odrstmt = " ORDER BY lists_date asc";
448 break;
449 case "Lab results":
450 $odrstmt = " ORDER BY procedure_result_date asc";
451 break;
452 case "Communication":
453 $odrstmt = "ORDER BY ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) asc, communications asc";
454 break;
455 case "Demographics":
456 $odrstmt = " ORDER BY patient_date asc";
457 //$odrstmt = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
458 break;
460 if(!empty($_REQUEST['sortby']) && !empty($_REQUEST['sortorder'])){
461 if($_REQUEST['sortby'] =="communications"){
462 $odrstmt = "ORDER BY ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) ".escape_sort_order($_REQUEST['sortorder']).", communications ".escape_sort_order($_REQUEST['sortorder']);
463 }else{
464 $odrstmt = "ORDER BY ".escape_identifier($_REQUEST['sortby'],$sort,TRUE)." ".escape_sort_order($_REQUEST['sortorder']);
468 $sqlstmt=$sqlstmt." ".$whr_stmt." ".$odrstmt;
469 //echo $sqlstmt."<hr>";
470 $result = sqlStatement($sqlstmt,$sqlBindArray);
471 //print_r($result);
472 $row_id = 1.1;//given to each row to identify and toggle
473 $img_id = 1.2;
474 $k=1.3;
476 if(sqlNumRows($result) > 0){
477 $patArr = array();
479 $patDataArr = array();
480 $smoke_codes_arr = getSmokeCodes();
481 while ($row = sqlFetchArray($result)) {
483 $patArr[] = $row['patient_id'];
484 $patInfoArr = array();
485 $patInfoArr['patient_id'] = $row['patient_id'];
486 //Diagnosis Check
487 if($srch_option == "Medications" || $srch_option == "Allergies" || $srch_option == "Problems"){
488 $patInfoArr['lists_date'] = $row['lists_date'];
489 $patInfoArr['lists_diagnosis'] = $row['lists_diagnosis'];
490 $patInfoArr['lists_title'] = $row['lists_title'];
491 $patInfoArr['patient_name'] = $row['patient_name'];
492 $patInfoArr['patient_age'] = $row['patient_age'];
493 $patInfoArr['patient_sex'] = $row['patient_sex'];
494 $patInfoArr['patient_race'] = $row['patient_race'];
495 $patInfoArr['patient_ethinic'] = $row['patient_ethinic'];
496 $patInfoArr['users_provider'] = $row['users_provider'];
497 }elseif($srch_option == "Lab results"){
498 $patInfoArr['procedure_result_date'] = $row['procedure_result_date'];
499 $patInfoArr['procedure_result_facility'] = $row['procedure_result_facility'];
500 $patInfoArr['procedure_result_units'] = $row['procedure_result_units'];
501 $patInfoArr['procedure_result_result'] = $row['procedure_result_result'];
502 $patInfoArr['procedure_result_range'] = $row['procedure_result_range'];
503 $patInfoArr['procedure_result_abnormal'] = $row['procedure_result_abnormal'];
504 $patInfoArr['procedure_result_comments'] = $row['procedure_result_comments'];
505 $patInfoArr['procedure_result_document_id'] = $row['procedure_result_document_id'];
506 }elseif($srch_option == "Communication"){
507 $patInfoArr['patient_date'] = $row['patient_date'];
508 $patInfoArr['patient_name'] = $row['patient_name'];
509 $patInfoArr['patient_age'] = $row['patient_age'];
510 $patInfoArr['patient_sex'] = $row['patient_sex'];
511 $patInfoArr['users_provider'] = $row['users_provider'];
512 $patInfoArr['communications'] = $row['communications'];
513 }elseif($srch_option == "Demographics"){
514 $patInfoArr['patient_date'] = $row['patient_date'];
515 $patInfoArr['patient_name'] = $row['patient_name'];
516 $patInfoArr['patient_age'] = $row['patient_age'];
517 $patInfoArr['patient_sex'] = $row['patient_sex'];
518 $patInfoArr['patient_race'] = $row['patient_race'];
519 $patInfoArr['patient_ethinic'] = $row['patient_ethinic'];
520 $patInfoArr['users_provider'] = $row['users_provider'];
523 $patFinalDataArr[] = $patInfoArr;
530 <br>
532 <input type="hidden" name="sortby" id="sortby" value="<?php echo attr($sortby); ?>" />
533 <input type="hidden" name="sortorder" id="sortorder" value="<?php echo attr($sortorder); ?>" />
534 <div id = "report_results">
535 <table>
536 <tr>
537 <td class="text"><strong><?php echo xlt('Total Number of Patients')?>:</strong>&nbsp;<span id="total_patients"><?php echo attr(count(array_unique($patArr)));?></span></td>
538 </tr>
539 </table>
541 <table width=90% align="center" cellpadding="5" cellspacing="0" style="font-family:tahoma;color:black;" border="0">
543 <?php if($srch_option == "Medications" || $srch_option == "Allergies" || $srch_option == "Problems"){ ?>
544 <tr style="font-size:15px;">
545 <td width="15%"><b><?php echo xlt('Diagnosis Date'); ?><?php echo $sortlink[0]; ?></b></td>
546 <td width="15%"><b><?php echo xlt('Diagnosis'); ?><?php echo $sortlink[1]; ?></b></td>
547 <td width="15%"><b><?php echo xlt('Diagnosis Name');?><?php echo $sortlink[2]; ?></b></td>
548 <td width="15%"><b><?php echo xlt('Patient Name'); ?></b></td>
549 <td width="5%"><b><?php echo xlt('PID');?></b></td>
550 <td width="5%"><b><?php echo xlt('Age');?></b></td>
551 <td width="10%"><b><?php echo xlt('Gender');?></b></td>
552 <td colspan=4><b><?php echo xlt('Provider');?></b></td>
553 </tr>
554 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
555 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
556 <td ><?php echo text($patDetailVal['lists_date']); ?></td>
557 <td ><?php echo text($patDetailVal['lists_diagnosis']); ?></td>
558 <td ><?php echo text($patDetailVal['lists_title']); ?></td>
559 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
560 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
561 <td ><?php echo text($patDetailVal['patient_age']);?></td>
562 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
563 <td colspan=4><?php echo text($patDetailVal['users_provider']);?></td>
564 </tr>
565 <?php }
566 }elseif($srch_option == "Lab results"){ ?>
567 <tr bgcolor="#C3FDB8" align= "left" >
568 <td width="15%"><b><?php echo xlt('Date'); ?><?php echo $sortlink[0]; ?></b></td>
569 <td width="15%"><b><?php echo xlt('Facility');?><?php echo $sortlink[1]; ?></b></td>
570 <td width="10%"><b><?php echo xlt('Unit');?></b><?php echo $sortlink[2]; ?></td>
571 <td width="10%"><b><?php echo xlt('Result');?></b><?php echo $sortlink[3]; ?></td>
572 <td width="10%"><b><?php echo xlt('Range');?></b><?php echo $sortlink[4]; ?></td>
573 <td width="10%"><b><?php echo xlt('Abnormal');?><?php echo $sortlink[5]; ?></b></td>
574 <td><b><?php echo xlt('Comments');?></b></td>
575 <td width="5%"><b><?php echo xlt('Document ID');?></b></td>
576 <td width="5%"><b><?php echo xlt('PID');?></b></td>
577 </tr>
578 <?php
579 foreach($patFinalDataArr as $patKey => $labResInsideArr){?>
580 <tr bgcolor = "#CCCCCC" >
581 <td> <?php echo text($labResInsideArr['procedure_result_date']);?>&nbsp;</td>
582 <td> <?php echo text($labResInsideArr['procedure_result_facility'],ENT_NOQUOTES); ?>&nbsp;</td>
583 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$labResInsideArr['procedure_result_units']); ?>&nbsp;</td>
584 <td> <?php echo text($labResInsideArr['procedure_result_result']); ?>&nbsp;</td>
585 <td> <?php echo text($labResInsideArr['procedure_result_range']); ?>&nbsp;</td>
586 <td> <?php echo text($labResInsideArr['procedure_result_abnormal']); ?>&nbsp;</td>
587 <td> <?php echo text($labResInsideArr['procedure_result_comments']); ?>&nbsp;</td>
588 <td> <?php echo text($labResInsideArr['procedure_result_document_id']); ?>&nbsp;</td>
589 <td colspan="3"> <?php echo text($labResInsideArr['patient_id']); ?>&nbsp;</td>
590 </tr>
591 <?php
593 }elseif($srch_option == "Communication"){ ?>
594 <tr style="font-size:15px;">
595 <td width="15%"><b><?php echo xlt('Date'); ?></b><?php echo $sortlink[0]; ?></td>
596 <td width="20%"><b><?php echo xlt('Patient Name'); ?></b><?php echo $sortlink[1]; ?></td>
597 <td width="5%"><b><?php echo xlt('PID');?></b><?php echo $sortlink[2]; ?></td>
598 <td width="5%"><b><?php echo xlt('Age');?></b><?php echo $sortlink[3]; ?></td>
599 <td width="10%"><b><?php echo xlt('Gender');?></b><?php echo $sortlink[4]; ?></td>
600 <td width="15%"><b><?php echo xlt('Provider');?></b><?php echo $sortlink[5]; ?></td>
601 <td ><b><?php echo xlt('Communication');?></b><?php echo $sortlink[6]; ?></td>
602 </tr>
603 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
604 <tr bgcolor = "#CCCCCC" >
605 <td ><?php if($patDetailVal['patient_date'] != ''){ echo text($patDetailVal['patient_date']); }else{ echo ""; }; ?></td>
606 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
607 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
608 <td ><?php echo text($patDetailVal['patient_age']);?></td>
609 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
610 <td ><?php echo text($patDetailVal['users_provider']);?></td>
611 <td ><?php echo text($patDetailVal['communications']);?></td>
612 </tr>
613 <?php
615 }elseif($srch_option == "Demographics"){ ?>
616 <tr style="font-size:15px;">
617 <td width="15%"><b><?php echo xlt('Date'); ?></b><?php echo $sortlink[0]; ?></td>
618 <td width="20%"><b><?php echo xlt('Patient Name'); ?></b><?php echo $sortlink[1]; ?></td>
619 <td width="15%"><b><?php echo xlt('PID');?></b><?php echo $sortlink[2]; ?></td>
620 <td width="5%"><b><?php echo xlt('Age');?></b><?php echo $sortlink[3]; ?></td>
621 <td width="10%"><b><?php echo xlt('Gender'); ?></b><?php echo $sortlink[4]; ?></td>
622 <td width="20%"><b><?php echo xlt('Race');?></b><?php echo $sortlink[5]; ?></td>
623 <td colspan=5><b><?php echo xlt('Provider');?></b><?php echo $sortlink[7]; ?></td>
624 </tr>
625 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
626 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
627 <td ><?php if($patDetailVal['patient_date'] != ''){ echo text($patDetailVal['patient_date']); }else{ echo ""; };?></td>
628 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
629 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
630 <td ><?php echo text($patDetailVal['patient_age']);?></td>
631 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
632 <td ><?php echo generate_display_field(array('data_type'=>'36','list_id'=>'race'), $patDetailVal['patient_race']); ?></td>
633 <td colspan=5><?php echo text($patDetailVal['users_provider']);?></td>
634 </tr>
635 <?php }
636 } ?>
638 </table>
639 <!-- Main table ends -->
640 <?php
641 }else{//End if $result?>
642 <table>
643 <tr>
644 <td class="text">&nbsp;&nbsp;<?php echo xlt('No records found.')?></td>
645 </tr>
646 </table>
647 <?php
650 </div>
652 <?php
653 }else{//End if form_refresh
654 ?><div class='text'> <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?> </div><?php
657 </form>
659 <!-- stuff for the popup calendar -->
660 <style type="text/css">
661 @import url(../../library/dynarch_calendar.css);
662 </style>
663 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
664 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
665 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
666 <script language="Javascript">
667 Calendar.setup({inputField:"date_from", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_from_date", showsTime:true});
668 Calendar.setup({inputField:"date_to", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_to_date", showsTime:true});
669 </script>
670 </body>
671 </html>