new datepicker in encounter
[openemr.git] / interface / reports / non_reported.php
blob33e52bef8eaa47845e20f16ce5937c265e0c66e7
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
33 require_once("../globals.php");
34 require_once("$srcdir/patient.inc");
35 require_once("../../custom/code_types.inc.php");
38 // Ensoftek: Jul-2015: Get the facility of the logged in user.
39 function getLoggedInUserFacility(){
40 $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=?";
41 $res = sqlStatement($sql, array($_SESSION['authUserID']) );
42 while ($arow = sqlFetchArray($res)) {
43 return $arow;
45 return null;
48 // Ensoftek: Jul-2015: Map codes to confirm to HL7.
49 function mapCodeType($incode){
50 $outcode = null;
51 $code = explode(":", $incode);
52 switch ($code[0]) {
53 case "ICD9":
54 $outcode = "I9CDX";
55 break;
56 case "ICD10":
57 $outcode = "I10";
58 break;
59 case "SNOMED-CT":
60 $outcode = "SCT";
61 break;
62 case "US Ext SNOMEDCT":
63 $outcode = "SCT";
64 break;
65 default:
66 $outcode = "I9CDX"; // default to ICD9
67 break;
68 // Only ICD9, ICD10 and SNOMED codes allowed in Syndromic Surveillance
70 return $outcode;
74 if(isset($_POST['form_from_date'])) {
75 $from_date = $_POST['form_from_date'] !== "" ?
76 fixDate($_POST['form_from_date'], date('Y-m-d')) :
79 if(isset($_POST['form_to_date'])) {
80 $to_date =$_POST['form_to_date'] !== "" ?
81 fixDate($_POST['form_to_date'], date('Y-m-d')) :
85 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : Array();
87 if (empty ($form_code) ) {
88 $query_codes = '';
89 } else {
90 $query_codes = 'c.id in (';
91 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
92 $query_codes = substr($query_codes ,0,-1);
93 $query_codes .= ') and ';
96 function tr($a) {
97 return (str_replace(' ','^',$a));
100 $query =
101 "select " .
102 "l.pid as patientid, " .
103 "p.language, ".
104 "l.diagnosis , " ;
105 if ($_POST['form_get_hl7']==='true') {
106 $query .=
107 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
108 "concat(p.street, '^',p.postal_code,'^', p.city, '^', p.state) as address, ".
109 "p.country_code, ".
110 "p.phone_home, ".
111 "p.phone_biz, ".
112 "p.status, ".
113 "p.sex, ".
114 "p.ethnoracial, ".
115 "c.code_text, ".
116 "c.code, ".
117 "c.code_type, ".
118 "DATE_FORMAT(l.date,'%Y%m%d') as issuedate, ".
119 "concat(p.fname, '^',p.mname,'^', p.lname) as patientname, ";
120 } else {
121 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
122 "l.date as issuedate, " ;
124 $query .=
125 "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
126 "from lists l, patient_data p, codes c ".
127 "where ".
128 "c.reportable=1 and ".
129 "l.id not in (select lists_id from syndromic_surveillance) and ";
130 if($from_date!=0) {
131 $query .= "l.date >= '$from_date' " ;
133 if($from_date!=0 and $to_date!=0) {
134 $query .= " and " ;
136 if($to_date!=0) {
137 $query .= "l.date <= '$to_date' ";
139 if($from_date!=0 or $to_date!=0) {
140 $query .= " and " ;
142 $query .= "l.pid=p.pid and ".
143 $query_codes .
144 "l.diagnosis LIKE 'ICD9:%' and ".
145 "substring(l.diagnosis,6) = c.code ";
147 //echo "<p> DEBUG query: $query </p>\n"; // debugging
149 $D="\r";
150 $nowdate = date('YmdHi');
151 $now = date('YmdGi');
152 $now1 = date('Y-m-d G:i');
153 $filename = "syn_sur_". $now . ".hl7";
156 // Ensoftek: Jul-2015: Get logged in user's facility to be used in the MSH segment
157 $facility_info = getLoggedInUserFacility();
159 // GENERATE HL7 FILE
160 if ($_POST['form_get_hl7']==='true') {
161 $content = '';
163 $res = sqlStatement($query);
165 while ($r = sqlFetchArray($res)) {
166 // MSH
167 $content .= "MSH|^~\&|".strtoupper($openemr_name).
168 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
169 "|||$now||".
170 "ADT^A01^ADT_A01" . // Hard-code to A01: Patient visits provider/facility
171 "|$nowdate|P^T|2.5.1|||||||||PH_SS-NoAck^SS Sender^2.16.840.1.114222.4.10.3^ISO" . // No acknowlegement
172 "$D";
174 // EVN
175 $content .= "EVN|" .
176 "|" . // 1.B Event Type Code
177 "$now" . // 2.R Recorded Date/Time
178 "||||" .
179 "|" . $facility_info['name'] . "^" . $facility_info['facility_npi'] . "^NPI" .
180 "$D" ;
182 if ($r['sex']==='Male') $r['sex'] = 'M';
183 if ($r['sex']==='Female') $r['sex'] = 'F';
184 if ($r['status']==='married') $r['status'] = 'M';
185 if ($r['status']==='single') $r['status'] = 'S';
186 if ($r['status']==='divorced') $r['status'] = 'D';
187 if ($r['status']==='widowed') $r['status'] = 'W';
188 if ($r['status']==='separated') $r['status'] = 'A';
189 if ($r['status']==='domestic partner') $r['status'] = 'P';
191 // PID
192 $content .= "PID|" .
193 "1|" . // 1. Set id
194 "|" .
195 $r['patientid']."^^^^MR"."|". // 3. (R) Patient indentifier list
196 "|" . // 4. (B) Alternate PID
197 "^^^^^^~^^^^^^S"."|" . // 5.R. Name
198 "|" . // 6. Mather Maiden Name
199 $r['DOB']."|" . // 7. Date, time of birth
200 $r['sex'] . // 8. Sex
201 "|||^^^||||||||||||||||||||||||||||" .
202 "$D" ;
204 $content .= "PV1|" .
205 "1|" . // 1. Set ID
206 "|||||||||||||||||" .
207 // Restrict the string to 15 characters. Will fail if longer.
208 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
209 "|||||||||||||||||||||||||" .
210 $r['begin_date'] .
211 "$D" ;
213 // OBX: Records chief complaint in LOINC code
214 $content .= "OBX|" .
215 "1|" . // 1. Set ID
216 "CWE|8661-1^^LN||" . // LOINC code for chief complaint
217 "^^^^^^^^" . $r['issuetitle'] .
218 "||||||" .
219 "F" .
220 "$D" ;
222 // DG1
223 $r['diagnosis'] = mapCodeType($r['diagnosis']); // Only ICD9, ICD10 and SNOMED
224 $r['code'] = str_replace(".", "", $r['code']); // strip periods code
226 $content .= "DG1|" .
227 "1|" . // 1. Set ID
228 "|" .
229 $r['code'] . "^" . $r['code_text'] . "^" . $r['diagnosis'] .
230 "|||W" .
231 "$D" ;
234 // mark if issues generated/sent
235 $query_insert = "insert into syndromic_surveillance(lists_id,submission_date,filename) " .
236 "values (" . $r['issueid'] . ",'" . $now1 . "','" . $filename . "')";
237 sqlStatement($query_insert);
240 // Ensoftek: Jul-2015: No need to tr the content
241 //$content = tr($content);
243 // send the header here
244 header('Content-type: text/plain');
245 header('Content-Disposition: attachment; filename=' . $filename );
247 // put the content in the file
248 echo($content);
249 exit;
253 <html>
254 <head>
255 <?php html_header_show();?>
256 <title><?php xl('Syndromic Surveillance - Non Reported Issues','e'); ?></title>
257 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
258 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
259 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
260 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
262 <script language="JavaScript">
264 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
266 $(document).ready(function() {
267 var win = top.printLogSetup ? top : opener.top;
268 win.printLogSetup(document.getElementById('printbutton'));
270 $('.datepicker').datetimepicker({
271 <?php $datetimepicker_timepicker = false; ?>
272 <?php $datetimepicker_formatInput = false; ?>
273 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
274 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
278 </script>
280 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
281 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
283 <style type="text/css">
284 /* specifically include & exclude from printing */
285 @media print {
286 #report_parameters {
287 visibility: hidden;
288 display: none;
290 #report_parameters_daterange {
291 visibility: visible;
292 display: inline;
293 margin-bottom: 10px;
295 #report_results table {
296 margin-top: 0px;
299 /* specifically exclude some from the screen */
300 @media screen {
301 #report_parameters_daterange {
302 visibility: hidden;
303 display: none;
305 #report_results {
306 width: 100%;
309 </style>
310 </head>
312 <body class="body_top">
314 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Syndromic Surveillance - Non Reported Issues','e'); ?></span>
316 <div id="report_parameters_daterange">
317 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
318 </div>
320 <form name='theform' id='theform' method='post' action='non_reported.php'
321 onsubmit='return top.restoreSession()'>
322 <div id="report_parameters">
323 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
324 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
325 <table>
326 <tr>
327 <td width='410px'>
328 <div style='float:left'>
329 <table class='text'>
330 <tr>
331 <td class='label'>
332 <?php xl('Diagnosis','e'); ?>:
333 </td>
334 <td>
335 <?php
336 // Build a drop-down list of codes.
338 $query1 = "select id, code as name, code_type from codes ".
339 " where reportable=1 ORDER BY name";
340 $cres = sqlStatement($query1);
341 echo " <select multiple='multiple' size='3' name='form_code[]'>\n";
342 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
343 while ($crow = sqlFetchArray($cres)) {
344 if (convert_type_id_to_key($crow['code_type']) == "ICD9") {
345 // This report currently only works for ICD9 codes. Need to make this work for other
346 // diagnosis code sets in the future.
347 $crow['name'] = convert_type_id_to_key($crow['code_type']) . ":" . $crow['name'];
348 $codeid = $crow['id'];
349 echo " <option value='$codeid'";
350 if (in_array($codeid, $form_code)) echo " selected";
351 echo ">" . $crow['name'] . "\n";
354 echo " </select>\n";
356 </td>
357 <td class='label'>
358 <?php xl('From','e'); ?>:
359 </td>
360 <td>
361 <input type='text' name='form_from_date' id="form_from_date"
362 class='datepicker'
363 size='10' value='<?php echo $form_from_date ?>'
364 title='yyyy-mm-dd'>
365 </td>
366 <td class='label'>
367 <?php xl('To','e'); ?>:
368 </td>
369 <td>
370 <input type='text' name='form_to_date' id="form_to_date"
371 class='datepicker'
372 size='10' value='<?php echo $form_to_date ?>'
373 title='yyyy-mm-dd'>
374 </td>
375 </tr>
376 </table>
377 </div>
378 </td>
379 <td align='left' valign='middle' height="100%">
380 <table style='border-left:1px solid; width:100%; height:100%' >
381 <tr>
382 <td>
383 <div style='margin-left:15px'>
384 <a href='#' class='css_button'
385 onclick='
386 $("#form_refresh").attr("value","true");
387 $("#form_get_hl7").attr("value","false");
388 $("#theform").submit();
390 <span>
391 <?php xl('Refresh','e'); ?>
392 </spain>
393 </a>
394 <?php if ($_POST['form_refresh']) { ?>
395 <a href='#' class='css_button' id='printbutton'>
396 <span>
397 <?php echo xlt('Print'); ?>
398 </span>
399 </a>
400 <a href='#' class='css_button' onclick=
401 "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'); ?>')) {
402 $('#form_get_hl7').attr('value','true');
403 $('#theform').submit();
405 <span>
406 <?php xl('Get HL7','e'); ?>
407 </span>
408 </a>
409 <?php } ?>
410 </div>
411 </td>
412 </tr>
413 </table>
414 </td>
415 </tr>
416 </table>
417 </div> <!-- end of parameters -->
420 <?php
421 if ($_POST['form_refresh']) {
423 <div id="report_results">
424 <table>
425 <thead align="left">
426 <th> <?php xl('Patient ID','e'); ?> </th>
427 <th> <?php xl('Patient Name','e'); ?> </th>
428 <th> <?php xl('Diagnosis','e'); ?> </th>
429 <th> <?php xl('Issue ID','e'); ?> </th>
430 <th> <?php xl('Issue Title','e'); ?> </th>
431 <th> <?php xl('Issue Date','e'); ?> </th>
432 </thead>
433 <tbody>
434 <?php
435 $total = 0;
436 //echo "<p> DEBUG query: $query </p>\n"; // debugging
437 $res = sqlStatement($query);
440 while ($row = sqlFetchArray($res)) {
442 <tr>
443 <td>
444 <?php echo htmlspecialchars($row['patientid']) ?>
445 </td>
446 <td>
447 <?php echo htmlspecialchars($row['patientname']) ?>
448 </td>
449 <td>
450 <?php echo htmlspecialchars($row['diagnosis']) ?>
451 </td>
452 <td>
453 <?php echo htmlspecialchars($row['issueid']) ?>
454 </td>
455 <td>
456 <?php echo htmlspecialchars($row['issuetitle']) ?>
457 </td>
458 <td>
459 <?php echo htmlspecialchars($row['issuedate']) ?>
460 </td>
461 </tr>
462 <?php
463 ++$total;
466 <tr class="report_totals">
467 <td colspan='9'>
468 <?php xl('Total Number of Issues','e'); ?>
470 <?php echo $total ?>
471 </td>
472 </tr>
474 </tbody>
475 </table>
476 </div> <!-- end of results -->
477 <?php } else { ?>
478 <div class='text'>
479 <?php echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?><br>
480 (<?php echo xlt('This report currently only works for ICD9 codes.'); ?>)
481 </div>
482 <?php } ?>
483 </form>
485 </body>
486 </html>