3 * This report lists patient immunizations for a given date range.
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']) : '';
24 return (str_replace(' ', '^', $a));
27 function format_cvx_code($cvx_code)
37 function format_phone($phone)
40 $phone = preg_replace("/[^0-9]/", "", $phone);
41 switch (strlen($phone)) {
43 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
45 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
47 return tr("000 0000000");
51 function format_ethnicity($ethnicity)
56 return ("H^Hispanic or Latino^HL70189");
57 case "not_hisp_or_latin":
58 return ("N^not Hispanic or Latino^HL70189");
60 return ("U^Unknown^HL70189");
64 $sqlBindArray = array();
67 "i.patient_id as patientid, " .
70 if ($_POST['form_get_hl7']==='true') {
72 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
73 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
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, ";
91 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
92 "i.vis_date as immunizationdate, " ;
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 ".
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)) {
116 $query_codes = "c.id in (";
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 ".
127 "i.cvx_code = c.code and ";
129 //do not show immunization added erroneously
130 $query .= "i.added_erroneously = 0";
133 $nowdate = date('Ymd');
134 $now = date('YmdGi');
135 $now1 = date('Y-m-d G:i');
136 $filename = "imm_reg_". $now . ".hl7";
139 if ($_POST['form_get_hl7']==='true') {
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" .
148 if ($r['sex']==='Male') {
152 if ($r['sex']==='Female') {
156 if ($r['status']==='married') {
160 if ($r['status']==='single') {
164 if ($r['status']==='divorced') {
168 if ($r['status']==='widowed') {
172 if ($r['status']==='separated') {
176 if ($r['status']==='domestic partner') {
180 $content .= "PID|" . // [[ 3.72 ]]
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
221 $content .= "ORC" . // ORC mandatory for 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
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
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 ?>
282 <style type
="text/css">
283 /* specifically include & exclude from printing */
289 #report_parameters_daterange {
294 #report_results table {
298 /* specifically exclude some from the screen */
300 #report_parameters_daterange {
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)) ." " . xlt('to') . " ". text(oeFormatShortDate($form_to_date)); ?
>
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
=''/>
326 <div style
='float:left'>
329 <td
class='control-label'>
330 <?php
echo xlt('Codes'); ?
>:
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)) {
349 echo ">" . text($crow['name']) . "\n";
355 <td
class='control-label'>
356 <?php
echo xlt('From'); ?
>:
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)); ?>'>
363 <td
class='control-label'>
364 <?php
echo xlt('To'); ?
>:
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)); ?>'>
375 <td align
='left' valign
='middle' height
="100%">
376 <table style
='border-left:1px solid; width:100%; height:100%' >
379 <div
class="text-center">
380 <div
class="btn-group" role
="group">
381 <a href
='#' class='btn btn-default btn-save'
383 $("#form_refresh").attr("value","true");
384 $("#form_get_hl7").attr("value","false");
385 $("#theform").submit();
387 <?php
echo xlt('Refresh'); ?
>
389 <?php
if ($_POST['form_refresh']) { ?
>
390 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
391 <?php
echo xlt('Print'); ?
>
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'); ?
>
409 </div
> <!-- end of parameters
-->
413 if ($_POST['form_refresh']) {
415 <div id
="report_results">
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
>
427 //echo "<p> DEBUG query: $query </p>\n"; // debugging
428 $res = sqlStatement($query, $sqlBindArray);
431 while ($row = sqlFetchArray($res)) {
435 <?php
echo text($row['patientid']); ?
>
438 <?php
echo text($row['patientname']); ?
>
441 <?php
echo text($row['cvx_code']); ?
>
444 <?php
echo text($row['immunizationtitle']); ?
>
447 <?php
echo text($row['immunizationdate']); ?
>
454 <tr
class="report_totals">
456 <?php
echo xlt('Total Number of Immunizations'); ?
>
458 <?php
echo text($total); ?
>
464 </div
> <!-- end of results
-->
467 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
>