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
25 require_once("../globals.php");
26 require_once("$srcdir/patient.inc");
28 if(isset($_POST['form_from_date'])) {
29 $from_date = $_POST['form_from_date'] !== "" ?
30 fixDate($_POST['form_from_date'], date('Y-m-d')) :
33 if(isset($_POST['form_to_date'])) {
34 $to_date =$_POST['form_to_date'] !== "" ?
35 fixDate($_POST['form_to_date'], date('Y-m-d')) :
39 $form_code = isset($_POST['form_code']) ?
$_POST['form_code'] : Array();
41 if (empty ($form_code) ) {
44 $query_codes = 'c.id in (';
45 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
46 $query_codes = substr($query_codes ,0,-1);
47 $query_codes .= ') and ';
51 return (str_replace(' ','^',$a));
54 function format_cvx_code($cvx_code) {
56 if ( $cvx_code < 10 ) {
63 function format_phone($phone) {
65 $phone = preg_replace("/[^0-9]/", "", $phone);
66 switch (strlen($phone))
69 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
71 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
73 return tr("000 0000000");
77 function format_ethnicity($ethnicity) {
82 return ("H^Hispanic or Latino^HL70189");
83 case "not_hisp_or_latin":
84 return ("N^not Hispanic or Latino^HL70189");
86 return ("U^Unknown^HL70189");
93 "i.patient_id as patientid, " .
96 if ($_POST['form_get_hl7']==='true') {
98 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
99 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
111 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
112 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
113 "i.lot_number as lot_number, ".
114 "i.manufacturer as manufacturer, ".
115 "concat(p.fname, '^', p.lname) as patientname, ";
117 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
118 "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 $query .= "i.vis_date >= '$from_date' " ;
129 if($from_date!=0 and $to_date!=0) {
133 $query .= "i.vis_date <= '$to_date' ";
135 if($from_date!=0 or $to_date!=0) {
138 $query .= "i.patient_id=p.pid and ".
140 "i.cvx_code = c.code and ";
142 //do not show immunization added erroneously
143 $query .= "i.added_erroneously = 0";
145 //echo "<p> DEBUG query: $query </p>\n"; // debugging
149 $nowdate = date('Ymd');
150 $now = date('YmdGi');
151 $now1 = date('Y-m-d G:i');
152 $filename = "imm_reg_". $now . ".hl7";
155 if ($_POST['form_get_hl7']==='true') {
158 $res = sqlStatement($query);
160 while ($r = sqlFetchArray($res)) {
161 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
162 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
164 if ($r['sex']==='Male') $r['sex'] = 'M';
165 if ($r['sex']==='Female') $r['sex'] = 'F';
166 if ($r['status']==='married') $r['status'] = 'M';
167 if ($r['status']==='single') $r['status'] = 'S';
168 if ($r['status']==='divorced') $r['status'] = 'D';
169 if ($r['status']==='widowed') $r['status'] = 'W';
170 if ($r['status']==='separated') $r['status'] = 'A';
171 if ($r['status']==='domestic partner') $r['status'] = 'P';
172 $content .= "PID|" . // [[ 3.72 ]]
174 "|" . // 2. (B)Patient id
175 $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.
176 "|" . // 4. (B) Alternate PID
177 $r['patientname']."|" . // 5.R. Name
178 "|" . // 6. Mather Maiden Name
179 $r['DOB']."|" . // 7. Date, time of birth
180 $r['sex']."|" . // 8. Sex
181 "|" . // 9.B Patient Alias
182 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
183 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
184 "|" . // 12. county code
185 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
186 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
187 "|" . // 15. Primary language
188 $r['status']."|" . // 16. Marital status
189 "|" . // 17. Religion
190 "|" . // 18. patient Account Number
191 "|" . // 19.B SSN Number
192 "|" . // 20.B Driver license number
193 "|" . // 21. Mathers Identifier
194 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
195 "|" . // 23. Birth Plase
196 "|" . // 24. Multiple birth indicator
197 "|" . // 25. Birth order
198 "|" . // 26. Citizenship
199 "|" . // 27. Veteran military status
200 "|" . // 28.B Nationality
201 "|" . // 29. Patient Death Date and Time
202 "|" . // 30. Patient Death Indicator
203 "|" . // 31. Identity Unknown Indicator
204 "|" . // 32. Identity Reliability Code
205 "|" . // 33. Last Update Date/Time
206 "|" . // 34. Last Update Facility
207 "|" . // 35. Species Code
208 "|" . // 36. Breed Code
209 "|" . // 37. Breed Code
210 "|" . // 38. Production Class Code
211 "" . // 39. Tribal Citizenship
213 $content .= "ORC" . // ORC mandatory for RXA
218 "0|" . // 1. Give Sub-ID Counter
219 "1|" . // 2. Administrattion Sub-ID Counter
220 $r['administered_date']."|" . // 3. Date/Time Start of Administration
221 $r['administered_date']."|" . // 4. Date/Time End of Administration
222 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
223 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
224 "|" . // 7. Administered Units
225 "|" . // 8. Administered Dosage Form
226 "|" . // 9. Administration Notes
227 "|" . // 10. Administering Provider
228 "|" . // 11. Administered-at Location
229 "|" . // 12. Administered Per (Time Unit)
230 "|" . // 13. Administered Strength
231 "|" . // 14. Administered Strength Units
232 $r['lot_number']."|" . // 15. Substance Lot Number
233 "|" . // 16. Substance Expiration Date
234 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
235 "|" . // 18. Substance/Treatment Refusal Reason
236 "|" . // 19.Indication
237 "|" . // 20.Completion Status
238 "A" . // 21.Action Code - RXA
243 // send the header here
244 header('Content-type: text/plain');
245 header('Content-Disposition: attachment; filename=' . $filename );
247 // put the content in the file
255 <?php
html_header_show();?
>
256 <title
><?php
xl('Immunization Registry','e'); ?
></title
>
258 <?php
$include_standard_style_js = array("datetimepicker","report_helper.js"); ?
>
259 <?php
require($GLOBALS['srcdir'] . '/templates/standard_header_template.php'); ?
>
261 <script language
="JavaScript">
262 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
264 $
(document
).ready(function() {
265 var win
= top
.printLogSetup ? top
: opener
.top
;
266 win
.printLogSetup(document
.getElementById('printbutton'));
268 $
('.datepicker').datetimepicker({
269 <?php
$datetimepicker_timepicker = false; ?
>
270 <?php
$datetimepicker_showseconds = false; ?
>
271 <?php
$datetimepicker_formatInput = false; ?
>
272 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
273 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
279 <style type
="text/css">
280 /* specifically include & exclude from printing */
286 #report_parameters_daterange {
291 #report_results table {
295 /* specifically exclude some from the screen */
297 #report_parameters_daterange {
308 <body
class="body_top">
310 <span
class='title'><?php
xl('Report','e'); ?
> - <?php
xl('Immunization Registry','e'); ?
></span
>
312 <div id
="report_parameters_daterange">
313 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
316 <form name
='theform' id
='theform' method
='post' action
='immunization_report.php'
317 onsubmit
='return top.restoreSession()'>
318 <div id
="report_parameters">
319 <input type
='hidden' name
='form_refresh' id
='form_refresh' value
=''/>
320 <input type
='hidden' name
='form_get_hl7' id
='form_get_hl7' value
=''/>
324 <div style
='float:left'>
327 <td
class='control-label'>
328 <?php
xl('Codes','e'); ?
>:
332 // Build a drop-down list of codes.
334 $query1 = "select id, concat('CVX:',code) as name from codes ".
335 " left join code_types ct on codes.code_type = ct.ct_id ".
336 " where ct.ct_key='CVX' ORDER BY name";
337 $cres = sqlStatement($query1);
338 echo " <select multiple='multiple' size='3' name='form_code[]' class='form-control'>\n";
339 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
340 while ($crow = sqlFetchArray($cres)) {
341 $codeid = $crow['id'];
342 echo " <option value='$codeid'";
343 if (in_array($codeid, $form_code)) echo " selected";
344 echo ">" . $crow['name'] . "\n";
349 <td
class='control-label'>
350 <?php
xl('From','e'); ?
>:
353 <input type
='text' name
='form_from_date' id
="form_from_date"
354 class='datepicker form-control'
355 size
='10' value
='<?php echo $form_from_date ?>'
358 <td
class='control-label'>
359 <?php
xl('To','e'); ?
>:
362 <input type
='text' name
='form_to_date' id
="form_to_date"
363 class='datepicker form-control'
364 size
='10' value
='<?php echo $form_to_date ?>'
371 <td align
='left' valign
='middle' height
="100%">
372 <table style
='border-left:1px solid; width:100%; height:100%' >
375 <div style
='margin-left:15px'>
376 <a href
='#' class='css_button'
378 $("#form_refresh").attr("value","true");
379 $("#form_get_hl7").attr("value","false");
380 $("#theform").submit();
383 <?php
xl('Refresh','e'); ?
>
386 <?php
if ($_POST['form_refresh']) { ?
>
387 <a href
='#' class='css_button' id
='printbutton'>
389 <?php
xl('Print','e'); ?
>
392 <a href
='#' class='css_button' onclick
=
393 "if(confirm('<?php xl('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?','e'); ?>')) {
394 $('#form_get_hl7').attr('value','true');
395 $('#theform').submit();
398 <?php
xl('Get HL7','e'); ?
>
409 </div
> <!-- end of parameters
-->
413 if ($_POST['form_refresh']) {
415 <div id
="report_results">
418 <th
> <?php
xl('Patient ID','e'); ?
> </th
>
419 <th
> <?php
xl('Patient Name','e'); ?
> </th
>
420 <th
> <?php
xl('Immunization Code','e'); ?
> </th
>
421 <th
> <?php
xl('Immunization Title','e'); ?
> </th
>
422 <th
> <?php
xl('Immunization Date','e'); ?
> </th
>
427 //echo "<p> DEBUG query: $query </p>\n"; // debugging
428 $res = sqlStatement($query);
431 while ($row = sqlFetchArray($res)) {
435 <?php
echo htmlspecialchars($row['patientid']) ?
>
438 <?php
echo htmlspecialchars($row['patientname']) ?
>
441 <?php
echo htmlspecialchars($row['cvx_code']) ?
>
444 <?php
echo htmlspecialchars($row['immunizationtitle']) ?
>
447 <?php
echo htmlspecialchars($row['immunizationdate']) ?
>
454 <tr
class="report_totals">
456 <?php
xl('Total Number of Immunizations','e'); ?
>
464 </div
> <!-- end of results
-->
467 <?php
echo xl('Click Refresh to view all results, or please input search criteria above to view specific results.', 'e' ); ?
>