Modified patient report for PDF output and faster inclusion of documents.
[openemr.git] / interface / patient_file / report / patient_report.php
blob4d997024ae493770cbc408b61b0d41ae3bd11b84
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_raw" value="<?php xl('Raw Report','e'); ?>" /> -->
121 </form>
122 <hr/>
123 <hr/>
125 </div>
126 <?php } // end CCR/CCD reporting options ?>
128 <form name='report_form' id="report_form" method='post' action='custom_report.php'>
131 <span class='title'><?php xl('Patient Report','e'); ?></span>&nbsp;&nbsp;
133 <!--
134 <a class="link_submit" href="full_report.php" onclick="top.restoreSession()">
135 [<?php xl('View Comprehensive Patient Report','e'); ?>]</a>
137 <a class="link_submit" href="#" onclick="return checkAll(true)"><?php xl('Check All','e'); ?></a>
139 <a class="link_submit" href="#" onclick="return checkAll(false)"><?php xl('Clear All','e'); ?></a>
142 <table class="includes">
143 <tr>
144 <td class='text'>
145 <input type='checkbox' name='include_demographics' id='include_demographics' value="demographics" checked><?php xl('Demographics','e'); ?><br>
146 <?php if (acl_check('patients', 'med')): ?>
147 <input type='checkbox' name='include_history' id='include_history' value="history"><?php xl(' History','e'); ?><br>
148 <?php endif; ?>
149 <!--
150 <input type='checkbox' name='include_employer' id='include_employer' value="employer"><?php xl('Employer','e'); ?><br>
152 <input type='checkbox' name='include_insurance' id='include_insurance' value="insurance"><?php xl('Insurance','e'); ?><br>
153 <input type='checkbox' name='include_billing' id='include_billing' value="billing"
154 <?php if (!$GLOBALS['simplified_demographics']) echo 'checked'; ?>><?php xl('Billing','e'); ?><br>
155 </td>
156 <td class='text'>
157 <!--
158 <input type='checkbox' name='include_allergies' id='include_allergies' value="allergies">Allergies<br>
159 <input type='checkbox' name='include_medications' id='include_medications' value="medications">Medications<br>
161 <input type='checkbox' name='include_immunizations' id='include_immunizations' value="immunizations"><?php xl('Immunizations','e'); ?><br>
162 <!--
163 <input type='checkbox' name='include_medical_problems' id='include_medical_problems' value="medical_problems">Medical Problems<br>
165 <input type='checkbox' name='include_notes' id='include_notes' value="notes"><?php xl('Patient Notes','e'); ?><br>
166 <input type='checkbox' name='include_transactions' id='include_transactions' value="transactions"><?php xl('Transactions','e'); ?><br>
167 <input type='checkbox' name='include_batchcom' id='include_batchcom' value="batchcom"><?php xl('Communications','e'); ?><br>
168 </td>
169 </tr>
170 </table>
172 <br>
173 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
174 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
175 <input type='hidden' name='pdf' value='0'>
176 <br>
178 <!-- old ccr button position -->
179 <hr/>
181 <table class="issues_encounters_forms">
182 <tr>
184 <!-- Issues -->
185 <td class='text'>
186 <div class="issues">
187 <span class='bold'><?php xl('Issues','e'); ?>:</span>
188 <br>
189 <br>
191 <?php if (! acl_check('patients', 'med')): ?>
192 <br>(Issues not authorized)
194 <?php else: ?>
195 <table>
197 <?php
198 // get issues
199 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
200 "ORDER BY type, begdate");
201 $lasttype = "";
202 while ($prow = sqlFetchArray($pres)) {
203 if ($lasttype != $prow['type']) {
204 $lasttype = $prow['type'];
206 /****
207 $disptype = $lasttype;
208 switch ($lasttype) {
209 case "allergy" : $disptype = "Allergies" ; break;
210 case "problem" :
211 case "medical_problem": $disptype = "Medical Problems"; break;
212 case "medication" : $disptype = "Medications" ; break;
213 case "surgery" : $disptype = "Surgeries" ; break;
215 ****/
216 $disptype = $ISSUE_TYPES[$lasttype][0];
218 echo " <tr>\n";
219 echo " <td colspan='4' class='bold'><b>$disptype</b></td>\n";
220 echo " </tr>\n";
222 $rowid = $prow['id'];
223 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
225 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
226 "pid = '$pid' AND list_id = '$rowid'");
228 echo " <tr class='text'>\n";
229 echo " <td>&nbsp;</td>\n";
230 echo " <td>";
231 echo "<input type='checkbox' name='issue_$rowid' id='issue_$rowid' class='issuecheckbox' value='/";
232 while ($ierow = sqlFetchArray($ieres)) {
233 echo $ierow['encounter'] . "/";
235 echo "' />$disptitle</td>\n";
236 echo " <td>" . $prow['begdate'];
238 if ($prow['enddate']) { echo " - " . $prow['enddate']; }
239 else { echo " Active"; }
241 echo "</td>\n";
242 echo "</tr>\n";
245 </table>
247 <?php endif; // end of Issues output ?>
249 </div> <!-- end issues DIV -->
250 </td>
252 <!-- Encounters and Forms -->
254 <td class='text'>
255 <div class='encounters'>
256 <span class='bold'><?php xl('Encounters &amp; Forms','e'); ?>:</span>
257 <br><br>
259 <?php if (!($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)): ?>
260 (Encounters not authorized)
261 <?php else: ?>
263 <?php
265 $isfirst = 1;
266 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
267 "forms.formdir, forms.date AS fdate, form_encounter.date " .
268 ",form_encounter.reason ".
269 "FROM forms, form_encounter WHERE " .
270 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
271 "form_encounter.encounter = forms.encounter " .
272 " AND forms.deleted=0 ". // --JRM--
273 "ORDER BY form_encounter.date DESC, fdate ASC");
274 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
275 $html_strings = array();
276 $registry_form_name = array();
277 while($result2 = sqlFetchArray($res2)) {
278 array_push($registry_form_name,trim($result2['name']));
280 while($result = sqlFetchArray($res)) {
281 if ($result{"form_name"} == "New Patient Encounter") {
282 if ($isfirst == 0) {
283 foreach($registry_form_name as $var) {
284 if ($toprint = $html_strings[$var]) {
285 foreach($toprint as $var) {print $var;}
288 $html_strings = array();
289 echo "</div>\n"; // end DIV encounter_forms
290 echo "</div>\n\n"; //end DIV encounter_data
291 echo "<br>";
293 $isfirst = 0;
294 echo "<div class='encounter_data'>\n";
295 echo "<input type=checkbox ".
296 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
297 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
298 " value='" . $result{"encounter"} . "'" .
299 " class='encounter'".
300 " >";
302 // show encounter reason, not just 'New Encounter'
303 // trim to a reasonable length for display purposes --cfapress
304 $maxReasonLength = 20;
305 if (strlen($result["reason"]) > $maxReasonLength) {
306 $result['reason'] = substr($result['reason'], 0, $maxReasonLength) . " ... ";
309 echo $result{"reason"}.
310 " (" . date("Y-m-d",strtotime($result{"date"})) .
311 ")\n";
312 echo "<div class='encounter_forms'>\n";
314 else {
315 $form_name = trim($result{"form_name"});
316 //if form name is not in registry, look for the closest match by
317 // finding a registry name which is at the start of the form name.
318 //this is to allow for forms to put additional helpful information
319 //in the database in the same string as their form name after the name
320 $form_name_found_flag = 0;
321 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
322 // if the form does not match precisely with any names in the registry, now see if any front partial matches
323 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
324 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
326 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
327 array_push($html_strings[$form_name], "<input type='checkbox' ".
328 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
329 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
330 " value='" . $result{"encounter"} . "'" .
331 " class='encounter_form' ".
332 ">" . xl_form_title($result{"form_name"}) . "<br>\n");
335 foreach($registry_form_name as $var) {
336 if ($toprint = $html_strings[$var]) {
337 foreach($toprint as $var) {print $var;}
342 <?php endif; ?>
344 </div> <!-- end encounters DIV -->
345 </td>
346 </tr>
347 </table>
348 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
349 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
351 <hr/>
353 <span class="bold"><?php xl('Documents','e'); ?></span>:<br>
354 <ul>
355 <?php
356 // show available documents
357 $db = $GLOBALS['adodb']['db'];
358 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
359 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
360 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
361 "d.foreign_id = " . $db->qstr($pid);
362 $result = $db->Execute($sql);
363 if ($db->ErrorMsg()) echo $db->ErrorMsg();
364 while ($result && !$result->EOF) {
365 echo "<li class='bold'>";
366 echo '<input type="checkbox" name="documents[]" value="' .
367 $result->fields['id'] . '">';
368 echo '&nbsp;&nbsp;<i>' . xl_document_category($result->fields['name']) . "</i>";
369 echo '&nbsp;&nbsp;' . xl('Name') . ': <i>' . basename($result->fields['url']) . "</i>";
370 echo '</li>';
371 $result->MoveNext();
374 </ul>
375 </form>
377 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />&nbsp;
378 <input type="button" class="genpdfrep" value="<?php xl('Download PDF','e'); ?>" />
380 </div> <!-- close patient_reports DIV -->
381 </body>
383 <script language="javascript">
385 // jQuery stuff to make the page a little easier to use
386 $(document).ready(function(){
387 $(".genreport").click(function() { top.restoreSession(); document.report_form.pdf.value = 0; $("#report_form").submit(); });
388 $(".genpdfrep").click(function() { top.restoreSession(); document.report_form.pdf.value = 1; $("#report_form").submit(); });
389 $("#genfullreport").click(function() { location.href='<?php echo "$rootdir/patient_file/encounter/$returnurl";?>'; });
390 //$("#printform").click(function() { PrintForm(); });
391 $(".issuecheckbox").click(function() { issueClick(this); });
393 // check/uncheck all Forms of an encounter
394 $(".encounter").click(function() { SelectForms($(this)); });
396 $(".generateCCR").click(
397 function() {
398 if(document.getElementById('show_date').checked == true){
399 if(document.getElementById('Start').value == '' || document.getElementById('End').value == ''){
400 alert('<?php echo addslashes( xl('Please select a start date and end date')) ?>');
401 return false;
404 var ccrAction = document.getElementsByName('ccrAction');
405 ccrAction[0].value = 'generate';
406 var raw = document.getElementsByName('raw');
407 raw[0].value = 'no';
408 top.restoreSession();
409 ccr_form.setAttribute("target", "_blank");
410 $("#ccr_form").submit();
411 ccr_form.setAttribute("target", "");
413 $(".generateCCR_raw").click(
414 function() {
415 var ccrAction = document.getElementsByName('ccrAction');
416 ccrAction[0].value = 'generate';
417 var raw = document.getElementsByName('raw');
418 raw[0].value = 'yes';
419 top.restoreSession();
420 ccr_form.setAttribute("target", "_blank");
421 $("#ccr_form").submit();
422 ccr_form.setAttribute("target", "");
424 $(".generateCCR_download_h").click(
425 function() {
426 var ccrAction = document.getElementsByName('ccrAction');
427 ccrAction[0].value = 'generate';
428 var raw = document.getElementsByName('raw');
429 raw[0].value = 'hybrid';
430 top.restoreSession();
431 $("#ccr_form").submit();
433 $(".generateCCR_download_p").click(
434 function() {
435 if(document.getElementById('show_date').checked == true){
436 if(document.getElementById('Start').value == '' || document.getElementById('End').value == ''){
437 alert('<?php echo addslashes( xl('Please select a start date and end date')) ?>');
438 return false;
441 var ccrAction = document.getElementsByName('ccrAction');
442 ccrAction[0].value = 'generate';
443 var raw = document.getElementsByName('raw');
444 raw[0].value = 'pure';
445 top.restoreSession();
446 $("#ccr_form").submit();
448 $(".viewCCD").click(
449 function() {
450 var ccrAction = document.getElementsByName('ccrAction');
451 ccrAction[0].value = 'viewccd';
452 var raw = document.getElementsByName('raw');
453 raw[0].value = 'no';
454 top.restoreSession();
455 ccr_form.setAttribute("target", "_blank");
456 $("#ccr_form").submit();
457 ccr_form.setAttribute("target", "");
459 $(".viewCCD_raw").click(
460 function() {
461 var ccrAction = document.getElementsByName('ccrAction');
462 ccrAction[0].value = 'viewccd';
463 var raw = document.getElementsByName('raw');
464 raw[0].value = 'yes';
465 top.restoreSession();
466 ccr_form.setAttribute("target", "_blank");
467 $("#ccr_form").submit();
468 ccr_form.setAttribute("target", "");
472 // select/deselect the Forms related to the selected Encounter
473 // (it ain't pretty code folks)
474 var SelectForms = function (selectedEncounter) {
475 if ($(selectedEncounter).attr("checked")) {
476 $(selectedEncounter).parent().children().each(function(i, obj) {
477 $(this).children().each(function(i, obj) {
478 $(this).attr("checked", "checked");
482 else {
483 $(selectedEncounter).parent().children().each(function(i, obj) {
484 $(this).children().each(function(i, obj) {
485 $(this).removeAttr("checked");
491 // When an issue is checked, auto-check all the related encounters and forms
492 function issueClick(issue) {
493 // do nothing when unchecked
494 if (! $(issue).attr("checked")) return;
496 $("#report_form :checkbox").each(function(i, obj) {
497 if ($(issue).val().indexOf('/' + $(this).val() + '/') >= 0) {
498 $(this).attr("checked", "checked");
504 </script>
506 </html>