immun updates (#4145)
[openemr.git] / interface / reports / non_reported.php
blob5c80339ce780e73e719f801d255c6d75f14d5d08
1 <?php
3 /**
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.
8 * @package OpenEMR
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;
28 if (!empty($_POST)) {
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)) {
40 return $arow;
43 return null;
46 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
47 function mapCodeType($incode)
49 $outcode = null;
50 $code = explode(":", $incode);
51 switch ($code[0]) {
52 case "ICD9":
53 $outcode = "I9CDX";
54 break;
55 case "ICD10":
56 $outcode = "I10";
57 break;
58 case "SNOMED-CT":
59 $outcode = "SCT";
60 break;
61 case "US Ext SNOMEDCT":
62 $outcode = "SCT";
63 break;
64 default:
65 $outcode = "I9CDX"; // default to ICD9
66 break;
67 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
70 return $outcode;
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']) : '';
78 function tr($a)
80 return (str_replace(' ', '^', $a));
83 $sqlBindArray = array();
84 $query =
85 "select " .
86 "l.pid as patientid, " .
87 "p.language, " .
88 "l.diagnosis , " ;
89 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
90 $query .=
91 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, " .
92 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, " .
93 "p.country_code, " .
94 "p.phone_home, " .
95 "p.phone_biz, " .
96 "p.status, " .
97 "p.sex, " .
98 "p.ethnoracial, " .
99 "c.code_text, " .
100 "c.code, " .
101 "c.code_type, " .
102 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, " .
103 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
104 } else {
105 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, " .
106 "l.date as issuedate, " ;
109 $query .=
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 " .
112 "where " .
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)) {
121 $query .= " and " ;
124 if (!empty($to_date)) {
125 $query .= "l.date <= ? ";
126 array_push($sqlBindArray, $to_date);
129 if (!empty($from_date) || !empty($to_date)) {
130 $query .= " and " ;
133 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : array();
134 if (empty($form_code)) {
135 $query_codes = '';
136 } else {
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 " .
147 $query_codes .
148 "l.diagnosis LIKE 'ICD9:%' and " .
149 "substring(l.diagnosis,6) = c.code ";
151 //echo "<p> DEBUG query: $query </p>\n"; // debugging
153 $D = "\r";
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();
163 // GENERATE HL7 FILE
164 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
165 $content = '';
167 $res = sqlStatement($query, $sqlBindArray);
169 while ($r = sqlFetchArray($res)) {
170 // MSH
171 $content .= "MSH|^~\&|" . strtoupper($openemr_name) .
172 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
173 "|||$now||" .
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
176 "$D";
178 // EVN
179 $content .= "EVN|" .
180 "|" . // 1.B Event Type Code
181 "$now" . // 2.R Recorded Date/Time
182 "||||" .
183 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
184 "$D" ;
186 if ($r['sex'] === 'Male') {
187 $r['sex'] = 'M';
190 if ($r['sex'] === 'Female') {
191 $r['sex'] = 'F';
194 if ($r['status'] === 'married') {
195 $r['status'] = 'M';
198 if ($r['status'] === 'single') {
199 $r['status'] = 'S';
202 if ($r['status'] === 'divorced') {
203 $r['status'] = 'D';
206 if ($r['status'] === 'widowed') {
207 $r['status'] = 'W';
210 if ($r['status'] === 'separated') {
211 $r['status'] = 'A';
214 if ($r['status'] === 'domestic partner') {
215 $r['status'] = 'P';
218 // PID
219 $content .= "PID|" .
220 "1|" . // 1. Set id
221 "|" .
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 "|||^^^||||||||||||||||||||||||||||" .
229 "$D" ;
231 $content .= "PV1|" .
232 "1|" . // 1. Set ID
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 "|||||||||||||||||||||||||" .
237 $r['begin_date'] .
238 "$D" ;
240 // OBX: Records chief complaint in LOINC code
241 $content .= "OBX|" .
242 "1|" . // 1. Set ID
243 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
244 "^^^^^^^^" . $r['issuetitle'] .
245 "||||||" .
246 "F" .
247 "$D" ;
249 // DG1
250 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
251 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
253 $content .= "DG1|" .
254 "1|" . // 1. Set ID
255 "|" .
256 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
257 "|||W" .
258 "$D" ;
261 // mark if issues generated/sent
262 $query_insert = "insert into syndromic_surveillance(lists_id, submission_date, filename) " .
263 "values (?, ?, ?)";
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
275 echo($content);
276 exit;
280 <html>
281 <head>
282 <title><?php echo xlt('Syndromic Surveillance - Non Reported Issues'); ?></title>
284 <?php Header::setupHeader('datetime-picker'); ?>
286 <script>
288 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
290 $(function () {
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 ?>
303 </script>
305 <style>
306 /* specifically include & exclude from printing */
307 @media print {
308 #report_parameters {
309 visibility: hidden;
310 display: none;
312 #report_parameters_daterange {
313 visibility: visible;
314 display: inline;
315 margin-bottom: 10px;
317 #report_results table {
318 margin-top: 0px;
321 /* specifically exclude some from the screen */
322 @media screen {
323 #report_parameters_daterange {
324 visibility: hidden;
325 display: none;
327 #report_results {
328 width: 100%;
331 </style>
332 </head>
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)) . " &nbsp; " . xlt('to{{Range}}') . "&nbsp; " . text(oeFormatShortDate($to_date)); ?>
340 </div>
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=''/>
347 <table>
348 <tr>
349 <td width='410px'>
350 <div style='float:left'>
351 <table class='text'>
352 <tr>
353 <td class='col-form-label'>
354 <?php echo xlt('Diagnosis'); ?>:
355 </td>
356 <td>
357 <?php
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)) {
373 echo " selected";
376 echo ">" . text($crow['name']) . "\n";
380 echo " </select>\n";
382 </td>
383 <td class='col-form-label'>
384 <?php echo xlt('From'); ?>:
385 </td>
386 <td>
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)); ?>'>
390 </td>
391 <td class='col-form-label'>
392 <?php echo xlt('To{{Range}}'); ?>:
393 </td>
394 <td>
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)); ?>'>
398 </td>
399 </tr>
400 </table>
401 </div>
402 </td>
403 <td class='h-100' align='left' valign='middle'>
404 <table class='w-100 h-100' style='border-left:1px solid;'>
405 <tr>
406 <td>
407 <div class="text-center">
408 <div class="btn-group" role="group">
409 <a href='#' class='btn btn-secondary btn-refresh'
410 onclick='
411 $("#form_refresh").attr("value","true");
412 $("#form_get_hl7").attr("value","false");
413 $("#theform").submit();
415 <?php echo xlt('Refresh'); ?>
416 </a>
417 <?php if (!empty($_POST['form_refresh'])) { ?>
418 <a href='#' class='btn btn-secondary btn-print' id='printbutton'>
419 <?php echo xlt('Print'); ?>
420 </a>
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'); ?>
427 </a>
428 <?php } ?>
429 </div>
430 </div>
431 </td>
432 </tr>
433 </table>
434 </td>
435 </tr>
436 </table>
437 </div> <!-- end of parameters -->
440 <?php
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>
452 </thead>
453 <tbody>
454 <?php
455 $total = 0;
456 //echo "<p> DEBUG query: $query </p>\n"; // debugging
457 $res = sqlStatement($query, $sqlBindArray);
460 while ($row = sqlFetchArray($res)) {
462 <tr>
463 <td>
464 <?php echo text($row['patientid']) ?>
465 </td>
466 <td>
467 <?php echo text($row['patientname']) ?>
468 </td>
469 <td>
470 <?php echo text($row['diagnosis']) ?>
471 </td>
472 <td>
473 <?php echo text($row['issueid']) ?>
474 </td>
475 <td>
476 <?php echo text($row['issuetitle']) ?>
477 </td>
478 <td>
479 <?php echo text($row['issuedate']) ?>
480 </td>
481 </tr>
482 <?php
483 ++$total;
486 <tr class="report_totals">
487 <td colspan='9'>
488 <?php echo xlt('Total Number of Issues'); ?>
490 <?php echo text($total); ?>
491 </td>
492 </tr>
494 </tbody>
495 </table>
496 </div> <!-- end of results -->
497 <?php } else { ?>
498 <div class='text'>
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.'); ?>)
501 </div>
502 <?php } ?>
503 </form>
505 </body>
506 </html>