Temporarily disabled CCR/CCD reporting in production release since not yet functional
[openemr.git] / interface / patient_file / report / patient_report.php
blobb0d775d06de84cef6f1666d14d93d6009f443d68
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">
24 <!-- include jQuery support -->
25 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
27 <script language='JavaScript'>
29 function checkAll(check) {
30 var f = document.forms['report_form'];
31 for (var i = 0; i < f.elements.length; ++i) {
32 if (f.elements[i].type == 'checkbox') f.elements[i].checked = check;
34 return false;
37 </script>
39 </head>
41 <body class="body_top">
42 <div id="patient_reports"> <!-- large outer DIV -->
44 <?php if ( $GLOBALS['activate_ccr_ccd_report'] ) { // show CCR/CCD reporting options ?>
46 <!-- Disabled CCR/CCD reporting in production release until functional
47 <div id="ccr_report">
49 <form name='ccr_form' id='ccr_form' method='post' action='../../../ccr/createCCR.php'>
50 <span class='title'><?php xl('Continuity of Care Record (CCR)','e'); ?></span>&nbsp;&nbsp;
51 <br/><br/>
52 <input type='hidden' name='ccrAction'>
53 <input type='hidden' name='raw'>
54 <input type="button" class="generateCCR" value="<?php xl('Formatted Report','e'); ?>" />
55 <input type="button" class="generateCCR_raw" value="<?php xl('Raw Report','e'); ?>" />
56 <hr/>
57 <span class='title'><?php xl('Continuity of Care Document (CCD)','e'); ?></span>&nbsp;&nbsp;
58 <br/><br/>
59 <input type="button" class="viewCCD" value="<?php xl('Formatted Report','e'); ?>" />
60 <input type="button" class="viewCCD_raw" value="<?php xl('Raw Report','e'); ?>" />
62 </form>
63 <hr/>
65 </div>
66 Disabled CCR/CCD reporting in production release until functional -->
68 <?php } // end CCR/CCD reporting options ?>
70 <form name='report_form' id="report_form" method='post' action='custom_report.php'>
73 <span class='title'><?php xl('Patient Report','e'); ?></span>&nbsp;&nbsp;
75 <!--
76 <a class="link_submit" href="full_report.php" onclick="top.restoreSession()">
77 [<?php xl('View Comprehensive Patient Report','e'); ?>]</a>
78 -->
79 <a class="link_submit" href="#" onclick="return checkAll(true)"><?php xl('Check All','e'); ?></a>
81 <a class="link_submit" href="#" onclick="return checkAll(false)"><?php xl('Clear All','e'); ?></a>
82 <p>
84 <table class="includes">
85 <tr>
86 <td class='text'>
87 <input type='checkbox' name='include_demographics' id='include_demographics' value="demographics" checked><?php xl('Demographics','e'); ?><br>
88 <?php if (acl_check('patients', 'med')): ?>
89 <input type='checkbox' name='include_history' id='include_history' value="history"><?php xl(' History','e'); ?><br>
90 <?php endif; ?>
91 <!--
92 <input type='checkbox' name='include_employer' id='include_employer' value="employer"><?php xl('Employer','e'); ?><br>
93 -->
94 <input type='checkbox' name='include_insurance' id='include_insurance' value="insurance"><?php xl('Insurance','e'); ?><br>
95 <input type='checkbox' name='include_billing' id='include_billing' value="billing"
96 <?php if (!$GLOBALS['simplified_demographics']) echo 'checked'; ?>><?php xl('Billing','e'); ?><br>
97 </td>
98 <td class='text'>
99 <!--
100 <input type='checkbox' name='include_allergies' id='include_allergies' value="allergies">Allergies<br>
101 <input type='checkbox' name='include_medications' id='include_medications' value="medications">Medications<br>
103 <input type='checkbox' name='include_immunizations' id='include_immunizations' value="immunizations"><?php xl('Immunizations','e'); ?><br>
104 <!--
105 <input type='checkbox' name='include_medical_problems' id='include_medical_problems' value="medical_problems">Medical Problems<br>
107 <input type='checkbox' name='include_notes' id='include_notes' value="notes"><?php xl('Patient Notes','e'); ?><br>
108 <input type='checkbox' name='include_transactions' id='include_transactions' value="transactions"><?php xl('Transactions','e'); ?><br>
109 <input type='checkbox' name='include_batchcom' id='include_batchcom' value="batchcom"><?php xl('Communications','e'); ?><br>
110 </td>
111 </tr>
112 </table>
114 <br>
115 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
116 <br>
118 <!-- old ccr button position -->
119 <hr/>
121 <table class="issues_encounters_forms">
122 <tr>
124 <!-- Issues -->
125 <td class='text'>
126 <div class="issues">
127 <span class='bold'><?php xl('Issues','e'); ?>:</span>
128 <br>
129 <br>
131 <?php if (! acl_check('patients', 'med')): ?>
132 <br>(Issues not authorized)
134 <?php else: ?>
135 <table>
137 <?php
138 // get issues
139 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
140 "ORDER BY type, begdate");
141 $lasttype = "";
142 while ($prow = sqlFetchArray($pres)) {
143 if ($lasttype != $prow['type']) {
144 $lasttype = $prow['type'];
146 /****
147 $disptype = $lasttype;
148 switch ($lasttype) {
149 case "allergy" : $disptype = "Allergies" ; break;
150 case "problem" :
151 case "medical_problem": $disptype = "Medical Problems"; break;
152 case "medication" : $disptype = "Medications" ; break;
153 case "surgery" : $disptype = "Surgeries" ; break;
155 ****/
156 $disptype = $ISSUE_TYPES[$lasttype][0];
158 echo " <tr>\n";
159 echo " <td colspan='4' class='bold'><b>$disptype</b></td>\n";
160 echo " </tr>\n";
162 $rowid = $prow['id'];
163 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
165 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
166 "pid = '$pid' AND list_id = '$rowid'");
168 echo " <tr class='text'>\n";
169 echo " <td>&nbsp;</td>\n";
170 echo " <td>";
171 echo "<input type='checkbox' name='issue_$rowid' id='issue_$rowid' class='issuecheckbox' value='/";
172 while ($ierow = sqlFetchArray($ieres)) {
173 echo $ierow['encounter'] . "/";
175 echo "' />$disptitle</td>\n";
176 echo " <td>" . $prow['begdate'];
178 if ($prow['enddate']) { echo " - " . $prow['enddate']; }
179 else { echo " Active"; }
181 echo "</td>\n";
182 echo "</tr>\n";
185 </table>
187 <?php endif; // end of Issues output ?>
189 </div> <!-- end issues DIV -->
190 </td>
192 <!-- Encounters and Forms -->
194 <td class='text'>
195 <div class='encounters'>
196 <span class='bold'><?php xl('Encounters &amp; Forms','e'); ?>:</span>
197 <br><br>
199 <?php if (!($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)): ?>
200 (Encounters not authorized)
201 <?php else: ?>
203 <?php
205 $isfirst = 1;
206 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
207 "forms.formdir, forms.date AS fdate, form_encounter.date " .
208 ",form_encounter.reason ".
209 "FROM forms, form_encounter WHERE " .
210 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
211 "form_encounter.encounter = forms.encounter " .
212 " AND forms.deleted=0 ". // --JRM--
213 "ORDER BY form_encounter.date DESC, fdate ASC");
214 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
215 $html_strings = array();
216 $registry_form_name = array();
217 while($result2 = sqlFetchArray($res2)) {
218 array_push($registry_form_name,trim($result2['name']));
220 while($result = sqlFetchArray($res)) {
221 if ($result{"form_name"} == "New Patient Encounter") {
222 if ($isfirst == 0) {
223 foreach($registry_form_name as $var) {
224 if ($toprint = $html_strings[$var]) {
225 foreach($toprint as $var) {print $var;}
228 $html_strings = array();
229 echo "</div>\n"; // end DIV encounter_forms
230 echo "</div>\n\n"; //end DIV encounter_data
231 echo "<br>";
233 $isfirst = 0;
234 echo "<div class='encounter_data'>\n";
235 echo "<input type=checkbox ".
236 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
237 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
238 " value='" . $result{"encounter"} . "'" .
239 " class='encounter'".
240 " >";
242 // show encounter reason, not just 'New Encounter'
243 // trim to a reasonable length for display purposes --cfapress
244 $maxReasonLength = 20;
245 if (strlen($result["reason"]) > $maxReasonLength) {
246 $result['reason'] = substr($result['reason'], 0, $maxReasonLength) . " ... ";
249 echo $result{"reason"}.
250 " (" . date("Y-m-d",strtotime($result{"date"})) .
251 ")\n";
252 echo "<div class='encounter_forms'>\n";
254 else {
255 $form_name = trim($result{"form_name"});
256 //if form name is not in registry, look for the closest match by
257 // finding a registry name which is at the start of the form name.
258 //this is to allow for forms to put additional helpful information
259 //in the database in the same string as their form name after the name
260 $form_name_found_flag = 0;
261 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
262 // if the form does not match precisely with any names in the registry, now see if any front partial matches
263 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
264 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
266 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
267 array_push($html_strings[$form_name], "<input type='checkbox' ".
268 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
269 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
270 " value='" . $result{"encounter"} . "'" .
271 " class='encounter_form' ".
272 ">" . xl_form_title($result{"form_name"}) . "<br>\n");
275 foreach($registry_form_name as $var) {
276 if ($toprint = $html_strings[$var]) {
277 foreach($toprint as $var) {print $var;}
282 <?php endif; ?>
284 </div> <!-- end encounters DIV -->
285 </td>
286 </tr>
287 </table>
288 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
290 <hr/>
292 <span class="bold"><?php xl('Documents','e'); ?></span>:<br>
293 <ul>
294 <?php
295 // show available documents
296 $db = $GLOBALS['adodb']['db'];
297 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
298 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
299 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
300 "d.foreign_id = " . $db->qstr($pid);
301 $result = $db->Execute($sql);
302 if ($db->ErrorMsg()) echo $db->ErrorMsg();
303 while ($result && !$result->EOF) {
304 echo "<li class='bold'>";
305 echo '<input type="checkbox" name="documents[]" value="' .
306 $result->fields['id'] . '">';
307 echo '&nbsp;&nbsp;<i>' . xl_document_category($result->fields['name']) . "</i>";
308 echo '&nbsp;&nbsp;' . xl('Name') . ': <i>' . basename($result->fields['url']) . "</i>";
309 echo '</li>';
310 $result->MoveNext();
313 </ul>
314 </form>
316 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
318 </div> <!-- close patient_reports DIV -->
319 </body>
321 <script language="javascript">
323 // jQuery stuff to make the page a little easier to use
324 $(document).ready(function(){
325 $(".genreport").click(function() { top.restoreSession(); $("#report_form").submit(); });
326 $("#genfullreport").click(function() { location.href='<?php echo "$rootdir/patient_file/encounter/$returnurl";?>'; });
327 //$("#printform").click(function() { PrintForm(); });
328 $(".issuecheckbox").click(function() { issueClick(this); });
330 // check/uncheck all Forms of an encounter
331 $(".encounter").click(function() { SelectForms($(this)); });
334 $(document).ready(
335 function(){
336 $(".generateCCR").click(
337 function() {
338 //alert('in generateCCR');
339 var ccrAction = document.getElementsByName('ccrAction');
340 ccrAction[0].value = 'generate';
341 var raw = document.getElementsByName('raw');
342 raw[0].value = 'no';
343 top.restoreSession();
344 $("#ccr_form").submit();
346 $(".generateCCR_raw").click(
347 function() {
348 //alert('in generateCCR');
349 var ccrAction = document.getElementsByName('ccrAction');
350 ccrAction[0].value = 'generate';
351 var raw = document.getElementsByName('raw');
352 raw[0].value = 'yes';
353 top.restoreSession();
354 $("#ccr_form").submit();
356 $(".viewCCD").click(
357 function() {
358 //alert('in viewCCD');
359 var ccrAction = document.getElementsByName('ccrAction');
360 ccrAction[0].value = 'viewccd';
361 var raw = document.getElementsByName('raw');
362 raw[0].value = 'no';
363 top.restoreSession();
364 $("#ccr_form").submit();
366 $(".viewCCD_raw").click(
367 function() {
368 //alert('in viewCCD');
369 var ccrAction = document.getElementsByName('ccrAction');
370 ccrAction[0].value = 'viewccd';
371 var raw = document.getElementsByName('raw');
372 raw[0].value = 'yes';
373 top.restoreSession();
374 $("#ccr_form").submit();
378 // select/deselect the Forms related to the selected Encounter
379 // (it ain't pretty code folks)
380 var SelectForms = function (selectedEncounter) {
381 if ($(selectedEncounter).attr("checked")) {
382 $(selectedEncounter).parent().children().each(function(i, obj) {
383 $(this).children().each(function(i, obj) {
384 $(this).attr("checked", "checked");
388 else {
389 $(selectedEncounter).parent().children().each(function(i, obj) {
390 $(this).children().each(function(i, obj) {
391 $(this).removeAttr("checked");
397 // When an issue is checked, auto-check all the related encounters and forms
398 function issueClick(issue) {
399 // do nothing when unchecked
400 if (! $(issue).attr("checked")) return;
402 $("#report_form :checkbox").each(function(i, obj) {
403 if ($(issue).val().indexOf('/' + $(this).val() + '/') >= 0) {
404 $(this).attr("checked", "checked");
410 </script>
412 </html>