more organization of autoloaded files (#424)
[openemr.git] / interface / patient_file / summary / shot_record.php
blobdb0e19b09a24f4894e43f500530bd1fcf7613a19
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/options.inc.php");
13 include_once("$srcdir/immunization_helper.php");
15 //collect facility data
16 $res = sqlQuery("select concat(f.name,'\n',f.street,'\n',f.city,', ',f.state,' ',f.postal_code) as facility_address ".
17 " from facility f, users u ".
18 " where u.facility = f.name ".
19 " and u.id = ?", array($_SESSION['authId'])
22 //collect patient data
23 $res2 = sqlQuery("select concat(p.lname,', ',p.fname,' ',p.mname) patient_name ".
24 ",date_format(p.DOB,'%c/%e/%Y') as patient_DOB ".
25 ",concat(p.street,'\n',p.city,', ',p.state,' ',p.postal_code) as patient_address".
26 " from patient_data p where p.pid = ?", array($pid)
29 //collect immunizations
30 $res3 = getImmunizationList($pid, $_GET['sortby'], false);
31 $data_array = convertToDataArray($res3);
33 $title = xl('Shot Record as of:','','',' ') . date('m/d/Y h:i:s a');
35 if ($_GET['output'] == "html") {
36 printHTML($res, $res2, $data_array);
38 else {
39 printPDF($res, $res2, $data_array);
43 function convertToDataArray($data_array) {
44 $current = 0;
45 while ($row = sqlFetchArray($data_array)) {
46 //admin date
47 $temp_date = new DateTime($row['administered_date']);
48 $data[$current][xl('Date') . "\n" . xl('Admin')] = $temp_date->format('Y-m-d H:i'); //->format('%Y-%m-%d %H:%i');
50 //Vaccine
51 // Figure out which name to use (ie. from cvx list or from the custom list)
52 if ($GLOBALS['use_custom_immun_list']) {
53 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
55 else {
56 if (!empty($row['code_text_short'])) {
57 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
59 else {
60 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
63 $data[$current][xl('Vaccine')] = $vaccine_display;
65 //Amount
66 if ($row['amount_administered'] > 0) {
67 $data[$current][xl('Amount') . "\n" . xl('Admin')] = $row['amount_administered'] . " " .
68 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['amount_administered_unit']);
70 else {
71 $data[$current][xl('Amount') . "\n" . xl('Admin')] = "";
74 //expiration date fixed by checking for empty value, smw 040214
75 if (isset($row['expiration_date'])) {
76 $temp_date = new DateTime($row['expiration_date']);
77 $data[$current][xl('Expiration') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
79 else{
80 $data[$current][xl('Expiration') . "\n" . xl('Date')] = '';//$temp_date->format('Y-m-d');
83 //Manufacturer
84 $data[$current][xl('Manufacturer')] = $row['manufacturer'];
86 //Lot Number
87 $data[$current][xl('Lot') . "\n" . xl('Number')] = $row['lot_number'];
89 //Admin By
90 $data[$current][xl('Admin') . "\n" . xl('By')] = $row['administered_by'];
92 //education date
93 $temp_date = new DateTime($row['education_date']);
94 $data[$current][xl('Patient') . "\n" . xl('Education') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
96 //Route
97 $data[$current][xl('Route')] = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']);
99 //Admin Site
100 $data[$current][xl('Admin') . "\n" . xl('Site')] = generate_display_field(array('data_type'=>'1','list_id'=>'proc_body_site'), $row['administration_site']);
102 //Comments
103 $data[$current][xl('Comments')] = $row['note'];
104 $current ++;
106 return $data;
109 function printPDF($res, $res2, $data) {
111 $pdf = new Cezpdf("LETTER");
112 $pdf->ezSetMargins(72,30,50,30);
113 $pdf->selectFont('Helvetica');
115 $opts = array('justification' => "center");
116 $pdf->ezText($res['facility_address'] ,"",$opts);
118 $pdf->ezText("\n" . $res2['patient_name'] . "\n" . xl('Date of Birth') . ": " . $res2['patient_DOB'] . "\n" . $res2['patient_address']);
119 $pdf->ezText("\n");
121 $opts = array('maxWidth' => 550, 'fontSize' => 8);
123 $pdf->ezTable($data, "", $title, $opts);
124 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________","",array('justification' => 'right'));
125 $pdf->ezStream();
128 function printHTML($res, $res2, $data) {
129 //print html css
131 //convert end of line characters to html (escape for html output first)
132 $patterns = array ('/\n/');
133 $replace = array ('<br>');
134 $res['facility_address'] = htmlspecialchars( $res['facility_address'], ENT_NOQUOTES);
135 $res['facility_address'] = preg_replace($patterns, $replace, $res['facility_address']);
136 $res2['patient_address'] = htmlspecialchars( $res2['patient_address'], ENT_NOQUOTES);
137 $res2['patient_address'] = preg_replace($patterns, $replace, $res2['patient_address']);
139 //deal with bug (last array index is empty)
140 //array_pop($data);
144 <html>
145 <head>
146 <style>
147 body {
148 font-family: sans-serif;
149 font-weight: normal;
150 font-size: 10pt;
151 background: white;
152 color: black;
154 div {
155 padding: 0;
156 margin: 0;
158 div.paddingdiv {
159 width: 524pt;
160 height: 668pt;
161 page-break-after: always;
163 div.patientAddress {
164 margin: 20pt 0 10pt 0;
165 font-size: 10pt;
167 div.clinicAddress {
168 text-align: center;
169 width: 100%;
170 font-size: 10pt;
172 div.sign {
173 margin: 30pt 0 0 20pt;
175 div.tabletitle {
176 font-size: 12pt;
177 text-align: center;
178 width: 100%;
180 table {
181 margin: 0 20pt 0 20pt;
182 border-collapse: collapse;
183 border: 1pt solid black;
185 td {
186 font-size: 10pt;
187 padding: 2pt 3pt 2pt 3pt;
188 border-right: 1pt solid black;
189 border-left: 1pt solid black;
191 td.odd {
192 background-color: #D8D8D8;
194 th {
195 font-size: 10pt;
196 border: 1pt solid black;
197 padding: 2pt 3pt 2pt 3pt;
199 div.pageNumber {
200 margin-top: 15pt;
201 font-size: 8pt;
202 text-align: center;
203 width: 100%;
205 </style>
206 <title><?php xl ('Shot Record','e'); ?></title>
207 </head>
208 <body>
210 <?php
211 //plan 15 lines per page
212 $linesPerPage=15;
213 $countTotalPages = (ceil((count($data))/$linesPerPage));
214 for ($i=0;$i<$countTotalPages;$i++) {
215 echo "<div class='paddingdiv'>\n";
217 //display facility information (Note it is already escaped)
218 echo "<div class='clinicAddress'>" . $res['facility_address'] . "</div>\n";
220 //display patient information (Note patient address is already escaped)
221 echo "<div class='patientAddress'>" . htmlspecialchars( $res2['patient_name'], ENT_NOQUOTES) . "<br>" .
222 htmlspecialchars( xl('Date of Birth') . ": " . $res2['patient_DOB'], ENT_NOQUOTES) . "<br>" .
223 $res2['patient_address'] . "</div>\n";
225 //display table title
226 echo "<div class='tabletitle'>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</div>\n";
228 echo "<table cellspacing='0' cellpadding='0'>\n";
230 //display header
231 echo "<tr>\n";
232 foreach ($data[0] as $key => $value) {
234 //convert end of line characters to space
235 $patterns = array ('/\n/');
236 $replace = array (' ');
237 $key = preg_replace($patterns, $replace, $key);
238 echo "<th>".htmlspecialchars( $key, ENT_NOQUOTES)."</th>\n";
240 echo "</tr>\n";
242 //display shot data
243 for ($j=0;$j<$linesPerPage;$j++) {
244 if ($rowData = array_shift($data)) {
245 echo "<tr>";
246 foreach ($rowData as $key => $value) {
248 //shading of cells
249 if ($j==0) {
250 echo "<td>";
252 elseif ($j%2) {
253 echo "<td class ='odd'>";
255 else {
256 echo "<td>";
259 // output data of cell
260 echo ($value == "") ? "&nbsp;" : htmlspecialchars($value, ENT_NOQUOTES);
261 echo "</td>";
264 else {
265 //done displaying shot data, so leave loop
266 break;
270 echo "</table>\n";
272 //display signature line
273 echo "<div class='sign'>" . htmlspecialchars( xl('Signature'), ENT_NOQUOTES) .
274 ":________________________________" . "</div>\n";
276 if ($countTotalPages > 1) {
277 //display page number if greater than one page
278 echo "<div class='pageNumber'>" .
279 htmlspecialchars( xl('Page') . " " . ($i+1) . "/" . $countTotalPages, ENT_NOQUOTES) .
280 "</div>\n";
283 echo "</div>\n";
288 <script language='JavaScript'>
289 opener.top.printLogPrint(window);
290 </script>
291 </body>
292 </html>
293 <?php