7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2010 OpenEMR Support LLC
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc.php");
16 require_once("$srcdir/options.inc.php");
17 require_once("../drugs/drugs.inc.php");
18 require_once("../../custom/code_types.inc.php");
20 use OpenEMR\Common\Acl\AclMain
;
21 use OpenEMR\Common\Csrf\CsrfUtils
;
22 use OpenEMR\Common\Twig\TwigContainer
;
23 use OpenEMR\Core\Header
;
25 if (!AclMain
::aclCheckCore('patients', 'med')) {
26 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Clinical Reports")]);
31 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
32 CsrfUtils
::csrfNotVerified();
36 $comarr = array('allow_sms' => xl('Allow SMS'),'allow_voice' => xl('Allow Voice Message'),'allow_mail' => xl('Allow Mail Message'),'allow_email' => xl('Allow Email'));
38 $sql_date_from = (!empty($_POST['date_from'])) ?
DateTimeToYYYYMMDDHHMMSS($_POST['date_from']) : date('Y-01-01 H:i:s');
39 $sql_date_to = (!empty($_POST['date_to'])) ?
DateTimeToYYYYMMDDHHMMSS($_POST['date_to']) : date('Y-m-d H:i:s');
41 $type = $_POST["type"] ??
'';
42 $facility = isset($_POST['facility']) ?
$_POST['facility'] : '';
43 $patient_id = trim($_POST["patient_id"] ??
'');
44 $age_from = $_POST["age_from"] ??
'';
45 $age_to = $_POST["age_to"] ??
'';
46 $sql_gender = $_POST["gender"] ??
'';
47 $sql_ethnicity = $_POST["ethnicity"] ??
'';
48 $sql_race = $_POST["race"] ??
'';
49 $form_drug_name = trim($_POST["form_drug_name"] ??
'');
50 $form_diagnosis = trim($_POST["form_diagnosis"] ??
'');
51 $form_lab_results = trim($_POST["form_lab_results"] ??
'');
52 $form_service_codes = trim($_POST["form_service_codes"] ??
'');
53 $form_immunization = trim($_POST["form_immunization"] ??
'');
54 $communication = trim($_POST["communication"] ??
'');
61 <?php
echo xlt('Clinical Reports'); ?
>
64 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
68 var win
= top
.printLogSetup ? top
: opener
.top
;
69 win
.printLogSetup(document
.getElementById('printbutton'));
73 var tr
= document
.getElementById(id
);
74 if (tr
==null) { return; }
75 var bExpand
= tr
.style
.display
== '';
76 tr
.style
.display
= (bExpand ?
'none' : '');
78 function changeimage(id
, sMinus
, sPlus
) {
79 var img
= document
.getElementById(id
);
81 var bExpand
= img
.src
.indexOf(sPlus
) >= 0;
83 img
.src
= "../pic/blue-up-arrow.gif";
85 img
.src
= "../pic/blue-down-arrow.gif";
88 function Toggle_trGrpHeader2(t_id
,i_id
) {
90 changeimage(img
, 'blue-down-arrow.gif', 'blue-up-arrow.gif');
94 // This is for callback by the find-code popup.
95 // Appends to or erases the current list of diagnoses.
96 function set_related(codetype
, code
, selector
, codedesc
) {
97 var f
= document
.forms
[0][current_sel_name
];
100 if (s
.length
> 0) s +
= ';';
101 s +
= codetype +
':' + code
;
108 //This invokes the find-code popup.
109 function sel_diagnosis(e
) {
110 current_sel_name
= e
.name
;
111 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr_url(collect_codetypes("diagnosis", "csv")); ?>', '_blank', 500, 400);
114 //This invokes the find-code popup.
115 function sel_procedure(e
) {
116 current_sel_name
= e
.name
;
117 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr_url(collect_codetypes("procedure", "csv")); ?>', '_blank', 500, 400);
122 /* specifically include & exclude from printing */
128 #report_parameters_daterange {
132 #report_results table {
137 /* specifically exclude some from the screen */
139 #report_parameters_daterange {
144 .optional_area_service_codes
{
146 if ($type != 'Service Codes' ||
$type == '') {
155 function checkType() {
156 if($
('#type').val() == 'Service Codes')
158 $
('.optional_area_service_codes').css("display", "inline");
162 $
('.optional_area_service_codes').css("display", "none");
166 function submitForm() {
167 var d_from
= new String($
('#date_from').val());
168 var d_to
= new String($
('#date_to').val());
170 var d_from_arr
= d_from
.split('-');
171 var d_to_arr
= d_to
.split('-');
173 var dt_from
= new Date(d_from_arr
[0], d_from_arr
[1], d_from_arr
[2]);
174 var dt_to
= new Date(d_to_arr
[0], d_to_arr
[1], d_to_arr
[2]);
176 var mili_from
= dt_from
.getTime();
177 var mili_to
= dt_to
.getTime();
178 var diff
= mili_to
- mili_from
;
180 $
('#date_error').css("display", "none");
182 if(diff
< 0) //negative
184 $
('#date_error').css("display", "inline");
188 $
("#form_refresh").attr("value","true");
189 $
("#theform").submit();
194 $
(".numeric_only").keydown(function(event
) {
195 //alert(event.keyCode);
196 // Allow only backspace and delete
197 if ( event
.keyCode
== 46 || event
.keyCode
== 8 ) {
198 // let it happen, don't do anything
201 if(!((event
.keyCode
>= 96 && event
.keyCode
<= 105) ||
(event
.keyCode
>= 48 && event
.keyCode
<= 57)))
203 event
.preventDefault();
208 $
('.datetimepicker').datetimepicker({
209 <?php
$datetimepicker_timepicker = true; ?
>
210 <?php
$datetimepicker_showseconds = true; ?
>
211 <?php
$datetimepicker_formatInput = true; ?
>
212 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
213 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
218 <body
class="body_top">
219 <!-- Required
for the popup date selectors
-->
220 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
222 <?php
echo htmlspecialchars(xl('Report - Clinical'), ENT_NOQUOTES
); ?
>
224 <!-- Search can be done using age range
, gender
, and ethnicity filters
.
225 Search options
include diagnosis
, procedure
, prescription
, medical history
, and lab results
.
227 <div id
="report_parameters_daterange"> <?php
echo text(oeFormatDateTime($sql_date_from, "global", true)) .
228 " " . xlt("to{{Range}}") . " " . text(oeFormatDateTime($sql_date_to, "global", true)); ?
> </div
>
229 <form name
='theform' id
='theform' method
='post' action
='clinical_reports.php' onsubmit
='return top.restoreSession()'>
230 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
231 <div id
="report_parameters">
232 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
235 <td width
='740px'><div style
='float:left'>
238 <td
class='col-form-label' width
="100"><?php
echo xlt('Facility'); ?
>: </td
>
239 <td width
="250"> <?php
dropdown_facility($facility, 'facility', false); ?
> </td
>
240 <td
class='col-form-label' width
="100"><?php
echo xlt('From'); ?
>: </td
>
241 <td
><input type
='text' class='datetimepicker form-control' name
='date_from' id
="date_from" size
='18' value
='<?php echo attr(oeFormatDateTime($sql_date_from, "global", true)); ?>'></td
>
244 <td
class='col-form-label'><?php
echo xlt('Patient ID'); ?
>:</td
>
245 <td
><input name
='patient_id' class="numeric_only form-control" type
='text' id
="patient_id" title
='<?php echo xla('Optional
numeric patient ID
'); ?>' value
='<?php echo attr($patient_id); ?>' size
='10' maxlength
='20' /></td
>
246 <td
class='col-form-label'><?php
echo xlt('To{{Range}}'); ?
>: </td
>
247 <td
><input type
='text' class='datetimepicker form-control' name
='date_to' id
="date_to" size
='18' value
='<?php echo attr(oeFormatDateTime($sql_date_to, "global", true)); ?>'></td
>
250 <td
class='col-form-label'><?php
echo xlt('Age Range'); ?
>:</td
>
253 <td
class='col-form-label'><?php
echo xlt('From'); ?
></td
>
255 <input name
='age_from' class="numeric_only form-control" type
='text' id
="age_from" value
="<?php echo attr($age_from); ?>" size
='3' maxlength
='3' />
257 <td
class='col-form-label'><?php
echo xlt('To{{Range}}'); ?
></td
>
259 <input name
='age_to' class="numeric_only form-control" type
='text' id
="age_to" value
="<?php echo attr($age_to); ?>" size
='3' maxlength
='3' />
263 <td
class='col-form-label'><?php
echo xlt('Problem DX'); ?
>:</td
>
264 <td
><input type
='text' name
='form_diagnosis' class= 'form-control' size
='10' maxlength
='250' value
='<?php echo attr($form_diagnosis); ?>' onclick
='sel_diagnosis(this)' title
='<?php echo xla('Click to select
or change diagnoses
'); ?>' readonly
/></td
>
269 <td
class='col-form-label'><?php
echo xlt('Gender'); ?
>:</td
>
270 <td
><?php
echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?
></td
>
271 <td
class='col-form-label'><?php
echo xlt('Drug'); ?
>:</td
>
272 <td
><input type
='text' name
='form_drug_name' class='form-control' size
='10' maxlength
='250' value
='<?php echo attr($form_drug_name); ?>' title
='<?php echo xla('Optional drug name
, use %
as a wildcard
'); ?>' /></td
>
276 <td
class='col-form-label'><?php
echo xlt('Race'); ?
>:</td
>
277 <td
><?php
echo generate_select_list('race', 'race', $sql_race, 'Select Race', 'Unassigned', '', ''); ?
></td
>
278 <td
class='col-form-label'><?php
echo xlt('Ethnicity'); ?
>:</td
>
279 <td
><?php
echo generate_select_list('ethnicity', 'ethnicity', $sql_ethnicity, 'Select Ethnicity', 'Unassigned', '', ''); ?
></td
>
280 <td
class='col-form-label'><?php
echo xlt('Immunization'); ?
>:</td
>
281 <td
><input type
='text' name
='form_immunization' class='form-control' size
='10' maxlength
='250' value
='<?php echo attr($form_immunization); ?>' title
='<?php echo xla('Optional immunization name
or code
, use %
as a wildcard
'); ?>' /></td
>
284 <td
class='col-form-label' width
='100'><?php
echo xlt('Lab Result'); ?
>:</td
>
285 <td width
='100'><input type
='text' name
='form_lab_results' class='form-control' size
='13' maxlength
='250' value
='<?php echo attr($form_lab_results); ?>' title
='<?php echo xla('Result
, use %
as a wildcard
'); ?>' /></td
>
287 <td
class='col-form-label' width
='100'><?php
echo xlt('Option'); ?
>:</td
>
288 <td
><select name
="type" class='form-control' id
="type" onChange
="checkType();">
289 <option
> <?php
echo xlt('Select'); ?
></option
>
290 <option value
="Procedure" <?php
291 if ($type == 'Procedure') {
293 } ?
>><?php
echo xlt('Procedure'); ?
></option
>
294 <option value
="Medical History" <?php
295 if ($type == 'Medical History') {
297 } ?
>><?php
echo xlt('Medical History'); ?
></option
>
298 <option value
="Service Codes" <?php
299 if ($type == 'Service Codes') {
301 } ?
>><?php
echo xlt('Service Codes'); ?
></option
>
304 <td
class='col-form-label'><?php
echo xlt('Communication'); ?
>:</td
>
306 <select name
="communication" class='form-control' id
="communication" title
="<?php echo xla('Select Communication Preferences'); ?>">
307 <option value
=""> <?php
echo xlt('Select'); ?
></option
>
308 <?php
foreach ($comarr as $comkey => $comvalue) { ?
>
309 <option value
="<?php echo attr($comkey); ?>" <?php
310 if ($communication == $comkey) {
312 } ?
>><?php
echo text($comvalue); ?
></option
>
319 <tr
class="optional_area_service_codes">
320 <td width
='100'> 
;</td
>
321 <td width
='100'> 
;</td
>
322 <td width
='195'> 
;</td
>
323 <td
class='col-form-label' width
='76'><?php
echo xlt('Code'); ?
>:</td
>
324 <td
> <input type
='text' name
='form_service_codes' class='form-control' size
='10' maxlength
='250' value
='<?php echo attr($form_service_codes); ?>' onclick
='sel_procedure(this)' title
='<?php echo xla('Click to select
or change service codes
'); ?>' readonly
/> 
;</td
>
329 <!-- Sort by Start
-->
330 <td
class='col-form-label' width
='63'><?php
echo xlt('Sort By'); ?
>:</td
>
335 <input type
='checkbox' class='form-control' name
='form_pt_name'<?php
336 if (!empty($_POST['form_pt_name'])) {
340 <td
class='col-form-label'>
341 <?php
echo xlt('Patient Name'); ?
> 
;
344 <input type
='checkbox' class='form-control' name
='form_pt_age'<?php
345 if (!empty($_POST['form_pt_age'])) {
349 <td
class='col-form-label'>
350 <?php
echo xlt('Age'); ?
> 
;
353 <input type
='checkbox' class='form-control' name
='form_diagnosis_allergy'<?php
354 if (!empty($_POST['form_diagnosis_allergy'])) {
358 <td
class='col-form-label'>
359 <?php
echo xlt('Allergies'); ?
> 
;
362 <input type
='checkbox' class='form-control' name
='form_diagnosis_medprb'<?php
363 if (!empty($_POST['form_diagnosis_medprb'])) {
367 <td
class='col-form-label'>
368 <?php
echo xlt('Medical Problems'); ?
> 
;
371 <input type
='checkbox' class='form-control' name
='form_drug'<?php
372 if (!empty($_POST['form_drug'])) {
376 <td
class='col-form-label'>
377 <?php
echo xlt('Drug'); ?
> 
;
380 <input type
='checkbox' class='form-control' name
='ndc_no'<?php
381 if (!empty($_POST['ndc_no'])) {
385 <td
class='col-form-label'>
386 <?php
echo xlt('NDC Number'); ?
> 
;
389 <input type
='checkbox' class='form-control' name
='lab_results'<?php
390 if (!empty($_POST['lab_results'])) {
394 <td
class='col-form-label'>
395 <?php
echo xlt('Lab Results'); ?
> 
;
398 <input type
='checkbox' class='form-control' name
='communication_check'<?php
399 if (!empty($_POST['communication_check'])) {
403 <td
class='col-form-label'>
404 <?php
echo xlt('Communication'); ?
>
410 <!-- Sort by ends
-->
413 <td colspan
=3><span id
="date_error" style
="color: #F00; font-siz: 11px; display: none;"><?php
echo xlt('From Date Cannot be Greater than To Date.'); ?
></span
> 
;</td
>
417 <td height
="100%" valign
='middle' width
="175">
418 <table
class='w-100 h-100' style
='border-left:1px solid;'>
421 <div
class="text-center">
422 <div
class="btn-group" role
="group">
423 <a href
='#' class='btn btn-secondary btn-save' onclick
='submitForm();'>
424 <?php
echo xlt('Submit'); ?
>
426 <?php
if (!empty($_POST['form_refresh'])) { ?
>
427 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
428 <?php
echo xlt('Print'); ?
>
439 <!-- end of parameters
-->
441 // SQL scripts for the various searches
442 $sqlBindArray = array();
443 if (!empty($_POST['form_refresh'])) {
445 concat(pd.fname, ' ', pd.lname) AS patient_name,
446 pd.pid AS patient_id,
447 DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 AS patient_age,
448 pd.sex AS patient_sex,
449 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
450 concat(u.fname, ' ', u.lname) AS users_provider,
451 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";
452 if (!empty($form_diagnosis)) {
453 $sqlstmt = $sqlstmt . ",li.date AS lists_date,
454 li.diagnosis AS lists_diagnosis,
455 li.title AS lists_title";
458 if (strlen($form_drug_name) > 0 ||
!empty($_POST['form_drug'])) {
459 $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,
460 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";
463 if (strlen($form_lab_results) > 0 ||
!empty($_POST['lab_results'])) {
464 $sqlstmt = $sqlstmt . ",pr.date AS procedure_result_date,
465 pr.facility AS procedure_result_facility,
466 pr.units AS procedure_result_units,
467 pr.result AS procedure_result_result,
468 pr.range AS procedure_result_range,
469 pr.abnormal AS procedure_result_abnormal,
470 pr.comments AS procedure_result_comments,
471 pr.document_id AS procedure_result_document_id";
474 if ($type == 'Procedure') {
475 $sqlstmt = $sqlstmt . ",po.date_ordered AS procedure_order_date_ordered,
476 pt.standard_code AS procedure_type_standard_code,
477 pc.procedure_name as procedure_name,
478 po.order_priority AS procedure_order_order_priority,
479 po.order_status AS procedure_order_order_status,
480 po.encounter_id AS procedure_order_encounter,
481 po.patient_instructions AS procedure_order_patient_instructions,
482 po.activity AS procedure_order_activity,
483 po.control_id AS procedure_order_control_id ";
486 if ($type == 'Medical History') {
487 $sqlstmt = $sqlstmt . ",hd.date AS history_data_date,
488 hd.tobacco AS history_data_tobacco,
489 hd.alcohol AS history_data_alcohol,
490 hd.recreational_drugs AS history_data_recreational_drugs ";
493 if ($type == 'Service Codes') {
494 $sqlstmt .= ", c.code as code,
495 c.code_text as code_text,
496 fe.encounter as encounter,
498 $mh_stmt = $mh_stmt . ",code,code_text,encounter,date";
501 if (strlen($form_immunization) > 0) {
502 $sqlstmt .= ", immc.code_text as imm_code, immc.code_text_short as imm_code_short, immc.id as cvx_code, imm.administered_date as imm_date, imm.amount_administered, imm.amount_administered_unit, imm.administration_site, imm.note as notes ";
506 $sqlstmt = $sqlstmt . " from patient_data as pd left outer join users as u on u.id = pd.providerid
507 left outer join facility as f on f.id = u.facility_id";
509 if (!empty($form_diagnosis)) {
510 $sqlstmt = $sqlstmt . " left outer join lists as li on (li.pid = pd.pid AND (li.type='medical_problem' OR li.type='allergy')) ";
513 if ($type == 'Procedure' ||
( strlen($form_lab_results) != 0) ||
!empty($_POST['lab_results'])) {
514 $sqlstmt = $sqlstmt . " left outer join procedure_order as po on po.patient_id = pd.pid
515 left outer join procedure_order_code as pc on pc.procedure_order_id = po.procedure_order_id
516 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
517 left outer join procedure_type as pt on pt.procedure_code = pc.procedure_code and pt.lab_id = po.lab_id ";
520 if (strlen($form_lab_results) != 0 ||
!empty($_POST['lab_results'])) {
521 $sqlstmt = $sqlstmt . " left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id ";
524 //Immunization added in clinical report
525 if (strlen($form_immunization) != 0) {
526 $sqlstmt = $sqlstmt . " LEFT OUTER JOIN immunizations as imm ON imm.patient_id = pd.pid
527 LEFT OUTER JOIN codes as immc ON imm.cvx_code = immc.id ";
530 if (strlen($form_drug_name) != 0 ||
!empty($_POST['form_drug'])) {
531 $sqlstmt = $sqlstmt . " left outer join prescriptions AS r on r.patient_id=pd.pid
532 LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id";
535 if ($type == 'Medical History') {
536 $sqlstmt = $sqlstmt . " left outer join history_data as hd on hd.pid = pd.pid
537 and (isnull(hd.tobacco) = 0
538 or isnull(hd.alcohol) = 0
539 or isnull(hd.recreational_drugs) = 0)";
542 if ($type == 'Service Codes') {
543 $sqlstmt = $sqlstmt . " left outer join billing as b on b.pid = pd.pid
544 left outer join form_encounter as fe on fe.encounter = b.encounter and b.code_type = 'CPT4'
545 left outer join codes as c on c.code = b.code ";
549 $whr_stmt = "where 1=1";
550 if (!empty($form_diagnosis)) {
551 $whr_stmt = $whr_stmt . " AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(li.date) <= ?";
552 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
555 if (strlen($form_lab_results) != 0 ||
!empty($_POST['lab_results'])) {
556 $whr_stmt = $whr_stmt . " AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(pr.date) <= ?";
557 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
560 if (strlen($form_drug_name) != 0 ||
!empty($_POST['form_drug'])) {
561 $whr_stmt = $whr_stmt . " AND r.date_modified >= ? AND r.date_modified < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(r.date_modified) <= ?";
562 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
565 if ($type == 'Medical History') {
566 $whr_stmt = $whr_stmt . " AND hd.date >= ? AND hd.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(hd.date) <= ?";
567 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
570 if ($type == 'Procedure') {
571 $whr_stmt = $whr_stmt . " AND po.date_ordered >= ? AND po.date_ordered < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(po.date_ordered) <= ?";
572 array_push($sqlBindArray, substr($sql_date_from, 0, 10), substr($sql_date_to, 0, 10), date("Y-m-d"));
575 if ($type == "Service Codes") {
576 $whr_stmt = $whr_stmt . " AND b.date >= ? AND b.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(b.date) <= ?";
577 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
580 if (strlen($form_lab_results) != 0 ||
!empty($_POST['lab_results'])) {
581 $whr_stmt = $whr_stmt . " AND (pr.result LIKE ?) ";
582 if (empty($form_lab_results)) {
583 $form_lab_results = "%";
586 array_push($sqlBindArray, $form_lab_results);
589 if (strlen($form_drug_name) > 0 ||
!empty($_POST['form_drug'])) {
594 if (empty($form_drug_name)) {
595 $form_drug_name = "%";
598 array_push($sqlBindArray, $form_drug_name, $form_drug_name);
601 if ($type == 'Service Codes') {
602 if (strlen($form_service_codes) != 0) {
603 $whr_stmt = $whr_stmt . " AND (b.code = ?) ";
604 $service_code = explode(":", $form_service_codes);
605 array_push($sqlBindArray, $service_code[1]);
609 if (strlen($patient_id) != 0) {
610 $whr_stmt = $whr_stmt . " and pd.pid = ?";
611 array_push($sqlBindArray, $patient_id);
614 if (strlen($age_from) != 0) {
615 $whr_stmt = $whr_stmt . " and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
616 array_push($sqlBindArray, $age_from);
619 if (strlen($age_to) != 0) {
620 $whr_stmt = $whr_stmt . " and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
621 array_push($sqlBindArray, $age_to);
624 if (strlen($sql_gender) != 0) {
625 $whr_stmt = $whr_stmt . " and pd.sex = ?";
626 array_push($sqlBindArray, $sql_gender);
629 if (strlen($sql_ethnicity) != 0) {
630 $whr_stmt = $whr_stmt . " and pd.ethnicity = ?";
631 array_push($sqlBindArray, $sql_ethnicity);
634 if (strlen($sql_race) != 0) {
635 $whr_stmt = $whr_stmt . " and pd.race = ?";
636 array_push($sqlBindArray, $sql_race);
639 if ($facility != '') {
640 $whr_stmt = $whr_stmt . " and f.id = ? ";
641 array_push($sqlBindArray, $facility);
644 if (!empty($form_diagnosis)) {
645 $whr_stmt = $whr_stmt . " AND (li.diagnosis LIKE ?) ";
646 array_push($sqlBindArray, '%' . $form_diagnosis . '%');
649 //communication preferences added in clinical report
650 if (strlen($communication) > 0 ||
!empty($_POST['communication_check'])) {
651 if ($communication == "allow_sms") {
652 $whr_stmt .= " AND pd.hipaa_allowsms = 'YES' ";
653 } elseif ($communication == "allow_voice") {
654 $whr_stmt .= " AND pd.hipaa_voice = 'YES' ";
655 } elseif ($communication == "allow_mail") {
656 $whr_stmt .= " AND pd.hipaa_mail = 'YES' ";
657 } elseif ($communication == "allow_email") {
658 $whr_stmt .= " AND pd.hipaa_allowemail = 'YES' ";
659 } elseif ($communication == "" && !empty($_POST['communication_check'])) {
660 $whr_stmt .= " AND (pd.hipaa_allowsms = 'YES' OR pd.hipaa_voice = 'YES' OR pd.hipaa_mail = 'YES' OR pd.hipaa_allowemail = 'YES') ";
664 //Immunization where condition for full text or short text
665 if (strlen($form_immunization) > 0) {
667 immc.code_text LIKE ?
668 OR immc.code_text_short LIKE ?
670 array_push($sqlBindArray, '%' . $form_immunization . '%', '%' . $form_immunization . '%');
674 if (!empty($_POST['form_pt_name'])) {
675 $odrstmt = $odrstmt . ",patient_name";
678 if (!empty($_POST['form_pt_age'])) {
679 $odrstmt = $odrstmt . ",patient_age";
682 if (!empty($form_diagnosis)) {
683 $odrstmt = $odrstmt . ",lists_diagnosis";
684 } elseif ((!empty($_POST['form_diagnosis_allergy'])) ||
(!empty($_POST['form_diagnosis_medprb']))) {
685 $odrstmt = $odrstmt . ",lists_title";
688 if ((!empty($_POST['form_drug'])) ||
(strlen($form_drug_name) > 0)) {
689 $odrstmt = $odrstmt . ",r.drug";
692 if ((!empty($_POST['ndc_no'])) && (strlen($form_drug_name) > 0)) {
693 $odrstmt = $odrstmt . ",d.ndc_number";
696 if ((!empty($_POST['lab_results'])) ||
(strlen($form_lab_results) > 0)) {
697 $odrstmt = $odrstmt . ",procedure_result_result";
700 if (strlen($communication) > 0 ||
!empty($_POST['communication_check'])) {
701 $odrstmt = $odrstmt . ",ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
705 if (empty($odrstmt)) {
706 $odrstmt = " ORDER BY patient_id";
708 $odrstmt = " ORDER BY " . ltrim($odrstmt, ",");
711 if ($type == 'Medical History') {
712 $sqlstmt = "select * from (" . $sqlstmt . " " . $whr_stmt . " " . $odrstmt . ",history_data_date desc) a group by patient_id";
714 $sqlstmt = $sqlstmt . " " . $whr_stmt . " " . $odrstmt;
717 $result = sqlStatement($sqlstmt, $sqlBindArray);
719 $row_id = 1.1;//given to each row to identify and toggle
723 if (sqlNumRows($result) > 0) {
724 //Added on 6-jun-2k14(regarding displaying smoking code descriptions)
725 $smoke_codes_arr = getSmokeCodes();
728 <div id
= "report_results">
730 <?php
$pidarr = array();
731 while ($row = sqlFetchArray($result)) { ?
>
732 <table
class='border-0' width
='90%' align
="center" cellpadding
="5" cellspacing
="0" style
="font-family: tahoma;">
733 <tr bgcolor
="#CCCCCC" style
="font-size:15px;">
734 <td
><strong
><?php
echo xlt('Summary of');
735 echo " "; ?
> <?php
echo text($row['patient_name']); ?
></strong
></td
>
739 <span onclick
="javascript:Toggle_trGrpHeader2(<?php echo attr($row_id); ?>,<?php echo attr($img_id); ?>);"><img src
="../pic/blue-down-arrow.gif" id
="<?php echo attr($img_id);
740 $img_id++; ?>" title
="<?php echo xla('Click here to view patient details'); ?>" /></span
>
742 <table width
="100%" align
="center" id
= "<?php echo attr($row_id);
743 $row_id++;?>" class="border1" style
="display:none; font-size:13px;" cellpadding
=5>
744 <tr bgcolor
="#C3FDB8" align
="left">
745 <td width
="15%"><strong
><?php
echo xlt('Patient Name'); ?
></strong
></td
>
746 <td width
="5%"><strong
><?php
echo xlt('PID');?
></strong
></td
>
747 <td width
="5%"><strong
><?php
echo xlt('Age');?
></strong
></td
>
748 <td width
="10%"><strong
><?php
echo xlt('Gender'); ?
></strong
></td
>
749 <td width
="15%"><strong
><?php
echo xlt('Race');?
></strong
></td
>
750 <td width
="15%"><strong
><?php
echo xlt('Ethnicity');?
></strong
></td
>
751 <td width
="15%" <?php
752 if (strlen($communication) == 0 ||
!empty($_POST['communication_check'])) {
754 } ?
>><strong
><?php
echo xlt('Provider');?
></strong
></td
>
755 <?php
if (strlen($communication) > 0 ||
(!empty($_POST['communication_check']))) { ?
>
756 <td colspan
='4'><strong
><?php
echo xlt('Communication');?
></strong
></td
>
759 <tr bgcolor
="#FFFFFF">
760 <td
><?php
echo text($row['patient_name']); ?
> 
;</td
>
761 <td
> <?php
echo text($row['patient_id']); ?
> 
;</td
>
762 <td
> <?php
echo text($row['patient_age']); ?
> 
;</td
>
763 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'sex'), $row['patient_sex']); ?
> 
;</td
>
764 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'race'), $row['patient_race']); ?
> 
;</td
>
765 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'ethnicity'), $row['patient_ethinic']); ?
> 
;</td
>
767 if (strlen($communication) == 0 ||
(!empty($_POST['communication_check']))) {
769 } ?
>> <?php
echo text($row['users_provider']); ?
> 
;</td
>
771 <?php
if (strlen($communication) > 0 ||
!empty($_POST['communication_check'])) { ?
>
772 <td colspan
='4'><?php
echo text($row['communications']); ?
></td
>
775 <!-- Diagnosis Report Start
-->
777 if (!empty($form_diagnosis)) {
779 <tr bgcolor
="#C3FDB8" align
="left">
780 <td colspan
='12'><strong
><?php
echo "#";
781 echo xlt('Diagnosis Report'); ?
></strong
></td
>
783 <tr bgcolor
="#C3FDB8" align
="left">
784 <td
><strong
><?php
echo xlt('Diagnosis Date');?
></strong
></td
>
785 <td
><strong
><?php
echo xlt('Diagnosis');?
></strong
></td
>
786 <td colspan
='10'><strong
><?php
echo xlt('Diagnosis Name');?
></strong
></td
>
788 <tr
class='bg-white'>
789 <td
><?php
echo text(oeFormatDateTime($row['lists_date'], "global", true)); ?
> 
;</td
>
790 <td
><?php
echo text($row['lists_diagnosis']); ?
> 
;</td
>
791 <td colspan
='10'><?php
echo text($row['lists_title']); ?
> 
;</td
>
795 <!-- Diagnosis Report End
-->
797 <!-- Prescription Report Start
-->
799 if (strlen($form_drug_name) > 0 ||
!empty($_POST['form_drug'])) {
801 <tr bgcolor
="#C3FDB8" align
= "left">
802 <td colspan
='12'><strong
><?php
echo "#";
803 echo xlt('Prescription Report');?
><strong
></td
>
805 <tr bgcolor
="#C3FDB8" align
= "left">
806 <td
><strong
><?php
echo xlt('Date'); ?
></strong
></td
>
807 <td
><strong
><?php
echo xlt('Drug Name');?
></strong
></td
>
808 <td
><strong
><?php
echo xlt('Route');?
></strong
></td
>
809 <td
><strong
><?php
echo xlt('Dosage');?
></strong
></td
>
810 <td
><strong
><?php
echo xlt('Form');?
></strong
></td
>
811 <td
><strong
><?php
echo xlt('Interval');?
></strong
></td
>
812 <td
><strong
><?php
echo xlt('Size');?
></strong
></td
>
813 <td
><strong
><?php
echo xlt('Unit');?
></strong
></td
>
814 <td
><strong
><?php
echo xlt('ReFill');?
></strong
></td
>
815 <td
><strong
><?php
echo xlt('Quantity');?
></strong
></td
>
816 <td colspan
="2"><strong
><?php
echo xlt('NDC');?
></strong
></td
>
818 <tr
class='bg-white' align
="">
820 $rx_route = generate_display_field(array('data_type' => '1','list_id' => 'drug_route'), $row['route']) ;
821 $rx_form = generate_display_field(array('data_type' => '1','list_id' => 'drug_form'), $row['hform']) ;
822 $rx_interval = generate_display_field(array('data_type' => '1','list_id' => 'drug_interval'), $row['hinterval']) ;
823 $rx_units = generate_display_field(array('data_type' => '1','list_id' => 'drug_units'), $row['hunit']);
825 <td
> <?php
echo text(oeFormatShortDate($row['prescriptions_date_modified'])); ?
> 
;</td
>
826 <td
><?php
echo text($row['drug']); ?
></td
>
827 <td
><?php
echo $rx_route; ?
></td
>
828 <td
><?php
echo text($row['dosage']); ?
></td
>
829 <td
><?php
echo $rx_form; ?
></td
>
830 <td
><?php
echo $rx_interval; ?
></td
>
831 <td
><?php
echo text($row['size']); ?
></td
>
832 <td
><?php
echo $rx_units; ?
></td
>
833 <td
><?php
echo text($row['refills']); ?
></td
>
834 <td
><?php
echo text($row['quantity']); ?
></td
>
835 <td colspan
="2"><?php
echo text($row['ndc_number']); ?
></td
>
839 <!-- Prescription Report End
-->
841 <!-- Lab Results Report Start
-->
843 if (strlen($form_lab_results) > 0 ||
!empty($_POST['lab_results'])) {
845 <tr bgcolor
="#C3FDB8" align
= "left">
846 <td colspan
='12'><strong
><?php
echo "#";
847 echo xlt('Lab Results Report');?
><strong
></td
></tr
>
848 <tr bgcolor
="#C3FDB8" align
= "left">
849 <td
><strong
><?php
echo xlt('Date'); ?
></strong
></td
>
850 <td
><strong
><?php
echo xlt('Facility');?
></strong
></td
>
851 <td
><strong
><?php
echo xlt('Unit');?
></strong
></td
>
852 <td
><strong
><?php
echo xlt('Result');?
></strong
></td
>
853 <td
><strong
><?php
echo xlt('Range');?
></strong
></td
>
854 <td
><strong
><?php
echo xlt('Abnormal');?
></strong
></td
>
855 <td
><strong
><?php
echo xlt('Comments');?
></strong
></td
>
856 <td colspan
='5'><strong
><?php
echo xlt('Document ID');?
></strong
></td
>
858 <tr
class='bg-white'>
859 <td
> <?php
echo text(oeFormatShortDate($row['procedure_result_date'])); ?
> 
;</td
>
860 <td
> <?php
echo text($row['procedure_result_facility']); ?
> 
;</td
>
861 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'proc_unit'), $row['procedure_result_units']); ?
> 
;</td
>
862 <td
> <?php
echo text($row['procedure_result_result']); ?
> 
;</td
>
863 <td
> <?php
echo text($row['procedure_result_range']); ?
> 
;</td
>
864 <td
> <?php
echo text($row['procedure_result_abnormal']); ?
> 
;</td
>
865 <td
> <?php
echo text($row['procedure_result_comments']); ?
> 
;</td
>
866 <td colspan
='5'> <?php
echo text($row['procedure_result_document_id']); ?
> 
;</td
>
870 <!-- Lab Results End
-->
872 <!-- Procedures Report Start
-->
874 if ($type == 'Procedure') {
876 <tr bgcolor
="#C3FDB8" align
= "left">
877 <td colspan
=12><strong
><?php
echo "#";
878 echo xlt('Procedure Report');?
><strong
></td
></tr
>
879 <tr bgcolor
="#C3FDB8" align
= "left">
880 <td
><strong
><?php
echo xlt('Date'); ?
></strong
></td
>
881 <td
><strong
><?php
echo xlt('Standard Name');?
></strong
></td
>
882 <td
><strong
><?php
echo xlt('Procedure'); ?
></strong
></td
>
883 <td
><strong
><?php
echo xlt('Encounter');?
></strong
></td
>
884 <td
><strong
><?php
echo xlt('Priority');?
></strong
></td
>
885 <td
><strong
><?php
echo xlt('Status');?
></strong
></td
>
886 <td
><strong
><?php
echo xlt('Instruction');?
></strong
></td
>
887 <td
><strong
><?php
echo xlt('Activity');?
></strong
></td
>
888 <td colspan
='3'><strong
><?php
echo xlt('Control ID');?
></strong
></td
>
890 <tr
class='bg-white'>
892 $procedure_type_standard_code_arr = explode(':', $row['procedure_type_standard_code']);
893 $procedure_type_standard_code = $procedure_type_standard_code_arr[1];
896 <td
> <?php
echo text(oeFormatShortDate($row['procedure_order_date_ordered'])); ?
> 
;</td
>
897 <td
> <?php
echo text($procedure_type_standard_code); ?
> 
;</td
>
898 <td
> <?php
echo text($row['procedure_name']); ?
> 
;</td
>
899 <td
> <?php
echo text($row['procedure_order_encounter']); ?
> 
;</td
>
900 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'ord_priority'), $row['procedure_order_order_priority']); ?
> 
;</td
>
901 <td
> <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'ord_status'), $row['procedure_order_order_status']); ?
> 
;</td
>
902 <td
> <?php
echo text($row['procedure_order_patient_instructions']); ?
> 
;</td
>
903 <td
> <?php
echo text($row['procedure_order_activity']); ?
> 
;</td
>
904 <td colspan
='3'> <?php
echo text($row['procedure_order_control_id']); ?
> 
;</td
>
909 <!-- Procedure Report End
-->
911 <!-- Medical History Report Start
-->
913 if ($type == 'Medical History') {
915 <tr bgcolor
="#C3FDB8" align
= "left">
916 <td colspan
=12><strong
><?php
echo "#" . xlt('Medical History');?
></strong
></td
></tr
>
917 <tr bgcolor
="#C3FDB8" align
= "left">
918 <td
><strong
><?php
echo xlt('History Date'); ?
></strong
></td
>
919 <td
><strong
><?php
echo xlt('Tobacco');?
></strong
></td
>
920 <td
><strong
><?php
echo xlt('Alcohol');?
></strong
></td
>
921 <td colspan
='8'><strong
><?php
echo xlt('Recreational Drugs');?
></strong
></td
>
923 <tr
class='bg-white'>
925 $tmp_t = explode('|', $row['history_data_tobacco']);
926 $tmp_a = explode('|', $row['history_data_alcohol']);
927 $tmp_d = explode('|', $row['history_data_recreational_drugs']);
928 $his_tobac = generate_display_field(array('data_type' => '1','list_id' => 'smoking_status'), $tmp_t[3]);
930 <td
> <?php
echo text(oeFormatShortDate($row['history_data_date'])); ?
> 
;</td
>
932 //Added on 6-jun-2k14(regarding displaying smoking code descriptions)
933 if (!empty($smoke_codes_arr[$tmp_t[3]])) {
934 $his_tobac .= " ( " . text($smoke_codes_arr[$tmp_t[3]]) . " )";
937 echo $his_tobac; ?
> 
;</td
>
939 $res = xl('No history recorded');
940 if ($tmp_a[1] == "currentalcohol") {
941 $res = xl('Current Alcohol');
944 if ($tmp_a[1] == "quitalcohol") {
945 $res = xl('Quit Alcohol');
948 if ($tmp_a[1] == "neveralcohol") {
949 $res = xl('Never Alcohol');
952 if ($tmp_a[1] == "not_applicablealcohol") {
956 <td
> <?php
echo text($res); ?
> 
;</td
>
959 $resd = xl('No history recorded');
960 if ($tmp_d[1] == "currentrecreational_drugs") {
961 $resd = xl('Current Recreational Drugs');
964 if ($tmp_d[1] == "quitrecreational_drugs") {
968 if ($tmp_d[1] == "neverrecreational_drugs") {
972 if ($tmp_d[1] == "not_applicablerecreational_drugs") {
976 <td colspan
='8'> <?php
echo text($resd); ?
> 
;</td
>
980 <!-- Medical History Report End
-->
982 <!-- Service Codes Report Start
-->
984 if ($type == 'Service Codes') {
986 <tr bgcolor
="#C3FDB8" align
= "left">
987 <td colspan
='11'><strong
><?php
echo "#";
988 echo xlt('Service Codes');?
><strong
></td
></tr
>
989 <tr bgcolor
="#C3FDB8" align
= "left">
990 <td
><strong
><?php
echo xlt('Date'); ?
></strong
></td
>
991 <td
><strong
><?php
echo xlt('Code');?
></strong
></td
>
992 <td
><strong
><?php
echo xlt('Encounter ID');?
></strong
></td
>
993 <td colspan
='8'><strong
><?php
echo xlt('Code Text');?
></strong
></td
></tr
>
994 <tr
class='bg-white'>
995 <td
><?php
echo text(oeFormatShortDate($row['date'])); ?
> 
;</td
>
996 <td
><?php
echo text($row['code']); ?
> 
;</td
>
997 <td
><?php
echo text($row['encounter']); ?
> 
;</td
>
998 <td colspan
='8'><?php
echo text($row['code_text']); ?
> 
;</td
>
1002 <!-- Service Codes Report End
-->
1004 <!-- Immunization Report Start
-->
1006 if (strlen($form_immunization) > 0) {?
>
1007 <tr bgcolor
="#C3FDB8" align
= "left">
1008 <td colspan
='12'><strong
><?php
echo "#";
1009 echo xlt('Immunization Report');?
></strong
></td
>
1011 <tr bgcolor
="#C3FDB8" align
= "left">
1012 <td
><strong
><?php
echo xlt('Immunization Date');?
></strong
></td
>
1013 <td
><strong
><?php
echo xlt('CVX Code');?
></strong
></td
>
1014 <td
><strong
><?php
echo xlt('Vaccine');?
></strong
></td
>
1015 <td
><strong
><?php
echo xlt('Amount');?
></strong
></td
>
1016 <td
><strong
><?php
echo xlt('Administered Site');?
></strong
></td
>
1017 <td colspan
="7"><strong
><?php
echo xlt('Notes');?
></strong
></td
>
1019 <tr
class='bg-white'>
1020 <td
><?php
echo text(oeFormatDateTime($row['imm_date'])); ?
> 
;</td
>
1021 <td
><?php
echo text($row['cvx_code']); ?
> 
;</td
>
1022 <td
><?php
echo text($row['imm_code_short']) . " (" . text($row['imm_code']) . ")"; ?
> 
;</td
>
1025 if ($row["amount_administered"] > 0) {
1026 echo text($row["amount_administered"]) . " " . generate_display_field(array('data_type' => '1','list_id' => 'drug_units'), $row['amount_administered_unit']);
1035 <?php
echo generate_display_field(array('data_type' => '1','list_id' => 'proc_body_site'), $row['administration_site']); ?
>
1039 <?php
echo text($row['notes']); ?
>
1044 <!-- Immunization Report End
-->
1047 } //while loop end ?>
1048 </table
> <!-- Main table ends
-->
1051 } else { //End if form_refresh
1052 ?
><div
class='text'> <?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
> </div
><?php