f83cf84692a941917867513c183c39deaf46177d
[openemr.git] / interface / patient_file / report / patient_report.php
blobf83cf84692a941917867513c183c39deaf46177d
1 <?php
3 include_once("../../globals.php");
4 include_once("$srcdir/lists.inc");
5 include_once("$srcdir/acl.inc");
6 include_once("$srcdir/forms.inc");
8 // get various authorization levels
9 $auth_notes_a = acl_check('encounters', 'notes_a');
10 $auth_notes = acl_check('encounters', 'notes');
11 $auth_coding_a = acl_check('encounters', 'coding_a');
12 $auth_coding = acl_check('encounters', 'coding');
13 $auth_relaxed = acl_check('encounters', 'relaxed');
14 $auth_med = acl_check('patients' , 'med');
15 $auth_demo = acl_check('patients' , 'demo');
18 <html>
19 <head>
20 <?php html_header_show();?>
22 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
23 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
24 <script type="text/javascript" src="../../../library/textformat.js"></script>
25 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
26 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
27 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
29 <!-- include jQuery support -->
30 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
32 <script language='JavaScript'>
34 function checkAll(check) {
35 var f = document.forms['report_form'];
36 for (var i = 0; i < f.elements.length; ++i) {
37 if (f.elements[i].type == 'checkbox') f.elements[i].checked = check;
39 return false;
42 function show_date_fun(){
43 if(document.getElementById('show_date').checked == true){
44 document.getElementById('date_div').style.display = '';
45 }else{
46 document.getElementById('date_div').style.display = 'none';
48 return;
51 </script>
53 </head>
55 <body class="body_top">
56 <div id="patient_reports"> <!-- large outer DIV -->
58 <?php if ( $GLOBALS['activate_ccr_ccd_report'] ) { // show CCR/CCD reporting options ?>
59 <div id="ccr_report">
61 <form name='ccr_form' id='ccr_form' method='post' action='../../../ccr/createCCR.php'>
62 <span class='title'><?php xl('Continuity of Care Record (CCR)','e'); ?></span>&nbsp;&nbsp;
63 <br/>
64 <span class='text'>(<?php xl('Pop ups need to be enabled to see these reports','e'); ?>)</span>
65 <br/>
66 <br/>
67 <input type='hidden' name='ccrAction'>
68 <input type='hidden' name='raw'>
69 <input type="checkbox" name="show_date" id="show_date" onchange="show_date_fun();" ><span class='text'><?php xl('Use Date Range','e'); ?>
70 <br>
71 <div id="date_div" style="display:none" >
72 <br>
73 <table border="0" cellpadding="0" cellspacing="0" >
74 <tr>
75 <td>
76 <span class='bold'><?php xl('Start Date','e');?>: </span>
77 </td>
78 <td>
79 <input type='text' size='10' name='Start' id='Start'
80 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
81 title='<?php xl('yyyy-mm-dd','e'); ?>' />
82 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
83 id='img_start' border='0' alt='[?]' style='cursor:pointer'
84 title='<?php xl('Click here to choose a date','e'); ?>' >
85 <script LANGUAGE="JavaScript">
86 Calendar.setup({inputField:"Start", ifFormat:"%Y-%m-%d", button:"img_start"});
87 </script>
88 </td>
89 <td>
90 &nbsp;
91 <span class='bold'><?php xl('End Date','e');?>: </span>
92 </td>
93 <td>
94 <input type='text' size='10' name='End' id='End'
95 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
96 title='<?php xl('yyyy-mm-dd','e'); ?>' />
97 <img src='../../pic/show_calendar.gif' align='absbottom' width='24' height='22'
98 id='img_end' border='0' alt='[?]' style='cursor:pointer'
99 title='<?php xl('Click here to choose a date','e'); ?>' >
100 <script LANGUAGE="JavaScript">
101 Calendar.setup({inputField:"End", ifFormat:"%Y-%m-%d", button:"img_end"});
102 </script>
103 </td>
104 </tr>
105 </table>
106 </div>
107 <br>
108 <input type="button" class="generateCCR" value="<?php xl('View/Print','e'); ?>" />
109 <!-- <input type="button" class="generateCCR_download_h" value="<?php echo xl('Download')." (Hybrid)"; ?>" /> -->
110 <input type="button" class="generateCCR_download_p" value="<?php echo xl('Download'); ?>" />
111 <!-- <input type="button" class="generateCCR_raw" value="<?php xl('Raw Report','e'); ?>" /> -->
112 <hr/>
113 <span class='title'><?php xl('Continuity of Care Document (CCD)','e'); ?></span>&nbsp;&nbsp;
114 <br/>
115 <span class='text'>(<?php xl('Pop ups need to be enabled to see these reports','e'); ?>)</span>
116 <br/>
117 <br/>
118 <input type="button" class="viewCCD" value="<?php xl('View/Print','e'); ?>" />
119 <input type="button" class="viewCCD_download" value="<?php echo htmlspecialchars( xl('Download', ENT_QUOTES)); ?>" />
120 <!-- <input type="button" class="viewCCD_raw" value="<?php xl('Raw Report','e'); ?>" /> -->
121 <?php if ($GLOBALS['phimail_enable']==true) { ?>
122 <input type="button" class="viewCCD_send_dialog" value="<?php echo htmlspecialchars( xl('Transmit', ENT_QUOTES)); ?>" />
123 <br>
124 <div id="ccd_send_dialog" style="display:none" >
125 <br>
126 <table border="0" cellpadding="0" cellspacing="0" >
127 <tr>
128 <td>
129 <span class='bold'><?php echo htmlspecialchars( xl('Enter Recipient\'s Direct Address'), ENT_NOQUOTES);?>: </span>
130 <input type="text" size="64" name="ccd_send_to" id="ccd_send_to" value="">
131 <input type="hidden" name="ccd_sent_by" id="ccd_sent_by" value="user">
132 <input type="button" class="viewCCD_transmit" value="<?php echo htmlspecialchars( xl('Send', ENT_QUOTES)); ?>" />
133 <div id="ccd_send_result" style="display:none" >
134 <span class="text" id="ccd_send_message"></span>
135 </div>
136 </td>
137 </tr>
138 </table>
139 </div>
140 <?php } ?>
142 </form>
143 <hr/>
144 <hr/>
146 </div>
147 <?php } // end CCR/CCD reporting options ?>
149 <form name='report_form' id="report_form" method='post' action='custom_report.php'>
152 <span class='title'><?php xl('Patient Report','e'); ?></span>&nbsp;&nbsp;
154 <!--
155 <a class="link_submit" href="full_report.php" onclick="top.restoreSession()">
156 [<?php xl('View Comprehensive Patient Report','e'); ?>]</a>
158 <a class="link_submit" href="#" onclick="return checkAll(true)"><?php xl('Check All','e'); ?></a>
160 <a class="link_submit" href="#" onclick="return checkAll(false)"><?php xl('Clear All','e'); ?></a>
163 <table class="includes">
164 <tr>
165 <td class='text'>
166 <input type='checkbox' name='include_demographics' id='include_demographics' value="demographics" checked><?php xl('Demographics','e'); ?><br>
167 <?php if (acl_check('patients', 'med')): ?>
168 <input type='checkbox' name='include_history' id='include_history' value="history"><?php xl(' History','e'); ?><br>
169 <?php endif; ?>
170 <!--
171 <input type='checkbox' name='include_employer' id='include_employer' value="employer"><?php xl('Employer','e'); ?><br>
173 <input type='checkbox' name='include_insurance' id='include_insurance' value="insurance"><?php xl('Insurance','e'); ?><br>
174 <input type='checkbox' name='include_billing' id='include_billing' value="billing"
175 <?php if (!$GLOBALS['simplified_demographics']) echo 'checked'; ?>><?php xl('Billing','e'); ?><br>
176 </td>
177 <td class='text'>
178 <!--
179 <input type='checkbox' name='include_allergies' id='include_allergies' value="allergies">Allergies<br>
180 <input type='checkbox' name='include_medications' id='include_medications' value="medications">Medications<br>
182 <input type='checkbox' name='include_immunizations' id='include_immunizations' value="immunizations"><?php xl('Immunizations','e'); ?><br>
183 <!--
184 <input type='checkbox' name='include_medical_problems' id='include_medical_problems' value="medical_problems">Medical Problems<br>
186 <input type='checkbox' name='include_notes' id='include_notes' value="notes"><?php xl('Patient Notes','e'); ?><br>
187 <input type='checkbox' name='include_transactions' id='include_transactions' value="transactions"><?php xl('Transactions','e'); ?><br>
188 <input type='checkbox' name='include_batchcom' id='include_batchcom' value="batchcom"><?php xl('Communications','e'); ?><br>
189 </td>
190 </tr>
191 </table>
193 <br>
194 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
195 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
196 <input type='hidden' name='pdf' value='0'>
197 <br>
199 <!-- old ccr button position -->
200 <hr/>
202 <table class="issues_encounters_forms">
203 <tr>
205 <!-- Issues -->
206 <td class='text'>
207 <div class="issues">
208 <span class='bold'><?php xl('Issues','e'); ?>:</span>
209 <br>
210 <br>
212 <?php if (! acl_check('patients', 'med')): ?>
213 <br>(Issues not authorized)
215 <?php else: ?>
216 <table>
218 <?php
219 // get issues
220 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
221 "ORDER BY type, begdate");
222 $lasttype = "";
223 while ($prow = sqlFetchArray($pres)) {
224 if ($lasttype != $prow['type']) {
225 $lasttype = $prow['type'];
227 /****
228 $disptype = $lasttype;
229 switch ($lasttype) {
230 case "allergy" : $disptype = "Allergies" ; break;
231 case "problem" :
232 case "medical_problem": $disptype = "Medical Problems"; break;
233 case "medication" : $disptype = "Medications" ; break;
234 case "surgery" : $disptype = "Surgeries" ; break;
236 ****/
237 $disptype = $ISSUE_TYPES[$lasttype][0];
239 echo " <tr>\n";
240 echo " <td colspan='4' class='bold'><b>$disptype</b></td>\n";
241 echo " </tr>\n";
243 $rowid = $prow['id'];
244 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
246 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
247 "pid = '$pid' AND list_id = '$rowid'");
249 echo " <tr class='text'>\n";
250 echo " <td>&nbsp;</td>\n";
251 echo " <td>";
252 echo "<input type='checkbox' name='issue_$rowid' id='issue_$rowid' class='issuecheckbox' value='/";
253 while ($ierow = sqlFetchArray($ieres)) {
254 echo $ierow['encounter'] . "/";
256 echo "' />$disptitle</td>\n";
257 echo " <td>" . $prow['begdate'];
259 if ($prow['enddate']) { echo " - " . $prow['enddate']; }
260 else { echo " Active"; }
262 echo "</td>\n";
263 echo "</tr>\n";
266 </table>
268 <?php endif; // end of Issues output ?>
270 </div> <!-- end issues DIV -->
271 </td>
273 <!-- Encounters and Forms -->
275 <td class='text'>
276 <div class='encounters'>
277 <span class='bold'><?php xl('Encounters &amp; Forms','e'); ?>:</span>
278 <br><br>
280 <?php if (!($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)): ?>
281 (Encounters not authorized)
282 <?php else: ?>
284 <?php
286 $isfirst = 1;
287 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
288 "forms.formdir, forms.date AS fdate, form_encounter.date " .
289 ",form_encounter.reason ".
290 "FROM forms, form_encounter WHERE " .
291 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
292 "form_encounter.encounter = forms.encounter " .
293 " AND forms.deleted=0 ". // --JRM--
294 "ORDER BY form_encounter.date DESC, fdate ASC");
295 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
296 $html_strings = array();
297 $registry_form_name = array();
298 while($result2 = sqlFetchArray($res2)) {
299 array_push($registry_form_name,trim($result2['name']));
301 while($result = sqlFetchArray($res)) {
302 if ($result{"form_name"} == "New Patient Encounter") {
303 if ($isfirst == 0) {
304 foreach($registry_form_name as $var) {
305 if ($toprint = $html_strings[$var]) {
306 foreach($toprint as $var) {print $var;}
309 $html_strings = array();
310 echo "</div>\n"; // end DIV encounter_forms
311 echo "</div>\n\n"; //end DIV encounter_data
312 echo "<br>";
314 $isfirst = 0;
315 echo "<div class='encounter_data'>\n";
316 echo "<input type=checkbox ".
317 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
318 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
319 " value='" . $result{"encounter"} . "'" .
320 " class='encounter'".
321 " >";
323 // show encounter reason, not just 'New Encounter'
324 // trim to a reasonable length for display purposes --cfapress
325 $maxReasonLength = 20;
326 if (strlen($result["reason"]) > $maxReasonLength) {
327 $result['reason'] = substr($result['reason'], 0, $maxReasonLength) . " ... ";
330 echo $result{"reason"}.
331 " (" . date("Y-m-d",strtotime($result{"date"})) .
332 ")\n";
333 echo "<div class='encounter_forms'>\n";
335 else {
336 $form_name = trim($result{"form_name"});
337 //if form name is not in registry, look for the closest match by
338 // finding a registry name which is at the start of the form name.
339 //this is to allow for forms to put additional helpful information
340 //in the database in the same string as their form name after the name
341 $form_name_found_flag = 0;
342 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
343 // if the form does not match precisely with any names in the registry, now see if any front partial matches
344 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
345 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
347 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
348 array_push($html_strings[$form_name], "<input type='checkbox' ".
349 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
350 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
351 " value='" . $result{"encounter"} . "'" .
352 " class='encounter_form' ".
353 ">" . xl_form_title($result{"form_name"}) . "<br>\n");
356 foreach($registry_form_name as $var) {
357 if ($toprint = $html_strings[$var]) {
358 foreach($toprint as $var) {print $var;}
363 <?php endif; ?>
365 </div> <!-- end encounters DIV -->
366 </td>
367 </tr>
368 </table>
369 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
370 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
372 <hr/>
374 <span class="bold"><?php xl('Documents','e'); ?></span>:<br>
375 <ul>
376 <?php
377 // show available documents
378 $db = $GLOBALS['adodb']['db'];
379 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
380 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
381 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
382 "d.foreign_id = " . $db->qstr($pid);
383 $result = $db->Execute($sql);
384 if ($db->ErrorMsg()) echo $db->ErrorMsg();
385 while ($result && !$result->EOF) {
386 echo "<li class='bold'>";
387 echo '<input type="checkbox" name="documents[]" value="' .
388 $result->fields['id'] . '">';
389 echo '&nbsp;&nbsp;<i>' . xl_document_category($result->fields['name']) . "</i>";
390 echo '&nbsp;&nbsp;' . xl('Name') . ': <i>' . basename($result->fields['url']) . "</i>";
391 echo '</li>';
392 $result->MoveNext();
395 </ul>
396 </form>
398 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
399 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
401 </div> <!-- close patient_reports DIV -->
402 </body>
404 <script language="javascript">
406 // jQuery stuff to make the page a little easier to use
407 $(document).ready(function(){
408 $(".genreport").click(function() { top.restoreSession(); document.report_form.pdf.value = 0; $("#report_form").submit(); });
409 $(".genpdfrep").click(function() { top.restoreSession(); document.report_form.pdf.value = 1; $("#report_form").submit(); });
410 $("#genfullreport").click(function() { location.href='<?php echo "$rootdir/patient_file/encounter/$returnurl";?>'; });
411 //$("#printform").click(function() { PrintForm(); });
412 $(".issuecheckbox").click(function() { issueClick(this); });
414 // check/uncheck all Forms of an encounter
415 $(".encounter").click(function() { SelectForms($(this)); });
417 $(".generateCCR").click(
418 function() {
419 if(document.getElementById('show_date').checked == true){
420 if(document.getElementById('Start').value == '' || document.getElementById('End').value == ''){
421 alert('<?php echo addslashes( xl('Please select a start date and end date')) ?>');
422 return false;
425 var ccrAction = document.getElementsByName('ccrAction');
426 ccrAction[0].value = 'generate';
427 var raw = document.getElementsByName('raw');
428 raw[0].value = 'no';
429 top.restoreSession();
430 ccr_form.setAttribute("target", "_blank");
431 $("#ccr_form").submit();
432 ccr_form.setAttribute("target", "");
434 $(".generateCCR_raw").click(
435 function() {
436 var ccrAction = document.getElementsByName('ccrAction');
437 ccrAction[0].value = 'generate';
438 var raw = document.getElementsByName('raw');
439 raw[0].value = 'yes';
440 top.restoreSession();
441 ccr_form.setAttribute("target", "_blank");
442 $("#ccr_form").submit();
443 ccr_form.setAttribute("target", "");
445 $(".generateCCR_download_h").click(
446 function() {
447 var ccrAction = document.getElementsByName('ccrAction');
448 ccrAction[0].value = 'generate';
449 var raw = document.getElementsByName('raw');
450 raw[0].value = 'hybrid';
451 top.restoreSession();
452 $("#ccr_form").submit();
454 $(".generateCCR_download_p").click(
455 function() {
456 if(document.getElementById('show_date').checked == true){
457 if(document.getElementById('Start').value == '' || document.getElementById('End').value == ''){
458 alert('<?php echo addslashes( xl('Please select a start date and end date')) ?>');
459 return false;
462 var ccrAction = document.getElementsByName('ccrAction');
463 ccrAction[0].value = 'generate';
464 var raw = document.getElementsByName('raw');
465 raw[0].value = 'pure';
466 top.restoreSession();
467 $("#ccr_form").submit();
469 $(".viewCCD").click(
470 function() {
471 var ccrAction = document.getElementsByName('ccrAction');
472 ccrAction[0].value = 'viewccd';
473 var raw = document.getElementsByName('raw');
474 raw[0].value = 'no';
475 top.restoreSession();
476 ccr_form.setAttribute("target", "_blank");
477 $("#ccr_form").submit();
478 ccr_form.setAttribute("target", "");
480 $(".viewCCD_raw").click(
481 function() {
482 var ccrAction = document.getElementsByName('ccrAction');
483 ccrAction[0].value = 'viewccd';
484 var raw = document.getElementsByName('raw');
485 raw[0].value = 'yes';
486 top.restoreSession();
487 ccr_form.setAttribute("target", "_blank");
488 $("#ccr_form").submit();
489 ccr_form.setAttribute("target", "");
491 $(".viewCCD_download").click(
492 function() {
493 var ccrAction = document.getElementsByName('ccrAction');
494 ccrAction[0].value = 'viewccd';
495 var raw = document.getElementsByName('raw');
496 raw[0].value = 'pure';
497 $("#ccr_form").submit();
499 <?php if ($GLOBALS['phimail_enable']==true) { ?>
500 $(".viewCCD_send_dialog").click(
501 function() {
502 $("#ccd_send_dialog").toggle();
504 $(".viewCCD_transmit").click(
505 function() {
506 $(".viewCCD_transmit").attr('disabled','disabled');
507 var ccrAction = document.getElementsByName('ccrAction');
508 ccrAction[0].value = 'viewccd';
509 var ccdRecipient = $("#ccd_send_to").val();
510 var raw = document.getElementsByName('raw');
511 raw[0].value = 'send '+ccdRecipient;
512 if(ccdRecipient=="") {
513 $("#ccd_send_message").html("<?php
514 echo htmlspecialchars(xl('Please enter a valid Direct Address above.'), ENT_QUOTES);?>");
515 $("#ccd_send_result").show();
516 } else {
517 $(".viewCCD_transmit").attr('disabled','disabled');
518 $("#ccd_send_message").html("<?php
519 echo htmlspecialchars(xl('Working... this may take a minute.'), ENT_QUOTES);?>");
520 $("#ccd_send_result").show();
521 var action=$("#ccr_form").attr('action');
522 $.post(action, {ccrAction:'viewccd',raw:'send '+ccdRecipient,requested_by:'user'},
523 function(data) {
524 if(data=="SUCCESS") {
525 $("#ccd_send_message").html("<?php
526 echo htmlspecialchars(xl('Your message was submitted for delivery to'), ENT_QUOTES);
527 ?> "+ccdRecipient);
528 $("#ccd_send_to").val("");
529 } else {
530 $("#ccd_send_message").html(data);
532 $(".viewCCD_transmit").removeAttr('disabled');
536 <?php } ?>
540 // select/deselect the Forms related to the selected Encounter
541 // (it ain't pretty code folks)
542 var SelectForms = function (selectedEncounter) {
543 if ($(selectedEncounter).attr("checked")) {
544 $(selectedEncounter).parent().children().each(function(i, obj) {
545 $(this).children().each(function(i, obj) {
546 $(this).attr("checked", "checked");
550 else {
551 $(selectedEncounter).parent().children().each(function(i, obj) {
552 $(this).children().each(function(i, obj) {
553 $(this).removeAttr("checked");
559 // When an issue is checked, auto-check all the related encounters and forms
560 function issueClick(issue) {
561 // do nothing when unchecked
562 if (! $(issue).attr("checked")) return;
564 $("#report_form :checkbox").each(function(i, obj) {
565 if ($(issue).val().indexOf('/' + $(this).val() + '/') >= 0) {
566 $(this).attr("checked", "checked");
572 </script>
574 </html>