ongoing internationalization of date widget
[openemr.git] / interface / reports / non_reported.php
blob5084c7ae69cb981d2ad0e5575937d5c4d06bdf17
1 <?php
2 /*
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>;.
24 * @package OpenEMR
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)) {
45 return $arow;
48 return null;
51 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
52 function mapCodeType($incode)
54 $outcode = null;
55 $code = explode(":", $incode);
56 switch ($code[0]) {
57 case "ICD9":
58 $outcode = "I9CDX";
59 break;
60 case "ICD10":
61 $outcode = "I10";
62 break;
63 case "SNOMED-CT":
64 $outcode = "SCT";
65 break;
66 case "US Ext SNOMEDCT":
67 $outcode = "SCT";
68 break;
69 default:
70 $outcode = "I9CDX"; // default to ICD9
71 break;
72 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
75 return $outcode;
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)) {
95 $query_codes = '';
96 } else {
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 ';
107 function tr($a)
109 return (str_replace(' ', '^', $a));
112 $query =
113 "select " .
114 "l.pid as patientid, " .
115 "p.language, ".
116 "l.diagnosis , " ;
117 if ($_POST['form_get_hl7']==='true') {
118 $query .=
119 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
120 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
121 "p.country_code, ".
122 "p.phone_home, ".
123 "p.phone_biz, ".
124 "p.status, ".
125 "p.sex, ".
126 "p.ethnoracial, ".
127 "c.code_text, ".
128 "c.code, ".
129 "c.code_type, ".
130 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
131 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
132 } else {
133 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
134 "l.date as issuedate, " ;
137 $query .=
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 ".
140 "where ".
141 "c.reportable=1 and ".
142 "l.id not in (select lists_id from syndromic_surveillance) and ";
143 if ($from_date!=0) {
144 $query .= "l.date >= '$from_date' " ;
147 if ($from_date!=0 and $to_date!=0) {
148 $query .= " and " ;
151 if ($to_date!=0) {
152 $query .= "l.date <= '$to_date' ";
155 if ($from_date!=0 or $to_date!=0) {
156 $query .= " and " ;
159 $query .= "l.pid=p.pid and ".
160 $query_codes .
161 "l.diagnosis LIKE 'ICD9:%' and ".
162 "substring(l.diagnosis,6) = c.code ";
164 //echo "<p> DEBUG query: $query </p>\n"; // debugging
166 $D="\r";
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();
176 // GENERATE HL7 FILE
177 if ($_POST['form_get_hl7']==='true') {
178 $content = '';
180 $res = sqlStatement($query);
182 while ($r = sqlFetchArray($res)) {
183 // MSH
184 $content .= "MSH|^~\&|".strtoupper($openemr_name).
185 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
186 "|||$now||".
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
189 "$D";
191 // EVN
192 $content .= "EVN|" .
193 "|" . // 1.B Event Type Code
194 "$now" . // 2.R Recorded Date/Time
195 "||||" .
196 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
197 "$D" ;
199 if ($r['sex']==='Male') {
200 $r['sex'] = 'M';
203 if ($r['sex']==='Female') {
204 $r['sex'] = 'F';
207 if ($r['status']==='married') {
208 $r['status'] = 'M';
211 if ($r['status']==='single') {
212 $r['status'] = 'S';
215 if ($r['status']==='divorced') {
216 $r['status'] = 'D';
219 if ($r['status']==='widowed') {
220 $r['status'] = 'W';
223 if ($r['status']==='separated') {
224 $r['status'] = 'A';
227 if ($r['status']==='domestic partner') {
228 $r['status'] = 'P';
231 // PID
232 $content .= "PID|" .
233 "1|" . // 1. Set id
234 "|" .
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 "|||^^^||||||||||||||||||||||||||||" .
242 "$D" ;
244 $content .= "PV1|" .
245 "1|" . // 1. Set ID
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 "|||||||||||||||||||||||||" .
250 $r['begin_date'] .
251 "$D" ;
253 // OBX: Records chief complaint in LOINC code
254 $content .= "OBX|" .
255 "1|" . // 1. Set ID
256 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
257 "^^^^^^^^" . $r['issuetitle'] .
258 "||||||" .
259 "F" .
260 "$D" ;
262 // DG1
263 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
264 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
266 $content .= "DG1|" .
267 "1|" . // 1. Set ID
268 "|" .
269 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
270 "|||W" .
271 "$D" ;
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
288 echo($content);
289 exit;
293 <html>
294 <head>
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 ?>
316 </script>
318 <style type="text/css">
319 /* specifically include & exclude from printing */
320 @media print {
321 #report_parameters {
322 visibility: hidden;
323 display: none;
325 #report_parameters_daterange {
326 visibility: visible;
327 display: inline;
328 margin-bottom: 10px;
330 #report_results table {
331 margin-top: 0px;
334 /* specifically exclude some from the screen */
335 @media screen {
336 #report_parameters_daterange {
337 visibility: hidden;
338 display: none;
340 #report_results {
341 width: 100%;
344 </style>
345 </head>
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)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
353 </div>
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=''/>
360 <table>
361 <tr>
362 <td width='410px'>
363 <div style='float:left'>
364 <table class='text'>
365 <tr>
366 <td class='control-label'>
367 <?php xl('Diagnosis', 'e'); ?>:
368 </td>
369 <td>
370 <?php
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)) {
386 echo " selected";
389 echo ">" . $crow['name'] . "\n";
393 echo " </select>\n";
395 </td>
396 <td class='control-label'>
397 <?php xl('From', 'e'); ?>:
398 </td>
399 <td>
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 ?>'
403 title='yyyy-mm-dd'>
404 </td>
405 <td class='control-label'>
406 <?php xl('To', 'e'); ?>:
407 </td>
408 <td>
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 ?>'
412 title='yyyy-mm-dd'>
413 </td>
414 </tr>
415 </table>
416 </div>
417 </td>
418 <td align='left' valign='middle' height="100%">
419 <table style='border-left:1px solid; width:100%; height:100%' >
420 <tr>
421 <td>
422 <div class="text-center">
423 <div class="btn-group" role="group">
424 <a href='#' class='btn btn-default btn-refresh'
425 onclick='
426 $("#form_refresh").attr("value","true");
427 $("#form_get_hl7").attr("value","false");
428 $("#theform").submit();
430 <?php echo xlt('Refresh'); ?>
431 </a>
432 <?php if ($_POST['form_refresh']) { ?>
433 <a href='#' class='btn btn-default btn-print' id='printbutton'>
434 <?php echo xlt('Print'); ?>
435 </a>
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'); ?>
442 </a>
443 <?php } ?>
444 </div>
445 </div>
446 </td>
447 </tr>
448 </table>
449 </td>
450 </tr>
451 </table>
452 </div> <!-- end of parameters -->
455 <?php
456 if ($_POST['form_refresh']) {
458 <div id="report_results">
459 <table>
460 <thead align="left">
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>
467 </thead>
468 <tbody>
469 <?php
470 $total = 0;
471 //echo "<p> DEBUG query: $query </p>\n"; // debugging
472 $res = sqlStatement($query);
475 while ($row = sqlFetchArray($res)) {
477 <tr>
478 <td>
479 <?php echo htmlspecialchars($row['patientid']) ?>
480 </td>
481 <td>
482 <?php echo htmlspecialchars($row['patientname']) ?>
483 </td>
484 <td>
485 <?php echo htmlspecialchars($row['diagnosis']) ?>
486 </td>
487 <td>
488 <?php echo htmlspecialchars($row['issueid']) ?>
489 </td>
490 <td>
491 <?php echo htmlspecialchars($row['issuetitle']) ?>
492 </td>
493 <td>
494 <?php echo htmlspecialchars($row['issuedate']) ?>
495 </td>
496 </tr>
497 <?php
498 ++$total;
501 <tr class="report_totals">
502 <td colspan='9'>
503 <?php xl('Total Number of Issues', 'e'); ?>
505 <?php echo $total ?>
506 </td>
507 </tr>
509 </tbody>
510 </table>
511 </div> <!-- end of results -->
512 <?php } else { ?>
513 <div class='text'>
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.'); ?>)
516 </div>
517 <?php } ?>
518 </form>
520 </body>
521 </html>