Fee sheet and Codes revenue code (#7415)
[openemr.git] / interface / reports / clinical_reports.php
blob7882a5f46e1be20898cf6ca08ab7c296523ca981
1 <?php
3 /**
4 * Clinical reports.
6 * @package OpenEMR
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")]);
27 exit;
30 if (!empty($_POST)) {
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"] ?? '');
57 <html>
58 <head>
60 <title>
61 <?php echo xlt('Clinical Reports'); ?>
62 </title>
64 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
66 <script>
67 $(function () {
68 var win = top.printLogSetup ? top : opener.top;
69 win.printLogSetup(document.getElementById('printbutton'));
70 });
72 function toggle(id) {
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);
80 if (img!=null) {
81 var bExpand = img.src.indexOf(sPlus) >= 0;
82 if (!bExpand)
83 img.src = "../pic/blue-up-arrow.gif";
84 else
85 img.src = "../pic/blue-down-arrow.gif";
88 function Toggle_trGrpHeader2(t_id,i_id) {
89 var img=i_id;
90 changeimage(img, 'blue-down-arrow.gif', 'blue-up-arrow.gif');
91 var id1=t_id;
92 toggle(id1);
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];
98 var s = f.value;
99 if (code) {
100 if (s.length > 0) s += ';';
101 s += codetype + ':' + code;
102 } else {
103 s = '';
105 f.value = s;
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);
119 </script>
121 <style>
122 /* specifically include & exclude from printing */
123 @media print {
124 #report_parameters {
125 visibility: hidden;
126 display: none;
128 #report_parameters_daterange {
129 visibility: visible;
130 display: inline;
132 #report_results table {
133 margin-top: 0px;
137 /* specifically exclude some from the screen */
138 @media screen {
139 #report_parameters_daterange {
140 visibility: hidden;
141 display: none;
144 .optional_area_service_codes {
145 <?php
146 if ($type != 'Service Codes' || $type == '') {
148 display: none;
149 <?php
153 </style>
154 <script>
155 function checkType() {
156 if($('#type').val() == 'Service Codes')
158 $('.optional_area_service_codes').css("display", "inline");
160 else
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");
186 else
188 $("#form_refresh").attr("value","true");
189 $("#theform").submit();
193 $(function () {
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
200 else {
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 ?>
216 </script>
217 </head>
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>
221 <span class='title'>
222 <?php echo htmlspecialchars(xl('Report - Clinical'), ENT_NOQUOTES); ?>
223 </span>
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 " &nbsp; " . xlt("to{{Range}}") . " &nbsp; " . 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=''/>
233 <table>
234 <tr>
235 <td width='740px'><div style='float:left'>
236 <table class='text'>
237 <tr>
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, 0, true)); ?>'></td>
242 </tr>
243 <tr>
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, 0, true)); ?>'></td>
248 </tr>
249 <tr>
250 <td class='col-form-label'><?php echo xlt('Age Range'); ?>:</td>
251 <td><table>
252 <tr>
253 <td class='col-form-label'><?php echo xlt('From'); ?></td>
254 <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' />
256 </td>
257 <td class='col-form-label'><?php echo xlt('To{{Range}}'); ?></td>
258 <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' />
260 </td>
261 </tr>
262 </table></td>
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>
265 <td>&nbsp;</td>
266 <!-- Visolve -->
267 </tr>
268 <tr>
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>
274 </tr>
275 <tr>
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>
282 </tr>
283 <tr>
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') {
292 echo "selected";
293 } ?>><?php echo xlt('Procedure'); ?></option>
294 <option value="Medical History" <?php
295 if ($type == 'Medical History') {
296 echo "selected";
297 } ?>><?php echo xlt('Medical History'); ?></option>
298 <option value="Service Codes" <?php
299 if ($type == 'Service Codes') {
300 echo "selected";
301 } ?>><?php echo xlt('Service Codes'); ?></option>
302 </select>
303 </td>
304 <td class='col-form-label'><?php echo xlt('Communication'); ?>:</td>
305 <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) {
311 echo "selected";
312 } ?>><?php echo text($comvalue); ?></option>
313 <?php } ?>
314 </select>
315 </td>
316 </tr>
317 </table>
318 <table>
319 <tr class="optional_area_service_codes">
320 <td width='100'>&nbsp;</td>
321 <td width='100'>&nbsp;</td>
322 <td width='195'>&nbsp;</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 />&nbsp;</td>
325 </tr>
326 </table>
327 <table class='text'>
328 <tr>
329 <!-- Sort by Start -->
330 <td class='col-form-label' width='63'><?php echo xlt('Sort By'); ?>:</td>
331 <td>
332 <table>
333 <tr>
334 <td>
335 <input type='checkbox' class='form-control' name='form_pt_name'<?php
336 if (!empty($_POST['form_pt_name'])) {
337 echo ' checked';
338 } ?>>
339 </td>
340 <td class='col-form-label'>
341 <?php echo xlt('Patient Name'); ?>&nbsp;
342 </td>
343 <td>
344 <input type='checkbox' class='form-control' name='form_pt_age'<?php
345 if (!empty($_POST['form_pt_age'])) {
346 echo ' checked';
347 } ?>>
348 </td>
349 <td class='col-form-label'>
350 <?php echo xlt('Age'); ?>&nbsp;
351 </td>
352 <td>
353 <input type='checkbox' class='form-control' name='form_diagnosis_allergy'<?php
354 if (!empty($_POST['form_diagnosis_allergy'])) {
355 echo ' checked';
356 } ?>>
357 </td>
358 <td class='col-form-label'>
359 <?php echo xlt('Allergies'); ?>&nbsp;
360 </td>
361 <td>
362 <input type='checkbox' class='form-control' name='form_diagnosis_medprb'<?php
363 if (!empty($_POST['form_diagnosis_medprb'])) {
364 echo ' checked';
365 } ?>>
366 </td>
367 <td class='col-form-label'>
368 <?php echo xlt('Medical Problems'); ?>&nbsp;
369 </td>
370 <td>
371 <input type='checkbox' class='form-control' name='form_drug'<?php
372 if (!empty($_POST['form_drug'])) {
373 echo ' checked';
374 } ?>>
375 </td>
376 <td class='col-form-label'>
377 <?php echo xlt('Drug'); ?>&nbsp;
378 </td>
379 <td>
380 <input type='checkbox' class='form-control' name='ndc_no'<?php
381 if (!empty($_POST['ndc_no'])) {
382 echo ' checked';
383 } ?>>
384 </td>
385 <td class='col-form-label'>
386 <?php echo xlt('NDC Number'); ?>&nbsp;
387 </td>
388 <td>
389 <input type='checkbox' class='form-control' name='lab_results'<?php
390 if (!empty($_POST['lab_results'])) {
391 echo ' checked';
392 } ?>>
393 </td>
394 <td class='col-form-label'>
395 <?php echo xlt('Lab Results'); ?>&nbsp;
396 </td>
397 <td>
398 <input type='checkbox' class='form-control' name='communication_check'<?php
399 if (!empty($_POST['communication_check'])) {
400 echo ' checked';
401 } ?>>
402 </td>
403 <td class='col-form-label'>
404 <?php echo xlt('Communication'); ?>
405 </td>
406 </tr>
407 </table>
408 </td>
409 </tr>
410 <!-- Sort by ends -->
411 </tr>
412 <tr>
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>&nbsp;</td>
414 </tr>
415 </table>
416 </div></td>
417 <td height="100%" valign='middle' width="175">
418 <table class='w-100 h-100' style='border-left:1px solid;'>
419 <tr>
420 <td>
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'); ?>
425 </a>
426 <?php if (!empty($_POST['form_refresh'])) { ?>
427 <a href='#' class='btn btn-secondary btn-print' id='printbutton'>
428 <?php echo xlt('Print'); ?>
429 </a>
430 <?php } ?>
431 </div>
432 </div>
433 </td>
434 </tr>
435 </table></td>
436 </tr>
437 </table>
438 </div>
439 <!-- end of parameters -->
440 <?php
441 // SQL scripts for the various searches
442 $sqlBindArray = array();
443 if (!empty($_POST['form_refresh'])) {
444 $sqlstmt = "select
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,
497 b.date as date";
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 ";
505 //from
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 ";
548 //where
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'])) {
590 $whr_stmt .= " AND (
591 d.name LIKE ?
592 OR r.drug LIKE ?
593 ) ";
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) {
666 $whr_stmt .= " AND (
667 immc.code_text LIKE ?
668 OR immc.code_text_short LIKE ?
669 ) ";
670 array_push($sqlBindArray, '%' . $form_immunization . '%', '%' . $form_immunization . '%');
673 // order by
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";
707 } else {
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";
713 } else {
714 $sqlstmt = $sqlstmt . " " . $whr_stmt . " " . $odrstmt;
717 $result = sqlStatement($sqlstmt, $sqlBindArray);
719 $row_id = 1.1;//given to each row to identify and toggle
720 $img_id = 1.2;
721 $k = 1.3;
723 if (sqlNumRows($result) > 0) {
724 //Added on 6-jun-2k14(regarding displaying smoking code descriptions)
725 $smoke_codes_arr = getSmokeCodes();
727 <br />
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>
736 <td>&nbsp;</td>
737 <td>&nbsp;</td>
738 <td align="center">
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>
741 </td></tr>
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'])) {
753 ?> colspan='5' <?php
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>
757 <?php } ?>
758 </tr>
759 <tr bgcolor="#FFFFFF">
760 <td><?php echo text($row['patient_name']); ?>&nbsp;</td>
761 <td> <?php echo text($row['patient_id']); ?>&nbsp;</td>
762 <td> <?php echo text($row['patient_age']); ?>&nbsp;</td>
763 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'sex'), $row['patient_sex']); ?>&nbsp;</td>
764 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'race'), $row['patient_race']); ?>&nbsp;</td>
765 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'ethnicity'), $row['patient_ethinic']); ?>&nbsp;</td>
766 <td <?php
767 if (strlen($communication) == 0 || (!empty($_POST['communication_check']))) {
768 ?> colspan='5' <?php
769 } ?>> <?php echo text($row['users_provider']); ?>&nbsp;</td>
771 <?php if (strlen($communication) > 0 || !empty($_POST['communication_check'])) { ?>
772 <td colspan='4'><?php echo text($row['communications']); ?></td>
773 <?php } ?>
774 </tr>
775 <!-- Diagnosis Report Start-->
776 <?php
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>
782 </tr>
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>
787 </tr>
788 <tr class='bg-white'>
789 <td><?php echo text(oeFormatDateTime($row['lists_date'], "global", true)); ?>&nbsp;</td>
790 <td><?php echo text($row['lists_diagnosis']); ?>&nbsp;</td>
791 <td colspan='10'><?php echo text($row['lists_title']); ?>&nbsp;</td>
792 </tr>
793 <?php
794 } ?>
795 <!-- Diagnosis Report End-->
797 <!-- Prescription Report Start-->
798 <?php
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>
804 </tr>
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>
817 </tr>
818 <tr class='bg-white' align="">
819 <?php
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'])); ?>&nbsp;</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>
836 </tr>
837 <?php
838 } ?>
839 <!-- Prescription Report End-->
841 <!-- Lab Results Report Start-->
842 <?php
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>
857 </tr>
858 <tr class='bg-white'>
859 <td> <?php echo text(oeFormatShortDate($row['procedure_result_date'])); ?>&nbsp;</td>
860 <td> <?php echo text($row['procedure_result_facility']); ?>&nbsp;</td>
861 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'proc_unit'), $row['procedure_result_units']); ?>&nbsp;</td>
862 <td> <?php echo text($row['procedure_result_result']); ?>&nbsp;</td>
863 <td> <?php echo text($row['procedure_result_range']); ?>&nbsp;</td>
864 <td> <?php echo text($row['procedure_result_abnormal']); ?>&nbsp;</td>
865 <td> <?php echo text($row['procedure_result_comments']); ?>&nbsp;</td>
866 <td colspan='5'> <?php echo text($row['procedure_result_document_id']); ?>&nbsp;</td>
867 </tr>
868 <?php
869 } ?>
870 <!-- Lab Results End-->
872 <!-- Procedures Report Start-->
873 <?php
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>
889 </tr>
890 <tr class='bg-white'>
891 <?php
892 $procedure_type_standard_code_arr = explode(':', $row['procedure_type_standard_code']);
893 $procedure_type_standard_code = $procedure_type_standard_code_arr[1];
895 <!-- Procedure -->
896 <td> <?php echo text(oeFormatShortDate($row['procedure_order_date_ordered'])); ?>&nbsp;</td>
897 <td> <?php echo text($procedure_type_standard_code); ?>&nbsp;</td>
898 <td> <?php echo text($row['procedure_name']); ?>&nbsp;</td>
899 <td> <?php echo text($row['procedure_order_encounter']); ?>&nbsp;</td>
900 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'ord_priority'), $row['procedure_order_order_priority']); ?>&nbsp;</td>
901 <td> <?php echo generate_display_field(array('data_type' => '1','list_id' => 'ord_status'), $row['procedure_order_order_status']); ?>&nbsp;</td>
902 <td> <?php echo text($row['procedure_order_patient_instructions']); ?>&nbsp;</td>
903 <td> <?php echo text($row['procedure_order_activity']); ?>&nbsp;</td>
904 <td colspan='3'> <?php echo text($row['procedure_order_control_id']); ?>&nbsp;</td>
906 </tr>
907 <?php
908 } ?>
909 <!-- Procedure Report End-->
911 <!-- Medical History Report Start-->
912 <?php
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>
922 </tr>
923 <tr class='bg-white'>
924 <?php
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'])); ?>&nbsp;</td>
931 <td> <?php
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; ?>&nbsp;</td>
938 <?php
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") {
953 $res = xl('N/A');
956 <td> <?php echo text($res); ?>&nbsp;</td>
957 <?php
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") {
965 $resd = xl('Quit');
968 if ($tmp_d[1] == "neverrecreational_drugs") {
969 $resd = xl('Never');
972 if ($tmp_d[1] == "not_applicablerecreational_drugs") {
973 $resd = xl('N/A');
976 <td colspan='8'> <?php echo text($resd); ?>&nbsp;</td>
977 </tr>
978 <?php
979 } ?>
980 <!-- Medical History Report End-->
982 <!-- Service Codes Report Start-->
983 <?php
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'])); ?>&nbsp;</td>
996 <td><?php echo text($row['code']); ?>&nbsp;</td>
997 <td><?php echo text($row['encounter']); ?>&nbsp;</td>
998 <td colspan='8'><?php echo text($row['code_text']); ?>&nbsp;</td>
999 </tr>
1000 <?php
1001 } ?>
1002 <!-- Service Codes Report End-->
1004 <!-- Immunization Report Start-->
1005 <?php
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>
1010 </tr>
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>
1018 </tr>
1019 <tr class='bg-white'>
1020 <td><?php echo text(oeFormatDateTime($row['imm_date'])); ?>&nbsp;</td>
1021 <td><?php echo text($row['cvx_code']); ?>&nbsp;</td>
1022 <td><?php echo text($row['imm_code_short']) . " (" . text($row['imm_code']) . ")"; ?>&nbsp;</td>
1023 <td>
1024 <?php
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']);
1027 } else {
1028 echo "&nbsp;";
1032 </td>
1034 <td>
1035 <?php echo generate_display_field(array('data_type' => '1','list_id' => 'proc_body_site'), $row['administration_site']); ?>
1036 </td>
1038 <td colspan="7">
1039 <?php echo text($row['notes']); ?>
1040 </td>
1041 </tr>
1042 <?php
1043 } ?>
1044 <!-- Immunization Report End-->
1045 </table>
1046 <?php
1047 } //while loop end ?>
1048 </table> <!-- Main table ends -->
1049 <?php
1050 } //End if $result
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
1055 </form>
1056 </body>
1058 </html>