Integration of external ICD9/10 and SNOMED
[openemr.git] / interface / reports / non_reported.php
blob8efcec44f70bb8b5e77b2bf8b834df8ed76ed5bb
1 <?php
2 // Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
3 // Copyright (C) 2010 Tomasz Wyderka <wyderkat@cofoh.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This report lists non reported patient diagnoses for a given date range.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("../../custom/code_types.inc.php");
16 if(isset($_POST['form_from_date'])) {
17 $from_date = $_POST['form_from_date'] !== "" ?
18 fixDate($_POST['form_from_date'], date('Y-m-d')) :
21 if(isset($_POST['form_to_date'])) {
22 $to_date =$_POST['form_to_date'] !== "" ?
23 fixDate($_POST['form_to_date'], date('Y-m-d')) :
27 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : Array();
29 if (empty ($form_code) ) {
30 $query_codes = '';
31 } else {
32 $query_codes = 'c.id in (';
33 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
34 $query_codes = substr($query_codes ,0,-1);
35 $query_codes .= ') and ';
38 function tr($a) {
39 return (str_replace(' ','^',$a));
42 $query =
43 "select " .
44 "l.pid as patientid, " .
45 "p.language, ".
46 "l.diagnosis , " ;
47 if ($_POST['form_get_hl7']==='true') {
48 $query .=
49 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
50 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
51 "p.country_code, ".
52 "p.phone_home, ".
53 "p.phone_biz, ".
54 "p.status, ".
55 "p.sex, ".
56 "p.ethnoracial, ".
57 "c.code_text, ".
58 "c.code, ".
59 "c.code_type, ".
60 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
61 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
62 } else {
63 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
64 "l.date as issuedate, " ;
66 $query .=
67 "l.id as issueid, l.title as issuetitle ".
68 "from lists l, patient_data p, codes c ".
69 "where ".
70 "c.reportable=1 and ".
71 "l.id not in (select lists_id from syndromic_surveillance) and ";
72 if($from_date!=0) {
73 $query .= "l.date >= '$from_date' " ;
75 if($from_date!=0 and $to_date!=0) {
76 $query .= " and " ;
78 if($to_date!=0) {
79 $query .= "l.date <= '$to_date' ";
81 if($from_date!=0 or $to_date!=0) {
82 $query .= " and " ;
84 $query .= "l.pid=p.pid and ".
85 $query_codes .
86 "l.diagnosis LIKE 'ICD9:%' and ".
87 "substring(l.diagnosis,6) = c.code ";
89 //echo "<p> DEBUG query: $query </p>\n"; // debugging
91 $D="\r";
92 $nowdate = date('Ymd');
93 $now = date('YmdGi');
94 $now1 = date('Y-m-d G:i');
95 $filename = "syn_sur_". $now . ".hl7";
97 // GENERATE HL7 FILE
98 if ($_POST['form_get_hl7']==='true') {
99 $content = '';
100 //$content.="FHS|^~\&|OPENEMR||||$now||$filename||||$D";
101 //$content.="BHS|^~\&|OPENEMR||||$now||SyndromicSurveillance||||$D";
103 $res = sqlStatement($query);
105 while ($r = sqlFetchArray($res)) {
106 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
107 "ADT^A08|$nowdate|P^T|2.5.1|||||||||$D";
108 $content .= "EVN|" . // [[ 3.69 ]]
109 "A08|" . // 1.B Event Type Code
110 "$now|" . // 2.R Recorded Date/Time
111 "|" . // 3. Date/Time Planned Event
112 "|" . // 4. Event Reason Cod
113 "|" . // 5. Operator ID
114 "|" . // 6. Event Occurred
115 "" . // 7. Event Facility
116 "$D" ;
117 if ($r['sex']==='Male') $r['sex'] = 'M';
118 if ($r['sex']==='Female') $r['sex'] = 'F';
119 if ($r['status']==='married') $r['status'] = 'M';
120 if ($r['status']==='single') $r['status'] = 'S';
121 if ($r['status']==='divorced') $r['status'] = 'D';
122 if ($r['status']==='widowed') $r['status'] = 'W';
123 if ($r['status']==='separated') $r['status'] = 'A';
124 if ($r['status']==='domestic partner') $r['status'] = 'P';
125 $content .= "PID|" . // [[ 3.72 ]]
126 "|" . // 1. Set id
127 "|" . // 2. (B)Patient id
128 $r['patientid']."|". // 3. (R) Patient indentifier list
129 "|" . // 4. (B) Alternate PID
130 $r['patientname']."|" . // 5.R. Name
131 "|" . // 6. Mather Maiden Name
132 $r['DOB']."|" . // 7. Date, time of birth
133 $r['sex']."|" . // 8. Sex
134 "|" . // 9.B Patient Alias
135 //$r['ethnoracial']."|" . // 10. Race
136 "|" . // 10. Race
137 $r['address']."|" . // 11. Address
138 $r['country_code']."|" . // 12. country code
139 $r['phone_home']."|" . // 13. Phone Home
140 $r['phone_biz']."|" . // 14. Phone Bussines
141 "|" . // 15. Primary language
142 $r['status']."|" . // 16. Marital status
143 "|" . // 17. Religion
144 "|" . // 18. patient Account Number
145 "|" . // 19.B SSN Number
146 "|" . // 20.B Driver license number
147 "|" . // 21. Mathers Identifier
148 "|" . // 22. Ethnic Group
149 "|" . // 23. Birth Plase
150 "|" . // 24. Multiple birth indicator
151 "|" . // 25. Birth order
152 "|" . // 26. Citizenship
153 "|" . // 27. Veteran military status
154 "|" . // 28.B Nationality
155 "|" . // 29. Patient Death Date and Time
156 "|" . // 30. Patient Death Indicator
157 "|" . // 31. Identity Unknown Indicator
158 "|" . // 32. Identity Reliability Code
159 "|" . // 33. Last Update Date/Time
160 "|" . // 34. Last Update Facility
161 "|" . // 35. Species Code
162 "|" . // 36. Breed Code
163 "|" . // 37. Breed Code
164 "|" . // 38. Production Class Code
165 "" . // 39. Tribal Citizenship
166 "$D" ;
167 $content .= "PV1|" . // [[ 3.86 ]]
168 "|" . // 1. Set ID
169 "U|" . // 2.R Patient Class (U - unknown)
170 "" . // 3. ... 52.
171 "$D" ;
172 $content .= "DG1|" . // [[ 6.24 ]]
173 "1|" . // 1. Set ID
174 $r['diagnosis']."|" . // 2.B.R Diagnosis Coding Method
175 $r['code']."|" . // 3. Diagnosis Code - DG1
176 $r['code_text']."|" . // 4.B Diagnosis Description
177 $r['issuedate']."|" . // 5. Diagnosis Date/Time
178 "W|" . // 6.R Diagnosis Type // A - Admiting, W - working
179 "|" . // 7.B Major Diagnostic Category
180 "|" . // 8.B Diagnostic Related Group
181 "|" . // 9.B DRG Approval Indicator
182 "|" . // 10.B DRG Grouper Review Code
183 "|" . // 11.B Outlier Type
184 "|" . // 12.B Outlier Days
185 "|" . // 13.B Outlier Cost
186 "|" . // 14.B Grouper Version And Type
187 "|" . // 15. Diagnosis Priority
188 "|" . // 16. Diagnosing Clinician
189 "|" . // 17. Diagnosis Classification
190 "|" . // 18. Confidential Indicator
191 "|" . // 19. Attestation Date/Time
192 "|" . // 20.C Diagnosis Identifier
193 "" . // 21.C Diagnosis Action Code
194 "$D" ;
196 // mark if issues generated/sent
197 $query_insert = "insert into syndromic_surveillance(lists_id,submission_date,filename) " .
198 "values (" . $r['issueid'] . ",'" . $now1 . "','" . $filename . "')";
199 sqlStatement($query_insert);
201 //$content.="BTS|||$D";
202 //$content.="FTS||$D";
204 $content = tr($content);
205 // send the header here
206 header('Content-type: text/plain');
207 header('Content-Disposition: attachment; filename=' . $filename );
209 // put the content in the file
210 echo($content);
211 exit;
215 <html>
216 <head>
217 <?php html_header_show();?>
218 <title><?php xl('Syndromic Surveillance - Non Reported Issues','e'); ?></title>
219 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
220 <script type="text/javascript" src="../../library/dialog.js"></script>
221 <script type="text/javascript" src="../../library/textformat.js"></script>
222 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
223 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
224 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
225 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
226 <script language="JavaScript">
227 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
228 </script>
230 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
231 <style type="text/css">
232 /* specifically include & exclude from printing */
233 @media print {
234 #report_parameters {
235 visibility: hidden;
236 display: none;
238 #report_parameters_daterange {
239 visibility: visible;
240 display: inline;
241 margin-bottom: 10px;
243 #report_results table {
244 margin-top: 0px;
247 /* specifically exclude some from the screen */
248 @media screen {
249 #report_parameters_daterange {
250 visibility: hidden;
251 display: none;
253 #report_results {
254 width: 100%;
257 </style>
258 </head>
260 <body class="body_top">
262 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Syndromic Surveillance - Non Reported Issues','e'); ?></span>
264 <div id="report_parameters_daterange">
265 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
266 </div>
268 <form name='theform' id='theform' method='post' action='non_reported.php'
269 onsubmit='return top.restoreSession()'>
270 <div id="report_parameters">
271 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
272 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
273 <table>
274 <tr>
275 <td width='410px'>
276 <div style='float:left'>
277 <table class='text'>
278 <tr>
279 <td class='label'>
280 <?php xl('Diagnosis','e'); ?>:
281 </td>
282 <td>
283 <?php
284 // Build a drop-down list of codes.
286 $query1 = "select id, code as name, code_type from codes ".
287 " where reportable=1 ORDER BY name";
288 $cres = sqlStatement($query1);
289 echo " <select multiple='multiple' size='3' name='form_code[]'>\n";
290 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
291 while ($crow = sqlFetchArray($cres)) {
292 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
293 // This report currently only works for ICD9 codes. Need to make this work for other
294 // diagnosis code sets in the future.
295 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
296 $codeid = $crow['id'];
297 echo " <option value='$codeid'";
298 if (in_array($codeid, $form_code)) echo " selected";
299 echo ">" . $crow['name'] . "\n";
302 echo " </select>\n";
304 </td>
305 <td class='label'>
306 <?php xl('From','e'); ?>:
307 </td>
308 <td>
309 <input type='text' name='form_from_date' id="form_from_date"
310 size='10' value='<?php echo $form_from_date ?>'
311 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
312 title='yyyy-mm-dd'>
313 <img src='../pic/show_calendar.gif' align='absbottom'
314 width='24' height='22' id='img_from_date' border='0'
315 alt='[?]' style='cursor:pointer'
316 title='<?php xl('Click here to choose a date','e'); ?>'>
317 </td>
318 <td class='label'>
319 <?php xl('To','e'); ?>:
320 </td>
321 <td>
322 <input type='text' name='form_to_date' id="form_to_date"
323 size='10' value='<?php echo $form_to_date ?>'
324 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
325 title='yyyy-mm-dd'>
326 <img src='../pic/show_calendar.gif' align='absbottom'
327 width='24' height='22' id='img_to_date' border='0'
328 alt='[?]' style='cursor:pointer'
329 title='<?php xl('Click here to choose a date','e'); ?>'>
330 </td>
331 </tr>
332 </table>
333 </div>
334 </td>
335 <td align='left' valign='middle' height="100%">
336 <table style='border-left:1px solid; width:100%; height:100%' >
337 <tr>
338 <td>
339 <div style='margin-left:15px'>
340 <a href='#' class='css_button'
341 onclick='
342 $("#form_refresh").attr("value","true");
343 $("#form_get_hl7").attr("value","false");
344 $("#theform").submit();
346 <span>
347 <?php xl('Refresh','e'); ?>
348 </spain>
349 </a>
350 <?php if ($_POST['form_refresh']) { ?>
351 <a href='#' class='css_button' onclick='window.print()'>
352 <span>
353 <?php xl('Print','e'); ?>
354 </span>
355 </a>
356 <a href='#' class='css_button' onclick=
357 "if(confirm('<?php xl('This step will generate a file which you have to save for future use. The file cannot be generated again. Do you want to proceed?','e'); ?>')) {
358 $('#form_get_hl7').attr('value','true');
359 $('#theform').submit();
361 <span>
362 <?php xl('Get HL7','e'); ?>
363 </span>
364 </a>
365 <?php } ?>
366 </div>
367 </td>
368 </tr>
369 </table>
370 </td>
371 </tr>
372 </table>
373 </div> <!-- end of parameters -->
376 <?php
377 if ($_POST['form_refresh']) {
379 <div id="report_results">
380 <table>
381 <thead align="left">
382 <th> <?php xl('Patient ID','e'); ?> </th>
383 <th> <?php xl('Patient Name','e'); ?> </th>
384 <th> <?php xl('Diagnosis','e'); ?> </th>
385 <th> <?php xl('Issue ID','e'); ?> </th>
386 <th> <?php xl('Issue Title','e'); ?> </th>
387 <th> <?php xl('Issue Date','e'); ?> </th>
388 </thead>
389 <tbody>
390 <?php
391 $total = 0;
392 //echo "<p> DEBUG query: $query </p>\n"; // debugging
393 $res = sqlStatement($query);
396 while ($row = sqlFetchArray($res)) {
398 <tr>
399 <td>
400 <?php echo htmlspecialchars($row['patientid']) ?>
401 </td>
402 <td>
403 <?php echo htmlspecialchars($row['patientname']) ?>
404 </td>
405 <td>
406 <?php echo htmlspecialchars($row['diagnosis']) ?>
407 </td>
408 <td>
409 <?php echo htmlspecialchars($row['issueid']) ?>
410 </td>
411 <td>
412 <?php echo htmlspecialchars($row['issuetitle']) ?>
413 </td>
414 <td>
415 <?php echo htmlspecialchars($row['issuedate']) ?>
416 </td>
417 </tr>
418 <?php
419 ++$total;
422 <tr class="report_totals">
423 <td colspan='9'>
424 <?php xl('Total Number of Issues','e'); ?>
426 <?php echo $total ?>
427 </td>
428 </tr>
430 </tbody>
431 </table>
432 </div> <!-- end of results -->
433 <?php } else { ?>
434 <div class='text'>
435 <?php echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?><br>
436 (<?php echo xlt('This report currently only works for ICD9 codes.'); ?>)
437 </div>
438 <?php } ?>
439 </form>
441 <script language='JavaScript'>
442 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
443 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
444 </script>
446 </body>
447 </html>