Security improvement in setup script.
[openemr.git] / interface / reports / patient_list_creation.php
blobe10315aafae37bd2ceb812d71a8b998a44311673
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'>
225 <div class="cancel-float" style='float:left'>
226 <table class='text'>
227 <tr>
228 <td class='label' ><?php echo xlt('From'); ?>: </td>
229 <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>
230 <td class='label'><?php echo xlt('To{{range}}'); ?>: </td>
231 <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>
232 <td class='label'><?php echo xlt('Option'); ?>: </td>
233 <td class='label'>
234 <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();}">
235 <?php foreach($search_options as $skey => $svalue){ ?>
236 <option <?php if($_POST['srch_option'] == $skey) echo 'selected'; ?> value="<?php echo attr($skey); ?>"><?php echo text($svalue); ?></option>
237 <?php } ?>
238 </select>
239 <?php ?>
240 </td>
242 <td >
243 <span id="com_pref" style="display:none">
244 <select name="communication" id="communication" title="<?php echo xlt('Select Communication Preferences'); ?>">
245 <option> <?php echo xlt('All'); ?></option>
246 <option value="allow_sms" <?php if($communication == "allow_sms"){ echo "selected";}?>><?php echo xlt('Allow SMS'); ?></option>
247 <option value="allow_voice" <?php if($communication == "allow_voice"){ echo "selected";}?>><?php echo xlt('Allow Voice Message'); ?></option>
248 <option value="allow_mail" <?php if($communication == "allow_mail"){ echo "selected";}?>><?php echo xlt('Allow Mail Message'); ?></option>
249 <option value="allow_email" <?php if($communication == "allow_email"){ echo "selected";}?>><?php echo xlt('Allow Email'); ?></option>
250 </select>
251 </span>
252 </td>
254 </tr>
255 <tr>
256 <td class='label'><?php echo xlt('Patient ID'); ?>:</td>
257 <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>
258 <td class='label'><?php echo xlt('Age Range'); ?>:</td>
259 <td><?php echo xlt('From'); ?>
260 <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}}'); ?>
261 <input name='age_to' class="numeric_only" type='text' id="age_to" value="<?php echo attr($age_to); ?>" size='3' maxlength='3' /></td>
262 <td class='label'><?php echo xlt('Gender'); ?>:</td>
263 <td colspan="2"><?php echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?></td>
264 </tr>
266 </table>
268 </div></td>
269 <td height="100%" valign='middle' width="175"><table style='border-left:1px solid; width:100%; height:100%'>
270 <tr>
271 <td width="130px"><div style='margin-left:15px'> <a href='#' class='css_button' onclick='submitForm();'> <span>
272 <?php echo xlt('Submit'); ?>
273 </span> </a>
274 </div>
275 </td>
276 <td>
277 <div id='processing' style='display:none;' ><img src='../pic/ajax-loader.gif'/></div>
278 </td>
280 </tr>
281 </table></td>
282 </tr>
283 </table>
284 </div>
285 <!-- end of parameters -->
286 <?php
287 //$sql_date_from=DateTimeToYYYYMMDD($sql_date_from);
288 //$sql_date_to=DateTimeToYYYYMMDD($sql_date_to);
290 // SQL scripts for the various searches
291 $sqlBindArray = array();
292 if ($_POST['form_refresh']){
294 $sqlstmt = "select
295 pd.date as patient_date,
296 concat(pd.lname, ', ', pd.fname) AS patient_name,
297 pd.pid AS patient_id,
298 DATE_FORMAT(FROM_DAYS(DATEDIFF('".date('Y-m-d H:i:s')."',pd.dob)), '%Y')+0 AS patient_age,
299 pd.sex AS patient_sex,
300 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
301 concat(u.lname, ', ', u.fname) AS users_provider";
303 $srch_option = $_POST['srch_option'];
304 switch ($srch_option) {
305 case "Medications":
306 case "Allergies":
307 case "Problems":
308 $sqlstmt=$sqlstmt.",li.date AS lists_date,
309 li.diagnosis AS lists_diagnosis,
310 li.title AS lists_title";
311 break;
312 case "Lab results":
313 $sqlstmt = $sqlstmt.",pr.date AS procedure_result_date,
314 pr.facility AS procedure_result_facility,
315 pr.units AS procedure_result_units,
316 pr.result AS procedure_result_result,
317 pr.range AS procedure_result_range,
318 pr.abnormal AS procedure_result_abnormal,
319 pr.comments AS procedure_result_comments,
320 pr.document_id AS procedure_result_document_id";
321 break;
322 case "Communication":
323 $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";
324 break;
327 //from
328 $sqlstmt=$sqlstmt." from patient_data as pd left outer join users as u on u.id = pd.providerid";
329 //JOINS
330 switch ($srch_option) {
331 case "Problems":
332 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND li.type='medical_problem')";
333 break;
334 case "Medications":
335 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='medication')) ";
336 break;
337 case "Allergies":
338 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='allergy')) ";
339 break;
340 case "Lab results":
342 $sqlstmt = $sqlstmt." left outer join procedure_order as po on po.patient_id = pd.pid
343 left outer join procedure_order_code as pc on pc.procedure_order_id = po.procedure_order_id
344 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
345 left outer join procedure_type as pt on pt.procedure_code = pc.procedure_code and pt.lab_id = po.lab_id
346 left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id";
347 break;
350 //WHERE Conditions started
351 $whr_stmt="where 1=1";
352 switch ($srch_option) {
353 case "Medications":
354 case "Allergies":
355 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
356 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
357 break;
358 case "Problems":
359 $whr_stmt = $whr_stmt." AND li.title != '' ";
360 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
361 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
362 break;
363 case "Lab results":
364 $whr_stmt=$whr_stmt." AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND pr.date <= ?";
365 $whr_stmt= $whr_stmt." AND (pr.result != '') ";
366 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
367 break;
368 case "Communication":
369 $whr_stmt .= " AND (pd.hipaa_allowsms = 'YES' OR pd.hipaa_voice = 'YES' OR pd.hipaa_mail = 'YES' OR pd.hipaa_allowemail = 'YES') ";
370 break;
373 if(strlen($patient_id) != 0) {
374 $whr_stmt = $whr_stmt." and pd.pid = ?";
375 array_push($sqlBindArray, $patient_id);
378 if(strlen($age_from) != 0) {
379 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
380 array_push($sqlBindArray, $age_from);
383 if(strlen($age_to) != 0) {
384 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
385 array_push($sqlBindArray, $age_to);
388 if(strlen($sql_gender) != 0) {
389 $whr_stmt = $whr_stmt." and pd.sex = ?";
390 array_push($sqlBindArray, $sql_gender);
393 if($srch_option == "Communication" && strlen($communication) > 0){
394 if($communication == "allow_sms") $whr_stmt .= " AND pd.hipaa_allowsms = 'YES' ";
395 else if($communication == "allow_voice") $whr_stmt .= " AND pd.hipaa_voice = 'YES' ";
396 else if($communication == "allow_mail") $whr_stmt .= " AND pd.hipaa_mail = 'YES' ";
397 else if($communication == "allow_email") $whr_stmt .= " AND pd.hipaa_allowemail = 'YES' ";
400 //Sorting By filter fields
401 $sortby = $_REQUEST['sortby'];
402 $sortorder = $_REQUEST['sortorder'];
404 // This is for sorting the records.
405 switch ($srch_option) {
406 case "Medications":
407 case "Allergies":
408 case "Problems":
409 $sort = array("lists_date","lists_diagnosis","lists_title");
410 if($sortby == "")$sortby = $sort[1];
411 break;
412 case "Lab results":
413 $sort = array("procedure_result_date","procedure_result_facility","procedure_result_units","procedure_result_result","procedure_result_range","procedure_result_abnormal");
414 //$odrstmt = " procedure_result_result";
415 break;
416 case "Communication":
417 //$commsort = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(','))";
418 $sort = array("patient_date","patient_name","patient_id","patient_age","patient_sex","users_provider", "communications");
419 if($sortby == "")$sortby = $sort[6];
420 //$odrstmt = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
421 break;
422 case "Demographics":
423 $sort = array("patient_date","patient_name","patient_id","patient_age","patient_sex","patient_race","patient_ethinic","users_provider");
424 break;
426 if($sortby == "") {
427 $sortby = $sort[0];
429 if($sortorder == "") {
430 $sortorder = "asc";
432 for($i = 0; $i < count($sort); $i++) {
433 $sortlink[$i] = "<a href=\"#\" onclick=\"sortingCols('$sort[$i]','asc');\" ><img src=\"../../images/sortdown.gif\" border=0 alt=\"".xla('Sort Up')."\"></a>";
435 for($i = 0; $i < count($sort); $i++) {
436 if($sortby == $sort[$i]) {
437 switch($sortorder) {
438 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;
439 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;
440 } break;
444 switch ($srch_option) {
445 case "Medications":
446 case "Allergies":
447 case "Problems":
448 $odrstmt = " ORDER BY lists_date asc";
449 break;
450 case "Lab results":
451 $odrstmt = " ORDER BY procedure_result_date asc";
452 break;
453 case "Communication":
454 $odrstmt = "ORDER BY ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) asc, communications asc";
455 break;
456 case "Demographics":
457 $odrstmt = " ORDER BY patient_date asc";
458 //$odrstmt = " ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
459 break;
461 if(!empty($_REQUEST['sortby']) && !empty($_REQUEST['sortorder'])){
462 if($_REQUEST['sortby'] =="communications"){
463 $odrstmt = "ORDER BY ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) ".escape_sort_order($_REQUEST['sortorder']).", communications ".escape_sort_order($_REQUEST['sortorder']);
464 }else{
465 $odrstmt = "ORDER BY ".escape_identifier($_REQUEST['sortby'],$sort,TRUE)." ".escape_sort_order($_REQUEST['sortorder']);
469 $sqlstmt=$sqlstmt." ".$whr_stmt." ".$odrstmt;
470 //echo $sqlstmt."<hr>";
471 $result = sqlStatement($sqlstmt,$sqlBindArray);
472 //print_r($result);
473 $row_id = 1.1;//given to each row to identify and toggle
474 $img_id = 1.2;
475 $k=1.3;
477 if(sqlNumRows($result) > 0){
478 $patArr = array();
480 $patDataArr = array();
481 $smoke_codes_arr = getSmokeCodes();
482 while ($row = sqlFetchArray($result)) {
484 $patArr[] = $row['patient_id'];
485 $patInfoArr = array();
486 $patInfoArr['patient_id'] = $row['patient_id'];
487 //Diagnosis Check
488 if($srch_option == "Medications" || $srch_option == "Allergies" || $srch_option == "Problems"){
489 $patInfoArr['lists_date'] = $row['lists_date'];
490 $patInfoArr['lists_diagnosis'] = $row['lists_diagnosis'];
491 $patInfoArr['lists_title'] = $row['lists_title'];
492 $patInfoArr['patient_name'] = $row['patient_name'];
493 $patInfoArr['patient_age'] = $row['patient_age'];
494 $patInfoArr['patient_sex'] = $row['patient_sex'];
495 $patInfoArr['patient_race'] = $row['patient_race'];
496 $patInfoArr['patient_ethinic'] = $row['patient_ethinic'];
497 $patInfoArr['users_provider'] = $row['users_provider'];
498 }elseif($srch_option == "Lab results"){
499 $patInfoArr['procedure_result_date'] = $row['procedure_result_date'];
500 $patInfoArr['procedure_result_facility'] = $row['procedure_result_facility'];
501 $patInfoArr['procedure_result_units'] = $row['procedure_result_units'];
502 $patInfoArr['procedure_result_result'] = $row['procedure_result_result'];
503 $patInfoArr['procedure_result_range'] = $row['procedure_result_range'];
504 $patInfoArr['procedure_result_abnormal'] = $row['procedure_result_abnormal'];
505 $patInfoArr['procedure_result_comments'] = $row['procedure_result_comments'];
506 $patInfoArr['procedure_result_document_id'] = $row['procedure_result_document_id'];
507 }elseif($srch_option == "Communication"){
508 $patInfoArr['patient_date'] = $row['patient_date'];
509 $patInfoArr['patient_name'] = $row['patient_name'];
510 $patInfoArr['patient_age'] = $row['patient_age'];
511 $patInfoArr['patient_sex'] = $row['patient_sex'];
512 $patInfoArr['users_provider'] = $row['users_provider'];
513 $patInfoArr['communications'] = $row['communications'];
514 }elseif($srch_option == "Demographics"){
515 $patInfoArr['patient_date'] = $row['patient_date'];
516 $patInfoArr['patient_name'] = $row['patient_name'];
517 $patInfoArr['patient_age'] = $row['patient_age'];
518 $patInfoArr['patient_sex'] = $row['patient_sex'];
519 $patInfoArr['patient_race'] = $row['patient_race'];
520 $patInfoArr['patient_ethinic'] = $row['patient_ethinic'];
521 $patInfoArr['users_provider'] = $row['users_provider'];
524 $patFinalDataArr[] = $patInfoArr;
531 <br>
533 <input type="hidden" name="sortby" id="sortby" value="<?php echo attr($sortby); ?>" />
534 <input type="hidden" name="sortorder" id="sortorder" value="<?php echo attr($sortorder); ?>" />
535 <div id = "report_results">
536 <table>
537 <tr>
538 <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>
539 </tr>
540 </table>
542 <table width=90% align="center" cellpadding="5" cellspacing="0" style="font-family:tahoma;color:black;" border="0">
544 <?php if($srch_option == "Medications" || $srch_option == "Allergies" || $srch_option == "Problems"){ ?>
545 <tr style="font-size:15px;">
546 <td width="15%"><b><?php echo xlt('Diagnosis Date'); ?><?php echo $sortlink[0]; ?></b></td>
547 <td width="15%"><b><?php echo xlt('Diagnosis'); ?><?php echo $sortlink[1]; ?></b></td>
548 <td width="15%"><b><?php echo xlt('Diagnosis Name');?><?php echo $sortlink[2]; ?></b></td>
549 <td width="15%"><b><?php echo xlt('Patient Name'); ?></b></td>
550 <td width="5%"><b><?php echo xlt('PID');?></b></td>
551 <td width="5%"><b><?php echo xlt('Age');?></b></td>
552 <td width="10%"><b><?php echo xlt('Gender');?></b></td>
553 <td colspan=4><b><?php echo xlt('Provider');?></b></td>
554 </tr>
555 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
556 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
557 <td ><?php echo text($patDetailVal['lists_date']); ?></td>
558 <td ><?php echo text($patDetailVal['lists_diagnosis']); ?></td>
559 <td ><?php echo text($patDetailVal['lists_title']); ?></td>
560 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
561 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
562 <td ><?php echo text($patDetailVal['patient_age']);?></td>
563 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
564 <td colspan=4><?php echo text($patDetailVal['users_provider']);?></td>
565 </tr>
566 <?php }
567 }elseif($srch_option == "Lab results"){ ?>
568 <tr bgcolor="#C3FDB8" align= "left" >
569 <td width="15%"><b><?php echo xlt('Date'); ?><?php echo $sortlink[0]; ?></b></td>
570 <td width="15%"><b><?php echo xlt('Facility');?><?php echo $sortlink[1]; ?></b></td>
571 <td width="10%"><b><?php echo xlt('Unit');?></b><?php echo $sortlink[2]; ?></td>
572 <td width="10%"><b><?php echo xlt('Result');?></b><?php echo $sortlink[3]; ?></td>
573 <td width="10%"><b><?php echo xlt('Range');?></b><?php echo $sortlink[4]; ?></td>
574 <td width="10%"><b><?php echo xlt('Abnormal');?><?php echo $sortlink[5]; ?></b></td>
575 <td><b><?php echo xlt('Comments');?></b></td>
576 <td width="5%"><b><?php echo xlt('Document ID');?></b></td>
577 <td width="5%"><b><?php echo xlt('PID');?></b></td>
578 </tr>
579 <?php
580 foreach($patFinalDataArr as $patKey => $labResInsideArr){?>
581 <tr bgcolor = "#CCCCCC" >
582 <td> <?php echo text($labResInsideArr['procedure_result_date']);?>&nbsp;</td>
583 <td> <?php echo text($labResInsideArr['procedure_result_facility'],ENT_NOQUOTES); ?>&nbsp;</td>
584 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$labResInsideArr['procedure_result_units']); ?>&nbsp;</td>
585 <td> <?php echo text($labResInsideArr['procedure_result_result']); ?>&nbsp;</td>
586 <td> <?php echo text($labResInsideArr['procedure_result_range']); ?>&nbsp;</td>
587 <td> <?php echo text($labResInsideArr['procedure_result_abnormal']); ?>&nbsp;</td>
588 <td> <?php echo text($labResInsideArr['procedure_result_comments']); ?>&nbsp;</td>
589 <td> <?php echo text($labResInsideArr['procedure_result_document_id']); ?>&nbsp;</td>
590 <td colspan="3"> <?php echo text($labResInsideArr['patient_id']); ?>&nbsp;</td>
591 </tr>
592 <?php
594 }elseif($srch_option == "Communication"){ ?>
595 <tr style="font-size:15px;">
596 <td width="15%"><b><?php echo xlt('Date'); ?></b><?php echo $sortlink[0]; ?></td>
597 <td width="20%"><b><?php echo xlt('Patient Name'); ?></b><?php echo $sortlink[1]; ?></td>
598 <td width="5%"><b><?php echo xlt('PID');?></b><?php echo $sortlink[2]; ?></td>
599 <td width="5%"><b><?php echo xlt('Age');?></b><?php echo $sortlink[3]; ?></td>
600 <td width="10%"><b><?php echo xlt('Gender');?></b><?php echo $sortlink[4]; ?></td>
601 <td width="15%"><b><?php echo xlt('Provider');?></b><?php echo $sortlink[5]; ?></td>
602 <td ><b><?php echo xlt('Communication');?></b><?php echo $sortlink[6]; ?></td>
603 </tr>
604 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
605 <tr bgcolor = "#CCCCCC" >
606 <td ><?php if($patDetailVal['patient_date'] != ''){ echo text($patDetailVal['patient_date']); }else{ echo ""; }; ?></td>
607 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
608 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
609 <td ><?php echo text($patDetailVal['patient_age']);?></td>
610 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
611 <td ><?php echo text($patDetailVal['users_provider']);?></td>
612 <td ><?php echo text($patDetailVal['communications']);?></td>
613 </tr>
614 <?php
616 }elseif($srch_option == "Demographics"){ ?>
617 <tr style="font-size:15px;">
618 <td width="15%"><b><?php echo xlt('Date'); ?></b><?php echo $sortlink[0]; ?></td>
619 <td width="20%"><b><?php echo xlt('Patient Name'); ?></b><?php echo $sortlink[1]; ?></td>
620 <td width="15%"><b><?php echo xlt('PID');?></b><?php echo $sortlink[2]; ?></td>
621 <td width="5%"><b><?php echo xlt('Age');?></b><?php echo $sortlink[3]; ?></td>
622 <td width="10%"><b><?php echo xlt('Gender'); ?></b><?php echo $sortlink[4]; ?></td>
623 <td width="20%"><b><?php echo xlt('Race');?></b><?php echo $sortlink[5]; ?></td>
624 <td colspan=5><b><?php echo xlt('Provider');?></b><?php echo $sortlink[7]; ?></td>
625 </tr>
626 <?php foreach($patFinalDataArr as $patKey => $patDetailVal){ ?>
627 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
628 <td ><?php if($patDetailVal['patient_date'] != ''){ echo text($patDetailVal['patient_date']); }else{ echo ""; };?></td>
629 <td ><?php echo text($patDetailVal['patient_name']); ?></td>
630 <td ><?php echo text($patDetailVal['patient_id']); ?></td>
631 <td ><?php echo text($patDetailVal['patient_age']);?></td>
632 <td ><?php echo text($patDetailVal['patient_sex']);?></td>
633 <td ><?php echo generate_display_field(array('data_type'=>'36','list_id'=>'race'), $patDetailVal['patient_race']); ?></td>
634 <td colspan=5><?php echo text($patDetailVal['users_provider']);?></td>
635 </tr>
636 <?php }
637 } ?>
639 </table>
640 <!-- Main table ends -->
641 <?php
642 }else{//End if $result?>
643 <table>
644 <tr>
645 <td class="text">&nbsp;&nbsp;<?php echo xlt('No records found.')?></td>
646 </tr>
647 </table>
648 <?php
651 </div>
653 <?php
654 }else{//End if form_refresh
655 ?><div class='text'> <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?> </div><?php
658 </form>
660 <!-- stuff for the popup calendar -->
661 <style type="text/css">
662 @import url(../../library/dynarch_calendar.css);
663 </style>
664 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
665 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
666 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
667 <script language="Javascript">
668 Calendar.setup({inputField:"date_from", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_from_date", showsTime:true});
669 Calendar.setup({inputField:"date_to", ifFormat:"%Y-%m-%d %H:%M:%S", button:"img_to_date", showsTime:true});
670 </script>
671 </body>
672 </html>