Fixed bug where forms where not listed under the correct encounter.
[openemr.git] / interface / patient_file / report / patient_report.php
blob39f1347a22a946c903d171f075cbf3fc6eb59dc0
1 <?
2 include_once("../../globals.php");
3 include_once("$srcdir/lists.inc");
4 ?>
5 <html>
6 <head>
7 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
8 <script language='JavaScript'>
9 // When an issue is checked, auto-check all the related encounters.
10 function issueClick(icb) {
11 if (! icb.checked) return;
12 var f = document.forms[0];
13 var nel = f.elements.length;
14 for (var i = 0; i < nel; ++i) {
15 var ecb = f.elements[i];
16 if (ecb.name == 'documents[]' ||
17 ecb.name.indexOf('include_') == 0 ||
18 ecb.name.indexOf('issue_' ) == 0)
19 continue;
20 if (icb.value.indexOf('/' + ecb.value + '/') >= 0) {
21 ecb.checked = true;
25 </script>
26 </head>
28 <body <?echo $top_bg_line;?> topmargin='0' rightmargin='0' leftmargin='2'
29 bottommargin='0' marginwidth='2' marginheight='0'>
31 <font class='title'><? xl('Patient Report','e'); ?></font><br>
33 <a class="link_submit" href="full_report.php">[<? xl('View Comprehensive Patient Report','e'); ?>]</a>
35 <form name='report_form' method='post' action='custom_report.php'>
37 <table>
38 <tr>
39 <td class='text' valign='top'>
40 <input type='checkbox' name='include_demographics' value="demographics" checked><? xl('Demographics','e'); ?><br>
41 <input type='checkbox' name='include_history' value="history"><? xl(' History','e'); ?><br>
42 <input type='checkbox' name='include_employer' value="employer"><? xl('Employer','e'); ?><br>
43 <input type='checkbox' name='include_insurance' value="insurance"><? xl('Insurance','e'); ?><br>
44 <input type='checkbox' name='include_billing' value="billing" checked><? xl('Billing','e'); ?><br>
45 </td>
46 <td class='text' valign='top'>
47 <!--
48 <input type='checkbox' name='include_allergies' value="allergies">Allergies<br>
49 <input type='checkbox' name='include_medications' value="medications">Medications<br>
50 -->
51 <input type='checkbox' name='include_immunizations' value="immunizations"><? xl('Immunizations','e'); ?><br>
52 <!--
53 <input type='checkbox' name='include_medical_problems' value="medical_problems">Medical Problems<br>
54 -->
55 <input type='checkbox' name='include_notes' value="notes"><? xl('Patient Notes','e'); ?><br>
56 <input type='checkbox' name='include_transactions' value="transactions"><? xl('Transactions','e'); ?><br>
57 <input type='checkbox' name='include_batchcom' value="batchcom"><? xl('Communications','e'); ?><br>
58 </td>
59 </tr>
60 </table>
62 <br>
63 <a href='javascript:document.report_form.submit()' class='link_submit'><? xl('Generate Report','e'); ?></a>
64 <hr>
66 <table>
67 <tr>
69 <td valign='top' class='text'>
70 <span class='bold'><? xl('Issues to Include in this Report','e'); ?>: &nbsp; &nbsp;</span>
71 <br>&nbsp;
72 <table cellpadding='1' cellspacing='2'>
73 <!--
74 <tr class='bold'>
75 <td>Type</td>
76 <td>Title</td>
77 <td>Begin</td>
78 <td>End &nbsp; &nbsp; &nbsp;</td>
79 </tr>
80 -->
82 // get issues
83 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
84 "ORDER BY type, begdate");
85 $lasttype = "";
86 while ($prow = sqlFetchArray($pres)) {
87 if ($lasttype != $prow['type']) {
88 $lasttype = $prow['type'];
90 /****
91 $disptype = $lasttype;
92 switch ($lasttype) {
93 case "allergy" : $disptype = "Allergies" ; break;
94 case "problem" :
95 case "medical_problem": $disptype = "Medical Problems"; break;
96 case "medication" : $disptype = "Medications" ; break;
97 case "surgery" : $disptype = "Surgeries" ; break;
99 ****/
100 $disptype = $ISSUE_TYPES[$lasttype][0];
102 echo " <tr>\n";
103 echo " <td valign='top' colspan='4' class='bold'><b>$disptype</b></td>\n";
104 echo " </tr>\n";
106 $rowid = $prow['id'];
107 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
109 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
110 "pid = '$pid' AND list_id = '$rowid'");
112 echo " <tr class='text'>\n";
113 echo " <td valign='top'>&nbsp;</td>\n";
114 echo " <td valign='top'>";
115 echo "<input type='checkbox' name='issue_$rowid' onclick='issueClick(this)' value='/";
116 while ($ierow = sqlFetchArray($ieres)) {
117 echo $ierow['encounter'] . "/";
119 echo "' />$disptitle</td>\n";
120 echo " <td valign='top'>" . $prow['begdate'];
121 if ($prow['enddate']) {
122 echo " - " . $prow['enddate'];
123 } else {
124 echo " Active";
126 echo " &nbsp; &nbsp; </td>\n";
127 echo " </tr>\n";
130 </table>
131 <br>
132 </td>
134 <td valign='top' class='text'>
135 <span class='bold'><? xl('Encounter Forms to Include in this Report','e'); ?>:</span>
136 <br><br>
138 $isfirst = 1;
139 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
140 "forms.formdir, forms.date AS fdate, form_encounter.date " .
141 "FROM forms, form_encounter WHERE " .
142 "forms.pid = '$pid' AND form_encounter.encounter = forms.encounter " .
143 "ORDER BY form_encounter.date DESC, fdate ASC");
144 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
145 $html_strings = array();
146 $registry_form_name = array();
147 while($result2 = sqlFetchArray($res2)) {
148 array_push($registry_form_name,trim($result2['name']));
150 while($result = sqlFetchArray($res)) {
151 if ($result{"form_name"} == "New Patient Encounter") {
152 if ($isfirst == 0) {
153 foreach($registry_form_name as $var) {
154 if ($toprint = $html_strings[$var]) {
155 {foreach($toprint as $var) {print $var;}}
158 $html_strings = array();
159 print "</blockquote>\n\n";
161 $isfirst = 0;
162 print "<input type=checkbox name='" . $result{"formdir"} . "_" .
163 $result{"form_id"} . "' value='" . $result{"encounter"} . "'";
164 print " >New Encounter" .
165 " (" . date("Y-m-d",strtotime($result{"date"})) .
166 ")<blockquote>\n";
168 else {
169 $form_name = trim($result{"form_name"});
170 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
171 array_push($html_strings[$form_name], "<input type='checkbox' name='"
172 . $result{"formdir"} . "_"
173 . $result{"form_id"} . "' value='" . $result{"encounter"} . "'"
174 . ">" . $result{"form_name"} . "<br>\n");
177 foreach($registry_form_name as $var) {
178 if ($toprint = $html_strings[$var]) {
179 {foreach($toprint as $var) {print $var;}}
183 </blockquote>
185 </td>
186 </tr>
187 </table>
189 <span class="bold"><? xl('Documents','e'); ?></span>:<br>
190 <ul>
192 //code lists available images
193 $db = $GLOBALS['adodb']['db'];
194 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
195 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
196 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
197 "d.foreign_id = " . $db->qstr($pid);
198 $result = $db->Execute($sql);
199 echo $db->ErrorMsg();
200 while ($result && !$result->EOF) {
201 echo '<span class="bold"><input type="checkbox" name="documents[]" value="' .
202 $result->fields['id'] . '">';
203 echo '&nbsp;&nbsp;<i>' . $result->fields['name'] . "</i>";
204 echo '&nbsp;&nbsp;Name: <i>' . basename($result->fields['url']) . "</i>";
205 echo '</span><br>';
206 $result->MoveNext();
209 </ul>
210 </form>
212 <a href='javascript:document.report_form.submit()' class='link_submit'><? xl('Generate Report','e'); ?></a>
214 </body>
215 </html>