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.php");
23 require_once("../../custom/code_types.inc.php");
25 use OpenEMR\Common\Acl\AclMain
;
26 use OpenEMR\Common\Csrf\CsrfUtils
;
27 use OpenEMR\Common\Twig\TwigContainer
;
28 use OpenEMR\Core\Header
;
30 if (!AclMain
::aclCheckCore('patients', 'med')) {
31 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Syndromic Surveillance - Non Reported Issues")]);
36 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
37 CsrfUtils
::csrfNotVerified();
41 // Ensoftek: Jul-2015: Get the facility of the logged in user.
42 function getLoggedInUserFacility()
44 $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=?";
45 $res = sqlStatement($sql, array($_SESSION['authUserID']));
46 while ($arow = sqlFetchArray($res)) {
53 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
54 function mapCodeType($incode)
57 $code = explode(":", $incode);
68 case "US Ext SNOMEDCT":
72 $outcode = "I9CDX"; // default to ICD9
74 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
81 $from_date = (!empty($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
82 $to_date = (!empty($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : '';
87 return (str_replace(' ', '^', $a));
90 $sqlBindArray = array();
93 "l.pid as patientid, " .
96 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
98 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, " .
99 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, " .
109 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, " .
110 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
112 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, " .
113 "l.date as issuedate, " ;
117 "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
118 "from lists l, patient_data p, codes c " .
120 "c.reportable=1 and " .
121 "l.id not in (select lists_id from syndromic_surveillance) and ";
122 if (!empty($from_date)) {
123 $query .= "l.date >= ? " ;
124 array_push($sqlBindArray, $from_date);
127 if (!empty($from_date) && !empty($to_date)) {
131 if (!empty($to_date)) {
132 $query .= "l.date <= ? ";
133 array_push($sqlBindArray, $to_date);
136 if (!empty($from_date) ||
!empty($to_date)) {
140 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
141 if (empty($form_code)) {
144 $query_codes = 'c.id in (';
145 foreach ($form_code as $code) {
146 $query_codes .= '?,';
147 array_push($sqlBindArray, $code);
149 $query_codes = substr($query_codes, 0, -1);
150 $query_codes .= ') and ';
153 $query .= "l.pid=p.pid and " .
155 "l.diagnosis LIKE 'ICD9:%' and " .
156 "substring(l.diagnosis,6) = c.code ";
158 //echo "<p> DEBUG query: $query </p>\n"; // debugging
161 $nowdate = date('YmdHi');
162 $now = date('YmdGi');
163 $now1 = date('Y-m-d G:i');
164 $filename = "syn_sur_" . $now . ".hl7";
167 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
168 $facility_info = getLoggedInUserFacility();
171 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
174 $res = sqlStatement($query, $sqlBindArray);
176 while ($r = sqlFetchArray($res)) {
178 $content .= "MSH|^~\&|" . strtoupper($openemr_name) .
179 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
181 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
182 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
187 "|" . // 1.B Event Type Code
188 "$now" . // 2.R Recorded Date/Time
190 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
193 if ($r['sex'] === 'Male') {
197 if ($r['sex'] === 'Female') {
201 if ($r['status'] === 'married') {
205 if ($r['status'] === 'single') {
209 if ($r['status'] === 'divorced') {
213 if ($r['status'] === 'widowed') {
217 if ($r['status'] === 'separated') {
221 if ($r['status'] === 'domestic partner') {
229 $r['patientid'] . "^^^^MR" . "|" . // 3. (R) Patient identifier list
230 "|" . // 4. (B) Alternate PID
231 "^^^^^^~^^^^^^S" . "|" . // 5.R. Name
232 "|" . // 6. Mather Maiden Name
233 $r['DOB'] . "|" . // 7. Date, time of birth
234 $r['sex'] . // 8. Sex
235 "|||^^^||||||||||||||||||||||||||||" .
240 "|||||||||||||||||" .
241 // Restrict the string to 15 characters. Will fail if longer.
242 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
243 "|||||||||||||||||||||||||" .
247 // OBX: Records chief complaint in LOINC code
250 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
251 "^^^^^^^^" . $r['issuetitle'] .
257 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
258 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
263 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
268 // mark if issues generated/sent
269 $query_insert = "insert into syndromic_surveillance(lists_id, submission_date, filename) " .
271 sqlStatement($query_insert, array($r['issueid'], $now1, $filename));
274 // Ensoftek: Jul-2015: No need to tr the content
275 //$content = tr($content);
277 // send the header here
278 header('Content-type: text/plain');
279 header('Content-Disposition: attachment; filename=' . $filename);
281 // put the content in the file
289 <title
><?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></title
>
291 <?php Header
::setupHeader('datetime-picker'); ?
>
295 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
298 var win
= top
.printLogSetup ? top
: opener
.top
;
299 win
.printLogSetup(document
.getElementById('printbutton'));
301 $
('.datepicker').datetimepicker({
302 <?php
$datetimepicker_timepicker = false; ?
>
303 <?php
$datetimepicker_showseconds = false; ?
>
304 <?php
$datetimepicker_formatInput = true; ?
>
305 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
306 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
313 /* specifically include & exclude from printing */
319 #report_parameters_daterange {
324 #report_results table {
328 /* specifically exclude some from the screen */
330 #report_parameters_daterange {
341 <body
class="body_top">
343 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Syndromic Surveillance - Non Reported Issues'); ?
></span
>
345 <div id
="report_parameters_daterange">
346 <?php
echo text(oeFormatShortDate($from_date)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($to_date)); ?
>
349 <form name
='theform' id
='theform' method
='post' action
='non_reported.php' onsubmit
='return top.restoreSession()'>
350 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
351 <div id
="report_parameters">
352 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
353 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
357 <div style
='float:left'>
360 <td
class='col-form-label'>
361 <?php
echo xlt('Diagnosis'); ?
>:
365 // Build a drop-down list of codes.
367 $query1 = "select id, code as name, code_type from codes " .
368 " where reportable=1 ORDER BY name";
369 $cres = sqlStatement($query1);
370 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
371 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
372 while ($crow = sqlFetchArray($cres)) {
373 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
374 // This report currently only works for ICD9 codes. Need to make this work for other
375 // diagnosis code sets in the future.
376 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
377 $codeid = $crow['id'];
378 echo " <option value='" . attr($codeid) . "'";
379 if (in_array($codeid, $form_code)) {
383 echo ">" . text($crow['name']) . "\n";
390 <td
class='col-form-label'>
391 <?php
echo xlt('From'); ?
>:
394 <input type
='text' name
='form_from_date' id
="form_from_date"
395 class='datepicker form-control'
396 size
='10' value
='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
398 <td
class='col-form-label'>
399 <?php
echo xlt('To{{Range}}'); ?
>:
402 <input type
='text' name
='form_to_date' id
="form_to_date"
403 class='datepicker form-control'
404 size
='10' value
='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
410 <td
class='h-100' align
='left' valign
='middle'>
411 <table
class='w-100 h-100' style
='border-left:1px solid;'>
414 <div
class="text-center">
415 <div
class="btn-group" role
="group">
416 <a href
='#' class='btn btn-secondary btn-refresh'
418 $("#form_refresh").attr("value","true");
419 $("#form_get_hl7").attr("value","false");
420 $("#theform").submit();
422 <?php
echo xlt('Refresh'); ?
>
424 <?php
if (!empty($_POST['form_refresh'])) { ?
>
425 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
426 <?php
echo xlt('Print'); ?
>
428 <a href
='#' class='btn btn-secondary btn-transmit' onclick
=
429 "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?'); ?>)) {
430 $('#form_get_hl7').attr('value','true');
431 $('#theform').submit();
433 <?php
echo xlt('Get HL7'); ?
>
444 </div
> <!-- end of parameters
-->
448 if (!empty($_POST['form_refresh'])) {
450 <div id
="report_results">
451 <table
class='table'>
452 <thead
class='thead-light' align
="left">
453 <th
> <?php
echo xlt('Patient ID'); ?
> </th
>
454 <th
> <?php
echo xlt('Patient Name'); ?
> </th
>
455 <th
> <?php
echo xlt('Diagnosis'); ?
> </th
>
456 <th
> <?php
echo xlt('Issue ID'); ?
> </th
>
457 <th
> <?php
echo xlt('Issue Title'); ?
> </th
>
458 <th
> <?php
echo xlt('Issue Date'); ?
> </th
>
463 //echo "<p> DEBUG query: $query </p>\n"; // debugging
464 $res = sqlStatement($query, $sqlBindArray);
467 while ($row = sqlFetchArray($res)) {
471 <?php
echo text($row['patientid']) ?
>
474 <?php
echo text($row['patientname']) ?
>
477 <?php
echo text($row['diagnosis']) ?
>
480 <?php
echo text($row['issueid']) ?
>
483 <?php
echo text($row['issuetitle']) ?
>
486 <?php
echo text($row['issuedate']) ?
>
493 <tr
class="report_totals">
495 <?php
echo xlt('Total Number of Issues'); ?
>
497 <?php
echo text($total); ?
>
503 </div
> <!-- end of results
-->
506 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
><br
/>
507 (<?php
echo xlt('This report currently only works for ICD9 codes.'); ?
>)