Focus the search term on load
[openemr.git] / interface / reports / immunization_report.php
blob03f9a7a44657f831aef750a6104f5eecb67ec733
1 <?php
2 // Copyright (C) 2011 Ensoftek Inc.
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report lists patient immunizations for a given date range.
11 require_once("../globals.php");
12 require_once("$srcdir/patient.inc");
13 require_once("$srcdir/formatting.inc.php");
15 if(isset($_POST['form_from_date'])) {
16 $from_date = $_POST['form_from_date'] !== "" ?
17 fixDate($_POST['form_from_date'], date('Y-m-d')) :
20 if(isset($_POST['form_to_date'])) {
21 $to_date =$_POST['form_to_date'] !== "" ?
22 fixDate($_POST['form_to_date'], date('Y-m-d')) :
26 $form_code = isset($_POST['form_code']) ? $_POST['form_code'] : Array();
28 if (empty ($form_code) ) {
29 $query_codes = '';
30 } else {
31 $query_codes = 'c.id in (';
32 foreach( $form_code as $code ){ $query_codes .= $code . ","; }
33 $query_codes = substr($query_codes ,0,-1);
34 $query_codes .= ') and ';
37 function tr($a) {
38 return (str_replace(' ','^',$a));
41 function format_cvx_code($cvx_code) {
43 if ( $cvx_code < 10 ) {
44 return "0$cvx_code";
47 return $cvx_code;
50 function format_phone($phone) {
52 $phone = preg_replace("/[^0-9]/", "", $phone);
53 switch (strlen($phone))
55 case 7:
56 return tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
57 case 10:
58 return tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
59 default:
60 return tr("000 0000000");
64 function format_ethnicity($ethnicity) {
66 switch ($ethnicity)
68 case "hisp_or_latin":
69 return ("H^Hispanic or Latino^HL70189");
70 case "not_hisp_or_latin":
71 return ("N^not Hispanic or Latino^HL70189");
72 default: // Unknown
73 return ("U^Unknown^HL70189");
78 $query =
79 "select " .
80 "i.patient_id as patientid, " .
81 "p.language, ".
82 "i.cvx_code , " ;
83 if ($_POST['form_get_hl7']==='true') {
84 $query .=
85 "DATE_FORMAT(p.DOB,'%Y%m%d') as DOB, ".
86 "concat(p.street, '^^', p.city, '^', p.state, '^', p.postal_code) as address, ".
87 "p.country_code, ".
88 "p.phone_home, ".
89 "p.phone_biz, ".
90 "p.status, ".
91 "p.sex, ".
92 "p.ethnoracial, ".
93 "p.race, ".
94 "p.ethnicity, ".
95 "c.code_text, ".
96 "c.code, ".
97 "c.code_type, ".
98 "DATE_FORMAT(i.vis_date,'%Y%m%d') as immunizationdate, ".
99 "DATE_FORMAT(i.administered_date,'%Y%m%d') as administered_date, ".
100 "i.lot_number as lot_number, ".
101 "i.manufacturer as manufacturer, ".
102 "concat(p.fname, '^', p.lname) as patientname, ";
103 } else {
104 $query .= "concat(p.fname, ' ',p.mname,' ', p.lname) as patientname, ".
105 "i.vis_date as immunizationdate, " ;
107 $query .=
108 "i.id as immunizationid, c.code_text_short as immunizationtitle ".
109 "from immunizations i, patient_data p, codes c ".
110 "left join code_types ct on c.code_type = ct.ct_id ".
111 "where ".
112 "ct.ct_key='CVX' and ";
113 if($from_date!=0) {
114 $query .= "i.vis_date >= '$from_date' " ;
116 if($from_date!=0 and $to_date!=0) {
117 $query .= " and " ;
119 if($to_date!=0) {
120 $query .= "i.vis_date <= '$to_date' ";
122 if($from_date!=0 or $to_date!=0) {
123 $query .= " and " ;
125 $query .= "i.patient_id=p.pid and ".
126 $query_codes .
127 "i.cvx_code = c.code ";
129 //echo "<p> DEBUG query: $query </p>\n"; // debugging
132 $D="\r";
133 $nowdate = date('Ymd');
134 $now = date('YmdGi');
135 $now1 = date('Y-m-d G:i');
136 $filename = "imm_reg_". $now . ".hl7";
138 // GENERATE HL7 FILE
139 if ($_POST['form_get_hl7']==='true') {
140 $content = '';
142 $res = sqlStatement($query);
144 while ($r = sqlFetchArray($res)) {
145 $content .= "MSH|^~\&|OPENEMR||||$nowdate||".
146 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1" .
147 "$D" ;
148 if ($r['sex']==='Male') $r['sex'] = 'M';
149 if ($r['sex']==='Female') $r['sex'] = 'F';
150 if ($r['status']==='married') $r['status'] = 'M';
151 if ($r['status']==='single') $r['status'] = 'S';
152 if ($r['status']==='divorced') $r['status'] = 'D';
153 if ($r['status']==='widowed') $r['status'] = 'W';
154 if ($r['status']==='separated') $r['status'] = 'A';
155 if ($r['status']==='domestic partner') $r['status'] = 'P';
156 $content .= "PID|" . // [[ 3.72 ]]
157 "|" . // 1. Set id
158 "|" . // 2. (B)Patient id
159 $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.
160 "|" . // 4. (B) Alternate PID
161 $r['patientname']."|" . // 5.R. Name
162 "|" . // 6. Mather Maiden Name
163 $r['DOB']."|" . // 7. Date, time of birth
164 $r['sex']."|" . // 8. Sex
165 "|" . // 9.B Patient Alias
166 "2106-3^" . $r['race']. "^HL70005" . "|" . // 10. Race // Ram change
167 $r['address'] . "^^M" . "|" . // 11. Address. Default to address type Mailing Address(M)
168 "|" . // 12. county code
169 "^PRN^^^^" . format_phone($r['phone_home']) . "|" . // 13. Phone Home. Default to Primary Home Number(PRN)
170 "^WPN^^^^" . format_phone($r['phone_biz']) . "|" . // 14. Phone Work.
171 "|" . // 15. Primary language
172 $r['status']."|" . // 16. Marital status
173 "|" . // 17. Religion
174 "|" . // 18. patient Account Number
175 "|" . // 19.B SSN Number
176 "|" . // 20.B Driver license number
177 "|" . // 21. Mathers Identifier
178 format_ethnicity($r['ethnicity']) . "|" . // 22. Ethnic Group
179 "|" . // 23. Birth Plase
180 "|" . // 24. Multiple birth indicator
181 "|" . // 25. Birth order
182 "|" . // 26. Citizenship
183 "|" . // 27. Veteran military status
184 "|" . // 28.B Nationality
185 "|" . // 29. Patient Death Date and Time
186 "|" . // 30. Patient Death Indicator
187 "|" . // 31. Identity Unknown Indicator
188 "|" . // 32. Identity Reliability Code
189 "|" . // 33. Last Update Date/Time
190 "|" . // 34. Last Update Facility
191 "|" . // 35. Species Code
192 "|" . // 36. Breed Code
193 "|" . // 37. Breed Code
194 "|" . // 38. Production Class Code
195 "" . // 39. Tribal Citizenship
196 "$D" ;
197 $content .= "ORC" . // ORC mandatory for RXA
198 "|" .
199 "RE" .
200 "$D" ;
201 $content .= "RXA|" .
202 "0|" . // 1. Give Sub-ID Counter
203 "1|" . // 2. Administrattion Sub-ID Counter
204 $r['administered_date']."|" . // 3. Date/Time Start of Administration
205 $r['administered_date']."|" . // 4. Date/Time End of Administration
206 format_cvx_code($r['code']). "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
207 "999|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
208 "|" . // 7. Administered Units
209 "|" . // 8. Administered Dosage Form
210 "|" . // 9. Administration Notes
211 "|" . // 10. Administering Provider
212 "|" . // 11. Administered-at Location
213 "|" . // 12. Administered Per (Time Unit)
214 "|" . // 13. Administered Strength
215 "|" . // 14. Administered Strength Units
216 $r['lot_number']."|" . // 15. Substance Lot Number
217 "|" . // 16. Substance Expiration Date
218 "MSD" . "^" . $r['manufacturer']. "^" . "HL70227" . "|" . // 17. Substance Manufacturer Name
219 "|" . // 18. Substance/Treatment Refusal Reason
220 "|" . // 19.Indication
221 "|" . // 20.Completion Status
222 "A" . // 21.Action Code - RXA
223 "$D" ;
227 // send the header here
228 header('Content-type: text/plain');
229 header('Content-Disposition: attachment; filename=' . $filename );
231 // put the content in the file
232 echo($content);
233 exit;
237 <html>
238 <head>
239 <?php html_header_show();?>
240 <title><?php xl('Immunization Registry','e'); ?></title>
241 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
242 <script type="text/javascript" src="../../library/dialog.js"></script>
243 <script type="text/javascript" src="../../library/textformat.js"></script>
244 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
245 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
246 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
247 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
248 <script language="JavaScript">
249 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
250 </script>
252 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
253 <style type="text/css">
254 /* specifically include & exclude from printing */
255 @media print {
256 #report_parameters {
257 visibility: hidden;
258 display: none;
260 #report_parameters_daterange {
261 visibility: visible;
262 display: inline;
263 margin-bottom: 10px;
265 #report_results table {
266 margin-top: 0px;
269 /* specifically exclude some from the screen */
270 @media screen {
271 #report_parameters_daterange {
272 visibility: hidden;
273 display: none;
275 #report_results {
276 width: 100%;
279 </style>
280 </head>
282 <body class="body_top">
284 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Immunization Registry','e'); ?></span>
286 <div id="report_parameters_daterange">
287 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
288 </div>
290 <form name='theform' id='theform' method='post' action='immunization_report.php'
291 onsubmit='return top.restoreSession()'>
292 <div id="report_parameters">
293 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
294 <input type='hidden' name='form_get_hl7' id='form_get_hl7' value=''/>
295 <table>
296 <tr>
297 <td width='410px'>
298 <div style='float:left'>
299 <table class='text'>
300 <tr>
301 <td class='label'>
302 <?php xl('Codes','e'); ?>:
303 </td>
304 <td>
305 <?php
306 // Build a drop-down list of codes.
308 $query1 = "select id, concat('CVX:',code) as name from codes ".
309 " left join code_types ct on codes.code_type = ct.ct_id ".
310 " where ct.ct_key='CVX' ORDER BY name";
311 $cres = sqlStatement($query1);
312 echo " <select multiple='multiple' size='3' name='form_code[]'>\n";
313 //echo " <option value=''>-- " . xl('All Codes') . " --\n";
314 while ($crow = sqlFetchArray($cres)) {
315 $codeid = $crow['id'];
316 echo " <option value='$codeid'";
317 if (in_array($codeid, $form_code)) echo " selected";
318 echo ">" . $crow['name'] . "\n";
320 echo " </select>\n";
322 </td>
323 <td class='label'>
324 <?php xl('From','e'); ?>:
325 </td>
326 <td>
327 <input type='text' name='form_from_date' id="form_from_date"
328 size='10' value='<?php echo $form_from_date ?>'
329 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
330 title='yyyy-mm-dd'>
331 <img src='../pic/show_calendar.gif' align='absbottom'
332 width='24' height='22' id='img_from_date' border='0'
333 alt='[?]' style='cursor:pointer'
334 title='<?php xl('Click here to choose a date','e'); ?>'>
335 </td>
336 <td class='label'>
337 <?php xl('To','e'); ?>:
338 </td>
339 <td>
340 <input type='text' name='form_to_date' id="form_to_date"
341 size='10' value='<?php echo $form_to_date ?>'
342 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
343 title='yyyy-mm-dd'>
344 <img src='../pic/show_calendar.gif' align='absbottom'
345 width='24' height='22' id='img_to_date' border='0'
346 alt='[?]' style='cursor:pointer'
347 title='<?php xl('Click here to choose a date','e'); ?>'>
348 </td>
349 </tr>
350 </table>
351 </div>
352 </td>
353 <td align='left' valign='middle' height="100%">
354 <table style='border-left:1px solid; width:100%; height:100%' >
355 <tr>
356 <td>
357 <div style='margin-left:15px'>
358 <a href='#' class='css_button'
359 onclick='
360 $("#form_refresh").attr("value","true");
361 $("#form_get_hl7").attr("value","false");
362 $("#theform").submit();
364 <span>
365 <?php xl('Refresh','e'); ?>
366 </spain>
367 </a>
368 <?php if ($_POST['form_refresh']) { ?>
369 <a href='#' class='css_button' onclick='window.print()'>
370 <span>
371 <?php xl('Print','e'); ?>
372 </span>
373 </a>
374 <a href='#' class='css_button' onclick=
375 "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'); ?>')) {
376 $('#form_get_hl7').attr('value','true');
377 $('#theform').submit();
379 <span>
380 <?php xl('Get HL7','e'); ?>
381 </span>
382 </a>
383 <?php } ?>
384 </div>
385 </td>
386 </tr>
387 </table>
388 </td>
389 </tr>
390 </table>
391 </div> <!-- end of parameters -->
394 <?php
395 if ($_POST['form_refresh']) {
397 <div id="report_results">
398 <table>
399 <thead align="left">
400 <th> <?php xl('Patient ID','e'); ?> </th>
401 <th> <?php xl('Patient Name','e'); ?> </th>
402 <th> <?php xl('Immunization Code','e'); ?> </th>
403 <th> <?php xl('Immunization Title','e'); ?> </th>
404 <th> <?php xl('Immunization Date','e'); ?> </th>
405 </thead>
406 <tbody>
407 <?php
408 $total = 0;
409 //echo "<p> DEBUG query: $query </p>\n"; // debugging
410 $res = sqlStatement($query);
413 while ($row = sqlFetchArray($res)) {
415 <tr>
416 <td>
417 <?php echo htmlspecialchars($row['patientid']) ?>
418 </td>
419 <td>
420 <?php echo htmlspecialchars($row['patientname']) ?>
421 </td>
422 <td>
423 <?php echo htmlspecialchars($row['cvx_code']) ?>
424 </td>
425 <td>
426 <?php echo htmlspecialchars($row['immunizationtitle']) ?>
427 </td>
428 <td>
429 <?php echo htmlspecialchars($row['immunizationdate']) ?>
430 </td>
431 </tr>
432 <?php
433 ++$total;
436 <tr class="report_totals">
437 <td colspan='9'>
438 <?php xl('Total Number of Immunizations','e'); ?>
440 <?php echo $total ?>
441 </td>
442 </tr>
444 </tbody>
445 </table>
446 </div> <!-- end of results -->
447 <?php } else { ?>
448 <div class='text'>
449 <?php echo xl('Click Refresh to view all results, or please input search criteria above to view specific results.', 'e' ); ?>
450 </div>
451 <?php } ?>
452 </form>
454 <script language='JavaScript'>
455 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
456 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
457 </script>
459 </body>
460 </html>