Highway to PSR2
[openemr.git] / interface / patient_file / summary / shot_record.php
blob996516bb871dd346e9312d56e1f78600ce281a66
1 <?php
5 include_once("../../globals.php");
6 include_once("$srcdir/options.inc.php");
7 include_once("$srcdir/immunization_helper.php");
9 $facilityService = new \services\FacilityService();
11 //collect facility data
12 $res = $facilityService->getFacilityForUserFormatted($_SESSION['authId']);
14 //collect patient data
15 $res2 = sqlQuery("select concat(p.lname,', ',p.fname,' ',p.mname) patient_name ".
16 ",date_format(p.DOB,'%c/%e/%Y') as patient_DOB ".
17 ",concat(p.street,'\n',p.city,', ',p.state,' ',p.postal_code) as patient_address".
18 " from patient_data p where p.pid = ?", array($pid));
20 //collect immunizations
21 $res3 = getImmunizationList($pid, $_GET['sortby'], false);
22 $data_array = convertToDataArray($res3);
24 $title = xl('Shot Record as of:', '', '', ' ') . date('m/d/Y h:i:s a');
26 if ($_GET['output'] == "html") {
27 printHTML($res, $res2, $data_array);
28 } else {
29 printPDF($res, $res2, $data_array);
33 function convertToDataArray($data_array)
35 $current = 0;
36 while ($row = sqlFetchArray($data_array)) {
37 //admin date
38 $temp_date = new DateTime($row['administered_date']);
39 $data[$current][xl('Date') . "\n" . xl('Admin')] = $temp_date->format('Y-m-d H:i'); //->format('%Y-%m-%d %H:%i');
41 //Vaccine
42 // Figure out which name to use (ie. from cvx list or from the custom list)
43 if ($GLOBALS['use_custom_immun_list']) {
44 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
45 } else {
46 if (!empty($row['code_text_short'])) {
47 $vaccine_display = htmlspecialchars(xl($row['code_text_short']), ENT_NOQUOTES);
48 } else {
49 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
53 $data[$current][xl('Vaccine')] = $vaccine_display;
55 //Amount
56 if ($row['amount_administered'] > 0) {
57 $data[$current][xl('Amount') . "\n" . xl('Admin')] = $row['amount_administered'] . " " .
58 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['amount_administered_unit']);
59 } else {
60 $data[$current][xl('Amount') . "\n" . xl('Admin')] = "";
63 //expiration date fixed by checking for empty value, smw 040214
64 if (isset($row['expiration_date'])) {
65 $temp_date = new DateTime($row['expiration_date']);
66 $data[$current][xl('Expiration') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
67 } else {
68 $data[$current][xl('Expiration') . "\n" . xl('Date')] = '';//$temp_date->format('Y-m-d');
71 //Manufacturer
72 $data[$current][xl('Manufacturer')] = $row['manufacturer'];
74 //Lot Number
75 $data[$current][xl('Lot') . "\n" . xl('Number')] = $row['lot_number'];
77 //Admin By
78 $data[$current][xl('Admin') . "\n" . xl('By')] = $row['administered_by'];
80 //education date
81 $temp_date = new DateTime($row['education_date']);
82 $data[$current][xl('Patient') . "\n" . xl('Education') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
84 //Route
85 $data[$current][xl('Route')] = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']);
87 //Admin Site
88 $data[$current][xl('Admin') . "\n" . xl('Site')] = generate_display_field(array('data_type'=>'1','list_id'=>'proc_body_site'), $row['administration_site']);
90 //Comments
91 $data[$current][xl('Comments')] = $row['note'];
92 $current ++;
95 return $data;
98 function printPDF($res, $res2, $data)
101 $pdf = new Cezpdf("LETTER");
102 $pdf->ezSetMargins(72, 30, 50, 30);
103 $pdf->selectFont('Helvetica');
105 $opts = array('justification' => "center");
106 $pdf->ezText($res['facility_address'], "", $opts);
108 $pdf->ezText("\n" . $res2['patient_name'] . "\n" . xl('Date of Birth') . ": " . $res2['patient_DOB'] . "\n" . $res2['patient_address']);
109 $pdf->ezText("\n");
111 $opts = array('maxWidth' => 550, 'fontSize' => 8);
113 $pdf->ezTable($data, "", $title, $opts);
114 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________", "", array('justification' => 'right'));
115 $pdf->ezStream();
118 function printHTML($res, $res2, $data)
120 //print html css
122 //convert end of line characters to html (escape for html output first)
123 $patterns = array ('/\n/');
124 $replace = array ('<br>');
125 $res['facility_address'] = htmlspecialchars($res['facility_address'], ENT_NOQUOTES);
126 $res['facility_address'] = preg_replace($patterns, $replace, $res['facility_address']);
127 $res2['patient_address'] = htmlspecialchars($res2['patient_address'], ENT_NOQUOTES);
128 $res2['patient_address'] = preg_replace($patterns, $replace, $res2['patient_address']);
130 //deal with bug (last array index is empty)
131 //array_pop($data);
135 <html>
136 <head>
137 <style>
138 body {
139 font-family: sans-serif;
140 font-weight: normal;
141 font-size: 10pt;
142 background: white;
143 color: black;
145 div {
146 padding: 0;
147 margin: 0;
149 div.paddingdiv {
150 width: 524pt;
151 height: 668pt;
152 page-break-after: always;
154 div.patientAddress {
155 margin: 20pt 0 10pt 0;
156 font-size: 10pt;
158 div.clinicAddress {
159 text-align: center;
160 width: 100%;
161 font-size: 10pt;
163 div.sign {
164 margin: 30pt 0 0 20pt;
166 div.tabletitle {
167 font-size: 12pt;
168 text-align: center;
169 width: 100%;
171 table {
172 margin: 0 20pt 0 20pt;
173 border-collapse: collapse;
174 border: 1pt solid black;
176 td {
177 font-size: 10pt;
178 padding: 2pt 3pt 2pt 3pt;
179 border-right: 1pt solid black;
180 border-left: 1pt solid black;
182 td.odd {
183 background-color: #D8D8D8;
185 th {
186 font-size: 10pt;
187 border: 1pt solid black;
188 padding: 2pt 3pt 2pt 3pt;
190 div.pageNumber {
191 margin-top: 15pt;
192 font-size: 8pt;
193 text-align: center;
194 width: 100%;
196 </style>
197 <title><?php xl('Shot Record', 'e'); ?></title>
198 </head>
199 <body>
201 <?php
202 //plan 15 lines per page
203 $linesPerPage=15;
204 $countTotalPages = (ceil((count($data))/$linesPerPage));
205 for ($i=0; $i<$countTotalPages; $i++) {
206 echo "<div class='paddingdiv'>\n";
208 //display facility information (Note it is already escaped)
209 echo "<div class='clinicAddress'>" . $res['facility_address'] . "</div>\n";
211 //display patient information (Note patient address is already escaped)
212 echo "<div class='patientAddress'>" . htmlspecialchars($res2['patient_name'], ENT_NOQUOTES) . "<br>" .
213 htmlspecialchars(xl('Date of Birth') . ": " . $res2['patient_DOB'], ENT_NOQUOTES) . "<br>" .
214 $res2['patient_address'] . "</div>\n";
216 //display table title
217 echo "<div class='tabletitle'>" . htmlspecialchars($title, ENT_NOQUOTES) . "</div>\n";
219 echo "<table cellspacing='0' cellpadding='0'>\n";
221 //display header
222 echo "<tr>\n";
223 foreach ($data[0] as $key => $value) {
224 //convert end of line characters to space
225 $patterns = array ('/\n/');
226 $replace = array (' ');
227 $key = preg_replace($patterns, $replace, $key);
228 echo "<th>".htmlspecialchars($key, ENT_NOQUOTES)."</th>\n";
231 echo "</tr>\n";
233 //display shot data
234 for ($j=0; $j<$linesPerPage; $j++) {
235 if ($rowData = array_shift($data)) {
236 echo "<tr>";
237 foreach ($rowData as $key => $value) {
238 //shading of cells
239 if ($j==0) {
240 echo "<td>";
241 } elseif ($j%2) {
242 echo "<td class ='odd'>";
243 } else {
244 echo "<td>";
247 // output data of cell
248 echo ($value == "") ? "&nbsp;" : htmlspecialchars($value, ENT_NOQUOTES);
249 echo "</td>";
251 } else {
252 //done displaying shot data, so leave loop
253 break;
257 echo "</table>\n";
259 //display signature line
260 echo "<div class='sign'>" . htmlspecialchars(xl('Signature'), ENT_NOQUOTES) .
261 ":________________________________" . "</div>\n";
263 if ($countTotalPages > 1) {
264 //display page number if greater than one page
265 echo "<div class='pageNumber'>" .
266 htmlspecialchars(xl('Page') . " " . ($i+1) . "/" . $countTotalPages, ENT_NOQUOTES) .
267 "</div>\n";
270 echo "</div>\n";
275 <script language='JavaScript'>
276 opener.top.printLogPrint(window);
277 </script>
278 </body>
279 </html>
280 <?php