Immunization_information_(MU2) changes, take 5.
[openemr.git] / interface / patient_file / summary / shot_record.php
blob2ef9eb2060792ccb758d899ab1a4ee2608b6f655
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
76 $temp_date = new DateTime($row['expiration_date']);
77 $data[$current][xl('Expiration') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
79 //Manufacturer
80 $data[$current][xl('Manufacturer')] = $row['manufacturer'];
82 //Lot Number
83 $data[$current][xl('Lot') . "\n" . xl('Number')] = $row['lot_number'];
85 //Admin By
86 $data[$current][xl('Admin') . "\n" . xl('By')] = $row['administered_by'];
88 //education date
89 $temp_date = new DateTime($row['education_date']);
90 $data[$current][xl('Patient') . "\n" . xl('Education') . "\n" . xl('Date')] = $temp_date->format('Y-m-d');
92 //Route
93 $data[$current][xl('Route')] = generate_display_field(array('data_type'=>'1','list_id'=>'drug_route'), $row['route']);
95 //Admin Site
96 $data[$current][xl('Admin') . "\n" . xl('Site')] = generate_display_field(array('data_type'=>'1','list_id'=>'proc_body_site'), $row['administration_site']);
98 //Comments
99 $data[$current][xl('Comments')] = $row['note'];
100 $current ++;
102 return $data;
105 function printPDF($res, $res2, $data) {
106 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
108 $pdf =& new Cezpdf("LETTER");
109 $pdf->ezSetMargins(72,30,50,30);
110 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
112 $opts = array('justification' => "center");
113 $pdf->ezText($res['facility_address'] ,"",$opts);
115 $pdf->ezText("\n" . $res2['patient_name'] . "\n" . xl('Date of Birth') . ": " . $res2['patient_DOB'] . "\n" . $res2['patient_address']);
116 $pdf->ezText("\n");
118 $opts = array('maxWidth' => 550, 'fontSize' => 8);
120 $pdf->ezTable($data, "", $title, $opts);
121 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________","",array('justification' => 'right'));
122 $pdf->ezStream();
125 function printHTML($res, $res2, $data) {
126 //print html css
128 //convert end of line characters to html (escape for html output first)
129 $patterns = array ('/\n/');
130 $replace = array ('<br>');
131 $res['facility_address'] = htmlspecialchars( $res['facility_address'], ENT_NOQUOTES);
132 $res['facility_address'] = preg_replace($patterns, $replace, $res['facility_address']);
133 $res2['patient_address'] = htmlspecialchars( $res2['patient_address'], ENT_NOQUOTES);
134 $res2['patient_address'] = preg_replace($patterns, $replace, $res2['patient_address']);
136 //deal with bug (last array index is empty)
137 //array_pop($data);
141 <html>
142 <head>
143 <style>
144 body {
145 font-family: sans-serif;
146 font-weight: normal;
147 font-size: 10pt;
148 background: white;
149 color: black;
151 div {
152 padding: 0;
153 margin: 0;
155 div.paddingdiv {
156 width: 524pt;
157 height: 668pt;
158 page-break-after: always;
160 div.patientAddress {
161 margin: 20pt 0 10pt 0;
162 font-size: 10pt;
164 div.clinicAddress {
165 text-align: center;
166 width: 100%;
167 font-size: 10pt;
169 div.sign {
170 margin: 30pt 0 0 20pt;
172 div.tabletitle {
173 font-size: 12pt;
174 text-align: center;
175 width: 100%;
177 table {
178 margin: 0 20pt 0 20pt;
179 border-collapse: collapse;
180 border: 1pt solid black;
182 td {
183 font-size: 10pt;
184 padding: 2pt 3pt 2pt 3pt;
185 border-right: 1pt solid black;
186 border-left: 1pt solid black;
188 td.odd {
189 background-color: #D8D8D8;
191 th {
192 font-size: 10pt;
193 border: 1pt solid black;
194 padding: 2pt 3pt 2pt 3pt;
196 div.pageNumber {
197 margin-top: 15pt;
198 font-size: 8pt;
199 text-align: center;
200 width: 100%;
202 </style>
203 <title><?php xl ('Shot Record','e'); ?></title>
204 </head>
205 <body>
207 <?php
208 //plan 15 lines per page
209 $linesPerPage=15;
210 $countTotalPages = (ceil((count($data))/$linesPerPage));
211 for ($i=0;$i<$countTotalPages;$i++) {
212 echo "<div class='paddingdiv'>\n";
214 //display facility information (Note it is already escaped)
215 echo "<div class='clinicAddress'>" . $res['facility_address'] . "</div>\n";
217 //display patient information (Note patient address is already escaped)
218 echo "<div class='patientAddress'>" . htmlspecialchars( $res2['patient_name'], ENT_NOQUOTES) . "<br>" .
219 htmlspecialchars( xl('Date of Birth') . ": " . $res2['patient_DOB'], ENT_NOQUOTES) . "<br>" .
220 $res2['patient_address'] . "</div>\n";
222 //display table title
223 echo "<div class='tabletitle'>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</div>\n";
225 echo "<table cellspacing='0' cellpadding='0'>\n";
227 //display header
228 echo "<tr>\n";
229 foreach ($data[0] as $key => $value) {
231 //convert end of line characters to space
232 $patterns = array ('/\n/');
233 $replace = array (' ');
234 $key = preg_replace($patterns, $replace, $key);
235 echo "<th>".htmlspecialchars( $key, ENT_NOQUOTES)."</th>\n";
237 echo "</tr>\n";
239 //display shot data
240 for ($j=0;$j<$linesPerPage;$j++) {
241 if ($rowData = array_shift($data)) {
242 echo "<tr>";
243 foreach ($rowData as $key => $value) {
245 //shading of cells
246 if ($j==0) {
247 echo "<td>";
249 elseif ($j%2) {
250 echo "<td class ='odd'>";
252 else {
253 echo "<td>";
256 // output data of cell
257 echo ($value == "") ? "&nbsp;" : htmlspecialchars($value, ENT_NOQUOTES);
258 echo "</td>";
261 else {
262 //done displaying shot data, so leave loop
263 break;
267 echo "</table>\n";
269 //display signature line
270 echo "<div class='sign'>" . htmlspecialchars( xl('Signature'), ENT_NOQUOTES) .
271 ":________________________________" . "</div>\n";
273 if ($countTotalPages > 1) {
274 //display page number if greater than one page
275 echo "<div class='pageNumber'>" .
276 htmlspecialchars( xl('Page') . " " . ($i+1) . "/" . $countTotalPages, ENT_NOQUOTES) .
277 "</div>\n";
280 echo "</div>\n";
285 <script language='JavaScript'>
286 window.print();
287 </script>
288 </body>
289 </html>
290 <?php