Revert "1. add edit event fails when save edited single provider recurring events...
[openemr.git] / interface / reports / immunization_report.php
blobd587c31212a90954d51693c38c9a69fc7c3aad31
1 <?php
2 /**
3 * This report lists patient immunizations for a given date range.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Brady Miller <brady.g.miller@gmail.com>
8 * @copyright Copyright (c) 2011 Ensoftek Inc.
9 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
17 use OpenEMR\Core\Header;
19 $form_from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : '';
20 $form_to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : '';
22 function tr($a)
24 return (str_replace(' ', '^', $a));
27 function format_cvx_code($cvx_code)
30 if ($cvx_code < 10) {
31 return "0$cvx_code";
34 return $cvx_code;
37 function format_phone($phone)
40 $phone = preg_replace("/[^0-9]/", "", $phone);
41 switch (strlen($phone)) {
42 case 7:
43 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
44 case 10:
45 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
46 default:
47 return tr("000 0000000");
51 function format_ethnicity($ethnicity)
54 switch ($ethnicity) {
55 case "hisp_or_latin":
56 return ("H^Hispanic or Latino^HL70189");
57 case "not_hisp_or_latin":
58 return ("N^not Hispanic or Latino^HL70189");
59 default: // Unknown
60 return ("U^Unknown^HL70189");
64 $sqlBindArray = array();
65 $query =
66 "select " .
67 "i.patient_id as patientid, " .
68 "p.language, ".
69 "i.cvx_code , " ;
70 if ($_POST['form_get_hl7']==='true') {
71 $query .=
72 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
73 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
74 "p.country_code, ".
75 "p.phone_home, ".
76 "p.phone_biz, ".
77 "p.status, ".
78 "p.sex, ".
79 "p.ethnoracial, ".
80 "p.race, ".
81 "p.ethnicity, ".
82 "c.code_text, ".
83 "c.code, ".
84 "c.code_type, ".
85 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
86 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
87 "i.lot_number as lot_number, ".
88 "i.manufacturer as manufacturer, ".
89 "concat(p.fname, '^', p.lname) as patientname, ";
90 } else {
91 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
92 "i.vis_date as immunizationdate, " ;
95 $query .=
96 "i.id as immunizationid, c.code_text_short as immunizationtitle ".
97 "from immunizations i, patient_data p, codes c ".
98 "left join code_types ct on c.code_type = ct.ct_id ".
99 "where ".
100 "ct.ct_key='CVX' and ";
102 if (!empty($form_from_date)) {
103 $query .= "i.vis_date >= ? and " ;
104 array_push($sqlBindArray, $form_from_date);
107 if (!empty($form_to_date)) {
108 $query .= "i.vis_date <= ? and ";
109 array_push($sqlBindArray, $form_to_date);
112 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : array();
113 if (empty($form_code)) {
114 $query_codes = '';
115 } else {
116 $query_codes = "c.id in (";
117 $codes = '';
118 foreach ($form_code as $code) {
119 $codes .= $code . ',';
121 $codes = substr($codes, 0, -1);
122 $query_codes .= add_escape_custom($codes) . ") and ";
125 $query .= "i.patient_id=p.pid and ".
126 $query_codes .
127 "i.cvx_code = c.code and ";
129 //do not show immunization added erroneously
130 $query .= "i.added_erroneously = 0";
132 $D="\r";
133 $nowdate = date('Ymd');
134 $now = date('YmdGi');
135 $now1 = date('Y-m-d G:i');
136 $filename = "imm_reg_". $now . ".hl7";
138 // GENERATE HL7 FILE
139 if ($_POST['form_get_hl7']==='true') {
140 $content = '';
142 $res = sqlStatement($query, $sqlBindArray);
144 while ($r = sqlFetchArray($res)) {
145 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
146 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
147 "$D" ;
148 if ($r['sex']==='Male') {
149 $r['sex'] = 'M';
152 if ($r['sex']==='Female') {
153 $r['sex'] = 'F';
156 if ($r['status']==='married') {
157 $r['status'] = 'M';
160 if ($r['status']==='single') {
161 $r['status'] = 'S';
164 if ($r['status']==='divorced') {
165 $r['status'] = 'D';
168 if ($r['status']==='widowed') {
169 $r['status'] = 'W';
172 if ($r['status']==='separated') {
173 $r['status'] = 'A';
176 if ($r['status']==='domestic partner') {
177 $r['status'] = 'P';
180 $content .= "PID|" . // [[ 3.72 ]]
181 "|" . // 1. Set id
182 "|" . // 2. (B)Patient id
183 $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.
184 "|" . // 4. (B) Alternate PID
185 $r['patientname']."|" . // 5.R. Name
186 "|" . // 6. Mather Maiden Name
187 $r['DOB']."|" . // 7. Date, time of birth
188 $r['sex']."|" . // 8. Sex
189 "|" . // 9.B Patient Alias
190 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
191 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
192 "|" . // 12. county code
193 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
194 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
195 "|" . // 15. Primary language
196 $r['status']."|" . // 16. Marital status
197 "|" . // 17. Religion
198 "|" . // 18. patient Account Number
199 "|" . // 19.B SSN Number
200 "|" . // 20.B Driver license number
201 "|" . // 21. Mathers Identifier
202 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
203 "|" . // 23. Birth Plase
204 "|" . // 24. Multiple birth indicator
205 "|" . // 25. Birth order
206 "|" . // 26. Citizenship
207 "|" . // 27. Veteran military status
208 "|" . // 28.B Nationality
209 "|" . // 29. Patient Death Date and Time
210 "|" . // 30. Patient Death Indicator
211 "|" . // 31. Identity Unknown Indicator
212 "|" . // 32. Identity Reliability Code
213 "|" . // 33. Last Update Date/Time
214 "|" . // 34. Last Update Facility
215 "|" . // 35. Species Code
216 "|" . // 36. Breed Code
217 "|" . // 37. Breed Code
218 "|" . // 38. Production Class Code
219 "" . // 39. Tribal Citizenship
220 "$D" ;
221 $content .= "ORC" . // ORC mandatory for RXA
222 "|" .
223 "RE" .
224 "$D" ;
225 $content .= "RXA|" .
226 "0|" . // 1. Give Sub-ID Counter
227 "1|" . // 2. Administrattion Sub-ID Counter
228 $r['administered_date']."|" . // 3. Date/Time Start of Administration
229 $r['administered_date']."|" . // 4. Date/Time End of Administration
230 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
231 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
232 "|" . // 7. Administered Units
233 "|" . // 8. Administered Dosage Form
234 "|" . // 9. Administration Notes
235 "|" . // 10. Administering Provider
236 "|" . // 11. Administered-at Location
237 "|" . // 12. Administered Per (Time Unit)
238 "|" . // 13. Administered Strength
239 "|" . // 14. Administered Strength Units
240 $r['lot_number']."|" . // 15. Substance Lot Number
241 "|" . // 16. Substance Expiration Date
242 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
243 "|" . // 18. Substance/Treatment Refusal Reason
244 "|" . // 19.Indication
245 "|" . // 20.Completion Status
246 "A" . // 21.Action Code - RXA
247 "$D" ;
250 // send the header here
251 header('Content-type: text/plain');
252 header('Content-Disposition: attachment; filename=' . $filename);
254 // put the content in the file
255 echo($content);
256 exit;
259 <html>
260 <head>
261 <title><?php echo xlt('Immunization Registry'); ?></title>
263 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
265 <script language="JavaScript">
266 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
268 $(document).ready(function() {
269 var win = top.printLogSetup ? top : opener.top;
270 win.printLogSetup(document.getElementById('printbutton'));
272 $('.datepicker').datetimepicker({
273 <?php $datetimepicker_timepicker = false; ?>
274 <?php $datetimepicker_showseconds = false; ?>
275 <?php $datetimepicker_formatInput = true; ?>
276 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
277 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
280 </script>
282 <style type="text/css">
283 /* specifically include & exclude from printing */
284 @media print {
285 #report_parameters {
286 visibility: hidden;
287 display: none;
289 #report_parameters_daterange {
290 visibility: visible;
291 display: inline;
292 margin-bottom: 10px;
294 #report_results table {
295 margin-top: 0px;
298 /* specifically exclude some from the screen */
299 @media screen {
300 #report_parameters_daterange {
301 visibility: hidden;
302 display: none;
304 #report_results {
305 width: 100%;
308 </style>
309 </head>
311 <body class="body_top">
313 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Immunization Registry'); ?></span>
315 <div id="report_parameters_daterange">
316 <?php echo text(oeFormatShortDate($form_from_date)) ." &nbsp; " . xlt('to') . " &nbsp; ". text(oeFormatShortDate($form_to_date)); ?>
317 </div>
319 <form name='theform' id='theform' method='post' action='immunization_report.php' onsubmit='return top.restoreSession()'>
320 <div id="report_parameters">
321 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
322 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
323 <table>
324 <tr>
325 <td width='410px'>
326 <div style='float:left'>
327 <table class='text'>
328 <tr>
329 <td class='control-label'>
330 <?php echo xlt('Codes'); ?>:
331 </td>
332 <td>
333 <?php
334 // Build a drop-down list of codes.
336 $query1 = "select id, concat('CVX:',code) as name from codes ".
337 " left join code_types ct on codes.code_type = ct.ct_id ".
338 " where ct.ct_key='CVX' ORDER BY name";
339 $cres = sqlStatement($query1);
340 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
341 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
342 while ($crow = sqlFetchArray($cres)) {
343 $codeid = $crow['id'];
344 echo " <option value='" . attr($codeid) . "'";
345 if (in_array($codeid, $form_code)) {
346 echo " selected";
349 echo ">" . text($crow['name']) . "\n";
352 echo " </select>\n";
354 </td>
355 <td class='control-label'>
356 <?php echo xlt('From'); ?>:
357 </td>
358 <td>
359 <input type='text' name='form_from_date' id="form_from_date"
360 class='datepicker form-control'
361 size='10' value='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
362 </td>
363 <td class='control-label'>
364 <?php echo xlt('To'); ?>:
365 </td>
366 <td>
367 <input type='text' name='form_to_date' id="form_to_date"
368 class='datepicker form-control'
369 size='10' value='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
370 </td>
371 </tr>
372 </table>
373 </div>
374 </td>
375 <td align='left' valign='middle' height="100%">
376 <table style='border-left:1px solid; width:100%; height:100%' >
377 <tr>
378 <td>
379 <div class="text-center">
380 <div class="btn-group" role="group">
381 <a href='#' class='btn btn-default btn-save'
382 onclick='
383 $("#form_refresh").attr("value","true");
384 $("#form_get_hl7").attr("value","false");
385 $("#theform").submit();
387 <?php echo xlt('Refresh'); ?>
388 </a>
389 <?php if ($_POST['form_refresh']) { ?>
390 <a href='#' class='btn btn-default btn-print' id='printbutton'>
391 <?php echo xlt('Print'); ?>
392 </a>
393 <a href='#' class='btn btn-default btn-transmit' onclick=
394 "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?'); ?>')) {
395 $('#form_get_hl7').attr('value','true');
396 $('#theform').submit();
398 <?php echo xlt('Get HL7'); ?>
399 </a>
400 <?php } ?>
401 </div>
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 echo xlt('Patient ID'); ?> </th>
419 <th> <?php echo xlt('Patient Name'); ?> </th>
420 <th> <?php echo xlt('Immunization Code'); ?> </th>
421 <th> <?php echo xlt('Immunization Title'); ?> </th>
422 <th> <?php echo xlt('Immunization Date'); ?> </th>
423 </thead>
424 <tbody>
425 <?php
426 $total = 0;
427 //echo "<p> DEBUG query: $query </p>\n"; // debugging
428 $res = sqlStatement($query, $sqlBindArray);
431 while ($row = sqlFetchArray($res)) {
433 <tr>
434 <td>
435 <?php echo text($row['patientid']); ?>
436 </td>
437 <td>
438 <?php echo text($row['patientname']); ?>
439 </td>
440 <td>
441 <?php echo text($row['cvx_code']); ?>
442 </td>
443 <td>
444 <?php echo text($row['immunizationtitle']); ?>
445 </td>
446 <td>
447 <?php echo text($row['immunizationdate']); ?>
448 </td>
449 </tr>
450 <?php
451 ++$total;
454 <tr class="report_totals">
455 <td colspan='9'>
456 <?php echo xlt('Total Number of Immunizations'); ?>
458 <?php echo text($total); ?>
459 </td>
460 </tr>
462 </tbody>
463 </table>
464 </div> <!-- end of results -->
465 <?php } else { ?>
466 <div class='text'>
467 <?php echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?>
468 </div>
469 <?php } ?>
470 </form>
472 </body>
473 </html>