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 * @copyright Copyright (c) 2011 Ensoftek Inc.
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @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\Common\Csrf\CsrfUtils
;
18 use OpenEMR\Core\Header
;
21 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
22 CsrfUtils
::csrfNotVerified();
26 $form_from_date = (isset($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : '';
27 $form_to_date = (isset($_POST['form_to_date'])) ?
DateToYYYYMMDD($_POST['form_to_date']) : '';
31 return (str_replace(' ', '^', $a));
34 function format_cvx_code($cvx_code)
44 function format_phone($phone)
47 $phone = preg_replace("/[^0-9]/", "", $phone);
48 switch (strlen($phone)) {
50 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
52 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
54 return tr("000 0000000");
58 function format_ethnicity($ethnicity)
63 return ("H^Hispanic or Latino^HL70189");
64 case "not_hisp_or_latin":
65 return ("N^not Hispanic or Latino^HL70189");
67 return ("U^Unknown^HL70189");
71 $sqlBindArray = array();
74 "i.patient_id as patientid, " .
77 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
79 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, " .
80 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, " .
92 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, " .
93 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, " .
94 "i.lot_number as lot_number, " .
95 "i.manufacturer as manufacturer, " .
96 "concat(p.fname, '^', p.lname) as patientname, ";
98 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, " .
99 "i.vis_date as immunizationdate, ";
103 "i.id as immunizationid, c.code_text_short as immunizationtitle " .
104 "from immunizations i, patient_data p, codes c " .
105 "left join code_types ct on c.code_type = ct.ct_id " .
107 "ct.ct_key='CVX' and ";
109 if (!empty($form_from_date)) {
110 $query .= "i.vis_date >= ? and ";
111 array_push($sqlBindArray, $form_from_date);
114 if (!empty($form_to_date)) {
115 $query .= "i.vis_date <= ? and ";
116 array_push($sqlBindArray, $form_to_date);
119 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
120 if (empty($form_code)) {
123 $query_codes = "c.id in (";
125 foreach ($form_code as $code) {
127 array_push($sqlBindArray, $code);
129 $codes = substr($codes, 0, -1);
130 $query_codes .= $codes . ") and ";
133 $query .= "i.patient_id=p.pid and " .
135 "i.cvx_code = c.code and ";
137 //do not show immunization added erroneously
138 $query .= "i.added_erroneously = 0";
141 $nowdate = date('Ymd');
142 $now = date('YmdGi');
143 $now1 = date('Y-m-d G:i');
144 $filename = "imm_reg_" . $now . ".hl7";
147 if (!empty($_POST['form_get_hl7']) && ($_POST['form_get_hl7'] === 'true')) {
150 $res = sqlStatement($query, $sqlBindArray);
152 while ($r = sqlFetchArray($res)) {
153 $content .= "MSH|^~\&|OPENEMR||||$nowdate||" .
154 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
156 if ($r['sex'] === 'Male') {
160 if ($r['sex'] === 'Female') {
164 if ($r['status'] === 'married') {
168 if ($r['status'] === 'single') {
172 if ($r['status'] === 'divorced') {
176 if ($r['status'] === 'widowed') {
180 if ($r['status'] === 'separated') {
184 if ($r['status'] === 'domestic partner') {
188 $content .= "PID|" . // [[ 3.72 ]]
190 "|" . // 2. (B)Patient id
191 $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.
192 "|" . // 4. (B) Alternate PID
193 $r['patientname'] . "|" . // 5.R. Name
194 "|" . // 6. Mather Maiden Name
195 $r['DOB'] . "|" . // 7. Date, time of birth
196 $r['sex'] . "|" . // 8. Sex
197 "|" . // 9.B Patient Alias
198 "2106-3^" . $r['race'] . "^HL70005" . "|" . // 10. Race // Ram change
199 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
200 "|" . // 12. county code
201 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
202 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
203 "|" . // 15. Primary language
204 $r['status'] . "|" . // 16. Marital status
205 "|" . // 17. Religion
206 "|" . // 18. patient Account Number
207 "|" . // 19.B SSN Number
208 "|" . // 20.B Driver license number
209 "|" . // 21. Mathers Identifier
210 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
211 "|" . // 23. Birth Plase
212 "|" . // 24. Multiple birth indicator
213 "|" . // 25. Birth order
214 "|" . // 26. Citizenship
215 "|" . // 27. Veteran military status
216 "|" . // 28.B Nationality
217 "|" . // 29. Patient Death Date and Time
218 "|" . // 30. Patient Death Indicator
219 "|" . // 31. Identity Unknown Indicator
220 "|" . // 32. Identity Reliability Code
221 "|" . // 33. Last Update Date/Time
222 "|" . // 34. Last Update Facility
223 "|" . // 35. Species Code
224 "|" . // 36. Breed Code
225 "|" . // 37. Breed Code
226 "|" . // 38. Production Class Code
227 "" . // 39. Tribal Citizenship
229 $content .= "ORC" . // ORC mandatory for RXA
234 "0|" . // 1. Give Sub-ID Counter
235 "1|" . // 2. Administrattion Sub-ID Counter
236 $r['administered_date'] . "|" . // 3. Date/Time Start of Administration
237 $r['administered_date'] . "|" . // 4. Date/Time End of Administration
238 format_cvx_code($r['code']) . "^" . $r['immunizationtitle'] . "^" . "CVX" . "|" . // 5. Administration Code(CVX)
239 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
240 "|" . // 7. Administered Units
241 "|" . // 8. Administered Dosage Form
242 "|" . // 9. Administration Notes
243 "|" . // 10. Administering Provider
244 "|" . // 11. Administered-at Location
245 "|" . // 12. Administered Per (Time Unit)
246 "|" . // 13. Administered Strength
247 "|" . // 14. Administered Strength Units
248 $r['lot_number'] . "|" . // 15. Substance Lot Number
249 "|" . // 16. Substance Expiration Date
250 "MSD" . "^" . $r['manufacturer'] . "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
251 "|" . // 18. Substance/Treatment Refusal Reason
252 "|" . // 19.Indication
253 "|" . // 20.Completion Status
254 "A" . // 21.Action Code - RXA
258 // send the header here
259 header('Content-type: text/plain');
260 header('Content-Disposition: attachment; filename=' . $filename);
262 // put the content in the file
269 <title
><?php
echo xlt('Immunization Registry'); ?
></title
>
271 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
274 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
275 function confirmHl7() {
276 let msg
= <?php
echo js_escape(xlt('This step will generate a file which you have to save for future use.') .
277 '<br />' . xlt('The file cannot be generated again. Do you want to proceed?')); ?
>;
278 dialog
.confirm(msg
).then(returned
=> {
279 if (returned
=== true) {
280 $
('#form_get_hl7').attr('value', 'true');
281 $
('#theform').submit();
289 var win
= top
.printLogSetup ? top
: opener
.top
;
290 win
.printLogSetup(document
.getElementById('printbutton'));
292 $
('.datepicker').datetimepicker({
293 <?php
$datetimepicker_timepicker = false; ?
>
294 <?php
$datetimepicker_showseconds = false; ?
>
295 <?php
$datetimepicker_formatInput = true; ?
>
296 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
297 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
303 /* specifically include & exclude from printing */
310 #report_parameters_daterange {
316 #report_results table {
321 /* specifically exclude some from the screen */
323 #report_parameters_daterange {
335 <body
class="body_top">
337 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Immunization Registry'); ?
></span
>
339 <div id
="report_parameters_daterange">
340 <?php
echo text(oeFormatShortDate($form_from_date)) . " " . xlt('to{{Range}}') . " " . text(oeFormatShortDate($form_to_date)); ?
>
343 <form name
='theform' id
='theform' method
='post' action
='immunization_report.php' onsubmit
='return top.restoreSession()'>
344 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
345 <div id
="report_parameters">
346 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
='' />
347 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
='' />
351 <div style
='float:left'>
354 <td
class='col-form-label'>
355 <?php
echo xlt('Codes'); ?
>:
359 // Build a drop-down list of codes.
361 $query1 = "select id, concat('CVX:',code) as name from codes " .
362 " left join code_types ct on codes.code_type = ct.ct_id " .
363 " where ct.ct_key='CVX' ORDER BY name";
364 $cres = sqlStatement($query1);
365 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
366 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
367 while ($crow = sqlFetchArray($cres)) {
368 $codeid = $crow['id'];
369 echo " <option value='" . attr($codeid) . "'";
370 if (in_array($codeid, $form_code)) {
373 echo ">" . text($crow['name']) . "\n";
379 <td
class='col-form-label'>
380 <?php
echo xlt('From'); ?
>:
383 <input type
='text' name
='form_from_date' id
="form_from_date"
384 class='datepicker form-control'
385 size
='10' value
='<?php echo attr(oeFormatShortDate($form_from_date)); ?>' />
387 <td
class='col-form-label'>
388 <?php
echo xlt('To{{Range}}'); ?
>:
391 <input type
='text' name
='form_to_date' id
="form_to_date"
392 class='datepicker form-control'
393 size
='10' value
='<?php echo attr(oeFormatShortDate($form_to_date)); ?>' />
399 <td
class='h-100' valign
='middle'>
400 <table
class='w-100 h-100' style
='border-left:1px solid;'>
403 <div
class="text-center">
404 <div
class="btn-group" role
="group">
405 <a href
='#' class='btn btn-secondary btn-save'
407 $("#form_refresh").attr("value","true");
408 $("#form_get_hl7").attr("value","false");
409 $("#theform").submit();
411 <?php
echo xlt('Refresh'); ?
>
413 <?php
if (!empty($_POST['form_refresh'])) { ?
>
414 <a href
='#' class='btn btn-secondary btn-print' id
='printbutton'>
415 <?php
echo xlt('Print'); ?
>
417 <a href
='#' class='btn btn-secondary btn-transmit' onclick
="confirmHl7()">
418 <?php
echo xlt('Get HL7'); ?
>
429 </div
> <!-- end of parameters
-->
432 if (!empty($_POST['form_refresh'])) {
434 <div id
="report_results">
435 <table
class='table'>
436 <thead
class='thead-light'>
438 <th
> <?php
echo xlt('Patient ID'); ?
> </th
>
439 <th
> <?php
echo xlt('Patient Name'); ?
> </th
>
440 <th
> <?php
echo xlt('Immunization Code'); ?
> </th
>
441 <th
> <?php
echo xlt('Immunization Title'); ?
> </th
>
442 <th
> <?php
echo xlt('Immunization Date'); ?
> </th
>
448 //echo "<p> DEBUG query: $query </p>\n"; // debugging
449 $res = sqlStatement($query, $sqlBindArray);
451 while ($row = sqlFetchArray($res)) {
455 <?php
echo text($row['patientid']); ?
>
458 <?php
echo text($row['patientname']); ?
>
461 <?php
echo text($row['cvx_code']); ?
>
464 <?php
echo text($row['immunizationtitle']); ?
>
467 <?php
echo text($row['immunizationdate']); ?
>
474 <tr
class="report_totals">
476 <?php
echo xlt('Total Number of Immunizations'); ?
>
478 <?php
echo text($total); ?
>
483 </div
> <!-- end of results
-->
486 <?php
echo xlt('Click Refresh to view all results, or please input search criteria above to view specific results.'); ?
>