ongoing internationalization of date widget
[openemr.git] / interface / reports / immunization_report.php
blob4e3faad66f42067001fe8dc96f3321ee8c7ec1a6
1 <?php
2 /**
3 * This report lists patient immunizations for a given date range.
5 * Copyright (C) 2011 Ensoftek Inc.
6 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @package OpenEMR
20 * @author Brady Miller <brady.g.miller@gmail.com>
21 * @link http://www.open-emr.org
24 use OpenEMR\Core\Header;
26 require_once("../globals.php");
27 require_once("$srcdir/patient.inc");
29 if (isset($_POST['form_from_date'])) {
30 $from_date = $_POST['form_from_date'] !== "" ?
31 fixDate($_POST['form_from_date'], date('Y-m-d')) :
35 if (isset($_POST['form_to_date'])) {
36 $to_date =$_POST['form_to_date'] !== "" ?
37 fixDate($_POST['form_to_date'], date('Y-m-d')) :
42 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : array();
44 if (empty($form_code)) {
45 $query_codes = '';
46 } else {
47 $query_codes = 'c.id in (';
48 foreach ($form_code as $code) {
49 $query_codes .= $code . ",";
52 $query_codes = substr($query_codes, 0, -1);
53 $query_codes .= ') and ';
56 function tr($a)
58 return (str_replace(' ', '^', $a));
61 function format_cvx_code($cvx_code)
64 if ($cvx_code < 10) {
65 return "0$cvx_code";
68 return $cvx_code;
71 function format_phone($phone)
74 $phone = preg_replace("/[^0-9]/", "", $phone);
75 switch (strlen($phone)) {
76 case 7:
77 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
78 case 10:
79 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
80 default:
81 return tr("000 0000000");
85 function format_ethnicity($ethnicity)
88 switch ($ethnicity) {
89 case "hisp_or_latin":
90 return ("H^Hispanic or Latino^HL70189");
91 case "not_hisp_or_latin":
92 return ("N^not Hispanic or Latino^HL70189");
93 default: // Unknown
94 return ("U^Unknown^HL70189");
99 $query =
100 "select " .
101 "i.patient_id as patientid, " .
102 "p.language, ".
103 "i.cvx_code , " ;
104 if ($_POST['form_get_hl7']==='true') {
105 $query .=
106 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
107 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
108 "p.country_code, ".
109 "p.phone_home, ".
110 "p.phone_biz, ".
111 "p.status, ".
112 "p.sex, ".
113 "p.ethnoracial, ".
114 "p.race, ".
115 "p.ethnicity, ".
116 "c.code_text, ".
117 "c.code, ".
118 "c.code_type, ".
119 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
120 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
121 "i.lot_number as lot_number, ".
122 "i.manufacturer as manufacturer, ".
123 "concat(p.fname, '^', p.lname) as patientname, ";
124 } else {
125 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
126 "i.vis_date as immunizationdate, " ;
129 $query .=
130 "i.id as immunizationid, c.code_text_short as immunizationtitle ".
131 "from immunizations i, patient_data p, codes c ".
132 "left join code_types ct on c.code_type = ct.ct_id ".
133 "where ".
134 "ct.ct_key='CVX' and ";
135 if ($from_date!=0) {
136 $query .= "i.vis_date >= '$from_date' " ;
139 if ($from_date!=0 and $to_date!=0) {
140 $query .= " and " ;
143 if ($to_date!=0) {
144 $query .= "i.vis_date <= '$to_date' ";
147 if ($from_date!=0 or $to_date!=0) {
148 $query .= " and " ;
151 $query .= "i.patient_id=p.pid and ".
152 $query_codes .
153 "i.cvx_code = c.code and ";
155 //do not show immunization added erroneously
156 $query .= "i.added_erroneously = 0";
158 //echo "<p> DEBUG query: $query </p>\n"; // debugging
161 $D="\r";
162 $nowdate = date('Ymd');
163 $now = date('YmdGi');
164 $now1 = date('Y-m-d G:i');
165 $filename = "imm_reg_". $now . ".hl7";
167 // GENERATE HL7 FILE
168 if ($_POST['form_get_hl7']==='true') {
169 $content = '';
171 $res = sqlStatement($query);
173 while ($r = sqlFetchArray($res)) {
174 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
175 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
176 "$D" ;
177 if ($r['sex']==='Male') {
178 $r['sex'] = 'M';
181 if ($r['sex']==='Female') {
182 $r['sex'] = 'F';
185 if ($r['status']==='married') {
186 $r['status'] = 'M';
189 if ($r['status']==='single') {
190 $r['status'] = 'S';
193 if ($r['status']==='divorced') {
194 $r['status'] = 'D';
197 if ($r['status']==='widowed') {
198 $r['status'] = 'W';
201 if ($r['status']==='separated') {
202 $r['status'] = 'A';
205 if ($r['status']==='domestic partner') {
206 $r['status'] = 'P';
209 $content .= "PID|" . // [[ 3.72 ]]
210 "|" . // 1. Set id
211 "|" . // 2. (B)Patient id
212 $r['patientid']. "^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR" . "|". // 3. (R) Patient indentifier list. TODO: Hard-coded the OID from NIST test.
213 "|" . // 4. (B) Alternate PID
214 $r['patientname']."|" . // 5.R. Name
215 "|" . // 6. Mather Maiden Name
216 $r['DOB']."|" . // 7. Date, time of birth
217 $r['sex']."|" . // 8. Sex
218 "|" . // 9.B Patient Alias
219 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
220 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
221 "|" . // 12. county code
222 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
223 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
224 "|" . // 15. Primary language
225 $r['status']."|" . // 16. Marital status
226 "|" . // 17. Religion
227 "|" . // 18. patient Account Number
228 "|" . // 19.B SSN Number
229 "|" . // 20.B Driver license number
230 "|" . // 21. Mathers Identifier
231 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
232 "|" . // 23. Birth Plase
233 "|" . // 24. Multiple birth indicator
234 "|" . // 25. Birth order
235 "|" . // 26. Citizenship
236 "|" . // 27. Veteran military status
237 "|" . // 28.B Nationality
238 "|" . // 29. Patient Death Date and Time
239 "|" . // 30. Patient Death Indicator
240 "|" . // 31. Identity Unknown Indicator
241 "|" . // 32. Identity Reliability Code
242 "|" . // 33. Last Update Date/Time
243 "|" . // 34. Last Update Facility
244 "|" . // 35. Species Code
245 "|" . // 36. Breed Code
246 "|" . // 37. Breed Code
247 "|" . // 38. Production Class Code
248 "" . // 39. Tribal Citizenship
249 "$D" ;
250 $content .= "ORC" . // ORC mandatory for RXA
251 "|" .
252 "RE" .
253 "$D" ;
254 $content .= "RXA|" .
255 "0|" . // 1. Give Sub-ID Counter
256 "1|" . // 2. Administrattion Sub-ID Counter
257 $r['administered_date']."|" . // 3. Date/Time Start of Administration
258 $r['administered_date']."|" . // 4. Date/Time End of Administration
259 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
260 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
261 "|" . // 7. Administered Units
262 "|" . // 8. Administered Dosage Form
263 "|" . // 9. Administration Notes
264 "|" . // 10. Administering Provider
265 "|" . // 11. Administered-at Location
266 "|" . // 12. Administered Per (Time Unit)
267 "|" . // 13. Administered Strength
268 "|" . // 14. Administered Strength Units
269 $r['lot_number']."|" . // 15. Substance Lot Number
270 "|" . // 16. Substance Expiration Date
271 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
272 "|" . // 18. Substance/Treatment Refusal Reason
273 "|" . // 19.Indication
274 "|" . // 20.Completion Status
275 "A" . // 21.Action Code - RXA
276 "$D" ;
279 // send the header here
280 header('Content-type: text/plain');
281 header('Content-Disposition: attachment; filename=' . $filename);
283 // put the content in the file
284 echo($content);
285 exit;
289 <html>
290 <head>
292 <title><?php xl('Immunization Registry', 'e'); ?></title>
294 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
296 <script language="JavaScript">
297 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
299 $(document).ready(function() {
300 var win = top.printLogSetup ? top : opener.top;
301 win.printLogSetup(document.getElementById('printbutton'));
303 $('.datepicker').datetimepicker({
304 <?php $datetimepicker_timepicker = false; ?>
305 <?php $datetimepicker_showseconds = false; ?>
306 <?php $datetimepicker_formatInput = false; ?>
307 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
308 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
312 </script>
314 <style type="text/css">
315 /* specifically include & exclude from printing */
316 @media print {
317 #report_parameters {
318 visibility: hidden;
319 display: none;
321 #report_parameters_daterange {
322 visibility: visible;
323 display: inline;
324 margin-bottom: 10px;
326 #report_results table {
327 margin-top: 0px;
330 /* specifically exclude some from the screen */
331 @media screen {
332 #report_parameters_daterange {
333 visibility: hidden;
334 display: none;
336 #report_results {
337 width: 100%;
340 </style>
341 </head>
343 <body class="body_top">
345 <span class='title'><?php xl('Report', 'e'); ?> - <?php xl('Immunization Registry', 'e'); ?></span>
347 <div id="report_parameters_daterange">
348 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
349 </div>
351 <form name='theform' id='theform' method='post' action='immunization_report.php'
352 onsubmit='return top.restoreSession()'>
353 <div id="report_parameters">
354 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
355 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
356 <table>
357 <tr>
358 <td width='410px'>
359 <div style='float:left'>
360 <table class='text'>
361 <tr>
362 <td class='control-label'>
363 <?php xl('Codes', 'e'); ?>:
364 </td>
365 <td>
366 <?php
367 // Build a drop-down list of codes.
369 $query1 = "select id, concat('CVX:',code) as name from codes ".
370 " left join code_types ct on codes.code_type = ct.ct_id ".
371 " where ct.ct_key='CVX' ORDER BY name";
372 $cres = sqlStatement($query1);
373 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
374 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
375 while ($crow = sqlFetchArray($cres)) {
376 $codeid = $crow['id'];
377 echo " <option value='$codeid'";
378 if (in_array($codeid, $form_code)) {
379 echo " selected";
382 echo ">" . $crow['name'] . "\n";
385 echo " </select>\n";
387 </td>
388 <td class='control-label'>
389 <?php xl('From', 'e'); ?>:
390 </td>
391 <td>
392 <input type='text' name='form_from_date' id="form_from_date"
393 class='datepicker form-control'
394 size='10' value='<?php echo $form_from_date ?>'
395 title='yyyy-mm-dd'>
396 </td>
397 <td class='control-label'>
398 <?php xl('To', 'e'); ?>:
399 </td>
400 <td>
401 <input type='text' name='form_to_date' id="form_to_date"
402 class='datepicker form-control'
403 size='10' value='<?php echo $form_to_date ?>'
404 title='yyyy-mm-dd'>
405 </td>
406 </tr>
407 </table>
408 </div>
409 </td>
410 <td align='left' valign='middle' height="100%">
411 <table style='border-left:1px solid; width:100%; height:100%' >
412 <tr>
413 <td>
414 <div class="text-center">
415 <div class="btn-group" role="group">
416 <a href='#' class='btn btn-default btn-save'
417 onclick='
418 $("#form_refresh").attr("value","true");
419 $("#form_get_hl7").attr("value","false");
420 $("#theform").submit();
422 <?php echo xlt('Refresh'); ?>
423 </a>
424 <?php if ($_POST['form_refresh']) { ?>
425 <a href='#' class='btn btn-default btn-print' id='printbutton'>
426 <?php echo xlt('Print'); ?>
427 </a>
428 <a href='#' class='btn btn-default btn-transmit' onclick=
429 "if(confirm('<?php echo xls('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'); ?>
434 </a>
435 <?php } ?>
436 </div>
437 </div>
438 </td>
439 </tr>
440 </table>
441 </td>
442 </tr>
443 </table>
444 </div> <!-- end of parameters -->
447 <?php
448 if ($_POST['form_refresh']) {
450 <div id="report_results">
451 <table>
452 <thead align="left">
453 <th> <?php xl('Patient ID', 'e'); ?> </th>
454 <th> <?php xl('Patient Name', 'e'); ?> </th>
455 <th> <?php xl('Immunization Code', 'e'); ?> </th>
456 <th> <?php xl('Immunization Title', 'e'); ?> </th>
457 <th> <?php xl('Immunization Date', 'e'); ?> </th>
458 </thead>
459 <tbody>
460 <?php
461 $total = 0;
462 //echo "<p> DEBUG query: $query </p>\n"; // debugging
463 $res = sqlStatement($query);
466 while ($row = sqlFetchArray($res)) {
468 <tr>
469 <td>
470 <?php echo htmlspecialchars($row['patientid']) ?>
471 </td>
472 <td>
473 <?php echo htmlspecialchars($row['patientname']) ?>
474 </td>
475 <td>
476 <?php echo htmlspecialchars($row['cvx_code']) ?>
477 </td>
478 <td>
479 <?php echo htmlspecialchars($row['immunizationtitle']) ?>
480 </td>
481 <td>
482 <?php echo htmlspecialchars($row['immunizationdate']) ?>
483 </td>
484 </tr>
485 <?php
486 ++$total;
489 <tr class="report_totals">
490 <td colspan='9'>
491 <?php xl('Total Number of Immunizations', 'e'); ?>
493 <?php echo $total ?>
494 </td>
495 </tr>
497 </tbody>
498 </table>
499 </div> <!-- end of results -->
500 <?php } else { ?>
501 <div class='text'>
502 <?php echo xl('Click Refresh to view all results, or please input search criteria above to view specific results.', 'e'); ?>
503 </div>
504 <?php } ?>
505 </form>
507 </body>
508 </html>