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 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Tomasz Wyderka <wyderkat@cofoh.com>
11 * @author Ensoftek <rammohan@ensoftek.com>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2008 Rod Roark <rod@sunsetsystems.com>
14 * @copyright Copyright (c) 2010 Tomasz Wyderka <wyderkat@cofoh.com>
15 * @copyright Copyright (c) 2015 Ensoftek <rammohan@ensoftek.com>
16 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 require_once("../globals.php");
22 require_once("$srcdir/patient.inc");
23 require_once("../../custom/code_types.inc.php");
25 use OpenEMR\Core\Header
;
27 // Ensoftek: Jul-2015: Get the facility of the logged in user.
28 function getLoggedInUserFacility()
30 $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=?";
31 $res = sqlStatement($sql, array($_SESSION['authUserID']));
32 while ($arow = sqlFetchArray($res)) {
39 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
40 function mapCodeType($incode)
43 $code = explode(":", $incode);
54 case "US Ext SNOMEDCT":
58 $outcode = "I9CDX"; // default to ICD9
60 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
67 $from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
68 $to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : '';
71 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
73 if (empty($form_code)) {
76 $query_codes = 'c.id in (';
77 foreach ($form_code as $code) {
78 $query_codes .= add_escape_custom($code) . ",";
81 $query_codes = substr($query_codes, 0, -1);
82 $query_codes .= ') and ';
88 return (str_replace(' ', '^', $a));
91 $sqlBindArray = array();
94 "l.pid as patientid, " .
97 if ($_POST['form_get_hl7']==='true') {
99 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
100 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
110 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
111 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
113 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
114 "l.date as issuedate, " ;
118 "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
119 "from lists l, patient_data p, codes c ".
121 "c.reportable=1 and ".
122 "l.id not in (select lists_id from syndromic_surveillance) and ";
123 if (!empty($from_date)) {
124 $query .= "l.date >= ? " ;
125 array_push($sqlBindArray, $from_date);
128 if (!empty($from_date) && !empty($to_date)) {
132 if (!empty($to_date)) {
133 $query .= "l.date <= ? ";
134 array_push($sqlBindArray, $to_date);
137 if (!empty($from_date) ||
!empty($to_date)) {
141 $query .= "l.pid=p.pid and ".
143 "l.diagnosis LIKE 'ICD9:%' and ".
144 "substring(l.diagnosis,6) = c.code ";
146 //echo "<p> DEBUG query: $query </p>\n"; // debugging
149 $nowdate = date('YmdHi');
150 $now = date('YmdGi');
151 $now1 = date('Y-m-d G:i');
152 $filename = "syn_sur_". $now . ".hl7";
155 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
156 $facility_info = getLoggedInUserFacility();
159 if ($_POST['form_get_hl7']==='true') {
162 $res = sqlStatement($query, $sqlBindArray);
164 while ($r = sqlFetchArray($res)) {
166 $content .= "MSH|^~\&|".strtoupper($openemr_name).
167 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
169 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
170 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
175 "|" . // 1.B Event Type Code
176 "$now" . // 2.R Recorded Date/Time
178 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
181 if ($r['sex']==='Male') {
185 if ($r['sex']==='Female') {
189 if ($r['status']==='married') {
193 if ($r['status']==='single') {
197 if ($r['status']==='divorced') {
201 if ($r['status']==='widowed') {
205 if ($r['status']==='separated') {
209 if ($r['status']==='domestic partner') {
217 $r['patientid']."^^^^MR"."|". // 3. (R) Patient indentifier list
218 "|" . // 4. (B) Alternate PID
219 "^^^^^^~^^^^^^S"."|" . // 5.R. Name
220 "|" . // 6. Mather Maiden Name
221 $r['DOB']."|" . // 7. Date, time of birth
222 $r['sex'] . // 8. Sex
223 "|||^^^||||||||||||||||||||||||||||" .
228 "|||||||||||||||||" .
229 // Restrict the string to 15 characters. Will fail if longer.
230 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
231 "|||||||||||||||||||||||||" .
235 // OBX: Records chief complaint in LOINC code
238 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
239 "^^^^^^^^" . $r['issuetitle'] .
245 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
246 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
251 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
256 // mark if issues generated/sent
257 $query_insert = "insert into syndromic_surveillance(lists_id, submission_date, filename) " .
259 sqlStatement($query_insert, array($r['issueid'], $now1, $filename));
262 // Ensoftek: Jul-2015: No need to tr the content
263 //$content = tr($content);
265 // send the header here
266 header('Content-type: text/plain');
267 header('Content-Disposition: attachment; filename=' . $filename);
269 // put the content in the file
277 <title
><?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></title
>
279 <?php Header
::setupHeader('datetime-picker'); ?
>
281 <script language
="JavaScript">
283 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
285 $
(document
).ready(function() {
286 var win
= top
.printLogSetup ? top
: opener
.top
;
287 win
.printLogSetup(document
.getElementById('printbutton'));
289 $
('.datepicker').datetimepicker({
290 <?php
$datetimepicker_timepicker = false; ?
>
291 <?php
$datetimepicker_showseconds = false; ?
>
292 <?php
$datetimepicker_formatInput = true; ?
>
293 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
294 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
300 <style type
="text/css">
301 /* specifically include & exclude from printing */
307 #report_parameters_daterange {
312 #report_results table {
316 /* specifically exclude some from the screen */
318 #report_parameters_daterange {
329 <body
class="body_top">
331 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></span
>
333 <div id
="report_parameters_daterange">
334 <?php
echo text(oeFormatShortDate($from_date)) ." " . xlt('to') . " ". text(oeFormatShortDate($to_date)); ?
>
337 <form name
='theform' id
='theform' method
='post' action
='non_reported.php'
338 onsubmit
='return top.restoreSession()'>
339 <div id
="report_parameters">
340 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
341 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
345 <div style
='float:left'>
348 <td
class='control-label'>
349 <?php
echo xlt('Diagnosis'); ?
>:
353 // Build a drop-down list of codes.
355 $query1 = "select id, code as name, code_type from codes ".
356 " where reportable=1 ORDER BY name";
357 $cres = sqlStatement($query1);
358 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
359 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
360 while ($crow = sqlFetchArray($cres)) {
361 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
362 // This report currently only works for ICD9 codes. Need to make this work for other
363 // diagnosis code sets in the future.
364 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
365 $codeid = $crow['id'];
366 echo " <option value='" . attr($codeid) . "'";
367 if (in_array($codeid, $form_code)) {
371 echo ">" . text($crow['name']) . "\n";
378 <td
class='control-label'>
379 <?php
echo xlt('From'); ?
>:
382 <input type
='text' name
='form_from_date' id
="form_from_date"
383 class='datepicker form-control'
384 size
='10' value
='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
386 <td
class='control-label'>
387 <?php
xl('To', 'e'); ?
>:
390 <input type
='text' name
='form_to_date' id
="form_to_date"
391 class='datepicker form-control'
392 size
='10' value
='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
398 <td align
='left' valign
='middle' height
="100%">
399 <table style
='border-left:1px solid; width:100%; height:100%' >
402 <div
class="text-center">
403 <div
class="btn-group" role
="group">
404 <a href
='#' class='btn btn-default btn-refresh'
406 $("#form_refresh").attr("value","true");
407 $("#form_get_hl7").attr("value","false");
408 $("#theform").submit();
410 <?php
echo xlt('Refresh'); ?
>
412 <?php
if ($_POST['form_refresh']) { ?
>
413 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
414 <?php
echo xlt('Print'); ?
>
416 <a href
='#' class='btn btn-default btn-transmit' onclick
=
417 "if(confirm('<?php echo xls('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?'); ?>')) {
418 $('#form_get_hl7').attr('value','true');
419 $('#theform').submit();
421 <?php
echo xlt('Get HL7'); ?
>
432 </div
> <!-- end of parameters
-->
436 if ($_POST['form_refresh']) {
438 <div id
="report_results">
441 <th
> <?php
echo xlt('Patient ID'); ?
> </th
>
442 <th
> <?php
echo xlt('Patient Name'); ?
> </th
>
443 <th
> <?php
echo xlt('Diagnosis'); ?
> </th
>
444 <th
> <?php
echo xlt('Issue ID'); ?
> </th
>
445 <th
> <?php
echo xlt('Issue Title'); ?
> </th
>
446 <th
> <?php
echo xlt('Issue Date'); ?
> </th
>
451 //echo "<p> DEBUG query: $query </p>\n"; // debugging
452 $res = sqlStatement($query, $sqlBindArray);
455 while ($row = sqlFetchArray($res)) {
459 <?php
echo text($row['patientid']) ?
>
462 <?php
echo text($row['patientname']) ?
>
465 <?php
echo text($row['diagnosis']) ?
>
468 <?php
echo text($row['issueid']) ?
>
471 <?php
echo text($row['issuetitle']) ?
>
474 <?php
echo text($row['issuedate']) ?
>
481 <tr
class="report_totals">
483 <?php
echo xlt('Total Number of Issues'); ?
>
485 <?php
echo text($total); ?
>
491 </div
> <!-- end of results
-->
494 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
><br
>
495 (<?php
echo xlt('This report currently only works for ICD9 codes.'); ?
>)