4 * This report lists non reported patient diagnoses for a given date range.
5 * Ensoftek: Jul-2015: Modified HL7 generation to 2.5.1 spec and MU2 compliant.
6 * This implementation is only for the A01 profile which will suffice for MU2 certification.
9 * @link http://www.open-emr.org
10 * @author Rod Roark <rod@sunsetsystems.com>
11 * @author Tomasz Wyderka <wyderkat@cofoh.com>
12 * @author Ensoftek <rammohan@ensoftek.com>
13 * @author Brady Miller <brady.g.miller@gmail.com>
14 * @copyright Copyright (c) 2008 Rod Roark <rod@sunsetsystems.com>
15 * @copyright Copyright (c) 2010 Tomasz Wyderka <wyderkat@cofoh.com>
16 * @copyright Copyright (c) 2015 Ensoftek <rammohan@ensoftek.com>
17 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
18 * @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\Common\Csrf\CsrfUtils
;
26 use OpenEMR\Core\Header
;
29 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
30 CsrfUtils
::csrfNotVerified();
34 // Ensoftek: Jul-2015: Get the facility of the logged in user.
35 function getLoggedInUserFacility()
37 $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=?";
38 $res = sqlStatement($sql, array($_SESSION['authUserID']));
39 while ($arow = sqlFetchArray($res)) {
46 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
47 function mapCodeType($incode)
50 $code = explode(":", $incode);
61 case "US Ext SNOMEDCT":
65 $outcode = "I9CDX"; // default to ICD9
67 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
74 $from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
75 $to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : '';
80 return (str_replace(' ', '^', $a));
83 $sqlBindArray = array();
86 "l.pid as patientid, " .
89 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
91 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, " .
92 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, " .
102 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, " .
103 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
105 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, " .
106 "l.date as issuedate, " ;
110 "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
111 "from lists l, patient_data p, codes c " .
113 "c.reportable=1 and " .
114 "l.id not in (select lists_id from syndromic_surveillance) and ";
115 if (!empty($from_date)) {
116 $query .= "l.date >= ? " ;
117 array_push($sqlBindArray, $from_date);
120 if (!empty($from_date) && !empty($to_date)) {
124 if (!empty($to_date)) {
125 $query .= "l.date <= ? ";
126 array_push($sqlBindArray, $to_date);
129 if (!empty($from_date) ||
!empty($to_date)) {
133 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
134 if (empty($form_code)) {
137 $query_codes = 'c.id in (';
138 foreach ($form_code as $code) {
139 $query_codes .= '?,';
140 array_push($sqlBindArray, $code);
142 $query_codes = substr($query_codes, 0, -1);
143 $query_codes .= ') and ';
146 $query .= "l.pid=p.pid and " .
148 "l.diagnosis LIKE 'ICD9:%' and " .
149 "substring(l.diagnosis,6) = c.code ";
151 //echo "<p> DEBUG query: $query </p>\n"; // debugging
154 $nowdate = date('YmdHi');
155 $now = date('YmdGi');
156 $now1 = date('Y-m-d G:i');
157 $filename = "syn_sur_" . $now . ".hl7";
160 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
161 $facility_info = getLoggedInUserFacility();
164 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
167 $res = sqlStatement($query, $sqlBindArray);
169 while ($r = sqlFetchArray($res)) {
171 $content .= "MSH|^~\&|" . strtoupper($openemr_name) .
172 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
174 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
175 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
180 "|" . // 1.B Event Type Code
181 "$now" . // 2.R Recorded Date/Time
183 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
186 if ($r['sex'] === 'Male') {
190 if ($r['sex'] === 'Female') {
194 if ($r['status'] === 'married') {
198 if ($r['status'] === 'single') {
202 if ($r['status'] === 'divorced') {
206 if ($r['status'] === 'widowed') {
210 if ($r['status'] === 'separated') {
214 if ($r['status'] === 'domestic partner') {
222 $r['patientid'] . "^^^^MR" . "|" . // 3. (R) Patient indentifier list
223 "|" . // 4. (B) Alternate PID
224 "^^^^^^~^^^^^^S" . "|" . // 5.R. Name
225 "|" . // 6. Mather Maiden Name
226 $r['DOB'] . "|" . // 7. Date, time of birth
227 $r['sex'] . // 8. Sex
228 "|||^^^||||||||||||||||||||||||||||" .
233 "|||||||||||||||||" .
234 // Restrict the string to 15 characters. Will fail if longer.
235 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
236 "|||||||||||||||||||||||||" .
240 // OBX: Records chief complaint in LOINC code
243 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
244 "^^^^^^^^" . $r['issuetitle'] .
250 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
251 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
256 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
261 // mark if issues generated/sent
262 $query_insert = "insert into syndromic_surveillance(lists_id, submission_date, filename) " .
264 sqlStatement($query_insert, array($r['issueid'], $now1, $filename));
267 // Ensoftek: Jul-2015: No need to tr the content
268 //$content = tr($content);
270 // send the header here
271 header('Content-type: text/plain');
272 header('Content-Disposition: attachment; filename=' . $filename);
274 // put the content in the file
282 <title
><?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></title
>
284 <?php Header
::setupHeader('datetime-picker'); ?
>
288 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
291 var win
= top
.printLogSetup ? top
: opener
.top
;
292 win
.printLogSetup(document
.getElementById('printbutton'));
294 $
('.datepicker').datetimepicker({
295 <?php
$datetimepicker_timepicker = false; ?
>
296 <?php
$datetimepicker_showseconds = false; ?
>
297 <?php
$datetimepicker_formatInput = true; ?
>
298 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
299 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
306 /* specifically include & exclude from printing */
312 #report_parameters_daterange {
317 #report_results table {
321 /* specifically exclude some from the screen */
323 #report_parameters_daterange {
334 <body
class="body_top">
336 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></span
>
338 <div id
="report_parameters_daterange">
339 <?php
echo text(oeFormatShortDate($from_date)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($to_date)); ?
>
342 <form name
='theform' id
='theform' method
='post' action
='non_reported.php' onsubmit
='return top.restoreSession()'>
343 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
344 <div id
="report_parameters">
345 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
346 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
350 <div style
='float:left'>
353 <td
class='col-form-label'>
354 <?php
echo xlt('Diagnosis'); ?
>:
358 // Build a drop-down list of codes.
360 $query1 = "select id, code as name, code_type from codes " .
361 " where reportable=1 ORDER BY name";
362 $cres = sqlStatement($query1);
363 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
364 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
365 while ($crow = sqlFetchArray($cres)) {
366 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
367 // This report currently only works for ICD9 codes. Need to make this work for other
368 // diagnosis code sets in the future.
369 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
370 $codeid = $crow['id'];
371 echo " <option value='" . attr($codeid) . "'";
372 if (in_array($codeid, $form_code)) {
376 echo ">" . text($crow['name']) . "\n";
383 <td
class='col-form-label'>
384 <?php
echo xlt('From'); ?
>:
387 <input type
='text' name
='form_from_date' id
="form_from_date"
388 class='datepicker form-control'
389 size
='10' value
='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
391 <td
class='col-form-label'>
392 <?php
echo xlt('To{{Range}}'); ?
>:
395 <input type
='text' name
='form_to_date' id
="form_to_date"
396 class='datepicker form-control'
397 size
='10' value
='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
403 <td
class='h-100' align
='left' valign
='middle'>
404 <table
class='w-100 h-100' style
='border-left:1px solid;'>
407 <div
class="text-center">
408 <div
class="btn-group" role
="group">
409 <a href
='#' class='btn btn-secondary btn-refresh'
411 $("#form_refresh").attr("value","true");
412 $("#form_get_hl7").attr("value","false");
413 $("#theform").submit();
415 <?php
echo xlt('Refresh'); ?
>
417 <?php
if (!empty($_POST['form_refresh'])) { ?
>
418 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
419 <?php
echo xlt('Print'); ?
>
421 <a href
='#' class='btn btn-secondary btn-transmit' onclick
=
422 "if(confirm(<?php echo xlj('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?'); ?>)) {
423 $('#form_get_hl7').attr('value','true');
424 $('#theform').submit();
426 <?php
echo xlt('Get HL7'); ?
>
437 </div
> <!-- end of parameters
-->
441 if (!empty($_POST['form_refresh'])) {
443 <div id
="report_results">
444 <table
class='table'>
445 <thead
class='thead-light' align
="left">
446 <th
> <?php
echo xlt('Patient ID'); ?
> </th
>
447 <th
> <?php
echo xlt('Patient Name'); ?
> </th
>
448 <th
> <?php
echo xlt('Diagnosis'); ?
> </th
>
449 <th
> <?php
echo xlt('Issue ID'); ?
> </th
>
450 <th
> <?php
echo xlt('Issue Title'); ?
> </th
>
451 <th
> <?php
echo xlt('Issue Date'); ?
> </th
>
456 //echo "<p> DEBUG query: $query </p>\n"; // debugging
457 $res = sqlStatement($query, $sqlBindArray);
460 while ($row = sqlFetchArray($res)) {
464 <?php
echo text($row['patientid']) ?
>
467 <?php
echo text($row['patientname']) ?
>
470 <?php
echo text($row['diagnosis']) ?
>
473 <?php
echo text($row['issueid']) ?
>
476 <?php
echo text($row['issuetitle']) ?
>
479 <?php
echo text($row['issuedate']) ?
>
486 <tr
class="report_totals">
488 <?php
echo xlt('Total Number of Issues'); ?
>
490 <?php
echo text($total); ?
>
496 </div
> <!-- end of results
-->
499 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
><br
/>
500 (<?php
echo xlt('This report currently only works for ICD9 codes.'); ?
>)