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
32 use OpenEMR\Core\Header
;
34 require_once("../globals.php");
35 require_once("$srcdir/patient.inc");
36 require_once("../../custom/code_types.inc.php");
39 // Ensoftek: Jul-2015: Get the facility of the logged in user.
40 function getLoggedInUserFacility()
42 $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=?";
43 $res = sqlStatement($sql, array($_SESSION['authUserID']));
44 while ($arow = sqlFetchArray($res)) {
51 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
52 function mapCodeType($incode)
55 $code = explode(":", $incode);
66 case "US Ext SNOMEDCT":
70 $outcode = "I9CDX"; // default to ICD9
72 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
79 if (isset($_POST['form_from_date'])) {
80 $from_date = $_POST['form_from_date'] !== "" ?
81 fixDate($_POST['form_from_date'], date('Y-m-d')) :
85 if (isset($_POST['form_to_date'])) {
86 $to_date =$_POST['form_to_date'] !== "" ?
87 fixDate($_POST['form_to_date'], date('Y-m-d')) :
92 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
94 if (empty($form_code)) {
97 $query_codes = 'c.id in (';
98 foreach ($form_code as $code) {
99 $query_codes .= $code . ",";
102 $query_codes = substr($query_codes, 0, -1);
103 $query_codes .= ') and ';
109 return (str_replace(' ', '^', $a));
114 "l.pid as patientid, " .
117 if ($_POST['form_get_hl7']==='true') {
119 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
120 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
130 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
131 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
133 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
134 "l.date as issuedate, " ;
138 "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
139 "from lists l, patient_data p, codes c ".
141 "c.reportable=1 and ".
142 "l.id not in (select lists_id from syndromic_surveillance) and ";
144 $query .= "l.date >= '$from_date' " ;
147 if ($from_date!=0 and $to_date!=0) {
152 $query .= "l.date <= '$to_date' ";
155 if ($from_date!=0 or $to_date!=0) {
159 $query .= "l.pid=p.pid and ".
161 "l.diagnosis LIKE 'ICD9:%' and ".
162 "substring(l.diagnosis,6) = c.code ";
164 //echo "<p> DEBUG query: $query </p>\n"; // debugging
167 $nowdate = date('YmdHi');
168 $now = date('YmdGi');
169 $now1 = date('Y-m-d G:i');
170 $filename = "syn_sur_". $now . ".hl7";
173 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
174 $facility_info = getLoggedInUserFacility();
177 if ($_POST['form_get_hl7']==='true') {
180 $res = sqlStatement($query);
182 while ($r = sqlFetchArray($res)) {
184 $content .= "MSH|^~\&|".strtoupper($openemr_name).
185 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
187 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
188 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
193 "|" . // 1.B Event Type Code
194 "$now" . // 2.R Recorded Date/Time
196 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
199 if ($r['sex']==='Male') {
203 if ($r['sex']==='Female') {
207 if ($r['status']==='married') {
211 if ($r['status']==='single') {
215 if ($r['status']==='divorced') {
219 if ($r['status']==='widowed') {
223 if ($r['status']==='separated') {
227 if ($r['status']==='domestic partner') {
235 $r['patientid']."^^^^MR"."|". // 3. (R) Patient indentifier list
236 "|" . // 4. (B) Alternate PID
237 "^^^^^^~^^^^^^S"."|" . // 5.R. Name
238 "|" . // 6. Mather Maiden Name
239 $r['DOB']."|" . // 7. Date, time of birth
240 $r['sex'] . // 8. Sex
241 "|||^^^||||||||||||||||||||||||||||" .
246 "|||||||||||||||||" .
247 // Restrict the string to 15 characters. Will fail if longer.
248 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
249 "|||||||||||||||||||||||||" .
253 // OBX: Records chief complaint in LOINC code
256 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
257 "^^^^^^^^" . $r['issuetitle'] .
263 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
264 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
269 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
274 // mark if issues generated/sent
275 $query_insert = "insert into syndromic_surveillance(lists_id,submission_date,filename) " .
276 "values (" . $r['issueid'] . ",'" . $now1 . "','" . $filename . "')";
277 sqlStatement($query_insert);
280 // Ensoftek: Jul-2015: No need to tr the content
281 //$content = tr($content);
283 // send the header here
284 header('Content-type: text/plain');
285 header('Content-Disposition: attachment; filename=' . $filename);
287 // put the content in the file
296 <title
><?php
xl('Syndromic Surveillance - Non Reported Issues', 'e'); ?
></title
>
298 <?php Header
::setupHeader('datetime-picker'); ?
>
299 <script language
="JavaScript">
301 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
303 $
(document
).ready(function() {
304 var win
= top
.printLogSetup ? top
: opener
.top
;
305 win
.printLogSetup(document
.getElementById('printbutton'));
307 $
('.datepicker').datetimepicker({
308 <?php
$datetimepicker_timepicker = false; ?
>
309 <?php
$datetimepicker_showseconds = false; ?
>
310 <?php
$datetimepicker_formatInput = false; ?
>
311 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
312 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
318 <style type
="text/css">
319 /* specifically include & exclude from printing */
325 #report_parameters_daterange {
330 #report_results table {
334 /* specifically exclude some from the screen */
336 #report_parameters_daterange {
347 <body
class="body_top">
349 <span
class='title'><?php
xl('Report', 'e'); ?
> - <?php
xl('Syndromic Surveillance - Non Reported Issues', 'e'); ?
></span
>
351 <div id
="report_parameters_daterange">
352 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
355 <form name
='theform' id
='theform' method
='post' action
='non_reported.php'
356 onsubmit
='return top.restoreSession()'>
357 <div id
="report_parameters">
358 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
359 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
363 <div style
='float:left'>
366 <td
class='control-label'>
367 <?php
xl('Diagnosis', 'e'); ?
>:
371 // Build a drop-down list of codes.
373 $query1 = "select id, code as name, code_type from codes ".
374 " where reportable=1 ORDER BY name";
375 $cres = sqlStatement($query1);
376 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
377 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
378 while ($crow = sqlFetchArray($cres)) {
379 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
380 // This report currently only works for ICD9 codes. Need to make this work for other
381 // diagnosis code sets in the future.
382 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
383 $codeid = $crow['id'];
384 echo " <option value='$codeid'";
385 if (in_array($codeid, $form_code)) {
389 echo ">" . $crow['name'] . "\n";
396 <td
class='control-label'>
397 <?php
xl('From', 'e'); ?
>:
400 <input type
='text' name
='form_from_date' id
="form_from_date"
401 class='datepicker form-control'
402 size
='10' value
='<?php echo $form_from_date ?>'
405 <td
class='control-label'>
406 <?php
xl('To', 'e'); ?
>:
409 <input type
='text' name
='form_to_date' id
="form_to_date"
410 class='datepicker form-control'
411 size
='10' value
='<?php echo $form_to_date ?>'
418 <td align
='left' valign
='middle' height
="100%">
419 <table style
='border-left:1px solid; width:100%; height:100%' >
422 <div
class="text-center">
423 <div
class="btn-group" role
="group">
424 <a href
='#' class='btn btn-default btn-refresh'
426 $("#form_refresh").attr("value","true");
427 $("#form_get_hl7").attr("value","false");
428 $("#theform").submit();
430 <?php
echo xlt('Refresh'); ?
>
432 <?php
if ($_POST['form_refresh']) { ?
>
433 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
434 <?php
echo xlt('Print'); ?
>
436 <a href
='#' class='btn btn-default btn-transmit' onclick
=
437 "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'); ?>')) {
438 $('#form_get_hl7').attr('value','true');
439 $('#theform').submit();
441 <?php
echo xlt('Get HL7'); ?
>
452 </div
> <!-- end of parameters
-->
456 if ($_POST['form_refresh']) {
458 <div id
="report_results">
461 <th
> <?php
xl('Patient ID', 'e'); ?
> </th
>
462 <th
> <?php
xl('Patient Name', 'e'); ?
> </th
>
463 <th
> <?php
xl('Diagnosis', 'e'); ?
> </th
>
464 <th
> <?php
xl('Issue ID', 'e'); ?
> </th
>
465 <th
> <?php
xl('Issue Title', 'e'); ?
> </th
>
466 <th
> <?php
xl('Issue Date', 'e'); ?
> </th
>
471 //echo "<p> DEBUG query: $query </p>\n"; // debugging
472 $res = sqlStatement($query);
475 while ($row = sqlFetchArray($res)) {
479 <?php
echo htmlspecialchars($row['patientid']) ?
>
482 <?php
echo htmlspecialchars($row['patientname']) ?
>
485 <?php
echo htmlspecialchars($row['diagnosis']) ?
>
488 <?php
echo htmlspecialchars($row['issueid']) ?
>
491 <?php
echo htmlspecialchars($row['issuetitle']) ?
>
494 <?php
echo htmlspecialchars($row['issuedate']) ?
>
501 <tr
class="report_totals">
503 <?php
xl('Total Number of Issues', 'e'); ?
>
511 </div
> <!-- end of results
-->
514 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
><br
>
515 (<?php
echo xlt('This report currently only works for ICD9 codes.'); ?
>)