added untimely filing as an adjustment reason
[openemr.git] / interface / patient_file / report / patient_report.php
blobea65eb7b5e14d96dda0f4249677e1cdad5d55b0c
1 <?php
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" onclick="top.restoreSession()">
34 [<? 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><? xl('Demographics','e'); ?><br>
42 <input type='checkbox' name='include_history' value="history"><? xl(' History','e'); ?><br>
43 <input type='checkbox' name='include_employer' value="employer"><? xl('Employer','e'); ?><br>
44 <input type='checkbox' name='include_insurance' value="insurance"><? xl('Insurance','e'); ?><br>
45 <input type='checkbox' name='include_billing' value="billing" checked><? xl('Billing','e'); ?><br>
46 </td>
47 <td class='text' valign='top'>
48 <!--
49 <input type='checkbox' name='include_allergies' value="allergies">Allergies<br>
50 <input type='checkbox' name='include_medications' value="medications">Medications<br>
51 -->
52 <input type='checkbox' name='include_immunizations' value="immunizations"><? xl('Immunizations','e'); ?><br>
53 <!--
54 <input type='checkbox' name='include_medical_problems' value="medical_problems">Medical Problems<br>
55 -->
56 <input type='checkbox' name='include_notes' value="notes"><? xl('Patient Notes','e'); ?><br>
57 <input type='checkbox' name='include_transactions' value="transactions"><? xl('Transactions','e'); ?><br>
58 <input type='checkbox' name='include_batchcom' value="batchcom"><? xl('Communications','e'); ?><br>
59 </td>
60 </tr>
61 </table>
63 <br>
64 <a href='javascript:top.restoreSession();document.report_form.submit()' class='link_submit'><? xl('Generate Report','e'); ?></a>
65 <hr>
67 <table>
68 <tr>
70 <td valign='top' class='text'>
71 <span class='bold'><? xl('Issues to Include in this Report','e'); ?>: &nbsp; &nbsp;</span>
72 <br>&nbsp;
73 <table cellpadding='1' cellspacing='2'>
74 <!--
75 <tr class='bold'>
76 <td>Type</td>
77 <td>Title</td>
78 <td>Begin</td>
79 <td>End &nbsp; &nbsp; &nbsp;</td>
80 </tr>
81 -->
83 // get issues
84 $pres = sqlStatement("SELECT * FROM lists WHERE pid = $pid " .
85 "ORDER BY type, begdate");
86 $lasttype = "";
87 while ($prow = sqlFetchArray($pres)) {
88 if ($lasttype != $prow['type']) {
89 $lasttype = $prow['type'];
91 /****
92 $disptype = $lasttype;
93 switch ($lasttype) {
94 case "allergy" : $disptype = "Allergies" ; break;
95 case "problem" :
96 case "medical_problem": $disptype = "Medical Problems"; break;
97 case "medication" : $disptype = "Medications" ; break;
98 case "surgery" : $disptype = "Surgeries" ; break;
100 ****/
101 $disptype = $ISSUE_TYPES[$lasttype][0];
103 echo " <tr>\n";
104 echo " <td valign='top' colspan='4' class='bold'><b>$disptype</b></td>\n";
105 echo " </tr>\n";
107 $rowid = $prow['id'];
108 $disptitle = trim($prow['title']) ? $prow['title'] : "[Missing Title]";
110 $ieres = sqlStatement("SELECT encounter FROM issue_encounter WHERE " .
111 "pid = '$pid' AND list_id = '$rowid'");
113 echo " <tr class='text'>\n";
114 echo " <td valign='top'>&nbsp;</td>\n";
115 echo " <td valign='top'>";
116 echo "<input type='checkbox' name='issue_$rowid' onclick='issueClick(this)' value='/";
117 while ($ierow = sqlFetchArray($ieres)) {
118 echo $ierow['encounter'] . "/";
120 echo "' />$disptitle</td>\n";
121 echo " <td valign='top'>" . $prow['begdate'];
122 if ($prow['enddate']) {
123 echo " - " . $prow['enddate'];
124 } else {
125 echo " Active";
127 echo " &nbsp; &nbsp; </td>\n";
128 echo " </tr>\n";
131 </table>
132 <br>
133 </td>
135 <td valign='top' class='text'>
136 <span class='bold'><? xl('Encounter Forms to Include in this Report','e'); ?>:</span>
137 <br><br>
139 $isfirst = 1;
140 $res = sqlStatement("SELECT forms.encounter, forms.form_id, forms.form_name, " .
141 "forms.formdir, forms.date AS fdate, form_encounter.date " .
142 "FROM forms, form_encounter WHERE " .
143 "forms.pid = '$pid' AND form_encounter.pid = '$pid' AND " .
144 "form_encounter.encounter = forms.encounter " .
145 "ORDER BY form_encounter.date DESC, fdate ASC");
146 $res2 = sqlStatement("SELECT name FROM registry ORDER BY priority");
147 $html_strings = array();
148 $registry_form_name = array();
149 while($result2 = sqlFetchArray($res2)) {
150 array_push($registry_form_name,trim($result2['name']));
152 while($result = sqlFetchArray($res)) {
153 if ($result{"form_name"} == "New Patient Encounter") {
154 if ($isfirst == 0) {
155 foreach($registry_form_name as $var) {
156 if ($toprint = $html_strings[$var]) {
157 {foreach($toprint as $var) {print $var;}}
160 $html_strings = array();
161 print "</blockquote>\n\n";
163 $isfirst = 0;
164 print "<input type=checkbox name='" . $result{"formdir"} . "_" .
165 $result{"form_id"} . "' value='" . $result{"encounter"} . "'";
166 print " >New Encounter" .
167 " (" . date("Y-m-d",strtotime($result{"date"})) .
168 ")<blockquote>\n";
170 else {
171 $form_name = trim($result{"form_name"});
172 //if form name is not in registry, look for the closest match by
173 // finding a registry name which is at the start of the form name.
174 //this is to allow for forms to put additional helpful information
175 //in the database in the same string as their form name after the name
176 $form_name_found_flag = 0;
177 foreach($registry_form_name as $var) {if ($var == $form_name) {$form_name_found_flag = 1;}}
178 // if the form does not match precisely with any names in the registry, now see if any front partial matches
179 // and change $form_name appropriately so it will print above in $toprint = $html_strings[$var]
180 if (!$form_name_found_flag) { foreach($registry_form_name as $var) {if (strpos($form_name,$var) == 0) {$form_name = $var;}}}
182 if (!is_array($html_strings[$form_name])) {$html_strings[$form_name] = array();}
183 array_push($html_strings[$form_name], "<input type='checkbox' name='"
184 . $result{"formdir"} . "_"
185 . $result{"form_id"} . "' value='" . $result{"encounter"} . "'"
186 . ">" . $result{"form_name"} . "<br>\n");
189 foreach($registry_form_name as $var) {
190 if ($toprint = $html_strings[$var]) {
191 {foreach($toprint as $var) {print $var;}}
195 </blockquote>
197 </td>
198 </tr>
199 </table>
201 <span class="bold"><? xl('Documents','e'); ?></span>:<br>
202 <ul>
204 //code lists available images
205 $db = $GLOBALS['adodb']['db'];
206 $sql = "SELECT d.id, d.url, c.name FROM documents AS d " .
207 "LEFT JOIN categories_to_documents AS ctd ON d.id=ctd.document_id " .
208 "LEFT JOIN categories AS c ON c.id = ctd.category_id WHERE " .
209 "d.foreign_id = " . $db->qstr($pid);
210 $result = $db->Execute($sql);
211 echo $db->ErrorMsg();
212 while ($result && !$result->EOF) {
213 echo '<span class="bold"><input type="checkbox" name="documents[]" value="' .
214 $result->fields['id'] . '">';
215 echo '&nbsp;&nbsp;<i>' . $result->fields['name'] . "</i>";
216 echo '&nbsp;&nbsp;Name: <i>' . basename($result->fields['url']) . "</i>";
217 echo '</span><br>';
218 $result->MoveNext();
221 </ul>
222 </form>
224 <a href='javascript:top.restoreSession();document.report_form.submit()' class='link_submit'><? xl('Generate Report','e'); ?></a>
226 </body>
227 </html>