4 * This report lists patient immunizations for a given date range.
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Sherwin Gaddis <sherwingaddis@gmail.com>
10 * @author Stephen Waite <stephen.waite@open-emr.org>
11 * @copyright Copyright (c) 2011 Ensoftek Inc.
12 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2022 Sherwin Gaddis <sherwingaddis@gmail.com>
14 * @copyright Copyright (c) 2022-2023 Stephen Waite <stephen.waite@open-emr.org>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 require_once("../globals.php");
19 require_once("$srcdir/patient.inc.php");
21 use OpenEMR\Common\Acl\AclMain
;
22 use OpenEMR\Common\Csrf\CsrfUtils
;
23 use OpenEMR\Common\Twig\TwigContainer
;
24 use OpenEMR\Core\Header
;
26 if (!AclMain
::aclCheckCore('patients', 'med')) {
31 ))->getTwig()->render(
32 'core/unauthorized.html.twig',
33 ['pageTitle' => xl("Immunization Registry")]
39 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
40 CsrfUtils
::csrfNotVerified();
44 $form_from_date = (isset($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
45 $form_to_date = (isset($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : '';
49 return (str_replace(' ', '^', $a));
52 function format_cvx_code($cvx_code)
62 function format_phone($phone)
65 $phone = preg_replace("/[^0-9]/", "", $phone);
66 switch (strlen($phone)) {
68 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
70 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
72 return tr("000 0000000");
76 function format_ethnicity($ethnicity)
81 return ("H^Hispanic or Latino^HL70189");
82 case "not_hisp_or_latin":
83 return ("N^not Hispanic or Latino^HL70189");
85 return ("U^Unknown^HL70189");
89 $sqlBindArray = array();
92 "i.patient_id as patientid, " .
95 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
97 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, " .
98 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, " .
110 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, " .
111 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, " .
112 "i.lot_number as lot_number, " .
113 "i.manufacturer as manufacturer, " .
114 "concat(p.fname, '^', p.lname) as patientname, ";
116 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, " .
117 "i.vis_date as immunizationdate, ";
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 " .
125 "ct.ct_key='CVX' and ";
127 if (!empty($form_from_date)) {
128 $query .= "i.vis_date >= ? and ";
129 array_push($sqlBindArray, $form_from_date);
132 if (!empty($form_to_date)) {
133 $query .= "i.vis_date <= ? and ";
134 array_push($sqlBindArray, $form_to_date);
137 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
138 if (empty($form_code)) {
141 $query_codes = "c.id in (";
143 foreach ($form_code as $code) {
145 array_push($sqlBindArray, $code);
147 $codes = substr($codes, 0, -1);
148 $query_codes .= $codes . ") and ";
151 $query .= "i.patient_id=p.pid and " .
153 "i.cvx_code = c.code and ";
155 //do not show immunization added erroneously
156 $query .= "i.added_erroneously = 0";
159 $nowdate = date('Ymd');
160 $now = date('YmdGi');
161 $now1 = date('Y-m-d G:i');
162 $filename = "imm_reg_" . $now . ".hl7";
165 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
168 $res = sqlStatement($query, $sqlBindArray);
170 while ($r = sqlFetchArray($res)) {
171 $content .= "MSH|^~\&|OPENEMR||||$nowdate||" .
172 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
174 if ($r['sex'] === 'Male') {
178 if ($r['sex'] === 'Female') {
182 if ($r['status'] === 'married') {
186 if ($r['status'] === 'single') {
190 if ($r['status'] === 'divorced') {
194 if ($r['status'] === 'widowed') {
198 if ($r['status'] === 'separated') {
202 if ($r['status'] === 'domestic partner') {
206 $content .= "PID|" . // [[ 3.72 ]]
208 "|" . // 2. (B)Patient id
209 $r['patientid'] . "^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR" . "|" . // 3. (R) Patient identifier list. TODO: Hard-coded the OID from NIST test.
210 "|" . // 4. (B) Alternate PID
211 $r['patientname'] . "|" . // 5.R. Name
212 "|" . // 6. Mather Maiden Name
213 $r['DOB'] . "|" . // 7. Date, time of birth
214 $r['sex'] . "|" . // 8. Sex
215 "|" . // 9.B Patient Alias
216 "2106-3^" . $r['race'] . "^HL70005" . "|" . // 10. Race // Ram change
217 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
218 "|" . // 12. county code
219 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
220 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
221 "|" . // 15. Primary language
222 $r['status'] . "|" . // 16. Marital status
223 "|" . // 17. Religion
224 "|" . // 18. patient Account Number
225 "|" . // 19.B SSN Number
226 "|" . // 20.B Driver license number
227 "|" . // 21. Mathers Identifier
228 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
229 "|" . // 23. Birth Plase
230 "|" . // 24. Multiple birth indicator
231 "|" . // 25. Birth order
232 "|" . // 26. Citizenship
233 "|" . // 27. Veteran military status
234 "|" . // 28.B Nationality
235 "|" . // 29. Patient Death Date and Time
236 "|" . // 30. Patient Death Indicator
237 "|" . // 31. Identity Unknown Indicator
238 "|" . // 32. Identity Reliability Code
239 "|" . // 33. Last Update Date/Time
240 "|" . // 34. Last Update Facility
241 "|" . // 35. Species Code
242 "|" . // 36. Breed Code
243 "|" . // 37. Breed Code
244 "|" . // 38. Production Class Code
245 "" . // 39. Tribal Citizenship
247 $content .= "ORC" . // ORC mandatory for RXA
252 "0|" . // 1. Give Sub-ID Counter
253 "1|" . // 2. Administrattion Sub-ID Counter
254 $r['administered_date'] . "|" . // 3. Date/Time Start of Administration
255 $r['administered_date'] . "|" . // 4. Date/Time End of Administration
256 format_cvx_code($r['code']) . "^" . $r['immunizationtitle'] . "^" . "CVX" . "|" . // 5. Administration Code(CVX)
257 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
258 "|" . // 7. Administered Units
259 "|" . // 8. Administered Dosage Form
260 "|" . // 9. Administration Notes
261 "|" . // 10. Administering Provider
262 "|" . // 11. Administered-at Location
263 "|" . // 12. Administered Per (Time Unit)
264 "|" . // 13. Administered Strength
265 "|" . // 14. Administered Strength Units
266 $r['lot_number'] . "|" . // 15. Substance Lot Number
267 "|" . // 16. Substance Expiration Date
268 "MSD" . "^" . $r['manufacturer'] . "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
269 "|" . // 18. Substance/Treatment Refusal Reason
270 "|" . // 19.Indication
271 "|" . // 20.Completion Status
272 "A" . // 21.Action Code - RXA
276 // send the header here
277 header('Content-type: text/plain');
278 header('Content-Disposition: attachment; filename=' . $filename);
280 // put the content in the file
287 <title
><?php
echo xlt('Immunization Registry'); ?
></title
>
289 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
292 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
293 function confirmHl7() {
294 let msg
= <?php
echo js_escape(xlt('This step will generate a file which you have to save for future use.') .
295 '<br />' . xlt('The file cannot be generated again. Do you want to proceed?')); ?
>;
296 dialog
.confirm(msg
).then(returned
=> {
297 if (returned
=== true) {
298 $
('#form_get_hl7').attr('value', 'true');
299 $
('#theform').submit();
307 var win
= top
.printLogSetup ? top
: opener
.top
;
308 win
.printLogSetup(document
.getElementById('printbutton'));
310 $
('.datepicker').datetimepicker({
311 <?php
$datetimepicker_timepicker = false; ?
>
312 <?php
$datetimepicker_showseconds = false; ?
>
313 <?php
$datetimepicker_formatInput = true; ?
>
314 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
315 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
321 /* specifically include & exclude from printing */
328 #report_parameters_daterange {
334 #report_results table {
339 /* specifically exclude some from the screen */
341 #report_parameters_daterange {
353 <body
class="body_top">
355 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Immunization Registry'); ?
></span
>
357 <div id
="report_parameters_daterange">
358 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($form_to_date)); ?
>
361 <form name
='theform' id
='theform' method
='post' action
='immunization_report.php' onsubmit
='return top.restoreSession()'>
362 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
363 <div id
="report_parameters">
364 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
='' />
365 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
='' />
366 <input type
="hidden" name
="form_export" id
="form_export" value
="" />
370 <div style
='float:left'>
373 <td
class='col-form-label'>
374 <?php
echo xlt('Codes'); ?
>:
378 // Build a drop-down list of codes.
380 $query1 = "select id, concat('CVX:',code) as name from codes " .
381 " left join code_types ct on codes.code_type = ct.ct_id " .
382 " where ct.ct_key='CVX' ORDER BY name";
383 $cres = sqlStatement($query1);
384 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
385 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
386 while ($crow = sqlFetchArray($cres)) {
387 $codeid = $crow['id'];
388 echo " <option value='" . attr($codeid) . "'";
389 if (in_array($codeid, $form_code)) {
392 echo ">" . text($crow['name']) . "\n";
398 <td
class='col-form-label'>
399 <?php
echo xlt('From VIS Date'); ?
>:
402 <input type
='text' name
='form_from_date' id
="form_from_date"
403 class='datepicker form-control'
404 size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>' />
406 <td
class='col-form-label'>
407 <?php
echo xlt('To VIS Date{{Range}}'); ?
>:
410 <input type
='text' name
='form_to_date' id
="form_to_date"
411 class='datepicker form-control'
412 size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>' />
418 <td
class='h-100' valign
='middle'>
419 <table
class='w-100 h-100' style
='border-left:1px solid;'>
422 <div
class="text-center">
423 <div
class="btn-group" role
="group">
424 <a href
='#' class='btn btn-secondary btn-save'
426 $("#form_refresh").attr("value","true");
427 $("#form_get_hl7").attr("value","false");
428 $("#theform").submit();
430 <?php
echo xlt('Refresh'); ?
>
432 <?php
if (!empty($_POST['form_refresh'])) { ?
>
433 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
434 <?php
echo xlt('Print'); ?
>
436 <a href
='#' class='btn btn-secondary btn-transmit' onclick
="confirmHl7()">
437 <?php
echo xlt('Get HL7'); ?
>
439 <a href
='#' type
="submit" class='btn btn-secondary btn-sheet'
440 onclick
='exportData()'>
441 <?php
echo xlt('Export'); ?
>
453 </div
> <!-- end of parameters
-->
456 if (!empty($_POST['form_refresh'])) {
458 <div id
="report_results">
459 <table
class='table'>
460 <thead
class='thead-light'>
462 <th
> <?php
echo xlt('Patient ID'); ?
> </th
>
463 <th
> <?php
echo xlt('Patient Name'); ?
> </th
>
464 <th
> <?php
echo xlt('Immunization Code'); ?
> </th
>
465 <th
> <?php
echo xlt('Immunization Title'); ?
> </th
>
466 <th
> <?php
echo xlt('Immunization Date'); ?
> </th
>
473 $res = sqlStatement($query, $sqlBindArray);
475 while ($row = sqlFetchArray($res)) {
480 <?php
echo text($row['patientid']); ?
>
483 <?php
echo text($row['patientname']); ?
>
486 <?php
echo text($row['cvx_code']); ?
>
489 <?php
echo text($row['immunizationtitle']); ?
>
492 <?php
echo text($row['immunizationdate']); ?
>
499 <tr
class="report_totals">
501 <?php
echo xlt('Total Number of Immunizations'); ?
>
503 <?php
echo text($total); ?
>
508 </div
> <!-- end of results
-->
511 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
>
517 function exportData() {
518 let data
= <?php
echo json_encode($rows ??
''); ?
>;
519 let csrf_token
= <?php
echo js_escape(CsrfUtils
::collectCsrfToken()); ?
>;
521 "../../library/ajax/immunization_export.php?csrf_token_form=" +
encodeURIComponent(csrf_token
) +
522 "&data=" +
encodeURIComponent(data
),
530 {text
: <?php
echo xlj('Close'); ?
>, close
: true, style
: 'default btn-sm'}