3 * This report lists non reported patient diagnoses for a given date range.
4 * Ensoftek: Jul-2015: Modified HL7 generation to 2.5.1 spec and MU2 compliant.
5 * This implementation is only for the A01 profile which will suffice for MU2 certification.
8 * Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
9 * Copyright (C) 2010 Tomasz Wyderka <wyderkat@cofoh.com>
10 * Copyright (C) 2015 Ensoftek <rammohan@ensoftek.com>
11 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
13 * LICENSE: This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 3
16 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
25 * @author Rod Roark <rod@sunsetsystems.com>
26 * @author Tomasz Wyderka <wyderkat@cofoh.com>
27 * @author Ensoftek <rammohan@ensoftek.com>
28 * @author Brady Miller <brady.g.miller@gmail.com>
29 * @link http://www.open-emr.org
33 require_once("../globals.php");
34 require_once("$srcdir/patient.inc");
35 require_once("../../custom/code_types.inc.php");
38 // Ensoftek: Jul-2015: Get the facility of the logged in user.
39 function getLoggedInUserFacility(){
40 $sql = "SELECT f.name, f.facility_npi FROM users AS u LEFT JOIN facility AS f ON u.facility_id = f.id WHERE u.id=?";
41 $res = sqlStatement($sql, array($_SESSION['authUserID']) );
42 while ($arow = sqlFetchArray($res)) {
48 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
49 function mapCodeType($incode){
51 $code = explode(":", $incode);
62 case "US Ext SNOMEDCT":
66 $outcode = "I9CDX"; // default to ICD9
68 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
74 if(isset($_POST['form_from_date'])) {
75 $from_date = $_POST['form_from_date'] !== "" ?
76 fixDate($_POST['form_from_date'], date('Y-m-d')) :
79 if(isset($_POST['form_to_date'])) {
80 $to_date =$_POST['form_to_date'] !== "" ?
81 fixDate($_POST['form_to_date'], date('Y-m-d')) :
85 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : Array();
87 if (empty ($form_code) ) {
90 $query_codes = 'c.id in (';
91 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
92 $query_codes = substr($query_codes ,0,-1);
93 $query_codes .= ') and ';
97 return (str_replace(' ','^',$a));
102 "l.pid as patientid, " .
105 if ($_POST['form_get_hl7']==='true') {
107 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
108 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
118 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
119 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
121 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
122 "l.date as issuedate, " ;
125 "l.id as issueid, l.title as issuetitle, DATE_FORMAT(l.begdate,'%Y%m%d%H%i') as begin_date ". // Ensoftek: Jul-2015: Get begin date
126 "from lists l, patient_data p, codes c ".
128 "c.reportable=1 and ".
129 "l.id not in (select lists_id from syndromic_surveillance) and ";
131 $query .= "l.date >= '$from_date' " ;
133 if($from_date!=0 and $to_date!=0) {
137 $query .= "l.date <= '$to_date' ";
139 if($from_date!=0 or $to_date!=0) {
142 $query .= "l.pid=p.pid and ".
144 "l.diagnosis LIKE 'ICD9:%' and ".
145 "substring(l.diagnosis,6) = c.code ";
147 //echo "<p> DEBUG query: $query </p>\n"; // debugging
150 $nowdate = date('YmdHi');
151 $now = date('YmdGi');
152 $now1 = date('Y-m-d G:i');
153 $filename = "syn_sur_". $now . ".hl7";
156 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
157 $facility_info = getLoggedInUserFacility();
160 if ($_POST['form_get_hl7']==='true') {
163 $res = sqlStatement($query);
165 while ($r = sqlFetchArray($res)) {
167 $content .= "MSH|^~\&|".strtoupper($openemr_name).
168 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
170 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
171 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
176 "|" . // 1.B Event Type Code
177 "$now" . // 2.R Recorded Date/Time
179 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
182 if ($r['sex']==='Male') $r['sex'] = 'M';
183 if ($r['sex']==='Female') $r['sex'] = 'F';
184 if ($r['status']==='married') $r['status'] = 'M';
185 if ($r['status']==='single') $r['status'] = 'S';
186 if ($r['status']==='divorced') $r['status'] = 'D';
187 if ($r['status']==='widowed') $r['status'] = 'W';
188 if ($r['status']==='separated') $r['status'] = 'A';
189 if ($r['status']==='domestic partner') $r['status'] = 'P';
195 $r['patientid']."^^^^MR"."|". // 3. (R) Patient indentifier list
196 "|" . // 4. (B) Alternate PID
197 "^^^^^^~^^^^^^S"."|" . // 5.R. Name
198 "|" . // 6. Mather Maiden Name
199 $r['DOB']."|" . // 7. Date, time of birth
200 $r['sex'] . // 8. Sex
201 "|||^^^||||||||||||||||||||||||||||" .
206 "|||||||||||||||||" .
207 // Restrict the string to 15 characters. Will fail if longer.
208 substr($now . "_" . $r['patientid'], 0, 15) . "^^^^VN" . // Supposed to be visit number. Since, we don't have any encounter, we'll use the format 'date_pid' to make it unique
209 "|||||||||||||||||||||||||" .
213 // OBX: Records chief complaint in LOINC code
216 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
217 "^^^^^^^^" . $r['issuetitle'] .
223 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
224 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
229 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
234 // mark if issues generated/sent
235 $query_insert = "insert into syndromic_surveillance(lists_id,submission_date,filename) " .
236 "values (" . $r['issueid'] . ",'" . $now1 . "','" . $filename . "')";
237 sqlStatement($query_insert);
240 // Ensoftek: Jul-2015: No need to tr the content
241 //$content = tr($content);
243 // send the header here
244 header('Content-type: text/plain');
245 header('Content-Disposition: attachment; filename=' . $filename );
247 // put the content in the file
255 <?php
html_header_show();?
>
256 <title
><?php
xl('Syndromic Surveillance - Non Reported Issues','e'); ?
></title
>
257 <script type
="text/javascript" src
="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script
>
258 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
259 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
260 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
262 <script language
="JavaScript">
264 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
266 $
(document
).ready(function() {
267 var win
= top
.printLogSetup ? top
: opener
.top
;
268 win
.printLogSetup(document
.getElementById('printbutton'));
270 $
('.datepicker').datetimepicker({
271 <?php
$datetimepicker_timepicker = false; ?
>
272 <?php
$datetimepicker_formatInput = false; ?
>
273 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
274 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
280 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
281 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
283 <style type
="text/css">
284 /* specifically include & exclude from printing */
290 #report_parameters_daterange {
295 #report_results table {
299 /* specifically exclude some from the screen */
301 #report_parameters_daterange {
312 <body
class="body_top">
314 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Syndromic Surveillance - Non Reported Issues','e'); ?
></span
>
316 <div id
="report_parameters_daterange">
317 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
320 <form name
='theform' id
='theform' method
='post' action
='non_reported.php'
321 onsubmit
='return top.restoreSession()'>
322 <div id
="report_parameters">
323 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
324 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
328 <div style
='float:left'>
332 <?php
xl('Diagnosis','e'); ?
>:
336 // Build a drop-down list of codes.
338 $query1 = "select id, code as name, code_type from codes ".
339 " where reportable=1 ORDER BY name";
340 $cres = sqlStatement($query1);
341 echo " <select multiple='multiple' size='3' name='form_code[]'>\n";
342 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
343 while ($crow = sqlFetchArray($cres)) {
344 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
345 // This report currently only works for ICD9 codes. Need to make this work for other
346 // diagnosis code sets in the future.
347 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
348 $codeid = $crow['id'];
349 echo " <option value='$codeid'";
350 if (in_array($codeid, $form_code)) echo " selected";
351 echo ">" . $crow['name'] . "\n";
358 <?php
xl('From','e'); ?
>:
361 <input type
='text' name
='form_from_date' id
="form_from_date"
363 size
='10' value
='<?php echo $form_from_date ?>'
367 <?php
xl('To','e'); ?
>:
370 <input type
='text' name
='form_to_date' id
="form_to_date"
372 size
='10' value
='<?php echo $form_to_date ?>'
379 <td align
='left' valign
='middle' height
="100%">
380 <table style
='border-left:1px solid; width:100%; height:100%' >
383 <div style
='margin-left:15px'>
384 <a href
='#' class='css_button'
386 $("#form_refresh").attr("value","true");
387 $("#form_get_hl7").attr("value","false");
388 $("#theform").submit();
391 <?php
xl('Refresh','e'); ?
>
394 <?php
if ($_POST['form_refresh']) { ?
>
395 <a href
='#' class='css_button' id
='printbutton'>
397 <?php
echo xlt('Print'); ?
>
400 <a href
='#' class='css_button' onclick
=
401 "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'); ?>')) {
402 $('#form_get_hl7').attr('value','true');
403 $('#theform').submit();
406 <?php
xl('Get HL7','e'); ?
>
417 </div
> <!-- end of parameters
-->
421 if ($_POST['form_refresh']) {
423 <div id
="report_results">
426 <th
> <?php
xl('Patient ID','e'); ?
> </th
>
427 <th
> <?php
xl('Patient Name','e'); ?
> </th
>
428 <th
> <?php
xl('Diagnosis','e'); ?
> </th
>
429 <th
> <?php
xl('Issue ID','e'); ?
> </th
>
430 <th
> <?php
xl('Issue Title','e'); ?
> </th
>
431 <th
> <?php
xl('Issue Date','e'); ?
> </th
>
436 //echo "<p> DEBUG query: $query </p>\n"; // debugging
437 $res = sqlStatement($query);
440 while ($row = sqlFetchArray($res)) {
444 <?php
echo htmlspecialchars($row['patientid']) ?
>
447 <?php
echo htmlspecialchars($row['patientname']) ?
>
450 <?php
echo htmlspecialchars($row['diagnosis']) ?
>
453 <?php
echo htmlspecialchars($row['issueid']) ?
>
456 <?php
echo htmlspecialchars($row['issuetitle']) ?
>
459 <?php
echo htmlspecialchars($row['issuedate']) ?
>
466 <tr
class="report_totals">
468 <?php
xl('Total Number of Issues','e'); ?
>
476 </div
> <!-- end of results
-->
479 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
><br
>
480 (<?php
echo xlt('This report currently only works for ICD9 codes.'); ?
>)