added Urdu language
[openemr.git] / interface / reports / immunization_report.php
blobbfbd008782b2db7c3698c1c3ba308eeb2452f49a
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
25 require_once("../globals.php");
26 require_once("$srcdir/patient.inc");
28 if(isset($_POST['form_from_date'])) {
29 $from_date = $_POST['form_from_date'] !== "" ?
30 fixDate($_POST['form_from_date'], date('Y-m-d')) :
33 if(isset($_POST['form_to_date'])) {
34 $to_date =$_POST['form_to_date'] !== "" ?
35 fixDate($_POST['form_to_date'], date('Y-m-d')) :
39 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : Array();
41 if (empty ($form_code) ) {
42 $query_codes = '';
43 } else {
44 $query_codes = 'c.id in (';
45 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
46 $query_codes = substr($query_codes ,0,-1);
47 $query_codes .= ') and ';
50 function tr($a) {
51 return (str_replace(' ','^',$a));
54 function format_cvx_code($cvx_code) {
56 if ( $cvx_code < 10 ) {
57 return "0$cvx_code";
60 return $cvx_code;
63 function format_phone($phone) {
65 $phone = preg_replace("/[^0-9]/", "", $phone);
66 switch (strlen($phone))
68 case 7:
69 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
70 case 10:
71 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
72 default:
73 return tr("000 0000000");
77 function format_ethnicity($ethnicity) {
79 switch ($ethnicity)
81 case "hisp_or_latin":
82 return ("H^Hispanic or Latino^HL70189");
83 case "not_hisp_or_latin":
84 return ("N^not Hispanic or Latino^HL70189");
85 default: // Unknown
86 return ("U^Unknown^HL70189");
91 $query =
92 "select " .
93 "i.patient_id as patientid, " .
94 "p.language, ".
95 "i.cvx_code , " ;
96 if ($_POST['form_get_hl7']==='true') {
97 $query .=
98 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
99 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
100 "p.country_code, ".
101 "p.phone_home, ".
102 "p.phone_biz, ".
103 "p.status, ".
104 "p.sex, ".
105 "p.ethnoracial, ".
106 "p.race, ".
107 "p.ethnicity, ".
108 "c.code_text, ".
109 "c.code, ".
110 "c.code_type, ".
111 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
112 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
113 "i.lot_number as lot_number, ".
114 "i.manufacturer as manufacturer, ".
115 "concat(p.fname, '^', p.lname) as patientname, ";
116 } else {
117 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
118 "i.vis_date as immunizationdate, " ;
120 $query .=
121 "i.id as immunizationid, c.code_text_short as immunizationtitle ".
122 "from immunizations i, patient_data p, codes c ".
123 "left join code_types ct on c.code_type = ct.ct_id ".
124 "where ".
125 "ct.ct_key='CVX' and ";
126 if($from_date!=0) {
127 $query .= "i.vis_date >= '$from_date' " ;
129 if($from_date!=0 and $to_date!=0) {
130 $query .= " and " ;
132 if($to_date!=0) {
133 $query .= "i.vis_date <= '$to_date' ";
135 if($from_date!=0 or $to_date!=0) {
136 $query .= " and " ;
138 $query .= "i.patient_id=p.pid and ".
139 $query_codes .
140 "i.cvx_code = c.code and ";
142 //do not show immunization added erroneously
143 $query .= "i.added_erroneously = 0";
145 //echo "<p> DEBUG query: $query </p>\n"; // debugging
148 $D="\r";
149 $nowdate = date('Ymd');
150 $now = date('YmdGi');
151 $now1 = date('Y-m-d G:i');
152 $filename = "imm_reg_". $now . ".hl7";
154 // GENERATE HL7 FILE
155 if ($_POST['form_get_hl7']==='true') {
156 $content = '';
158 $res = sqlStatement($query);
160 while ($r = sqlFetchArray($res)) {
161 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
162 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
163 "$D" ;
164 if ($r['sex']==='Male') $r['sex'] = 'M';
165 if ($r['sex']==='Female') $r['sex'] = 'F';
166 if ($r['status']==='married') $r['status'] = 'M';
167 if ($r['status']==='single') $r['status'] = 'S';
168 if ($r['status']==='divorced') $r['status'] = 'D';
169 if ($r['status']==='widowed') $r['status'] = 'W';
170 if ($r['status']==='separated') $r['status'] = 'A';
171 if ($r['status']==='domestic partner') $r['status'] = 'P';
172 $content .= "PID|" . // [[ 3.72 ]]
173 "|" . // 1. Set id
174 "|" . // 2. (B)Patient id
175 $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.
176 "|" . // 4. (B) Alternate PID
177 $r['patientname']."|" . // 5.R. Name
178 "|" . // 6. Mather Maiden Name
179 $r['DOB']."|" . // 7. Date, time of birth
180 $r['sex']."|" . // 8. Sex
181 "|" . // 9.B Patient Alias
182 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
183 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
184 "|" . // 12. county code
185 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
186 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
187 "|" . // 15. Primary language
188 $r['status']."|" . // 16. Marital status
189 "|" . // 17. Religion
190 "|" . // 18. patient Account Number
191 "|" . // 19.B SSN Number
192 "|" . // 20.B Driver license number
193 "|" . // 21. Mathers Identifier
194 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
195 "|" . // 23. Birth Plase
196 "|" . // 24. Multiple birth indicator
197 "|" . // 25. Birth order
198 "|" . // 26. Citizenship
199 "|" . // 27. Veteran military status
200 "|" . // 28.B Nationality
201 "|" . // 29. Patient Death Date and Time
202 "|" . // 30. Patient Death Indicator
203 "|" . // 31. Identity Unknown Indicator
204 "|" . // 32. Identity Reliability Code
205 "|" . // 33. Last Update Date/Time
206 "|" . // 34. Last Update Facility
207 "|" . // 35. Species Code
208 "|" . // 36. Breed Code
209 "|" . // 37. Breed Code
210 "|" . // 38. Production Class Code
211 "" . // 39. Tribal Citizenship
212 "$D" ;
213 $content .= "ORC" . // ORC mandatory for RXA
214 "|" .
215 "RE" .
216 "$D" ;
217 $content .= "RXA|" .
218 "0|" . // 1. Give Sub-ID Counter
219 "1|" . // 2. Administrattion Sub-ID Counter
220 $r['administered_date']."|" . // 3. Date/Time Start of Administration
221 $r['administered_date']."|" . // 4. Date/Time End of Administration
222 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
223 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
224 "|" . // 7. Administered Units
225 "|" . // 8. Administered Dosage Form
226 "|" . // 9. Administration Notes
227 "|" . // 10. Administering Provider
228 "|" . // 11. Administered-at Location
229 "|" . // 12. Administered Per (Time Unit)
230 "|" . // 13. Administered Strength
231 "|" . // 14. Administered Strength Units
232 $r['lot_number']."|" . // 15. Substance Lot Number
233 "|" . // 16. Substance Expiration Date
234 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
235 "|" . // 18. Substance/Treatment Refusal Reason
236 "|" . // 19.Indication
237 "|" . // 20.Completion Status
238 "A" . // 21.Action Code - RXA
239 "$D" ;
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('Immunization Registry','e'); ?></title>
258 <?php $include_standard_style_js = array("datetimepicker","report_helper.js"); ?>
259 <?php require($GLOBALS['srcdir'] . '/templates/standard_header_template.php'); ?>
261 <script language="JavaScript">
262 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
264 $(document).ready(function() {
265 var win = top.printLogSetup ? top : opener.top;
266 win.printLogSetup(document.getElementById('printbutton'));
268 $('.datepicker').datetimepicker({
269 <?php $datetimepicker_timepicker = false; ?>
270 <?php $datetimepicker_showseconds = false; ?>
271 <?php $datetimepicker_formatInput = false; ?>
272 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
273 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
277 </script>
279 <style type="text/css">
280 /* specifically include & exclude from printing */
281 @media print {
282 #report_parameters {
283 visibility: hidden;
284 display: none;
286 #report_parameters_daterange {
287 visibility: visible;
288 display: inline;
289 margin-bottom: 10px;
291 #report_results table {
292 margin-top: 0px;
295 /* specifically exclude some from the screen */
296 @media screen {
297 #report_parameters_daterange {
298 visibility: hidden;
299 display: none;
301 #report_results {
302 width: 100%;
305 </style>
306 </head>
308 <body class="body_top">
310 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Immunization Registry','e'); ?></span>
312 <div id="report_parameters_daterange">
313 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
314 </div>
316 <form name='theform' id='theform' method='post' action='immunization_report.php'
317 onsubmit='return top.restoreSession()'>
318 <div id="report_parameters">
319 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
320 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
321 <table>
322 <tr>
323 <td width='410px'>
324 <div style='float:left'>
325 <table class='text'>
326 <tr>
327 <td class='control-label'>
328 <?php xl('Codes','e'); ?>:
329 </td>
330 <td>
331 <?php
332 // Build a drop-down list of codes.
334 $query1 = "select id, concat('CVX:',code) as name from codes ".
335 " left join code_types ct on codes.code_type = ct.ct_id ".
336 " where ct.ct_key='CVX' ORDER BY name";
337 $cres = sqlStatement($query1);
338 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
339 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
340 while ($crow = sqlFetchArray($cres)) {
341 $codeid = $crow['id'];
342 echo " <option value='$codeid'";
343 if (in_array($codeid, $form_code)) echo " selected";
344 echo ">" . $crow['name'] . "\n";
346 echo " </select>\n";
348 </td>
349 <td class='control-label'>
350 <?php xl('From','e'); ?>:
351 </td>
352 <td>
353 <input type='text' name='form_from_date' id="form_from_date"
354 class='datepicker form-control'
355 size='10' value='<?php echo $form_from_date ?>'
356 title='yyyy-mm-dd'>
357 </td>
358 <td class='control-label'>
359 <?php xl('To','e'); ?>:
360 </td>
361 <td>
362 <input type='text' name='form_to_date' id="form_to_date"
363 class='datepicker form-control'
364 size='10' value='<?php echo $form_to_date ?>'
365 title='yyyy-mm-dd'>
366 </td>
367 </tr>
368 </table>
369 </div>
370 </td>
371 <td align='left' valign='middle' height="100%">
372 <table style='border-left:1px solid; width:100%; height:100%' >
373 <tr>
374 <td>
375 <div style='margin-left:15px'>
376 <a href='#' class='css_button'
377 onclick='
378 $("#form_refresh").attr("value","true");
379 $("#form_get_hl7").attr("value","false");
380 $("#theform").submit();
382 <span>
383 <?php xl('Refresh','e'); ?>
384 </spain>
385 </a>
386 <?php if ($_POST['form_refresh']) { ?>
387 <a href='#' class='css_button' id='printbutton'>
388 <span>
389 <?php xl('Print','e'); ?>
390 </span>
391 </a>
392 <a href='#' class='css_button' onclick=
393 "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'); ?>')) {
394 $('#form_get_hl7').attr('value','true');
395 $('#theform').submit();
397 <span>
398 <?php xl('Get HL7','e'); ?>
399 </span>
400 </a>
401 <?php } ?>
402 </div>
403 </td>
404 </tr>
405 </table>
406 </td>
407 </tr>
408 </table>
409 </div> <!-- end of parameters -->
412 <?php
413 if ($_POST['form_refresh']) {
415 <div id="report_results">
416 <table>
417 <thead align="left">
418 <th> <?php xl('Patient ID','e'); ?> </th>
419 <th> <?php xl('Patient Name','e'); ?> </th>
420 <th> <?php xl('Immunization Code','e'); ?> </th>
421 <th> <?php xl('Immunization Title','e'); ?> </th>
422 <th> <?php xl('Immunization Date','e'); ?> </th>
423 </thead>
424 <tbody>
425 <?php
426 $total = 0;
427 //echo "<p> DEBUG query: $query </p>\n"; // debugging
428 $res = sqlStatement($query);
431 while ($row = sqlFetchArray($res)) {
433 <tr>
434 <td>
435 <?php echo htmlspecialchars($row['patientid']) ?>
436 </td>
437 <td>
438 <?php echo htmlspecialchars($row['patientname']) ?>
439 </td>
440 <td>
441 <?php echo htmlspecialchars($row['cvx_code']) ?>
442 </td>
443 <td>
444 <?php echo htmlspecialchars($row['immunizationtitle']) ?>
445 </td>
446 <td>
447 <?php echo htmlspecialchars($row['immunizationdate']) ?>
448 </td>
449 </tr>
450 <?php
451 ++$total;
454 <tr class="report_totals">
455 <td colspan='9'>
456 <?php xl('Total Number of Immunizations','e'); ?>
458 <?php echo $total ?>
459 </td>
460 </tr>
462 </tbody>
463 </table>
464 </div> <!-- end of results -->
465 <?php } else { ?>
466 <div class='text'>
467 <?php echo xl('Click Refresh to view all results, or please input search criteria above to view specific results.', 'e' ); ?>
468 </div>
469 <?php } ?>
470 </form>
472 </body>
473 </html>