2 // Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
3 // Copyright (C) 2010 Tomasz Wyderka <wyderkat@cofoh.com>
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) ) {
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 ';
39 return (str_replace(' ','^',$a));
44 "l.pid as patientid, " .
47 if ($_POST['form_get_hl7']==='true') {
49 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
50 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
60 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
61 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
63 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
64 "l.date as issuedate, " ;
67 "l.id as issueid, l.title as issuetitle ".
68 "from lists l, patient_data p, codes c ".
70 "c.reportable=1 and ".
71 "l.id not in (select lists_id from syndromic_surveillance) and ";
73 $query .= "l.date >= '$from_date' " ;
75 if($from_date!=0 and $to_date!=0) {
79 $query .= "l.date <= '$to_date' ";
81 if($from_date!=0 or $to_date!=0) {
84 $query .= "l.pid=p.pid and ".
86 "l.diagnosis LIKE 'ICD9:%' and ".
87 "substring(l.diagnosis,6) = c.code ";
89 //echo "<p> DEBUG query: $query </p>\n"; // debugging
92 $nowdate = date('Ymd');
94 $now1 = date('Y-m-d G:i');
95 $filename = "syn_sur_". $now . ".hl7";
98 if ($_POST['form_get_hl7']==='true') {
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
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 ]]
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
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
167 $content .= "PV1|" . // [[ 3.86 ]]
169 "U|" . // 2.R Patient Class (U - unknown)
172 $content .= "DG1|" . // [[ 6.24 ]]
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
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
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"); ?
>
230 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
231 <style type
="text/css">
232 /* specifically include & exclude from printing */
238 #report_parameters_daterange {
243 #report_results table {
247 /* specifically exclude some from the screen */
249 #report_parameters_daterange {
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)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
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
=''/>
276 <div style
='float:left'>
280 <?php
xl('Diagnosis','e'); ?
>:
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";
306 <?php
xl('From','e'); ?
>:
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)'
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
'); ?>'>
319 <?php
xl('To','e'); ?
>:
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)'
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
'); ?>'>
335 <td align
='left' valign
='middle' height
="100%">
336 <table style
='border-left:1px solid; width:100%; height:100%' >
339 <div style
='margin-left:15px'>
340 <a href
='#' class='css_button'
342 $("#form_refresh").attr("value","true");
343 $("#form_get_hl7").attr("value","false");
344 $("#theform").submit();
347 <?php
xl('Refresh','e'); ?
>
350 <?php
if ($_POST['form_refresh']) { ?
>
351 <a href
='#' class='css_button' onclick
='window.print()'>
353 <?php
xl('Print','e'); ?
>
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();
362 <?php
xl('Get HL7','e'); ?
>
373 </div
> <!-- end of parameters
-->
377 if ($_POST['form_refresh']) {
379 <div id
="report_results">
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
>
392 //echo "<p> DEBUG query: $query </p>\n"; // debugging
393 $res = sqlStatement($query);
396 while ($row = sqlFetchArray($res)) {
400 <?php
echo htmlspecialchars($row['patientid']) ?
>
403 <?php
echo htmlspecialchars($row['patientname']) ?
>
406 <?php
echo htmlspecialchars($row['diagnosis']) ?
>
409 <?php
echo htmlspecialchars($row['issueid']) ?
>
412 <?php
echo htmlspecialchars($row['issuetitle']) ?
>
415 <?php
echo htmlspecialchars($row['issuedate']) ?
>
422 <tr
class="report_totals">
424 <?php
xl('Total Number of Issues','e'); ?
>
432 </div
> <!-- end of results
-->
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.'); ?
>)
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"});