Portal updates and general bug fixes (#2318)
[openemr.git] / interface / reports / clinical_reports.php
blobd8a8d570b9240813ba311daa5dfe666eac6af847
1 <?php
2 /**
3 * Clinical reports.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2010 OpenEMR Support LLC
9 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
14 require_once("$srcdir/patient.inc");
15 require_once("$srcdir/options.inc.php");
16 require_once("../drugs/drugs.inc.php");
17 require_once("../../custom/code_types.inc.php");
19 use OpenEMR\Core\Header;
21 if (!empty($_POST)) {
22 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
23 csrfNotVerified();
27 $comarr = array('allow_sms'=>xl('Allow SMS'),'allow_voice'=>xl('Allow Voice Message'),'allow_mail'=>xl('Allow Mail Message'),'allow_email'=>xl('Allow Email'));
29 $sql_date_from = (!empty($_POST['date_from'])) ? DateTimeToYYYYMMDDHHMMSS($_POST['date_from']) : date('Y-01-01 H:i:s');
30 $sql_date_to = (!empty($_POST['date_to'])) ? DateTimeToYYYYMMDDHHMMSS($_POST['date_to']) : date('Y-m-d H:i:s');
32 $type = $_POST["type"];
33 $facility = isset($_POST['facility']) ? $_POST['facility'] : '';
34 $patient_id = trim($_POST["patient_id"]);
35 $age_from = $_POST["age_from"];
36 $age_to = $_POST["age_to"];
37 $sql_gender = $_POST["gender"];
38 $sql_ethnicity = $_POST["ethnicity"];
39 $sql_race=$_POST["race"];
40 $form_drug_name = trim($_POST["form_drug_name"]);
41 $form_diagnosis = trim($_POST["form_diagnosis"]);
42 $form_lab_results = trim($_POST["form_lab_results"]);
43 $form_service_codes = trim($_POST["form_service_codes"]);
44 $form_immunization = trim($_POST["form_immunization"]);
45 $communication = trim($_POST["communication"]);
48 <html>
49 <head>
51 <title>
52 <?php echo xlt('Clinical Reports'); ?>
53 </title>
55 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
57 <script language="JavaScript">
58 $(document).ready(function() {
59 var win = top.printLogSetup ? top : opener.top;
60 win.printLogSetup(document.getElementById('printbutton'));
61 });
63 function toggle(id) {
64 var tr = document.getElementById(id);
65 if (tr==null) { return; }
66 var bExpand = tr.style.display == '';
67 tr.style.display = (bExpand ? 'none' : '');
69 function changeimage(id, sMinus, sPlus) {
70 var img = document.getElementById(id);
71 if (img!=null) {
72 var bExpand = img.src.indexOf(sPlus) >= 0;
73 if (!bExpand)
74 img.src = "../pic/blue-up-arrow.gif";
75 else
76 img.src = "../pic/blue-down-arrow.gif";
79 function Toggle_trGrpHeader2(t_id,i_id) {
80 var img=i_id;
81 changeimage(img, 'blue-down-arrow.gif', 'blue-up-arrow.gif');
82 var id1=t_id;
83 toggle(id1);
85 // This is for callback by the find-code popup.
86 // Appends to or erases the current list of diagnoses.
87 function set_related(codetype, code, selector, codedesc) {
88 var f = document.forms[0][current_sel_name];
89 var s = f.value;
90 if (code) {
91 if (s.length > 0) s += ';';
92 s += codetype + ':' + code;
93 } else {
94 s = '';
96 f.value = s;
99 //This invokes the find-code popup.
100 function sel_diagnosis(e) {
101 current_sel_name = e.name;
102 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr_url(collect_codetypes("diagnosis", "csv")); ?>', '_blank', 500, 400);
105 //This invokes the find-code popup.
106 function sel_procedure(e) {
107 current_sel_name = e.name;
108 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr_url(collect_codetypes("procedure", "csv")); ?>', '_blank', 500, 400);
110 </script>
112 <style type="text/css">
113 /* specifically include & exclude from printing */
114 @media print {
115 #report_parameters {
116 visibility: hidden;
117 display: none;
119 #report_parameters_daterange {
120 visibility: visible;
121 display: inline;
123 #report_results table {
124 margin-top: 0px;
128 /* specifically exclude some from the screen */
129 @media screen {
130 #report_parameters_daterange {
131 visibility: hidden;
132 display: none;
135 .optional_area_service_codes {
136 <?php
137 if ($type != 'Service Codes' || $type == '') {
139 display: none;
140 <?php
144 </style>
145 <script language="javascript" type="text/javascript">
146 function checkType() {
147 if($('#type').val() == 'Service Codes')
149 $('.optional_area_service_codes').css("display", "inline");
151 else
153 $('.optional_area_service_codes').css("display", "none");
157 function submitForm() {
158 var d_from = new String($('#date_from').val());
159 var d_to = new String($('#date_to').val());
161 var d_from_arr = d_from.split('-');
162 var d_to_arr = d_to.split('-');
164 var dt_from = new Date(d_from_arr[0], d_from_arr[1], d_from_arr[2]);
165 var dt_to = new Date(d_to_arr[0], d_to_arr[1], d_to_arr[2]);
167 var mili_from = dt_from.getTime();
168 var mili_to = dt_to.getTime();
169 var diff = mili_to - mili_from;
171 $('#date_error').css("display", "none");
173 if(diff < 0) //negative
175 $('#date_error').css("display", "inline");
177 else
179 $("#form_refresh").attr("value","true");
180 $("#theform").submit();
184 $(document).ready(function() {
185 $(".numeric_only").keydown(function(event) {
186 //alert(event.keyCode);
187 // Allow only backspace and delete
188 if ( event.keyCode == 46 || event.keyCode == 8 ) {
189 // let it happen, don't do anything
191 else {
192 if(!((event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 48 && event.keyCode <= 57)))
194 event.preventDefault();
199 $('.datetimepicker').datetimepicker({
200 <?php $datetimepicker_timepicker = true; ?>
201 <?php $datetimepicker_showseconds = true; ?>
202 <?php $datetimepicker_formatInput = true; ?>
203 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
204 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
207 </script>
208 </head>
209 <body class="body_top">
210 <!-- Required for the popup date selectors -->
211 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
212 <span class='title'>
213 <?php echo htmlspecialchars(xl('Report - Clinical'), ENT_NOQUOTES); ?>
214 </span>
215 <!-- Search can be done using age range, gender, and ethnicity filters.
216 Search options include diagnosis, procedure, prescription, medical history, and lab results.
218 <div id="report_parameters_daterange"> <?php echo text(oeFormatDateTime($sql_date_from, "global", true)) .
219 " &nbsp; " . xlt("to") . " &nbsp; ". text(oeFormatDateTime($sql_date_to, "global", true)); ?> </div>
220 <form name='theform' id='theform' method='post' action='clinical_reports.php' onsubmit='return top.restoreSession()'>
221 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
222 <div id="report_parameters">
223 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
224 <table>
225 <tr>
226 <td width='740px'><div style='float:left'>
227 <table class='text'>
228 <tr>
229 <td class='control-label' width="100"><?php echo xlt('Facility'); ?>: </td>
230 <td width="250"> <?php dropdown_facility($facility, 'facility', false); ?> </td>
231 <td class='control-label' width="100"><?php echo xlt('From'); ?>: </td>
232 <td><input type='text' class='datetimepicker form-control' name='date_from' id="date_from" size='18' value='<?php echo attr(oeFormatDateTime($sql_date_from, 0, true)); ?>'></td>
233 </tr>
234 <tr>
235 <td class='control-label'><?php echo xlt('Patient ID'); ?>:</td>
236 <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>
237 <td class='control-label'><?php echo xlt('To'); ?>: </td>
238 <td><input type='text' class='datetimepicker form-control' name='date_to' id="date_to" size='18' value='<?php echo attr(oeFormatDateTime($sql_date_to, 0, true)); ?>'></td>
239 </tr>
240 <tr>
241 <td class='control-label'><?php echo xlt('Age Range'); ?>:</td>
242 <td><table>
243 <tr>
244 <td class='control-label'><?php echo xlt('From'); ?></td>
245 <td>
246 <input name='age_from' class="numeric_only form-control" type='text' id="age_from" value="<?php echo attr($age_from); ?>" size='3' maxlength='3' />
247 </td>
248 <td class='control-label'><?php echo xlt('To'); ?></td>
249 <td>
250 <input name='age_to' class="numeric_only form-control" type='text' id="age_to" value="<?php echo attr($age_to); ?>" size='3' maxlength='3' />
251 </td>
252 </tr>
253 </table></td>
254 <td class='control-label'><?php echo xlt('Problem DX'); ?>:</td>
255 <td><input type='text' name='form_diagnosis form-control' 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>
256 <td>&nbsp;</td>
257 <!-- Visolve -->
258 </tr>
259 <tr>
260 <td class='control-label'><?php echo xlt('Gender'); ?>:</td>
261 <td><?php echo generate_select_list('gender', 'sex', $sql_gender, 'Select Gender', 'Unassigned', '', ''); ?></td>
262 <td class='control-label'><?php echo xlt('Drug'); ?>:</td>
263 <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>
265 </tr>
266 <tr>
267 <td class='control-label'><?php echo xlt('Race'); ?>:</td>
268 <td><?php echo generate_select_list('race', 'race', $sql_race, 'Select Race', 'Unassigned', '', ''); ?></td>
269 <td class='control-label'><?php echo xlt('Ethnicity'); ?>:</td>
270 <td><?php echo generate_select_list('ethnicity', 'ethnicity', $sql_ethnicity, 'Select Ethnicity', 'Unassigned', '', ''); ?></td>
271 <td class='control-label'><?php echo xlt('Immunization'); ?>:</td>
272 <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>
273 </tr>
274 <tr>
275 <td class='control-label' width='100'><?php echo xlt('Lab Result'); ?>:</td>
276 <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>
278 <td class='control-label' width='100'><?php echo xlt('Option'); ?>:</td>
279 <td><select name="type" class='form-control' id="type" onChange="checkType();">
280 <option> <?php echo xlt('Select'); ?></option>
281 <option value="Procedure" <?php
282 if ($type == 'Procedure') {
283 echo "selected";
284 } ?>><?php echo xlt('Procedure'); ?></option>
285 <option value="Medical History" <?php
286 if ($type == 'Medical History') {
287 echo "selected";
288 } ?>><?php echo xlt('Medical History'); ?></option>
289 <option value="Service Codes" <?php
290 if ($type == 'Service Codes') {
291 echo "selected";
292 } ?>><?php echo xlt('Service Codes'); ?></option>
293 </select>
294 </td>
295 <td class='control-label'><?php echo xlt('Communication'); ?>:</td>
296 <td>
297 <select name="communication" class='form-control' id="communication" title="<?php echo xla('Select Communication Preferences'); ?>">
298 <option value=""> <?php echo xlt('Select'); ?></option>
299 <?php foreach ($comarr as $comkey => $comvalue) { ?>
300 <option value="<?php echo attr($comkey); ?>" <?php
301 if ($communication == $comkey) {
302 echo "selected";
303 } ?>><?php echo text($comvalue); ?></option>
304 <?php } ?>
305 </select>
306 </td>
307 </tr>
308 </table>
309 <table>
310 <tr class="optional_area_service_codes">
311 <td width='100'>&nbsp;</td>
312 <td width='100'>&nbsp;</td>
313 <td width='195'>&nbsp;</td>
314 <td class='control-label' width='76'><?php echo xlt('Code'); ?>:</td>
315 <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 />&nbsp;</td>
316 </tr>
317 </table>
318 <table class='text'>
319 <tr>
320 <!-- Sort by Start -->
321 <td class='control-label' width='63'><?php echo xlt('Sort By'); ?>:</td>
322 <td>
323 <table>
324 <tr>
325 <td>
326 <input type='checkbox' class='form-control' name='form_pt_name'<?php
327 if ($_POST['form_pt_name'] == true) {
328 echo ' checked';
329 } ?>>
330 </td>
331 <td class='control-label'>
332 <?php echo xlt('Patient Name'); ?>&nbsp;
333 </td>
334 <td>
335 <input type='checkbox' class='form-control' name='form_pt_age'<?php
336 if ($_POST['form_pt_age'] == true) {
337 echo ' checked';
338 } ?>>
339 </td>
340 <td class='control-label'>
341 <?php echo xlt('Age'); ?>&nbsp;
342 </td>
343 <td>
344 <input type='checkbox' class='form-control' name='form_diagnosis_allergy'<?php
345 if ($_POST['form_diagnosis_allergy'] == true) {
346 echo ' checked';
347 } ?>>
348 </td>
349 <td class='control-label'>
350 <?php echo xlt('Allergies'); ?>&nbsp;
351 </td>
352 <td>
353 <input type='checkbox' class='form-control' name='form_diagnosis_medprb'<?php
354 if ($_POST['form_diagnosis_medprb'] == true) {
355 echo ' checked';
356 } ?>>
357 </td>
358 <td class='control-label'>
359 <?php echo xlt('Medical Problems'); ?>&nbsp;
360 </td>
361 <td>
362 <input type='checkbox' class='form-control' name='form_drug'<?php
363 if ($_POST['form_drug'] == true) {
364 echo ' checked';
365 } ?>>
366 </td>
367 <td class='control-label'>
368 <?php echo xlt('Drug'); ?>&nbsp;
369 </td>
370 <td>
371 <input type='checkbox' class='form-control' name='ndc_no'<?php
372 if ($_POST['ndc_no'] == true) {
373 echo ' checked';
374 } ?>>
375 </td>
376 <td class='control-label'>
377 <?php echo xlt('NDC Number'); ?>&nbsp;
378 </td>
379 <td>
380 <input type='checkbox' class='form-control' name='lab_results'<?php
381 if ($_POST['lab_results'] == true) {
382 echo ' checked';
383 } ?>>
384 </td>
385 <td class='control-label'>
386 <?php echo xlt('Lab Results'); ?>&nbsp;
387 </td>
388 <td>
389 <input type='checkbox' class='form-control' name='communication_check'<?php
390 if ($_POST['communication_check'] == true) {
391 echo ' checked';
392 } ?>>
393 </td>
394 <td class='control-label'>
395 <?php echo xlt('Communication'); ?>
396 </td>
397 </tr>
398 </table>
399 </td>
400 </tr>
401 <!-- Sort by ends -->
402 </tr>
403 <tr>
404 <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>&nbsp;</td>
405 </tr>
406 </table>
407 </div></td>
408 <td height="100%" valign='middle' width="175"><table style='border-left:1px solid; width:100%; height:100%'>
409 <tr>
410 <td>
411 <div class="text-center">
412 <div class="btn-group" role="group">
413 <a href='#' class='btn btn-default btn-save' onclick='submitForm();'>
414 <?php echo xlt('Submit'); ?>
415 </a>
416 <?php if ($_POST['form_refresh']) { ?>
417 <a href='#' class='btn btn-default btn-print' id='printbutton'>
418 <?php echo xlt('Print'); ?>
419 </a>
420 <?php } ?>
421 </div>
422 </div>
423 </td>
424 </tr>
425 </table></td>
426 </tr>
427 </table>
428 </div>
429 <!-- end of parameters -->
430 <?php
431 // SQL scripts for the various searches
432 $sqlBindArray = array();
433 if ($_POST['form_refresh']) {
434 $sqlstmt = "select
435 concat(pd.fname, ' ', pd.lname) AS patient_name,
436 pd.pid AS patient_id,
437 DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 AS patient_age,
438 pd.sex AS patient_sex,
439 pd.race AS patient_race,pd.ethnicity AS patient_ethinic,
440 concat(u.fname, ' ', u.lname) AS users_provider,
441 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";
442 if (strlen($form_diagnosis) > 0 || $_POST['form_diagnosis_allergy'] == true || $_POST['form_diagnosis_medprb'] == true) {
443 $sqlstmt=$sqlstmt.",li.date AS lists_date,
444 li.diagnosis AS lists_diagnosis,
445 li.title AS lists_title";
448 if (strlen($form_drug_name) > 0 || $_POST['form_drug'] == true) {
449 $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,
450 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";
453 if (strlen($form_lab_results) > 0 || $_POST['lab_results'] == true) {
454 $sqlstmt = $sqlstmt.",pr.date AS procedure_result_date,
455 pr.facility AS procedure_result_facility,
456 pr.units AS procedure_result_units,
457 pr.result AS procedure_result_result,
458 pr.range AS procedure_result_range,
459 pr.abnormal AS procedure_result_abnormal,
460 pr.comments AS procedure_result_comments,
461 pr.document_id AS procedure_result_document_id";
464 if ($type == 'Procedure') {
465 $sqlstmt = $sqlstmt.",po.date_ordered AS procedure_order_date_ordered,
466 pt.standard_code AS procedure_type_standard_code,
467 pc.procedure_name as procedure_name,
468 po.order_priority AS procedure_order_order_priority,
469 po.order_status AS procedure_order_order_status,
470 po.encounter_id AS procedure_order_encounter,
471 po.patient_instructions AS procedure_order_patient_instructions,
472 po.activity AS procedure_order_activity,
473 po.control_id AS procedure_order_control_id ";
476 if ($type == 'Medical History') {
477 $sqlstmt = $sqlstmt.",hd.date AS history_data_date,
478 hd.tobacco AS history_data_tobacco,
479 hd.alcohol AS history_data_alcohol,
480 hd.recreational_drugs AS history_data_recreational_drugs ";
483 if ($type == 'Service Codes') {
484 $sqlstmt .= ", c.code as code,
485 c.code_text as code_text,
486 fe.encounter as encounter,
487 b.date as date";
488 $mh_stmt = $mh_stmt.",code,code_text,encounter,date";
491 if (strlen($form_immunization) > 0) {
492 $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 ";
495 //from
496 $sqlstmt=$sqlstmt." from patient_data as pd left outer join users as u on u.id = pd.providerid
497 left outer join facility as f on f.id = u.facility_id";
499 if (strlen($form_diagnosis) > 0 || ($_POST['form_diagnosis_allergy'] == true && $_POST['form_diagnosis_medprb'] == true)) {
500 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='medical_problem' OR li.type='allergy')) ";
501 } elseif ($_POST['form_diagnosis_allergy'] == true) {
502 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='allergy')) ";
503 } elseif ($_POST['form_diagnosis_medprb'] == true) {
504 $sqlstmt = $sqlstmt." left outer join lists as li on (li.pid = pd.pid AND (li.type='medical_problem')) ";
507 if ($type == 'Procedure' ||( strlen($form_lab_results)!=0) || $_POST['lab_results'] == true) {
508 $sqlstmt = $sqlstmt." left outer join procedure_order as po on po.patient_id = pd.pid
509 left outer join procedure_order_code as pc on pc.procedure_order_id = po.procedure_order_id
510 left outer join procedure_report as pp on pp.procedure_order_id = po.procedure_order_id
511 left outer join procedure_type as pt on pt.procedure_code = pc.procedure_code and pt.lab_id = po.lab_id ";
514 if (strlen($form_lab_results)!=0 || $_POST['lab_results'] == true) {
515 $sqlstmt = $sqlstmt." left outer join procedure_result as pr on pr.procedure_report_id = pp.procedure_report_id ";
518 //Immunization added in clinical report
519 if (strlen($form_immunization)!=0) {
520 $sqlstmt = $sqlstmt." LEFT OUTER JOIN immunizations as imm ON imm.patient_id = pd.pid
521 LEFT OUTER JOIN codes as immc ON imm.cvx_code = immc.id ";
524 if (strlen($form_drug_name)!=0 || $_POST['form_drug'] == true) {
525 $sqlstmt=$sqlstmt." left outer join prescriptions AS r on r.patient_id=pd.pid
526 LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id";
529 if ($type == 'Medical History') {
530 $sqlstmt = $sqlstmt." left outer join history_data as hd on hd.pid = pd.pid
531 and (isnull(hd.tobacco) = 0
532 or isnull(hd.alcohol) = 0
533 or isnull(hd.recreational_drugs) = 0)";
536 if ($type == 'Service Codes') {
537 $sqlstmt = $sqlstmt." left outer join billing as b on b.pid = pd.pid
538 left outer join form_encounter as fe on fe.encounter = b.encounter and b.code_type = 'CPT4'
539 left outer join codes as c on c.code = b.code ";
542 //where
543 $whr_stmt="where 1=1";
544 if (strlen($form_diagnosis) > 0 || $_POST['form_diagnosis_allergy'] == true || $_POST['form_diagnosis_medprb'] == true) {
545 $whr_stmt=$whr_stmt." AND li.date >= ? AND li.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(li.date) <= ?";
546 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
549 if (strlen($form_lab_results)!=0 || $_POST['lab_results'] == true) {
550 $whr_stmt=$whr_stmt." AND pr.date >= ? AND pr.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(pr.date) <= ?";
551 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
554 if (strlen($form_drug_name)!=0 || $_POST['form_drug'] == true) {
555 $whr_stmt=$whr_stmt." AND r.date_modified >= ? AND r.date_modified < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(r.date_modified) <= ?";
556 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
559 if ($type == 'Medical History') {
560 $whr_stmt=$whr_stmt." AND hd.date >= ? AND hd.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(hd.date) <= ?";
561 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
564 if ($type == 'Procedure') {
565 $whr_stmt=$whr_stmt." AND po.date_ordered >= ? AND po.date_ordered < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(po.date_ordered) <= ?";
566 array_push($sqlBindArray, substr($sql_date_from, 0, 10), substr($sql_date_to, 0, 10), date("Y-m-d"));
569 if ($type == "Service Codes") {
570 $whr_stmt=$whr_stmt." AND b.date >= ? AND b.date < DATE_ADD(?, INTERVAL 1 DAY) AND DATE(b.date) <= ?";
571 array_push($sqlBindArray, $sql_date_from, $sql_date_to, date("Y-m-d"));
574 if (strlen($form_lab_results) != 0 || $_POST['lab_results'] == true) {
575 $whr_stmt= $whr_stmt." AND (pr.result LIKE ?) ";
576 if (empty($form_lab_results)) {
577 $form_lab_results ="%";
580 array_push($sqlBindArray, $form_lab_results);
583 if (strlen($form_drug_name) > 0 || $_POST['form_drug'] == true) {
584 $whr_stmt .= " AND (
585 d.name LIKE ?
586 OR r.drug LIKE ?
587 ) ";
588 if (empty($form_drug_name)) {
589 $form_drug_name ="%";
592 array_push($sqlBindArray, $form_drug_name, $form_drug_name);
595 if ($type == 'Service Codes') {
596 if (strlen($form_service_codes) != 0) {
597 $whr_stmt = $whr_stmt." AND (b.code = ?) ";
598 $service_code = explode(":", $form_service_codes);
599 array_push($sqlBindArray, $service_code[1]);
603 if (strlen($patient_id) != 0) {
604 $whr_stmt = $whr_stmt." and pd.pid = ?";
605 array_push($sqlBindArray, $patient_id);
608 if (strlen($age_from) != 0) {
609 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 >= ?";
610 array_push($sqlBindArray, $age_from);
613 if (strlen($age_to) != 0) {
614 $whr_stmt = $whr_stmt." and DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),pd.dob)), '%Y')+0 <= ?";
615 array_push($sqlBindArray, $age_to);
618 if (strlen($sql_gender) != 0) {
619 $whr_stmt = $whr_stmt." and pd.sex = ?";
620 array_push($sqlBindArray, $sql_gender);
623 if (strlen($sql_ethnicity) != 0) {
624 $whr_stmt = $whr_stmt." and pd.ethnicity = ?";
625 array_push($sqlBindArray, $sql_ethnicity);
628 if (strlen($sql_race) != 0) {
629 $whr_stmt = $whr_stmt." and pd.race = ?";
630 array_push($sqlBindArray, $sql_race);
633 if ($facility != '') {
634 $whr_stmt = $whr_stmt." and f.id = ? ";
635 array_push($sqlBindArray, $facility);
638 if (strlen($form_diagnosis) > 0) {
639 $whr_stmt = $whr_stmt." AND (li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis LIKE ? or li.diagnosis = ?) ";
640 array_push($sqlBindArray, $form_diagnosis."%", '%'.$form_diagnosis.'%', '%'.$form_diagnosis, $form_diagnosis);
643 //communication preferences added in clinical report
644 if (strlen($communication) > 0 || $_POST['communication_check'] == true) {
645 if ($communication == "allow_sms") {
646 $whr_stmt .= " AND pd.hipaa_allowsms = 'YES' ";
647 } else if ($communication == "allow_voice") {
648 $whr_stmt .= " AND pd.hipaa_voice = 'YES' ";
649 } else if ($communication == "allow_mail") {
650 $whr_stmt .= " AND pd.hipaa_mail = 'YES' ";
651 } else if ($communication == "allow_email") {
652 $whr_stmt .= " AND pd.hipaa_allowemail = 'YES' ";
653 } else if ($communication == "" && $_POST['communication_check'] == true) {
654 $whr_stmt .= " AND (pd.hipaa_allowsms = 'YES' OR pd.hipaa_voice = 'YES' OR pd.hipaa_mail = 'YES' OR pd.hipaa_allowemail = 'YES') ";
658 //Immunization where condition for full text or short text
659 if (strlen($form_immunization) > 0) {
660 $whr_stmt .= " AND (
661 immc.code_text LIKE ?
662 OR immc.code_text_short LIKE ?
663 ) ";
664 array_push($sqlBindArray, '%'.$form_immunization.'%', '%'.$form_immunization.'%');
667 // order by
668 if ($_POST['form_pt_name'] == true) {
669 $odrstmt=$odrstmt.",patient_name";
672 if ($_POST['form_pt_age'] == true) {
673 $odrstmt=$odrstmt.",patient_age";
676 if ((strlen($form_diagnosis) > 0)) {
677 $odrstmt=$odrstmt.",lists_diagnosis";
678 } elseif (($_POST['form_diagnosis_allergy'] == true) || ($_POST['form_diagnosis_medprb'] == true)) {
679 $odrstmt=$odrstmt.",lists_title";
682 if (($_POST['form_drug'] == true) || (strlen($form_drug_name) > 0)) {
683 $odrstmt=$odrstmt.",r.drug";
686 if (($_POST['ndc_no'] == true) && (strlen($form_drug_name) > 0)) {
687 $odrstmt=$odrstmt.",d.ndc_number";
690 if (($_POST['lab_results'] == true) || (strlen($form_lab_results) > 0)) {
691 $odrstmt=$odrstmt.",procedure_result_result";
694 if (strlen($communication) > 0 || $_POST['communication_check'] == true) {
695 $odrstmt=$odrstmt.",ROUND((LENGTH(communications) - LENGTH(REPLACE(communications, ',', '')))/LENGTH(',')) , communications";
699 if ($odrstmt == '') {
700 $odrstmt = " ORDER BY patient_id";
701 } else {
702 $odrstmt = " ORDER BY ".ltrim($odrstmt, ",");
705 if ($type == 'Medical History') {
706 $sqlstmt="select * from (".$sqlstmt." ".$whr_stmt." ".$odrstmt.",history_data_date desc) a group by patient_id";
707 } else {
708 $sqlstmt=$sqlstmt." ".$whr_stmt." ".$odrstmt;
711 $result = sqlStatement($sqlstmt, $sqlBindArray);
713 $row_id = 1.1;//given to each row to identify and toggle
714 $img_id = 1.2;
715 $k=1.3;
717 if (sqlNumRows($result) > 0) {
718 //Added on 6-jun-2k14(regarding displaying smoking code descriptions)
719 $smoke_codes_arr = getSmokeCodes();
721 <br>
722 <div id = "report_results">
724 <?php $pidarr = array();
725 while ($row = sqlFetchArray($result)) { ?>
726 <table width=90% align="center" cellpadding="5" cellspacing="0" style="font-family:tahoma;color:black;" border="0">
727 <tr bgcolor = "#CCCCCC" style="font-size:15px;">
728 <td><b><?php echo xlt('Summary of');
729 echo " "; ?> <?php echo text($row['patient_name']); ?></b></td>
730 <td>&nbsp;</td>
731 <td>&nbsp;</td>
732 <td align="center">
733 <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);
734 $img_id++; ?>" title="<?php echo xla('Click here to view patient details'); ?>" /></span>
735 </td></tr>
736 <table width="100%" align="center" id = "<?php echo attr($row_id);
737 $row_id++;?>" class="border1" style="display:none; font-size:13px;" cellpadding=5>
738 <tr bgcolor="#C3FDB8" align="left">
739 <td width="15%"><b><?php echo xlt('Patient Name'); ?></b></td>
740 <td width="5%"><b><?php echo xlt('PID');?></b></td>
741 <td width="5%"><b><?php echo xlt('Age');?></b></td>
742 <td width="10%"><b><?php echo xlt('Gender'); ?></b></td>
743 <td width="15%"><b><?php echo xlt('Race');?></b></td>
744 <td width="15%"><b><?php echo xlt('Ethnicity');?></b></td>
745 <td width="15%" <?php
746 if (strlen($communication) == 0 || $_POST['communication_check'] == true) {
747 ?> colspan=5 <?php
748 } ?>><b><?php echo xlt('Provider');?></b></td>
749 <?php if (strlen($communication) > 0 || ($_POST['communication_check'] == true)) { ?>
750 <td colspan=4><b><?php echo xlt('Communication');?></b></td>
751 <?php } ?>
752 </tr>
753 <tr bgcolor="#FFFFFF">
754 <td><?php echo text($row['patient_name']); ?>&nbsp;</td>
755 <td> <?php echo text($row['patient_id']); ?>&nbsp;</td>
756 <td> <?php echo text($row['patient_age']); ?>&nbsp;</td>
757 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'sex'), $row['patient_sex']); ?>&nbsp;</td>
758 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'race'), $row['patient_race']); ?>&nbsp;</td>
759 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'ethnicity'), $row['patient_ethinic']); ?>&nbsp;</td>
760 <td <?php
761 if (strlen($communication) == 0 || ($_POST['communication_check'] == true)) {
762 ?> colspan=5 <?php
763 } ?>> <?php echo text($row['users_provider']); ?>&nbsp;</td>
765 <?php if (strlen($communication) > 0 || $_POST['communication_check'] == true) { ?>
766 <td colspan=4><?php echo text($row['communications']); ?></td>
767 <?php } ?>
768 </tr>
769 <!-- Diagnosis Report Start-->
770 <?php
771 if (strlen($form_diagnosis) > 0 || $_POST['form_diagnosis_allergy'] == true || $_POST['form_diagnosis_medprb'] == true) {
773 <tr bgcolor="#C3FDB8" align= "left">
774 <td colspan=12><b><?php echo "#";
775 echo xlt('Diagnosis Report');?></b></td>
776 </tr>
777 <tr bgcolor="#C3FDB8" align= "left">
778 <td><b><?php echo xlt('Diagnosis Date');?></b></td>
779 <td><b><?php echo xlt('Diagnosis');?></b></td>
780 <td colspan=10><b><?php echo xlt('Diagnosis Name');?></b></td>
781 </tr>
782 <tr bgcolor="#FFFFFF">
783 <td><?php echo text(oeFormatDateTime($row['lists_date'], "global", true)); ?>&nbsp;</td>
784 <td><?php echo text($row['lists_diagnosis']); ?>&nbsp;</td>
785 <td colspan=10><?php echo text($row['lists_title']); ?>&nbsp;</td>
786 </tr>
787 <?php
788 } ?>
789 <!-- Diagnosis Report End-->
791 <!-- Prescription Report Start-->
792 <?php
793 if (strlen($form_drug_name) > 0 || $_POST['form_drug'] == true) {
795 <tr bgcolor="#C3FDB8" align= "left">
796 <td colspan=12><b><?php echo "#";
797 echo xlt('Prescription Report');?><b></td></tr>
798 <tr bgcolor="#C3FDB8" align= "left">
799 <td><b><?php echo xlt('Date'); ?></b></td>
800 <td><b><?php echo xlt('Drug Name');?></b></td>
801 <td><b><?php echo xlt('Route');?></b></td>
802 <td><b><?php echo xlt('Dosage');?></b></td>
803 <td><b><?php echo xlt('Form');?></b></td>
804 <td><b><?php echo xlt('Interval');?></b></td>
805 <td><b><?php echo xlt('Size');?></b></td>
806 <td><b><?php echo xlt('Unit');?></b></td>
807 <td><b><?php echo xlt('ReFill');?></b></td>
808 <td><b><?php echo xlt('Quantity');?></b></td>
809 <td colspan="2"><b><?php echo xlt('NDC');?></b></td>
810 </tr>
811 <tr bgcolor="#FFFFFF" align="">
812 <?php
813 $rx_route = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']) ;
814 $rx_form = generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['hform']) ;
815 $rx_interval = generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['hinterval']) ;
816 $rx_units = generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['hunit']);
818 <td> <?php echo text(oeFormatShortDate($row['prescriptions_date_modified'])); ?>&nbsp;</td>
819 <td><?php echo text($row['drug']); ?></td>
820 <td><?php echo $rx_route; ?></td>
821 <td><?php echo text($row['dosage']); ?></td>
822 <td><?php echo $rx_form; ?></td>
823 <td><?php echo $rx_interval; ?></td>
824 <td><?php echo text($row['size']); ?></td>
825 <td><?php echo $rx_units; ?></td>
826 <td><?php echo text($row['refills']); ?></td>
827 <td><?php echo text($row['quantity']); ?></td>
828 <td colspan="2"><?php echo text($row['ndc_number']); ?></td>
829 </tr>
830 <?php
831 } ?>
832 <!-- Prescription Report End-->
834 <!-- Lab Results Report Start-->
835 <?php
836 if (strlen($form_lab_results) > 0 || $_POST['lab_results'] == true) {
838 <tr bgcolor="#C3FDB8" align= "left">
839 <td colspan=12><b><?php echo "#";
840 echo xlt('Lab Results Report');?><b></td></tr>
841 <tr bgcolor="#C3FDB8" align= "left">
842 <td><b><?php echo xlt('Date'); ?></b></td>
843 <td><b><?php echo xlt('Facility');?></b></td>
844 <td><b><?php echo xlt('Unit');?></b></td>
845 <td><b><?php echo xlt('Result');?></b></td>
846 <td><b><?php echo xlt('Range');?></b></td>
847 <td><b><?php echo xlt('Abnormal');?></b></td>
848 <td><b><?php echo xlt('Comments');?></b></td>
849 <td colspan=5><b><?php echo xlt('Document ID');?></b></td>
850 </tr>
851 <tr bgcolor="#FFFFFF">
852 <td> <?php echo text(oeFormatShortDate($row['procedure_result_date'])); ?>&nbsp;</td>
853 <td> <?php echo text($row['procedure_result_facility']); ?>&nbsp;</td>
854 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'proc_unit'), $row['procedure_result_units']); ?>&nbsp;</td>
855 <td> <?php echo text($row['procedure_result_result']); ?>&nbsp;</td>
856 <td> <?php echo text($row['procedure_result_range']); ?>&nbsp;</td>
857 <td> <?php echo text($row['procedure_result_abnormal']); ?>&nbsp;</td>
858 <td> <?php echo text($row['procedure_result_comments']); ?>&nbsp;</td>
859 <td colspan=5> <?php echo text($row['procedure_result_document_id']); ?>&nbsp;</td>
860 </tr>
861 <?php
862 } ?>
863 <!-- Lab Results End-->
865 <!-- Procedures Report Start-->
866 <?php
867 if ($type == 'Procedure') {
869 <tr bgcolor="#C3FDB8" align= "left">
870 <td colspan=12><b><?php echo "#";
871 echo xlt('Procedure Report');?><b></td></tr>
872 <tr bgcolor="#C3FDB8" align= "left">
873 <td><b><?php echo xlt('Date'); ?></b></td>
874 <td><b><?php echo xlt('Standard Name');?></b></td>
875 <td><b><?php echo xlt('Procedure'); ?></b></td>
876 <td><b><?php echo xlt('Encounter');?></b></td>
877 <td><b><?php echo xlt('Priority');?></b></td>
878 <td><b><?php echo xlt('Status');?></b></td>
879 <td><b><?php echo xlt('Instruction');?></b></td>
880 <td><b><?php echo xlt('Activity');?></b></td>
881 <td colspan=3><b><?php echo xlt('Control ID');?></b></td>
882 </tr>
883 <tr bgcolor="#FFFFFF">
884 <?php
885 $procedure_type_standard_code_arr = explode(':', $row['procedure_type_standard_code']);
886 $procedure_type_standard_code = $procedure_type_standard_code_arr[1];
888 <!-- Procedure -->
889 <td> <?php echo text(oeFormatShortDate($row['procedure_order_date_ordered'])); ?>&nbsp;</td>
890 <td> <?php echo text($procedure_type_standard_code); ?>&nbsp;</td>
891 <td> <?php echo text($row['procedure_name']); ?>&nbsp;</td>
892 <td> <?php echo text($row['procedure_order_encounter']); ?>&nbsp;</td>
893 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'ord_priority'), $row['procedure_order_order_priority']); ?>&nbsp;</td>
894 <td> <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'ord_status'), $row['procedure_order_order_status']); ?>&nbsp;</td>
895 <td> <?php echo text($row['procedure_order_patient_instructions']); ?>&nbsp;</td>
896 <td> <?php echo text($row['procedure_order_activity']); ?>&nbsp;</td>
897 <td colspan=3> <?php echo text($row['procedure_order_control_id']); ?>&nbsp;</td>
899 </tr>
900 <?php
901 } ?>
902 <!-- Procedure Report End-->
904 <!-- Medical History Report Start-->
905 <?php
906 if ($type == 'Medical History') {
908 <tr bgcolor="#C3FDB8" align= "left">
909 <td colspan=12><b><?php echo "#";
910 echo xlt('Medical History');?><b></td></tr>
911 <tr bgcolor="#C3FDB8" align= "left">
912 <td><b><?php echo xlt('History Date'); ?></b></td>
913 <td><b><?php echo xlt('Tobacco');?></b></td>
914 <td><b><?php echo xlt('Alcohol');?></b></td>
915 <td colspan=8><b><?php echo xlt('Recreational Drugs');?></b></td>
916 </tr>
917 <tr bgcolor="#FFFFFF">
918 <?php
919 $tmp_t = explode('|', $row['history_data_tobacco']);
920 $tmp_a = explode('|', $row['history_data_alcohol']);
921 $tmp_d = explode('|', $row['history_data_recreational_drugs']);
922 $his_tobac = generate_display_field(array('data_type'=>'1','list_id'=>'smoking_status'), $tmp_t[3]) ;
924 <td> <?php echo text(oeFormatShortDate($row['history_data_date'])); ?>&nbsp;</td>
925 <td> <?php
926 //Added on 6-jun-2k14(regarding displaying smoking code descriptions)
927 if (!empty($smoke_codes_arr[$tmp_t[3]])) {
928 $his_tobac.= " ( ".text($smoke_codes_arr[$tmp_t[3]])." )";
931 echo $his_tobac; ?>&nbsp;</td>
932 <?php
933 if ($tmp_a[1] == "currentalcohol") {
934 $res = xl('Current Alcohol');
937 if ($tmp_a[1] == "quitalcohol") {
938 $res = xl('Quit Alcohol');
941 if ($tmp_a[1] == "neveralcohol") {
942 $res = xl('Never Alcohol');
945 if ($tmp_a[1] == "not_applicablealcohol") {
946 $res = xl('N/A');
949 <td> <?php echo text($res); ?>&nbsp;</td>
950 <?php
951 if ($tmp_d[1] == "currentrecreational_drugs") {
952 $resd = xl('Current Recreational Drugs');
955 if ($tmp_d[1] == "quitrecreational_drugs") {
956 $resd = xl('Quit');
959 if ($tmp_d[1] == "neverrecreational_drugs") {
960 $resd = xl('Never');
963 if ($tmp_d[1] == "not_applicablerecreational_drugs") {
964 $resd = xl('N/A');
967 <td colspan=8> <?php echo text($resd); ?>&nbsp;</td>
968 </tr>
969 <?php
970 } ?>
971 <!-- Medical History Report End-->
973 <!-- Service Codes Report Start-->
974 <?php
975 if ($type == 'Service Codes') {
977 <tr bgcolor="#C3FDB8" align= "left">
978 <td colspan=11><b><?php echo "#";
979 echo xlt('Service Codes');?><b></td></tr>
980 <tr bgcolor="#C3FDB8" align= "left">
981 <td><b><?php echo xlt('Date'); ?></b></td>
982 <td><b><?php echo xlt('Code');?></b></td>
983 <td><b><?php echo xlt('Encounter ID');?></b></td>
984 <td colspan=8><b><?php echo xlt('Code Text');?></b></td></tr>
985 <tr bgcolor="#FFFFFF">
986 <td><?php echo text(oeFormatShortDate($row['date'])); ?>&nbsp;</td>
987 <td><?php echo text($row['code']); ?>&nbsp;</td>
988 <td><?php echo text($row['encounter']); ?>&nbsp;</td>
989 <td colspan=8><?php echo text($row['code_text']); ?>&nbsp;</td>
990 </tr>
991 <?php
992 } ?>
993 <!-- Service Codes Report End-->
995 <!-- Immunization Report Start-->
996 <?php
997 if (strlen($form_immunization) > 0) {?>
998 <tr bgcolor="#C3FDB8" align= "left">
999 <td colspan=12><b><?php echo "#";
1000 echo xlt('Immunization Report');?></b></td>
1001 </tr>
1002 <tr bgcolor="#C3FDB8" align= "left">
1003 <td><b><?php echo xlt('Immunization Date');?></b></td>
1004 <td><b><?php echo xlt('CVX Code');?></b></td>
1005 <td><b><?php echo xlt('Vaccine');?></b></td>
1006 <td><b><?php echo xlt('Amount');?></b></td>
1007 <td><b><?php echo xlt('Administered Site');?></b></td>
1008 <td colspan="7"><b><?php echo xlt('Notes');?></b></td>
1009 </tr>
1010 <tr bgcolor="#FFFFFF">
1011 <td><?php echo text(oeFormatDateTime($row['imm_date'])); ?>&nbsp;</td>
1012 <td><?php echo text($row['cvx_code']); ?>&nbsp;</td>
1013 <td><?php echo text($row['imm_code_short'])." (".text($row['imm_code']).")"; ?>&nbsp;</td>
1014 <td>
1015 <?php
1016 if ($row["amount_administered"] > 0) {
1017 echo text($row["amount_administered"]) . " " . generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['amount_administered_unit']);
1018 } else {
1019 echo "&nbsp;";
1023 </td>
1025 <td>
1026 <?php echo generate_display_field(array('data_type'=>'1','list_id'=>'proc_body_site'), $row['administration_site']); ?>
1027 </td>
1029 <td colspan="7">
1030 <?php echo text($row['notes']); ?>
1031 </td>
1032 </tr>
1033 <?php
1034 } ?>
1035 <!-- Immunization Report End-->
1036 </table>
1037 <?php
1038 } //while loop end ?>
1039 </table> <!-- Main table ends -->
1040 <?php
1041 } //End if $result
1042 } //End if form_refresh
1043 else {
1044 ?><div class='text'> <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?> </div><?php
1047 </form>
1048 </body>
1050 </html>