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>;.
20 * @author Brady Miller <brady.g.miller@gmail.com>
21 * @link http://www.open-emr.org
24 use OpenEMR\Core\Header
;
26 require_once("../globals.php");
27 require_once("$srcdir/patient.inc");
29 if (isset($_POST['form_from_date'])) {
30 $from_date = $_POST['form_from_date'] !== "" ?
31 fixDate($_POST['form_from_date'], date('Y-m-d')) :
35 if (isset($_POST['form_to_date'])) {
36 $to_date =$_POST['form_to_date'] !== "" ?
37 fixDate($_POST['form_to_date'], date('Y-m-d')) :
42 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : array();
44 if (empty($form_code)) {
47 $query_codes = 'c.id in (';
48 foreach ($form_code as $code) {
49 $query_codes .= $code . ",";
52 $query_codes = substr($query_codes, 0, -1);
53 $query_codes .= ') and ';
58 return (str_replace(' ', '^', $a));
61 function format_cvx_code($cvx_code)
71 function format_phone($phone)
74 $phone = preg_replace("/[^0-9]/", "", $phone);
75 switch (strlen($phone)) {
77 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
79 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
81 return tr("000 0000000");
85 function format_ethnicity($ethnicity)
90 return ("H^Hispanic or Latino^HL70189");
91 case "not_hisp_or_latin":
92 return ("N^not Hispanic or Latino^HL70189");
94 return ("U^Unknown^HL70189");
101 "i.patient_id as patientid, " .
104 if ($_POST['form_get_hl7']==='true') {
106 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
107 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
119 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
120 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
121 "i.lot_number as lot_number, ".
122 "i.manufacturer as manufacturer, ".
123 "concat(p.fname, '^', p.lname) as patientname, ";
125 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
126 "i.vis_date as immunizationdate, " ;
130 "i.id as immunizationid, c.code_text_short as immunizationtitle ".
131 "from immunizations i, patient_data p, codes c ".
132 "left join code_types ct on c.code_type = ct.ct_id ".
134 "ct.ct_key='CVX' and ";
136 $query .= "i.vis_date >= '$from_date' " ;
139 if ($from_date!=0 and $to_date!=0) {
144 $query .= "i.vis_date <= '$to_date' ";
147 if ($from_date!=0 or $to_date!=0) {
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";
158 //echo "<p> DEBUG query: $query </p>\n"; // debugging
162 $nowdate = date('Ymd');
163 $now = date('YmdGi');
164 $now1 = date('Y-m-d G:i');
165 $filename = "imm_reg_". $now . ".hl7";
168 if ($_POST['form_get_hl7']==='true') {
171 $res = sqlStatement($query);
173 while ($r = sqlFetchArray($res)) {
174 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
175 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
177 if ($r['sex']==='Male') {
181 if ($r['sex']==='Female') {
185 if ($r['status']==='married') {
189 if ($r['status']==='single') {
193 if ($r['status']==='divorced') {
197 if ($r['status']==='widowed') {
201 if ($r['status']==='separated') {
205 if ($r['status']==='domestic partner') {
209 $content .= "PID|" . // [[ 3.72 ]]
211 "|" . // 2. (B)Patient id
212 $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.
213 "|" . // 4. (B) Alternate PID
214 $r['patientname']."|" . // 5.R. Name
215 "|" . // 6. Mather Maiden Name
216 $r['DOB']."|" . // 7. Date, time of birth
217 $r['sex']."|" . // 8. Sex
218 "|" . // 9.B Patient Alias
219 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
220 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
221 "|" . // 12. county code
222 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
223 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
224 "|" . // 15. Primary language
225 $r['status']."|" . // 16. Marital status
226 "|" . // 17. Religion
227 "|" . // 18. patient Account Number
228 "|" . // 19.B SSN Number
229 "|" . // 20.B Driver license number
230 "|" . // 21. Mathers Identifier
231 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
232 "|" . // 23. Birth Plase
233 "|" . // 24. Multiple birth indicator
234 "|" . // 25. Birth order
235 "|" . // 26. Citizenship
236 "|" . // 27. Veteran military status
237 "|" . // 28.B Nationality
238 "|" . // 29. Patient Death Date and Time
239 "|" . // 30. Patient Death Indicator
240 "|" . // 31. Identity Unknown Indicator
241 "|" . // 32. Identity Reliability Code
242 "|" . // 33. Last Update Date/Time
243 "|" . // 34. Last Update Facility
244 "|" . // 35. Species Code
245 "|" . // 36. Breed Code
246 "|" . // 37. Breed Code
247 "|" . // 38. Production Class Code
248 "" . // 39. Tribal Citizenship
250 $content .= "ORC" . // ORC mandatory for RXA
255 "0|" . // 1. Give Sub-ID Counter
256 "1|" . // 2. Administrattion Sub-ID Counter
257 $r['administered_date']."|" . // 3. Date/Time Start of Administration
258 $r['administered_date']."|" . // 4. Date/Time End of Administration
259 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
260 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
261 "|" . // 7. Administered Units
262 "|" . // 8. Administered Dosage Form
263 "|" . // 9. Administration Notes
264 "|" . // 10. Administering Provider
265 "|" . // 11. Administered-at Location
266 "|" . // 12. Administered Per (Time Unit)
267 "|" . // 13. Administered Strength
268 "|" . // 14. Administered Strength Units
269 $r['lot_number']."|" . // 15. Substance Lot Number
270 "|" . // 16. Substance Expiration Date
271 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
272 "|" . // 18. Substance/Treatment Refusal Reason
273 "|" . // 19.Indication
274 "|" . // 20.Completion Status
275 "A" . // 21.Action Code - RXA
279 // send the header here
280 header('Content-type: text/plain');
281 header('Content-Disposition: attachment; filename=' . $filename);
283 // put the content in the file
292 <title
><?php
xl('Immunization Registry', 'e'); ?
></title
>
294 <?php Header
::setupHeader(['datetime-picker', 'report-helper']); ?
>
296 <script language
="JavaScript">
297 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
299 $
(document
).ready(function() {
300 var win
= top
.printLogSetup ? top
: opener
.top
;
301 win
.printLogSetup(document
.getElementById('printbutton'));
303 $
('.datepicker').datetimepicker({
304 <?php
$datetimepicker_timepicker = false; ?
>
305 <?php
$datetimepicker_showseconds = false; ?
>
306 <?php
$datetimepicker_formatInput = false; ?
>
307 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
308 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
314 <style type
="text/css">
315 /* specifically include & exclude from printing */
321 #report_parameters_daterange {
326 #report_results table {
330 /* specifically exclude some from the screen */
332 #report_parameters_daterange {
343 <body
class="body_top">
345 <span
class='title'><?php
xl('Report', 'e'); ?
> - <?php
xl('Immunization Registry', 'e'); ?
></span
>
347 <div id
="report_parameters_daterange">
348 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
351 <form name
='theform' id
='theform' method
='post' action
='immunization_report.php'
352 onsubmit
='return top.restoreSession()'>
353 <div id
="report_parameters">
354 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
355 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
359 <div style
='float:left'>
362 <td
class='control-label'>
363 <?php
xl('Codes', 'e'); ?
>:
367 // Build a drop-down list of codes.
369 $query1 = "select id, concat('CVX:',code) as name from codes ".
370 " left join code_types ct on codes.code_type = ct.ct_id ".
371 " where ct.ct_key='CVX' ORDER BY name";
372 $cres = sqlStatement($query1);
373 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
374 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
375 while ($crow = sqlFetchArray($cres)) {
376 $codeid = $crow['id'];
377 echo " <option value='$codeid'";
378 if (in_array($codeid, $form_code)) {
382 echo ">" . $crow['name'] . "\n";
388 <td
class='control-label'>
389 <?php
xl('From', 'e'); ?
>:
392 <input type
='text' name
='form_from_date' id
="form_from_date"
393 class='datepicker form-control'
394 size
='10' value
='<?php echo $form_from_date ?>'
397 <td
class='control-label'>
398 <?php
xl('To', 'e'); ?
>:
401 <input type
='text' name
='form_to_date' id
="form_to_date"
402 class='datepicker form-control'
403 size
='10' value
='<?php echo $form_to_date ?>'
410 <td align
='left' valign
='middle' height
="100%">
411 <table style
='border-left:1px solid; width:100%; height:100%' >
414 <div
class="text-center">
415 <div
class="btn-group" role
="group">
416 <a href
='#' class='btn btn-default btn-save'
418 $("#form_refresh").attr("value","true");
419 $("#form_get_hl7").attr("value","false");
420 $("#theform").submit();
422 <?php
echo xlt('Refresh'); ?
>
424 <?php
if ($_POST['form_refresh']) { ?
>
425 <a href
='#' class='btn btn-default btn-print' id
='printbutton'>
426 <?php
echo xlt('Print'); ?
>
428 <a href
='#' class='btn btn-default btn-transmit' onclick
=
429 "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?'); ?>')) {
430 $('#form_get_hl7').attr('value','true');
431 $('#theform').submit();
433 <?php
echo xlt('Get HL7'); ?
>
444 </div
> <!-- end of parameters
-->
448 if ($_POST['form_refresh']) {
450 <div id
="report_results">
453 <th
> <?php
xl('Patient ID', 'e'); ?
> </th
>
454 <th
> <?php
xl('Patient Name', 'e'); ?
> </th
>
455 <th
> <?php
xl('Immunization Code', 'e'); ?
> </th
>
456 <th
> <?php
xl('Immunization Title', 'e'); ?
> </th
>
457 <th
> <?php
xl('Immunization Date', 'e'); ?
> </th
>
462 //echo "<p> DEBUG query: $query </p>\n"; // debugging
463 $res = sqlStatement($query);
466 while ($row = sqlFetchArray($res)) {
470 <?php
echo htmlspecialchars($row['patientid']) ?
>
473 <?php
echo htmlspecialchars($row['patientname']) ?
>
476 <?php
echo htmlspecialchars($row['cvx_code']) ?
>
479 <?php
echo htmlspecialchars($row['immunizationtitle']) ?
>
482 <?php
echo htmlspecialchars($row['immunizationdate']) ?
>
489 <tr
class="report_totals">
491 <?php
xl('Total Number of Immunizations', 'e'); ?
>
499 </div
> <!-- end of results
-->
502 <?php
echo xl('Click Refresh to view all results, or please input search criteria above to view specific results.', 'e'); ?
>