2 // Copyright (C) 2010 OpenEMR Support LLC
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");
29 function add_date($givendate,$day=0,$mth=0,$yr=0) {
30 $cd = strtotime($givendate);
31 $newdate = date('Y-m-d', mktime(date('h',$cd),
32 date('i',$cd), date('s',$cd), date('m',$cd)+
$mth,
33 date('d',$cd)+
$day, date('Y',$cd)+
$yr));
37 $type = $_POST["type"];
38 $facility = isset($_POST['facility']) ?
$_POST['facility'] : '';
39 $sql_date_from = fixDate($_POST['date_from'], date('Y-01-01'));
40 $sql_date_to = fixDate($_POST['date_to'] , add_date(date('Y-m-d')));
41 $patient_id = trim($_POST["patient_id"]);
42 $age_from = $_POST["age_from"];
43 $age_to = $_POST["age_to"];
44 $sql_gender = $_POST["gender"];
45 $sql_ethnicity = $_POST["ethnicity"];
46 $sql_race=$_POST["race"];
47 $form_drug_name = trim($_POST["form_drug_name"]);
48 $form_diagnosis = trim($_POST["form_diagnosis"]);
49 $form_lab_results = trim($_POST["form_lab_results"]);
50 $form_service_codes = trim($_POST["form_service_codes"]);
54 <?php
html_header_show();?
>
56 <?php
echo htmlspecialchars(xl('Clinical Reports'),ENT_NOQUOTES
); ?
>
58 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
59 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
60 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
61 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
62 <script language
="JavaScript">
64 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
67 var tr
= document
.getElementById(id
);
68 if (tr
==null) { return; }
69 var bExpand
= tr
.style
.display
== '';
70 tr
.style
.display
= (bExpand ?
'none' : '');
72 function changeimage(id
, sMinus
, sPlus
) {
73 var img
= document
.getElementById(id
);
75 var bExpand
= img
.src
.indexOf(sPlus
) >= 0;
77 img
.src
= "../pic/blue-up-arrow.gif";
79 img
.src
= "../pic/blue-down-arrow.gif";
82 function Toggle_trGrpHeader2(t_id
,i_id
) {
84 changeimage(img
, 'blue-down-arrow.gif', 'blue-up-arrow.gif');
88 // This is for callback by the find-code popup.
89 // Appends to or erases the current list of diagnoses.
90 function set_related(codetype
, code
, selector
, codedesc
) {
91 var f
= document
.forms
[0][current_sel_name
];
94 if (s
.length
> 0) s +
= ';';
95 s +
= codetype +
':' + code
;
102 //This invokes the find-code popup.
103 function sel_diagnosis(e
) {
104 current_sel_name
= e
.name
;
105 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=ICD9<?php if ($GLOBALS['ippf_specific
']) echo '&?codetype
=IPPF
' ?>', '_blank', 500, 400);
108 //This invokes the find-code popup.
109 function sel_procedure(e
) {
110 current_sel_name
= e
.name
;
111 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=CPT4<?php if ($GLOBALS['ippf_specific
']) echo '&?codetype
=IPPF
' ?>', '_blank', 500, 400);
114 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
115 <style type
="text/css">
116 /* specifically include & exclude from printing */
122 #report_parameters_daterange {
126 #report_results table {
131 /* specifically exclude some from the screen */
133 #report_parameters_daterange {
138 .optional_area_service_codes
{
140 if($type != 'Service Codes' ||
$type == '')
149 <script language
="javascript" type
="text/javascript">
150 function checkType() {
151 if($
('#type').val() == 'Service Codes')
153 $
('.optional_area_service_codes').css("display", "inline");
157 $
('.optional_area_service_codes').css("display", "none");
161 function submitForm() {
162 var d_from
= new String($
('#date_from').val());
163 var d_to
= new String($
('#date_to').val());
165 var d_from_arr
= d_from
.split('-');
166 var d_to_arr
= d_to
.split('-');
168 var dt_from
= new Date(d_from_arr
[0], d_from_arr
[1], d_from_arr
[2]);
169 var dt_to
= new Date(d_to_arr
[0], d_to_arr
[1], d_to_arr
[2]);
171 var mili_from
= dt_from
.getTime();
172 var mili_to
= dt_to
.getTime();
173 var diff
= mili_to
- mili_from
;
175 $
('#date_error').css("display", "none");
177 if(diff
< 0) //negative
179 $
('#date_error').css("display", "inline");
183 $
("#form_refresh").attr("value","true");
184 $
("#theform").submit();
188 $
(document
).ready(function() {
189 $
(".numeric_only").keydown(function(event
) {
190 //alert(event.keyCode);
191 // Allow only backspace and delete
192 if ( event
.keyCode
== 46 || event
.keyCode
== 8 ) {
193 // let it happen, don't do anything
196 if(!((event
.keyCode
>= 96 && event
.keyCode
<= 105) ||
(event
.keyCode
>= 48 && event
.keyCode
<= 57)))
198 event
.preventDefault();
205 <body
class="body_top">
206 <!-- Required
for the popup date selectors
-->
207 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
209 <?php
echo htmlspecialchars(xl('Report - Clinical'),ENT_NOQUOTES
); ?
>
211 <!-- Search can be done using age range
, gender
, and ethnicity filters
.
212 Search options
include diagnosis
, procedure
, prescription
, medical history
, and lab results
.
214 <div id
="report_parameters_daterange"> <?php
echo htmlspecialchars(date("d F Y", strtotime($sql_date_from)),ENT_NOQUOTES
) .
215 " to ". htmlspecialchars(date("d F Y", strtotime($sql_date_to)),ENT_NOQUOTES
); ?
> </div
>
216 <form name
='theform' id
='theform' method
='post' action
='clinical_reports.php'>
217 <div id
="report_parameters">
218 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
221 <td width
='740px'><div style
='float:left'>
224 <td
class='label' width
="100"><?php
echo htmlspecialchars(xl('Facility'),ENT_NOQUOTES
); ?
>: </td
>
225 <td width
="250"> <?php
dropdown_facility($facility,'facility',false); ?
> </td
>
226 <td
class='label' width
="100"><?php
echo htmlspecialchars(xl('From'),ENT_NOQUOTES
); ?
>: </td
>
227 <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
>
230 <td
class='label'><?php
echo htmlspecialchars(xl('Patient ID'),ENT_NOQUOTES
); ?
>:</td
>
231 <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
>
232 <td
class='label'><?php
echo htmlspecialchars(xl('To'),ENT_NOQUOTES
); ?
>: </td
>
233 <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
>
236 <td
class='label'><?php
echo htmlspecialchars(xl('Age Range'),ENT_NOQUOTES
); ?
>:</td
>
237 <td
><?php
echo htmlspecialchars(xl('From'),ENT_NOQUOTES
); ?
>
238 <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
); ?
>
239 <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
>
240 <td
class='label'><?php
echo htmlspecialchars(xl('Problem DX'),ENT_NOQUOTES
); ?
>:</td
>
241 <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
>
246 <td
class='label'><?php
echo htmlspecialchars(xl('Gender'),ENT_NOQUOTES
); ?
>:</td
>
247 <td
><?php
echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?
></td
>
248 <td
class='label'><?php
echo htmlspecialchars(xl('Drug'),ENT_NOQUOTES
); ?
>:</td
>
249 <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
>
253 <td
class='label'><?php
echo htmlspecialchars(xl('Race'),ENT_NOQUOTES
); ?
>:</td
>
254 <td
><?php
echo generate_select_list('race', 'race', $sql_race, 'Select Race', 'Unassigned', '', ''); ?
></td
>
255 <td
class='label'><?php
echo htmlspecialchars(xl('Ethnicity'),ENT_NOQUOTES
); ?
>:</td
>
256 <td
><?php
echo generate_select_list('ethnicity', 'ethnicity', $sql_ethnicity, 'Select Ethnicity', 'Unassigned', '', ''); ?
></td
>
260 <td
class='label' width
='100'><?php
echo htmlspecialchars(xl('Lab Result'),ENT_NOQUOTES
); ?
>:</td
>
261 <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
>
263 <td
class='label' width
='100'><?php
echo htmlspecialchars(xl('Option'),ENT_NOQUOTES
); ?
>:</td
>
264 <td
><select name
="type" id
="type" onChange
="checkType();">
265 <option
> <?php
echo htmlspecialchars(xl('Select'),ENT_NOQUOTES
); ?
></option
>
266 <option value
="Procedure" <?php
if($type == 'Procedure') { echo "selected"; } ?
>><?php
echo htmlspecialchars(xl('Procedure'),ENT_NOQUOTES
); ?
></option
>
267 <option value
="Medical History" <?php
if($type == 'Medical History') { echo "selected"; } ?
>><?php
echo htmlspecialchars(xl('Medical History'),ENT_NOQUOTES
); ?
></option
>
269 <option value
="Service Codes" <?php
if($type == 'Service Codes') { echo "selected"; } ?
>><?php
echo htmlspecialchars(xl('Service Codes'),ENT_NOQUOTES
); ?
></option
>
275 <tr
class="optional_area_service_codes">
276 <td width
='100'> 
;</td
>
277 <td width
='100'> 
;</td
>
278 <td width
='195'> 
;</td
>
279 <td
class='label' width
='76'><?php
echo htmlspecialchars(xl('Code'),ENT_NOQUOTES
); ?
>:</td
>
280 <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
/> 
;</td
>
285 <!-- Sort by Start
-->
286 <td
class='label' width
='63'><?php
echo htmlspecialchars(xl('Sort By'),ENT_NOQUOTES
); ?
>:</td
>
288 <input type
='checkbox' name
='form_pt_name'<?php
if ($_POST['form_pt_name'] == true) echo ' checked'; ?
>>
289 <?php
echo htmlspecialchars(xl('Patient Name'),ENT_NOQUOTES
); ?
> 
;
291 <input type
='checkbox' name
='form_pt_age'<?php
if ($_POST['form_pt_age'] == true) echo ' checked'; ?
>>
292 <?php
echo htmlspecialchars(xl('Age'),ENT_NOQUOTES
); ?
> 
;
294 <input type
='checkbox' name
='form_diagnosis_code'<?php
if ($_POST['form_diagnosis_code'] == true) echo ' checked'; ?
>>
295 <?php
echo htmlspecialchars(xl('Diagnosis Code'),ENT_NOQUOTES
); ?
> 
;
297 <input type
='checkbox' name
='form_diagnosis_tit'<?php
if ($_POST['form_diagnosis_tit'] == true) echo ' checked'; ?
>>
298 <?php
echo htmlspecialchars(xl('Diagnosis Title'),ENT_NOQUOTES
); ?
> 
;
300 <input type
='checkbox' name
='form_drug'<?php
if ($_POST['form_drug'] == true) echo ' checked'; ?
>>
301 <?php
echo htmlspecialchars(xl('Drug'),ENT_NOQUOTES
); ?
> 
;
303 <input type
='checkbox' name
='ndc_no'<?php
if ($_POST['ndc_no'] == true) echo ' checked'; ?
>>
304 <?php
echo htmlspecialchars(xl('NDC Number'),ENT_NOQUOTES
); ?
> 
;
305 <input type
='checkbox' name
='lab_results'<?php
if ($_POST['lab_results'] == true) echo ' checked'; ?
>>
306 <?php
echo htmlspecialchars(xl('Lab Results'),ENT_NOQUOTES
); ?
> 
;
309 <!-- Sort by ends
-->
312 <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
> 
;</td
>
316 <td height
="100%" valign
='middle' width
="175"><table style
='border-left:1px solid; width:100%; height:100%'>
318 <td
><div style
='margin-left:15px'> <a href
='#' class='css_button' onclick
='submitForm();'> <span
>
319 <?php
echo htmlspecialchars(xl('Submit'),ENT_NOQUOTES
); ?
>
321 <?php
if ($_POST['form_refresh']) { ?
>
322 <a href
='#' class='css_button' onclick
='window.print()'> <span
>
323 <?php
echo htmlspecialchars(xl('Print'),ENT_NOQUOTES
); ?
>
332 <!-- end of parameters
-->
334 // SQL scripts for the various searches
335 $sqlBindArray = array();
336 if ($_POST['form_refresh'])
339 concat(pd.fname, ' ', pd.lname) AS patient_name,
340 pd.pid AS patient_id,
341 DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 AS patient_age,
342 pd.sex AS patient_sex,
343 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
344 concat(u.fname, ' ', u.lname) AS users_provider";
345 if(strlen($form_diagnosis) > 0) {
346 $sqlstmt=$sqlstmt.",li.date AS lists_date,
347 li.diagnosis AS lists_diagnosis,
348 li.title AS lists_title";
350 if(strlen($form_drug_name) > 0) {
352 $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,
353 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";
355 if(strlen($form_lab_results) > 0) {
357 $sqlstmt = $sqlstmt.",pr.date AS procedure_result_date,
358 pr.facility AS procedure_result_facility,
359 pr.units AS procedure_result_units,
360 pr.result AS procedure_result_result,
361 pr.range AS procedure_result_range,
362 pr.abnormal AS procedure_result_abnormal,
363 pr.comments AS procedure_result_comments,
364 pr.document_id AS procedure_result_document_id";
366 if ( $type == 'Procedure') {
367 $sqlstmt = $sqlstmt.",po.date_ordered AS procedure_order_date_ordered,
368 pt.standard_code AS procedure_type_standard_code,
369 pt.name as procedure_name,
370 po.order_priority AS procedure_order_order_priority,
371 po.order_status AS procedure_order_order_status,
372 po.encounter_id AS procedure_order_encounter,
373 po.patient_instructions AS procedure_order_patient_instructions,
374 po.activity AS procedure_order_activity,
375 po.control_id AS procedure_order_control_id ";
377 if ( $type == 'Medical History') {
378 $sqlstmt = $sqlstmt.",hd.date AS history_data_date,
379 hd.tobacco AS history_data_tobacco,
380 hd.alcohol AS history_data_alcohol,
381 hd.recreational_drugs AS history_data_recreational_drugs ";
383 if($type == 'Service Codes') {
384 $sqlstmt .= ", c.code as code,
385 c.code_text as code_text,
386 fe.encounter as encounter,
388 $mh_stmt = $mh_stmt.",code,code_text,encounter,date";
391 $sqlstmt=$sqlstmt." from patient_data as pd left outer join users as u on u.id = pd.providerid
392 left outer join facility as f on f.id = u.facility_id";
394 if(strlen($form_diagnosis) > 0 ){
395 $sqlstmt = $sqlstmt." left outer join lists as li on li.pid = pd.pid ";
397 if ( $type == 'Procedure' ||
( strlen($form_lab_results)!=0) ) {
398 $sqlstmt = $sqlstmt." left outer join procedure_order as po on po.patient_id = pd.pid
399 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
400 left outer join procedure_type as pt on pt.procedure_type_id = po.procedure_type_id ";
402 if (strlen($form_lab_results)!=0 ) {
403 $sqlstmt = $sqlstmt." left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id
404 and pr.procedure_type_id = po.procedure_type_id ";
406 if(strlen($form_drug_name)!=0) {
407 $sqlstmt=$sqlstmt." left outer join prescriptions AS r on r.patient_id=pd.pid
408 LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id";
410 if ( $type == 'Medical History') {
411 $sqlstmt = $sqlstmt." left outer join history_data as hd on hd.pid = pd.pid
412 and (isnull(hd.tobacco) = 0
413 or isnull(hd.alcohol) = 0
414 or isnull(hd.recreational_drugs) = 0)";
416 if($type == 'Service Codes') {
417 $sqlstmt = $sqlstmt." left outer join billing as b on b.pid = pd.pid
418 left outer join form_encounter as fe on fe.encounter = b.encounter and b.code_type = 'CPT4'
419 left outer join codes as c on c.code = b.code ";
422 $whr_stmt="where 1=1";
423 if(strlen($form_diagnosis) > 0 ) {
424 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND li.date <= ?";
425 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
427 if(strlen($form_lab_results)!=0 ) {
428 $whr_stmt=$whr_stmt." AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND pr.date <= ?";
429 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
431 if(strlen($form_drug_name)!=0) {
432 $whr_stmt=$whr_stmt." AND r.date_modified >= ? AND r.date_modified < DATE_ADD(?, INTERVAL 1 DAY) AND r.date_modified <= ?";
433 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
435 if($type == 'Medical History') {
436 $whr_stmt=$whr_stmt." AND hd.date >= ? AND hd.date < DATE_ADD(?, INTERVAL 1 DAY) AND hd.date <= ?";
437 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
439 if($type == 'Procedure') {
440 $whr_stmt=$whr_stmt." AND po.date_ordered >= ? AND po.date_ordered < DATE_ADD(?, INTERVAL 1 DAY) AND po.date_ordered <= ?";
441 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
443 if($type == "Service Codes") {
444 $whr_stmt=$whr_stmt." AND b.date >= ? AND b.date < DATE_ADD(?, INTERVAL 1 DAY) AND b.date <= ?";
445 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d H:i:s"));
447 if(strlen($form_lab_results) != 0) {
448 $whr_stmt= $whr_stmt." AND (pr.result LIKE ?) ";
449 array_push($sqlBindArray, $form_lab_results);
451 if(strlen($form_drug_name) > 0) {
456 array_push($sqlBindArray, $form_drug_name, $form_drug_name);
458 if($type == 'Service Codes') {
459 if(strlen($form_service_codes) != 0) {
460 $whr_stmt = $whr_stmt." AND (b.code = ?) ";
461 $service_code = explode(":",$form_service_codes);
462 array_push($sqlBindArray, $service_code[1]);
465 if(strlen($patient_id) != 0) {
466 $whr_stmt = $whr_stmt." and pd.pid = ?";
467 array_push($sqlBindArray, $patient_id);
470 if(strlen($age_from) != 0) {
471 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
472 array_push($sqlBindArray, $age_from);
474 if(strlen($age_to) != 0) {
475 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
476 array_push($sqlBindArray, $age_to);
478 if(strlen($sql_gender) != 0) {
479 $whr_stmt = $whr_stmt." and pd.sex = ?";
480 array_push($sqlBindArray, $sql_gender);
482 if(strlen($sql_ethnicity) != 0) {
483 $whr_stmt = $whr_stmt." and pd.ethnicity = ?";
484 array_push($sqlBindArray, $sql_ethnicity);
486 if(strlen($sql_race) != 0) {
487 $whr_stmt = $whr_stmt." and pd.race = ?";
488 array_push($sqlBindArray, $sql_race);
490 if($facility != '') {
491 $whr_stmt = $whr_stmt." and f.id = ? ";
492 array_push($sqlBindArray, $facility);
494 if(strlen($form_diagnosis) > 0) {
495 $whr_stmt = $whr_stmt." AND (li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis = ?) ";
496 array_push($sqlBindArray, $form_diagnosis.";%", '%;'.$form_diagnosis.';%', '%;'.$form_diagnosis, $form_diagnosis);
499 $odrstmt = $odrstmt."ORDER BY patient_id";
500 if ($_POST['form_pt_name'] == true){
501 $odrstmt=$odrstmt.",patient_name";
503 if ($_POST['form_pt_age'] == true) {
504 $odrstmt=$odrstmt.",patient_age";
506 if (($_POST['form_diagnosis_code'] == true) && (strlen($form_diagnosis) > 0)){
507 $odrstmt=$odrstmt.",lists_diagnosis";
509 if (($_POST['form_diagnosis_tit'] == true) && (strlen($form_diagnosis) > 0)){
510 $odrstmt=$odrstmt.",lists_title";
512 if (($_POST['form_drug'] == true)&& (strlen($form_drug_name) > 0)){
513 $odrstmt=$odrstmt.",r.drug";
515 if (($_POST['ndc_no'] == true) && (strlen($form_drug_name) > 0)) {
516 $odrstmt=$odrstmt.",d.ndc_number";
518 if (($_POST['lab_results'] == true) && (strlen($form_lab_results) > 0)) {
519 $odrstmt=$odrstmt.",procedure_result_result";
523 if($type == 'Medical History') {
524 $sqlstmt="select * from (".$sqlstmt." ".$whr_stmt." ".$odrstmt.",history_data_date desc) a group by patient_id";
527 $sqlstmt=$sqlstmt." ".$whr_stmt." ".$odrstmt;
529 $result = sqlStatement($sqlstmt,$sqlBindArray);
531 $row_id = 1.1;//given to each row to identify and toggle
535 if(sqlNumRows($result) > 0)
539 <div id
= "report_results">
540 <?php
while ($row = sqlFetchArray($result)) { ?
>
541 <table width
=90% align
="center" cellpadding
="5" cellspacing
="0" style
="font-family:tahoma;color:black;" border
="0">
542 <tr bgcolor
= "#CCCCCC" style
="font-size:15px;">
543 <td
><b
><?php
echo htmlspecialchars(xl('Summary of'),ENT_NOQUOTES
); echo " "; ?
> <?php
echo htmlspecialchars($row['patient_name'],ENT_NOQUOTES
); ?
></b
></td
>
547 <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
>
549 <table width
="100%" align
="center" id
= "<?php echo $row_id; $row_id++;?>" class="border1" style
="display:none; font-size:13px;" cellpadding
=5>
550 <tr bgcolor
="#C3FDB8" align
="left">
551 <td
><b
><?php
echo htmlspecialchars(xl('Patient Name'),ENT_NOQUOTES
); ?
></b
></td
>
552 <td
><b
><?php
echo htmlspecialchars(xl('PID'),ENT_NOQUOTES
);?
></b
></td
>
553 <td
><b
><?php
echo htmlspecialchars(xl('Age'),ENT_NOQUOTES
);?
></b
></td
>
554 <td
><b
><?php
echo htmlspecialchars(xl('Gender'),ENT_NOQUOTES
); ?
></b
></td
>
555 <td
><b
><?php
echo htmlspecialchars(xl('Race'),ENT_NOQUOTES
);?
></b
></td
>
556 <td
><b
><?php
echo htmlspecialchars(xl('Ethnicity'),ENT_NOQUOTES
);?
></b
></td
>
557 <td colspan
=5><b
><?php
echo htmlspecialchars(xl('Provider'),ENT_NOQUOTES
);?
></b
></td
>
559 <tr bgcolor
="#FFFFFF">
560 <td
><?php
echo htmlspecialchars($row['patient_name'],ENT_NOQUOTES
); ?
> 
;</td
>
561 <td
> <?php
echo htmlspecialchars($row['patient_id'],ENT_NOQUOTES
); ?
> 
;</td
>
562 <td
> <?php
echo htmlspecialchars($row['patient_age'],ENT_NOQUOTES
); ?
> 
;</td
>
563 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'sex'), $row['patient_sex']),ENT_NOQUOTES
); ?
> 
;</td
>
564 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'race'), $row['patient_race']),ENT_NOQUOTES
); ?
> 
;</td
>
565 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ethnicity'), $row['patient_ethinic']),ENT_NOQUOTES
); ?
> 
;</td
>
566 <td colspan
=5> <?php
echo htmlspecialchars($row['users_provider'],ENT_NOQUOTES
); ?
> 
;</td
>
568 <!-- Diagnosis Report Start
-->
570 if(strlen($form_diagnosis) > 0)
573 <tr bgcolor
="#C3FDB8" align
= "left">
574 <td colspan
=12><b
><?php
echo "#"; echo htmlspecialchars(xl('Diagnosis Report'),ENT_NOQUOTES
);?
></b
></td
>
576 <tr bgcolor
="#C3FDB8" align
= "left">
577 <td
><b
><?php
echo htmlspecialchars(xl('Diagnosis Date'),ENT_NOQUOTES
);?
></b
></td
>
578 <td
><b
><?php
echo htmlspecialchars(xl('Diagnosis'),ENT_NOQUOTES
);?
></b
></td
>
579 <td colspan
=9><b
><?php
echo htmlspecialchars(xl('Diagnosis Name'),ENT_NOQUOTES
);?
></b
></td
>
581 <tr bgcolor
="#FFFFFF">
582 <td
><?php
echo htmlspecialchars($row['lists_date'],ENT_NOQUOTES
); ?
> 
;</td
>
583 <td
><?php
echo htmlspecialchars($row['lists_diagnosis'],ENT_NOQUOTES
); ?
> 
;</td
>
584 <td colspan
=9><?php
echo htmlspecialchars($row['lists_title'],ENT_NOQUOTES
); ?
> 
;</td
>
587 <!-- Diagnosis Report End
-->
589 <!-- Prescription Report Start
-->
591 if(strlen($form_drug_name) > 0)
594 <tr bgcolor
="#C3FDB8" align
= "left">
595 <td colspan
=12><b
><?php
echo "#"; echo htmlspecialchars(xl('Prescription Report'),ENT_NOQUOTES
);?
><b
></td
></tr
>
596 <tr bgcolor
="#C3FDB8" align
= "left">
597 <td
><b
><?php
echo htmlspecialchars(xl('Date'),ENT_NOQUOTES
); ?
></b
></td
>
598 <td
><b
><?php
echo htmlspecialchars(xl('Drug Name'),ENT_NOQUOTES
);?
></b
></td
>
599 <td
><b
><?php
echo htmlspecialchars(xl('Route'),ENT_NOQUOTES
);?
></b
></td
>
600 <td
><b
><?php
echo htmlspecialchars(xl('Dosage'),ENT_NOQUOTES
);?
></b
></td
>
601 <td
><b
><?php
echo htmlspecialchars(xl('Form'),ENT_NOQUOTES
);?
></b
></td
>
602 <td
><b
><?php
echo htmlspecialchars(xl('Interval'),ENT_NOQUOTES
);?
></b
></td
>
603 <td
><b
><?php
echo htmlspecialchars(xl('Size'),ENT_NOQUOTES
);?
></b
></td
>
604 <td
><b
><?php
echo htmlspecialchars(xl('Unit'),ENT_NOQUOTES
);?
></b
></td
>
605 <td
><b
><?php
echo htmlspecialchars(xl('ReFill'),ENT_NOQUOTES
);?
></b
></td
>
606 <td
><b
><?php
echo htmlspecialchars(xl('Quantity'),ENT_NOQUOTES
);?
></b
></td
>
607 <td
><b
><?php
echo htmlspecialchars(xl('NDC'),ENT_NOQUOTES
);?
></b
></td
>
609 <tr bgcolor
="#FFFFFF" align
="">
611 $rx_route = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']) ;
612 $rx_form = generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['hform']) ;
613 $rx_interval = generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['hinterval']) ;
614 $rx_units = generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['hunit']);
616 <td
> <?php
echo htmlspecialchars(oeFormatShortDate($row['prescriptions_date_modified']),ENT_NOQUOTES
); ?
> 
;</td
>
617 <td
><?php
echo htmlspecialchars($row['drug'],ENT_NOQUOTES
); ?
></td
>
618 <td
><?php
echo htmlspecialchars($rx_route,ENT_NOQUOTES
); ?
></td
>
619 <td
><?php
echo htmlspecialchars($row['dosage'],ENT_NOQUOTES
); ?
></td
>
620 <td
><?php
echo htmlspecialchars($rx_form,ENT_NOQUOTES
); ?
></td
>
621 <td
><?php
echo htmlspecialchars($rx_interval,ENT_NOQUOTES
); ?
></td
>
622 <td
><?php
echo htmlspecialchars($row['size'],ENT_NOQUOTES
); ?
></td
>
623 <td
><?php
echo htmlspecialchars($rx_units,ENT_NOQUOTES
); ?
></td
>
624 <td
><?php
echo htmlspecialchars($row['refills'],ENT_NOQUOTES
); ?
></td
>
625 <td
><?php
echo htmlspecialchars($row['quantity'],ENT_NOQUOTES
); ?
></td
>
626 <td
><?php
echo htmlspecialchars($row['ndc_number'],ENT_NOQUOTES
); ?
></td
>
629 <!-- Prescription Report End
-->
631 <!-- Lab Results Report Start
-->
633 if(strlen($form_lab_results) > 0)
636 <tr bgcolor
="#C3FDB8" align
= "left">
637 <td colspan
=12><b
><?php
echo "#"; echo htmlspecialchars(xl('Lab Results Report'),ENT_NOQUOTES
);?
><b
></td
></tr
>
638 <tr bgcolor
="#C3FDB8" align
= "left">
639 <td
><b
><?php
echo htmlspecialchars(xl('Date'),ENT_NOQUOTES
); ?
></b
></td
>
640 <td
><b
><?php
echo htmlspecialchars(xl('Facility'),ENT_NOQUOTES
);?
></b
></td
>
641 <td
><b
><?php
echo htmlspecialchars(xl('Unit'),ENT_NOQUOTES
);?
></b
></td
>
642 <td
><b
><?php
echo htmlspecialchars(xl('Result'),ENT_NOQUOTES
);?
></b
></td
>
643 <td
><b
><?php
echo htmlspecialchars(xl('Range'),ENT_NOQUOTES
);?
></b
></td
>
644 <td
><b
><?php
echo htmlspecialchars(xl('Abnormal'),ENT_NOQUOTES
);?
></b
></td
>
645 <td
><b
><?php
echo htmlspecialchars(xl('Comments'),ENT_NOQUOTES
);?
></b
></td
>
646 <td colspan
=4><b
><?php
echo htmlspecialchars(xl('Document ID'),ENT_NOQUOTES
);?
></b
></td
>
648 <tr bgcolor
="#FFFFFF">
649 <td
> <?php
echo htmlspecialchars(oeFormatShortDate($row['procedure_result_date']),ENT_NOQUOTES
); ?
> 
;</td
>
650 <td
> <?php
echo htmlspecialchars($row['procedure_result_facility'],ENT_NOQUOTES
); ?
> 
;</td
>
651 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'),$row['procedure_result_units']),ENT_NOQUOTES
); ?
> 
;</td
>
652 <td
> <?php
echo htmlspecialchars($row['procedure_result_result'],ENT_NOQUOTES
); ?
> 
;</td
>
653 <td
> <?php
echo htmlspecialchars($row['procedure_result_range'],ENT_NOQUOTES
); ?
> 
;</td
>
654 <td
> <?php
echo htmlspecialchars($row['procedure_result_abnormal'],ENT_NOQUOTES
); ?
> 
;</td
>
655 <td
> <?php
echo htmlspecialchars($row['procedure_result_comments'],ENT_NOQUOTES
); ?
> 
;</td
>
656 <td colspan
=4> <?php
echo htmlspecialchars($row['procedure_result_document_id'],ENT_NOQUOTES
); ?
> 
;</td
>
659 <!-- Lab Results End
-->
661 <!-- Procedures Report Start
-->
663 if ( $type == 'Procedure')
666 <tr bgcolor
="#C3FDB8" align
= "left">
667 <td colspan
=12><b
><?php
echo "#"; echo htmlspecialchars(xl('Procedure Report'),ENT_NOQUOTES
);?
><b
></td
></tr
>
668 <tr bgcolor
="#C3FDB8" align
= "left">
669 <td
><b
><?php
echo htmlspecialchars(xl('Date'),ENT_NOQUOTES
); ?
></b
></td
>
670 <td
><b
><?php
echo htmlspecialchars(xl('Standard Name'),ENT_NOQUOTES
);?
></b
></td
>
671 <td
><b
><?php
echo htmlspecialchars(xl('Procedure'),ENT_NOQUOTES
); ?
></b
></td
>
672 <td
><b
><?php
echo htmlspecialchars(xl('Encounter'),ENT_NOQUOTES
);?
></b
></td
>
673 <td
><b
><?php
echo htmlspecialchars(xl('Priority'),ENT_NOQUOTES
);?
></b
></td
>
674 <td
><b
><?php
echo htmlspecialchars(xl('Status'),ENT_NOQUOTES
);?
></b
></td
>
675 <td
><b
><?php
echo htmlspecialchars(xl('Instruction'),ENT_NOQUOTES
);?
></b
></td
>
676 <td
><b
><?php
echo htmlspecialchars(xl('Activity'),ENT_NOQUOTES
);?
></b
></td
>
677 <td colspan
=3><b
><?php
echo htmlspecialchars(xl('Control ID'),ENT_NOQUOTES
);?
></b
></td
>
679 <tr bgcolor
="#FFFFFF">
681 $procedure_type_standard_code_arr = explode(':', $row['procedure_type_standard_code']);
682 $procedure_type_standard_code = $procedure_type_standard_code_arr[1];
685 <td
> <?php
echo htmlspecialchars(oeFormatShortDate($row['procedure_order_date_ordered']),ENT_NOQUOTES
); ?
> 
;</td
>
686 <td
> <?php
echo htmlspecialchars($procedure_type_standard_code,ENT_NOQUOTES
); ?
> 
;</td
>
687 <td
> <?php
echo htmlspecialchars($row['procedure_name'],ENT_NOQUOTES
); ?
> 
;</td
>
688 <td
> <?php
echo htmlspecialchars($row['procedure_order_encounter'],ENT_NOQUOTES
); ?
> 
;</td
>
689 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ord_priority'),$row['procedure_order_order_priority']),ENT_NOQUOTES
); ?
> 
;</td
>
690 <td
> <?php
echo htmlspecialchars(generate_display_field(array('data_type'=>'1','list_id'=>'ord_status'),$row['procedure_order_order_status']),ENT_NOQUOTES
); ?
> 
;</td
>
691 <td
> <?php
echo htmlspecialchars($row['procedure_order_patient_instructions'],ENT_NOQUOTES
); ?
> 
;</td
>
692 <td
> <?php
echo htmlspecialchars($row['procedure_order_activity'],ENT_NOQUOTES
); ?
> 
;</td
>
693 <td colspan
=3> <?php
echo htmlspecialchars($row['procedure_order_control_id'],ENT_NOQUOTES
); ?
> 
;</td
>
697 <!-- Procedure Report End
-->
699 <!-- Medical History Report Start
-->
701 if ( $type == 'Medical History')
704 <tr bgcolor
="#C3FDB8" align
= "left">
705 <td colspan
=12><b
><?php
echo "#"; echo htmlspecialchars(xl('Medical History'),ENT_NOQUOTES
);?
><b
></td
></tr
>
706 <tr bgcolor
="#C3FDB8" align
= "left">
707 <td
><b
><?php
echo htmlspecialchars(xl('History Date'),ENT_NOQUOTES
); ?
></b
></td
>
708 <td
><b
><?php
echo htmlspecialchars(xl('Tobacco'),ENT_NOQUOTES
);?
></b
></td
>
709 <td
><b
><?php
echo htmlspecialchars(xl('Alcohol'),ENT_NOQUOTES
);?
></b
></td
>
710 <td colspan
=8><b
><?php
echo htmlspecialchars(xl('Recreational Drugs'),ENT_NOQUOTES
);?
></b
></td
>
712 <tr bgcolor
="#FFFFFF">
714 $tmp_t = explode('|', $row['history_data_tobacco']);
715 $tmp_a = explode('|', $row['history_data_alcohol']);
716 $tmp_d = explode('|', $row['history_data_recreational_drugs']);
717 $his_tobac = generate_display_field(array('data_type'=>'1','list_id'=>'smoking_status'), $tmp_t[3]) ;
719 <td
> <?php
echo htmlspecialchars(oeFormatShortDate($row['history_data_date']),ENT_NOQUOTES
); ?
> 
;</td
>
720 <td
> <?php
echo htmlspecialchars($his_tobac,ENT_NOQUOTES
); ?
> 
;</td
>
722 if ($tmp_a[1] == "currentalcohol") $res = xl('Current Alcohol');
723 if ($tmp_a[1] == "quitalcohol") $res = xl('Quit Alcohol');
724 if ($tmp_a[1] == "neveralcohol") $res = xl('Never Alcohol');
725 if ($tmp_a[1] == "not_applicablealcohol") $res = xl('N/A');
727 <td
> <?php
echo htmlspecialchars($res,ENT_NOQUOTES
); ?
> 
;</td
>
729 if ($tmp_d[1] == "currentrecreational_drugs") $resd = xl('Current Recreational Drugs');
730 if ($tmp_d[1] == "quitrecreational_drugs") $resd = xl('Quit');
731 if ($tmp_d[1] == "neverrecreational_drugs") $resd = xl('Never');
732 if ($tmp_d[1] == "not_applicablerecreational_drugs") $resd = xl('N/A');
734 <td colspan
=8> <?php
echo htmlspecialchars($resd,ENT_NOQUOTES
); ?
> 
;</td
>
737 <!-- Medical History Report End
-->
739 <!-- Service Codes Report Start
-->
741 if ( $type == 'Service Codes') {
743 <tr bgcolor
="#C3FDB8" align
= "left">
744 <td colspan
=11><b
><?php
echo "#"; echo htmlspecialchars(xl('Service Codes'),ENT_NOQUOTES
);?
><b
></td
></tr
>
745 <tr bgcolor
="#C3FDB8" align
= "left">
746 <td
><b
><?php
echo htmlspecialchars(xl('Date'),ENT_NOQUOTES
); ?
></b
></td
>
747 <td
><b
><?php
echo htmlspecialchars(xl('Code'),ENT_NOQUOTES
);?
></b
></td
>
748 <td
><b
><?php
echo htmlspecialchars(xl('Encounter ID'),ENT_NOQUOTES
);?
></b
></td
>
749 <td colspan
=8><b
><?php
echo htmlspecialchars(xl('Code Text'),ENT_NOQUOTES
);?
></b
></td
></tr
>
750 <tr bgcolor
="#FFFFFF">
751 <td
><?php
echo htmlspecialchars(oeFormatShortDate($row['date']),ENT_NOQUOTES
); ?
> 
;</td
>
752 <td
><?php
echo htmlspecialchars($row['code'],ENT_NOQUOTES
); ?
> 
;</td
>
753 <td
><?php
echo htmlspecialchars($row['encounter'],ENT_NOQUOTES
); ?
> 
;</td
>
754 <td colspan
=8><?php
echo htmlspecialchars($row['code_text'],ENT_NOQUOTES
); ?
> 
;</td
>
757 <!-- Service Codes Report End
-->
759 <?php
} //while loop end ?>
760 </table
> <!-- Main table ends
-->
763 } //End if form_refresh
766 ?
><div
class='text'> <?php
echo htmlspecialchars(xl('Please input search criteria above, and click Submit to view results.'),ENT_NOQUOTES
); ?
> </div
><?php
772 <!-- stuff
for the popup calendar
-->
773 <style type
="text/css">
774 @import
url(../../library
/dynarch_calendar
.css
);
776 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
777 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
778 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
779 <script language
="Javascript">
780 Calendar
.setup({inputField
:"date_from", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
781 Calendar
.setup({inputField
:"date_to", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});