adapting new demographics and history layouts to the patient report
[openemr.git] / interface / patient_file / report / patient_report.php
blobb54d1b283d6ab52ec8e9745c9cce4e064ed3b884
1 <?php
2 include_once("../../globals.php");
3 include_once("$srcdir/lists.inc");
4 ?>
5 <html>
6 <head>
7 <?php html_header_show();?>
8 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
9 <script language='JavaScript'>
10 // When an issue is checked, auto-check all the related encounters.
11 function issueClick(icb) {
12 if (! icb.checked) return;
13 var f = document.forms[0];
14 var nel = f.elements.length;
15 for (var i = 0; i < nel; ++i) {
16 var ecb = f.elements[i];
17 if (ecb.name == 'documents[]' ||
18 ecb.name.indexOf('include_') == 0 ||
19 ecb.name.indexOf('issue_' ) == 0)
20 continue;
21 if (icb.value.indexOf('/' + ecb.value + '/') >= 0) {
22 ecb.checked = true;
26 </script>
27 </head>
29 <body class="body_top">
31 <font class='title'><?php xl('Patient Report','e'); ?></font><br>
33 <a class="link_submit" href="full_report.php" onclick="top.restoreSession()">
34 [<?php xl('View Comprehensive Patient Report','e'); ?>]</a>
36 <form name='report_form' method='post' action='custom_report.php'>
38 <table>
39 <tr>
40 <td class='text' valign='top'>
41 <input type='checkbox' name='include_demographics' value="demographics" checked><?php xl('Demographics','e'); ?><br>
42 <input type='checkbox' name='include_history' value="history"><?php xl(' History','e'); ?><br>
43 <!--
44 <input type='checkbox' name='include_employer' value="employer"><?php xl('Employer','e'); ?><br>
45 -->
46 <input type='checkbox' name='include_insurance' value="insurance"><?php xl('Insurance','e'); ?><br>
47 <input type='checkbox' name='include_billing' value="billing" checked><?php xl('Billing','e'); ?><br>
48 </td>
49 <td class='text' valign='top'>
50 <!--
51 <input type='checkbox' name='include_allergies' value="allergies">Allergies<br>
52 <input type='checkbox' name='include_medications' value="medications">Medications<br>
53 -->
54 <input type='checkbox' name='include_immunizations' value="immunizations"><?php xl('Immunizations','e'); ?><br>
55 <!--
56 <input type='checkbox' name='include_medical_problems' value="medical_problems">Medical Problems<br>
57 -->
58 <input type='checkbox' name='include_notes' value="notes"><?php xl('Patient Notes','e'); ?><br>
59 <input type='checkbox' name='include_transactions' value="transactions"><?php xl('Transactions','e'); ?><br>
60 <input type='checkbox' name='include_batchcom' value="batchcom"><?php xl('Communications','e'); ?><br>
61 </td>
62 </tr>
63 </table>
65 <br>
66 <a href='javascript:top.restoreSession();document.report_form.submit()' class='link_submit'><?php xl('Generate Report','e'); ?></a>
67 <hr>
69 <table>
70 <tr>
72 <td valign='top' class='text'>
73 <span class='bold'><?php xl('Issues to Include in this Report','e'); ?>: &nbsp; &nbsp;</span>
74 <br>&nbsp;
75 <table cellpadding='1' cellspacing='2'>
76 <!--
77 <tr class='bold'>
78 <td>Type</td>
79 <td>Title</td>
80 <td>Begin</td>
81 <td>End &nbsp; &nbsp; &nbsp;</td>
82 </tr>
83 -->
84 <?php
85 // get issues
86 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
87 "ORDER BY type, begdate");
88 $lasttype = "";
89 while ($prow = sqlFetchArray($pres)) {
90 if ($lasttype != $prow['type']) {
91 $lasttype = $prow['type'];
93 /****
94 $disptype = $lasttype;
95 switch ($lasttype) {
96 case "allergy" : $disptype = "Allergies" ; break;
97 case "problem" :
98 case "medical_problem": $disptype = "Medical Problems"; break;
99 case "medication" : $disptype = "Medications" ; break;
100 case "surgery" : $disptype = "Surgeries" ; break;
102 ****/
103 $disptype = $ISSUE_TYPES[$lasttype][0];
105 echo " <tr>\n";
106 echo " <td valign='top' colspan='4' class='bold'><b>$disptype</b></td>\n";
107 echo " </tr>\n";
109 $rowid = $prow['id'];
110 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
112 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
113 "pid = '$pid' AND list_id = '$rowid'");
115 echo " <tr class='text'>\n";
116 echo " <td valign='top'>&nbsp;</td>\n";
117 echo " <td valign='top'>";
118 echo "<input type='checkbox' name='issue_$rowid' onclick='issueClick(this)' value='/";
119 while ($ierow = sqlFetchArray($ieres)) {
120 echo $ierow['encounter'] . "/";
122 echo "' />$disptitle</td>\n";
123 echo " <td valign='top'>" . $prow['begdate'];
124 if ($prow['enddate']) {
125 echo " - " . $prow['enddate'];
126 } else {
127 echo " Active";
129 echo " &nbsp; &nbsp; </td>\n";
130 echo " </tr>\n";
133 </table>
134 <br>
135 </td>
137 <td valign='top' class='text'>
138 <span class='bold'><?php xl('Encounter Forms to Include in this Report','e'); ?>:</span>
139 <br><br>
140 <?php
141 $isfirst = 1;
142 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
143 "forms.formdir, forms.date AS fdate, form_encounter.date " .
144 "FROM forms, form_encounter WHERE " .
145 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
146 "form_encounter.encounter = forms.encounter " .
147 "ORDER BY form_encounter.date DESC, fdate ASC");
148 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
149 $html_strings = array();
150 $registry_form_name = array();
151 while($result2 = sqlFetchArray($res2)) {
152 array_push($registry_form_name,trim($result2['name']));
154 while($result = sqlFetchArray($res)) {
155 if ($result{"form_name"} == "New Patient Encounter") {
156 if ($isfirst == 0) {
157 foreach($registry_form_name as $var) {
158 if ($toprint = $html_strings[$var]) {
159 {foreach($toprint as $var) {print $var;}}
162 $html_strings = array();
163 print "</blockquote>\n\n";
165 $isfirst = 0;
166 print "<input type=checkbox name='" . $result{"formdir"} . "_" .
167 $result{"form_id"} . "' value='" . $result{"encounter"} . "'";
168 print " >New Encounter" .
169 " (" . date("Y-m-d",strtotime($result{"date"})) .
170 ")<blockquote>\n";
172 else {
173 $form_name = trim($result{"form_name"});
174 //if form name is not in registry, look for the closest match by
175 // finding a registry name which is at the start of the form name.
176 //this is to allow for forms to put additional helpful information
177 //in the database in the same string as their form name after the name
178 $form_name_found_flag = 0;
179 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
180 // if the form does not match precisely with any names in the registry, now see if any front partial matches
181 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
182 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
184 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
185 array_push($html_strings[$form_name], "<input type='checkbox' name='"
186 . $result{"formdir"} . "_"
187 . $result{"form_id"} . "' value='" . $result{"encounter"} . "'"
188 . ">" . $result{"form_name"} . "<br>\n");
191 foreach($registry_form_name as $var) {
192 if ($toprint = $html_strings[$var]) {
193 {foreach($toprint as $var) {print $var;}}
197 </blockquote>
199 </td>
200 </tr>
201 </table>
203 <span class="bold"><?php xl('Documents','e'); ?></span>:<br>
204 <ul>
205 <?php
206 //code lists available images
207 $db = $GLOBALS['adodb']['db'];
208 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
209 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
210 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
211 "d.foreign_id = " . $db->qstr($pid);
212 $result = $db->Execute($sql);
213 echo $db->ErrorMsg();
214 while ($result && !$result->EOF) {
215 echo '<span class="bold"><input type="checkbox" name="documents[]" value="' .
216 $result->fields['id'] . '">';
217 echo '&nbsp;&nbsp;<i>' . $result->fields['name'] . "</i>";
218 echo '&nbsp;&nbsp;Name: <i>' . basename($result->fields['url']) . "</i>";
219 echo '</span><br>';
220 $result->MoveNext();
223 </ul>
224 </form>
226 <a href='javascript:top.restoreSession();document.report_form.submit()' class='link_submit'><?php xl('Generate Report','e'); ?></a>
228 </body>
229 </html>