fix to immun expiration date print on shot record
[openemr.git] / interface / patient_file / summary / shot_record.php
blobe1158209ed7beaae25fd8e1e00ba56b3d08b62d6
1 <?php
3 //SANITIZE ALL ESCAPES
4 $sanitize_all_escapes=true;
5 //
7 //STOP FAKE REGISTER GLOBALS
8 $fake_register_globals=false;
9 //
11 include_once("../../globals.php");
12 include_once("$srcdir/sql.inc");
13 include_once("$srcdir/options.inc.php");
14 include_once("$srcdir/immunization_helper.php");
16 //collect facility data
17 $res = sqlQuery("select concat(f.name,'\n',f.street,'\n',f.city,', ',f.state,' ',f.postal_code) as facility_address ".
18 " from facility f, users u ".
19 " where u.facility = f.name ".
20 " and u.id = ?", array($_SESSION['authId'])
23 //collect patient data
24 $res2 = sqlQuery("select concat(p.lname,', ',p.fname,' ',p.mname) patient_name ".
25 ",date_format(p.DOB,'%c/%e/%Y') as patient_DOB ".
26 ",concat(p.street,'\n',p.city,', ',p.state,' ',p.postal_code) as patient_address".
27 " from patient_data p where p.pid = ?", array($pid)
30 //collect immunizations
31 $res3 = getImmunizationList($pid, $_GET['sortby'], false);
32 $data_array = convertToDataArray($res3);
34 $title = xl('Shot Record as of:','','',' ') . date('m/d/Y h:i:s a');
36 if ($_GET['output'] == "html") {
37 printHTML($res, $res2, $data_array);
39 else {
40 printPDF($res, $res2, $data_array);
44 function convertToDataArray($data_array) {
45 $current = 0;
46 while ($row = sqlFetchArray($data_array)) {
47 //admin date
48 $temp_date = new DateTime($row['administered_date']);
49 $data[$current][xl('Date') . "\n" . xl('Admin')] = $temp_date->format('Y-m-d H:i'); //->format('%Y-%m-%d %H:%i');
51 //Vaccine
52 // Figure out which name to use (ie. from cvx list or from the custom list)
53 if ($GLOBALS['use_custom_immun_list']) {
54 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
56 else {
57 if (!empty($row['code_text_short'])) {
58 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
60 else {
61 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
64 $data[$current][xl('Vaccine')] = $vaccine_display;
66 //Amount
67 if ($row['amount_administered'] > 0) {
68 $data[$current][xl('Amount') . "\n" . xl('Admin')] = $row['amount_administered'] . " " .
69 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['amount_administered_unit']);
71 else {
72 $data[$current][xl('Amount') . "\n" . xl('Admin')] = "";
75 //expiration date fixed by checking for empty value, smw 040214
76 if (isset($row['expiration_date'])) {
77 $temp_date = new DateTime($row['expiration_date']);
78 $data[$current][xl('Expiration') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
80 else{
81 $data[$current][xl('Expiration') . "\n" . xl('Date')] = '';//$temp_date->format('Y-m-d');
84 //Manufacturer
85 $data[$current][xl('Manufacturer')] = $row['manufacturer'];
87 //Lot Number
88 $data[$current][xl('Lot') . "\n" . xl('Number')] = $row['lot_number'];
90 //Admin By
91 $data[$current][xl('Admin') . "\n" . xl('By')] = $row['administered_by'];
93 //education date
94 $temp_date = new DateTime($row['education_date']);
95 $data[$current][xl('Patient') . "\n" . xl('Education') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
97 //Route
98 $data[$current][xl('Route')] = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']);
100 //Admin Site
101 $data[$current][xl('Admin') . "\n" . xl('Site')] = generate_display_field(array('data_type'=>'1','list_id'=>'proc_body_site'), $row['administration_site']);
103 //Comments
104 $data[$current][xl('Comments')] = $row['note'];
105 $current ++;
107 return $data;
110 function printPDF($res, $res2, $data) {
111 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
113 $pdf =& new Cezpdf("LETTER");
114 $pdf->ezSetMargins(72,30,50,30);
115 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
117 $opts = array('justification' => "center");
118 $pdf->ezText($res['facility_address'] ,"",$opts);
120 $pdf->ezText("\n" . $res2['patient_name'] . "\n" . xl('Date of Birth') . ": " . $res2['patient_DOB'] . "\n" . $res2['patient_address']);
121 $pdf->ezText("\n");
123 $opts = array('maxWidth' => 550, 'fontSize' => 8);
125 $pdf->ezTable($data, "", $title, $opts);
126 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________","",array('justification' => 'right'));
127 $pdf->ezStream();
130 function printHTML($res, $res2, $data) {
131 //print html css
133 //convert end of line characters to html (escape for html output first)
134 $patterns = array ('/\n/');
135 $replace = array ('<br>');
136 $res['facility_address'] = htmlspecialchars( $res['facility_address'], ENT_NOQUOTES);
137 $res['facility_address'] = preg_replace($patterns, $replace, $res['facility_address']);
138 $res2['patient_address'] = htmlspecialchars( $res2['patient_address'], ENT_NOQUOTES);
139 $res2['patient_address'] = preg_replace($patterns, $replace, $res2['patient_address']);
141 //deal with bug (last array index is empty)
142 //array_pop($data);
146 <html>
147 <head>
148 <style>
149 body {
150 font-family: sans-serif;
151 font-weight: normal;
152 font-size: 10pt;
153 background: white;
154 color: black;
156 div {
157 padding: 0;
158 margin: 0;
160 div.paddingdiv {
161 width: 524pt;
162 height: 668pt;
163 page-break-after: always;
165 div.patientAddress {
166 margin: 20pt 0 10pt 0;
167 font-size: 10pt;
169 div.clinicAddress {
170 text-align: center;
171 width: 100%;
172 font-size: 10pt;
174 div.sign {
175 margin: 30pt 0 0 20pt;
177 div.tabletitle {
178 font-size: 12pt;
179 text-align: center;
180 width: 100%;
182 table {
183 margin: 0 20pt 0 20pt;
184 border-collapse: collapse;
185 border: 1pt solid black;
187 td {
188 font-size: 10pt;
189 padding: 2pt 3pt 2pt 3pt;
190 border-right: 1pt solid black;
191 border-left: 1pt solid black;
193 td.odd {
194 background-color: #D8D8D8;
196 th {
197 font-size: 10pt;
198 border: 1pt solid black;
199 padding: 2pt 3pt 2pt 3pt;
201 div.pageNumber {
202 margin-top: 15pt;
203 font-size: 8pt;
204 text-align: center;
205 width: 100%;
207 </style>
208 <title><?php xl ('Shot Record','e'); ?></title>
209 </head>
210 <body>
212 <?php
213 //plan 15 lines per page
214 $linesPerPage=15;
215 $countTotalPages = (ceil((count($data))/$linesPerPage));
216 for ($i=0;$i<$countTotalPages;$i++) {
217 echo "<div class='paddingdiv'>\n";
219 //display facility information (Note it is already escaped)
220 echo "<div class='clinicAddress'>" . $res['facility_address'] . "</div>\n";
222 //display patient information (Note patient address is already escaped)
223 echo "<div class='patientAddress'>" . htmlspecialchars( $res2['patient_name'], ENT_NOQUOTES) . "<br>" .
224 htmlspecialchars( xl('Date of Birth') . ": " . $res2['patient_DOB'], ENT_NOQUOTES) . "<br>" .
225 $res2['patient_address'] . "</div>\n";
227 //display table title
228 echo "<div class='tabletitle'>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</div>\n";
230 echo "<table cellspacing='0' cellpadding='0'>\n";
232 //display header
233 echo "<tr>\n";
234 foreach ($data[0] as $key => $value) {
236 //convert end of line characters to space
237 $patterns = array ('/\n/');
238 $replace = array (' ');
239 $key = preg_replace($patterns, $replace, $key);
240 echo "<th>".htmlspecialchars( $key, ENT_NOQUOTES)."</th>\n";
242 echo "</tr>\n";
244 //display shot data
245 for ($j=0;$j<$linesPerPage;$j++) {
246 if ($rowData = array_shift($data)) {
247 echo "<tr>";
248 foreach ($rowData as $key => $value) {
250 //shading of cells
251 if ($j==0) {
252 echo "<td>";
254 elseif ($j%2) {
255 echo "<td class ='odd'>";
257 else {
258 echo "<td>";
261 // output data of cell
262 echo ($value == "") ? "&nbsp;" : htmlspecialchars($value, ENT_NOQUOTES);
263 echo "</td>";
266 else {
267 //done displaying shot data, so leave loop
268 break;
272 echo "</table>\n";
274 //display signature line
275 echo "<div class='sign'>" . htmlspecialchars( xl('Signature'), ENT_NOQUOTES) .
276 ":________________________________" . "</div>\n";
278 if ($countTotalPages > 1) {
279 //display page number if greater than one page
280 echo "<div class='pageNumber'>" .
281 htmlspecialchars( xl('Page') . " " . ($i+1) . "/" . $countTotalPages, ENT_NOQUOTES) .
282 "</div>\n";
285 echo "</div>\n";
290 <script language='JavaScript'>
291 window.print();
292 </script>
293 </body>
294 </html>
295 <?php