CCR/CCD reporting module: added option to see the raw xml
[openemr.git] / interface / patient_file / report / patient_report.php
blob2da3cc3854f636fe110f6c1be8bb0a03f9eeff9f
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 ?>
45 <div id="ccr_report">
47 <form name='ccr_form' id='ccr_form' method='post' action='../../../ccr/createCCR.php'>
48 <span class='title'><?php xl('Continuity of Care Record (CCR)','e'); ?></span>&nbsp;&nbsp;
49 <br/><br/>
50 <input type='hidden' name='ccrAction'>
51 <input type='hidden' name='raw'>
52 <input type="button" class="generateCCR" value="<?php xl('Formatted Report','e'); ?>" />
53 <input type="button" class="generateCCR_raw" value="<?php xl('Raw Report','e'); ?>" />
54 <hr/>
55 <span class='title'><?php xl('Continuity of Care Document (CCD)','e'); ?></span>&nbsp;&nbsp;
56 <br/><br/>
57 <input type="button" class="viewCCD" value="<?php xl('Formatted Report','e'); ?>" />
58 <input type="button" class="viewCCD_raw" value="<?php xl('Raw Report','e'); ?>" />
60 </form>
61 <hr/>
63 </div>
64 <?php } // end CCR/CCD reporting options ?>
66 <form name='report_form' id="report_form" method='post' action='custom_report.php'>
69 <span class='title'><?php xl('Patient Report','e'); ?></span>&nbsp;&nbsp;
71 <!--
72 <a class="link_submit" href="full_report.php" onclick="top.restoreSession()">
73 [<?php xl('View Comprehensive Patient Report','e'); ?>]</a>
74 -->
75 <a class="link_submit" href="#" onclick="return checkAll(true)"><?php xl('Check All','e'); ?></a>
77 <a class="link_submit" href="#" onclick="return checkAll(false)"><?php xl('Clear All','e'); ?></a>
78 <p>
80 <table class="includes">
81 <tr>
82 <td class='text'>
83 <input type='checkbox' name='include_demographics' id='include_demographics' value="demographics" checked><?php xl('Demographics','e'); ?><br>
84 <?php if (acl_check('patients', 'med')): ?>
85 <input type='checkbox' name='include_history' id='include_history' value="history"><?php xl(' History','e'); ?><br>
86 <?php endif; ?>
87 <!--
88 <input type='checkbox' name='include_employer' id='include_employer' value="employer"><?php xl('Employer','e'); ?><br>
89 -->
90 <input type='checkbox' name='include_insurance' id='include_insurance' value="insurance"><?php xl('Insurance','e'); ?><br>
91 <input type='checkbox' name='include_billing' id='include_billing' value="billing"
92 <?php if (!$GLOBALS['simplified_demographics']) echo 'checked'; ?>><?php xl('Billing','e'); ?><br>
93 </td>
94 <td class='text'>
95 <!--
96 <input type='checkbox' name='include_allergies' id='include_allergies' value="allergies">Allergies<br>
97 <input type='checkbox' name='include_medications' id='include_medications' value="medications">Medications<br>
98 -->
99 <input type='checkbox' name='include_immunizations' id='include_immunizations' value="immunizations"><?php xl('Immunizations','e'); ?><br>
100 <!--
101 <input type='checkbox' name='include_medical_problems' id='include_medical_problems' value="medical_problems">Medical Problems<br>
103 <input type='checkbox' name='include_notes' id='include_notes' value="notes"><?php xl('Patient Notes','e'); ?><br>
104 <input type='checkbox' name='include_transactions' id='include_transactions' value="transactions"><?php xl('Transactions','e'); ?><br>
105 <input type='checkbox' name='include_batchcom' id='include_batchcom' value="batchcom"><?php xl('Communications','e'); ?><br>
106 </td>
107 </tr>
108 </table>
110 <br>
111 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
112 <br>
114 <!-- old ccr button position -->
115 <hr/>
117 <table class="issues_encounters_forms">
118 <tr>
120 <!-- Issues -->
121 <td class='text'>
122 <div class="issues">
123 <span class='bold'><?php xl('Issues','e'); ?>:</span>
124 <br>
125 <br>
127 <?php if (! acl_check('patients', 'med')): ?>
128 <br>(Issues not authorized)
130 <?php else: ?>
131 <table>
133 <?php
134 // get issues
135 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
136 "ORDER BY type, begdate");
137 $lasttype = "";
138 while ($prow = sqlFetchArray($pres)) {
139 if ($lasttype != $prow['type']) {
140 $lasttype = $prow['type'];
142 /****
143 $disptype = $lasttype;
144 switch ($lasttype) {
145 case "allergy" : $disptype = "Allergies" ; break;
146 case "problem" :
147 case "medical_problem": $disptype = "Medical Problems"; break;
148 case "medication" : $disptype = "Medications" ; break;
149 case "surgery" : $disptype = "Surgeries" ; break;
151 ****/
152 $disptype = $ISSUE_TYPES[$lasttype][0];
154 echo " <tr>\n";
155 echo " <td colspan='4' class='bold'><b>$disptype</b></td>\n";
156 echo " </tr>\n";
158 $rowid = $prow['id'];
159 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
161 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
162 "pid = '$pid' AND list_id = '$rowid'");
164 echo " <tr class='text'>\n";
165 echo " <td>&nbsp;</td>\n";
166 echo " <td>";
167 echo "<input type='checkbox' name='issue_$rowid' id='issue_$rowid' class='issuecheckbox' value='/";
168 while ($ierow = sqlFetchArray($ieres)) {
169 echo $ierow['encounter'] . "/";
171 echo "' />$disptitle</td>\n";
172 echo " <td>" . $prow['begdate'];
174 if ($prow['enddate']) { echo " - " . $prow['enddate']; }
175 else { echo " Active"; }
177 echo "</td>\n";
178 echo "</tr>\n";
181 </table>
183 <?php endif; // end of Issues output ?>
185 </div> <!-- end issues DIV -->
186 </td>
188 <!-- Encounters and Forms -->
190 <td class='text'>
191 <div class='encounters'>
192 <span class='bold'><?php xl('Encounters &amp; Forms','e'); ?>:</span>
193 <br><br>
195 <?php if (!($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)): ?>
196 (Encounters not authorized)
197 <?php else: ?>
199 <?php
201 $isfirst = 1;
202 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
203 "forms.formdir, forms.date AS fdate, form_encounter.date " .
204 ",form_encounter.reason ".
205 "FROM forms, form_encounter WHERE " .
206 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
207 "form_encounter.encounter = forms.encounter " .
208 " AND forms.deleted=0 ". // --JRM--
209 "ORDER BY form_encounter.date DESC, fdate ASC");
210 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
211 $html_strings = array();
212 $registry_form_name = array();
213 while($result2 = sqlFetchArray($res2)) {
214 array_push($registry_form_name,trim($result2['name']));
216 while($result = sqlFetchArray($res)) {
217 if ($result{"form_name"} == "New Patient Encounter") {
218 if ($isfirst == 0) {
219 foreach($registry_form_name as $var) {
220 if ($toprint = $html_strings[$var]) {
221 foreach($toprint as $var) {print $var;}
224 $html_strings = array();
225 echo "</div>\n"; // end DIV encounter_forms
226 echo "</div>\n\n"; //end DIV encounter_data
227 echo "<br>";
229 $isfirst = 0;
230 echo "<div class='encounter_data'>\n";
231 echo "<input type=checkbox ".
232 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
233 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
234 " value='" . $result{"encounter"} . "'" .
235 " class='encounter'".
236 " >";
238 // show encounter reason, not just 'New Encounter'
239 // trim to a reasonable length for display purposes --cfapress
240 $maxReasonLength = 20;
241 if (strlen($result["reason"]) > $maxReasonLength) {
242 $result['reason'] = substr($result['reason'], 0, $maxReasonLength) . " ... ";
245 echo $result{"reason"}.
246 " (" . date("Y-m-d",strtotime($result{"date"})) .
247 ")\n";
248 echo "<div class='encounter_forms'>\n";
250 else {
251 $form_name = trim($result{"form_name"});
252 //if form name is not in registry, look for the closest match by
253 // finding a registry name which is at the start of the form name.
254 //this is to allow for forms to put additional helpful information
255 //in the database in the same string as their form name after the name
256 $form_name_found_flag = 0;
257 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
258 // if the form does not match precisely with any names in the registry, now see if any front partial matches
259 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
260 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
262 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
263 array_push($html_strings[$form_name], "<input type='checkbox' ".
264 " name='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
265 " id='" . $result{"formdir"} . "_" . $result{"form_id"} . "'".
266 " value='" . $result{"encounter"} . "'" .
267 " class='encounter_form' ".
268 ">" . xl_form_title($result{"form_name"}) . "<br>\n");
271 foreach($registry_form_name as $var) {
272 if ($toprint = $html_strings[$var]) {
273 foreach($toprint as $var) {print $var;}
278 <?php endif; ?>
280 </div> <!-- end encounters DIV -->
281 </td>
282 </tr>
283 </table>
284 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
286 <hr/>
288 <span class="bold"><?php xl('Documents','e'); ?></span>:<br>
289 <ul>
290 <?php
291 // show available documents
292 $db = $GLOBALS['adodb']['db'];
293 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
294 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
295 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
296 "d.foreign_id = " . $db->qstr($pid);
297 $result = $db->Execute($sql);
298 if ($db->ErrorMsg()) echo $db->ErrorMsg();
299 while ($result && !$result->EOF) {
300 echo "<li class='bold'>";
301 echo '<input type="checkbox" name="documents[]" value="' .
302 $result->fields['id'] . '">';
303 echo '&nbsp;&nbsp;<i>' . xl_document_category($result->fields['name']) . "</i>";
304 echo '&nbsp;&nbsp;' . xl('Name') . ': <i>' . basename($result->fields['url']) . "</i>";
305 echo '</li>';
306 $result->MoveNext();
309 </ul>
310 </form>
312 <input type="button" class="genreport" value="<?php xl('Generate Report','e'); ?>" />
314 </div> <!-- close patient_reports DIV -->
315 </body>
317 <script language="javascript">
319 // jQuery stuff to make the page a little easier to use
320 $(document).ready(function(){
321 $(".genreport").click(function() { top.restoreSession(); $("#report_form").submit(); });
322 $("#genfullreport").click(function() { location.href='<?php echo "$rootdir/patient_file/encounter/$returnurl";?>'; });
323 //$("#printform").click(function() { PrintForm(); });
324 $(".issuecheckbox").click(function() { issueClick(this); });
326 // check/uncheck all Forms of an encounter
327 $(".encounter").click(function() { SelectForms($(this)); });
330 $(document).ready(
331 function(){
332 $(".generateCCR").click(
333 function() {
334 //alert('in generateCCR');
335 var ccrAction = document.getElementsByName('ccrAction');
336 ccrAction[0].value = 'generate';
337 var raw = document.getElementsByName('raw');
338 raw[0].value = 'no';
339 top.restoreSession();
340 $("#ccr_form").submit();
342 $(".generateCCR_raw").click(
343 function() {
344 //alert('in generateCCR');
345 var ccrAction = document.getElementsByName('ccrAction');
346 ccrAction[0].value = 'generate';
347 var raw = document.getElementsByName('raw');
348 raw[0].value = 'yes';
349 top.restoreSession();
350 $("#ccr_form").submit();
352 $(".viewCCD").click(
353 function() {
354 //alert('in viewCCD');
355 var ccrAction = document.getElementsByName('ccrAction');
356 ccrAction[0].value = 'viewccd';
357 var raw = document.getElementsByName('raw');
358 raw[0].value = 'no';
359 top.restoreSession();
360 $("#ccr_form").submit();
362 $(".viewCCD_raw").click(
363 function() {
364 //alert('in viewCCD');
365 var ccrAction = document.getElementsByName('ccrAction');
366 ccrAction[0].value = 'viewccd';
367 var raw = document.getElementsByName('raw');
368 raw[0].value = 'yes';
369 top.restoreSession();
370 $("#ccr_form").submit();
374 // select/deselect the Forms related to the selected Encounter
375 // (it ain't pretty code folks)
376 var SelectForms = function (selectedEncounter) {
377 if ($(selectedEncounter).attr("checked")) {
378 $(selectedEncounter).parent().children().each(function(i, obj) {
379 $(this).children().each(function(i, obj) {
380 $(this).attr("checked", "checked");
384 else {
385 $(selectedEncounter).parent().children().each(function(i, obj) {
386 $(this).children().each(function(i, obj) {
387 $(this).removeAttr("checked");
393 // When an issue is checked, auto-check all the related encounters and forms
394 function issueClick(issue) {
395 // do nothing when unchecked
396 if (! $(issue).attr("checked")) return;
398 $("#report_form :checkbox").each(function(i, obj) {
399 if ($(issue).val().indexOf('/' + $(this).val() + '/') >= 0) {
400 $(this).attr("checked", "checked");
406 </script>
408 </html>