The Third Reminders email bug fix - contributed by arnabnaha
[openemr.git] / interface / patient_file / summary / shot_record.php
blob74a29bf1bba5c86fb36386f6a0ff3d7c51e1409a
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");
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 $sqlstmt = "select date_format(i1.administered_date,'%Y-%m-%d') as '" . xl('Date') . "\n" . xl('Administered') . "' ".
31 ",i1.immunization_id as '" . xl('Vaccine') . "' ".
32 ",c.code_text_short as cvx_text ".
33 ",i1.manufacturer as '" . xl('Manufacturer') . "' ".
34 ",i1.lot_number as '" . xl('Lot') . "\n" . xl('Number') . "' ".
35 ",concat(u.lname,', ',u.fname) as '" . xl('Administered By') . "' ".
36 ",date_format(i1.education_date,'%Y-%m-%d') as '" . xl('Patient') . "\n" . xl('Education') . "\n" . xl('Date') . "' ".
37 ",i1.note as '" . xl('Comments') . "'".
38 " from immunizations i1 ".
39 " left join users u on i1.administered_by_id = u.id ".
40 " left join patient_data p on i1.patient_id = p.pid ".
41 " left join code_types ct on ct.ct_key = 'CVX' ".
42 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
43 " where p.pid = ? ";
45 // sort the results, as they are on the user's screen
46 $sqlstmt .= " order by ";
47 if ($_GET['sortby'] == "vacc") { $sqlstmt .= " i1.immunization_id, i1.administered_date DESC"; }
48 else { $sqlstmt .= " i1.administered_date desc"; }
50 $res3 = sqlStatement($sqlstmt, array($pid) );
52 while ($data[] = sqlFetchArray($res3)) {}
54 for ($i=0;$i<count($data);$i++) {
55 // Figure out which name to use (ie. from cvx list or from the custom list)
56 if ($GLOBALS['use_custom_immun_list']) {
57 $data[$i][xl('Vaccine')] = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $data[$i][xl('Vaccine')]);
59 else {
60 if (!(empty($data[$i]['cvx_text']))) {
61 $data[$i][xl('Vaccine')] = htmlspecialchars( xl($data[$i]['cvx_text']), ENT_NOQUOTES);
63 else {
64 $data[$i][xl('Vaccine')] = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $data[$i][xl('Vaccine')]);
67 unset( $data[$i]['cvx_text'] );
71 $title = xl('Shot Record as of:','','',' ') . date('m/d/Y h:i:s a');
74 if ($_GET['output'] == "html") { //print html css
76 //convert end of line characters to html (escape for html output first)
77 $patterns = array ('/\n/');
78 $replace = array ('<br>');
79 $res['facility_address'] = htmlspecialchars( $res['facility_address'], ENT_NOQUOTES);
80 $res['facility_address'] = preg_replace($patterns, $replace, $res['facility_address']);
81 $res2['patient_address'] = htmlspecialchars( $res2['patient_address'], ENT_NOQUOTES);
82 $res2['patient_address'] = preg_replace($patterns, $replace, $res2['patient_address']);
84 //deal with bug (last array index is empty)
85 array_pop($data);
87 ?>
89 <html>
90 <head>
91 <style>
92 body {
93 font-family: sans-serif;
94 font-weight: normal;
95 font-size: 10pt;
96 background: white;
97 color: black;
99 div {
100 padding: 0;
101 margin: 0;
103 div.paddingdiv {
104 width: 524pt;
105 height: 668pt;
106 page-break-after: always;
108 div.patientAddress {
109 margin: 20pt 0 10pt 0;
110 font-size: 10pt;
112 div.clinicAddress {
113 text-align: center;
114 width: 100%;
115 font-size: 10pt;
117 div.sign {
118 margin: 30pt 0 0 20pt;
120 div.tabletitle {
121 font-size: 12pt;
122 text-align: center;
123 width: 100%;
125 table {
126 margin: 0 20pt 0 20pt;
127 border-collapse: collapse;
128 border: 1pt solid black;
130 td {
131 font-size: 10pt;
132 padding: 2pt 3pt 2pt 3pt;
133 border-right: 1pt solid black;
134 border-left: 1pt solid black;
136 td.odd {
137 background-color: #D8D8D8;
139 th {
140 font-size: 10pt;
141 border: 1pt solid black;
142 padding: 2pt 3pt 2pt 3pt;
144 div.pageNumber {
145 margin-top: 15pt;
146 font-size: 8pt;
147 text-align: center;
148 width: 100%;
150 </style>
151 <title><?php xl ('Shot Record','e'); ?></title>
152 </head>
153 <body>
155 <?php
156 //plan 15 lines per page
157 $linesPerPage=15;
158 $countTotalPages = (ceil((count($data))/$linesPerPage));
159 for ($i=0;$i<$countTotalPages;$i++) {
160 echo "<div class='paddingdiv'>\n";
162 //display facility information (Note it is already escaped)
163 echo "<div class='clinicAddress'>" . $res['facility_address'] . "</div>\n";
165 //display patient information (Note patient address is already escaped)
166 echo "<div class='patientAddress'>" . htmlspecialchars( $res2['patient_name'], ENT_NOQUOTES) . "<br>" .
167 htmlspecialchars( xl('Date of Birth') . ": " . $res2['patient_DOB'], ENT_NOQUOTES) . "<br>" .
168 $res2['patient_address'] . "</div>\n";
170 //display table title
171 echo "<div class='tabletitle'>" . htmlspecialchars( $title, ENT_NOQUOTES) . "</div>\n";
173 echo "<table cellspacing='0' cellpadding='0'>\n";
175 //display header
176 echo "<tr>\n";
177 foreach ($data[0] as $key => $value) {
178 //convert end of line characters to space
179 $patterns = array ('/\n/');
180 $replace = array (' ');
181 $key = preg_replace($patterns, $replace, $key);
182 echo "<th>".htmlspecialchars( $key, ENT_NOQUOTES)."</th>\n";
184 echo "</tr>\n";
186 //display shot data
187 for ($j=0;$j<$linesPerPage;$j++) {
188 if ($rowData = array_shift($data)) {
189 echo "<tr>";
190 foreach ($rowData as $key => $value) {
192 //shading of cells
193 if ($j==0) {
194 echo "<td>";
196 elseif ($j%2) {
197 echo "<td class ='odd'>";
199 else {
200 echo "<td>";
203 // output data of cell
204 echo ($value == "") ? "&nbsp;" : htmlspecialchars($value, ENT_NOQUOTES);
205 echo "</td>";
207 echo "<tr>\n";
209 else {
210 //done displaying shot data, so leave loop
211 break;
215 echo "</table>\n";
217 //display signature line
218 echo "<div class='sign'>" . htmlspecialchars( xl('Signature'), ENT_NOQUOTES) .
219 ":________________________________" . "</div>\n";
221 if ($countTotalPages > 1) {
222 //display page number if greater than one page
223 echo "<div class='pageNumber'>" .
224 htmlspecialchars( xl('Page') . " " . ($i+1) . "/" . $countTotalPages, ENT_NOQUOTES) .
225 "</div>\n";
228 echo "</div>\n";
233 <script language='JavaScript'>
234 window.print();
235 </script>
236 </body>
237 </html>
239 <?php
242 else { //print pdf
243 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
245 $pdf =& new Cezpdf("LETTER");
246 $pdf->ezSetMargins(72,30,50,30);
247 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
249 $opts = array('justification' => "center");
250 $pdf->ezText($res['facility_address'] ,"",$opts);
252 $pdf->ezText("\n" . $res2['patient_name'] . "\n" . xl('Date of Birth') . ": " . $res2['patient_DOB'] . "\n" . $res2['patient_address']);
253 $pdf->ezText("\n");
255 $opts = array('maxWidth' => 504, 'fontSize' => 8);
257 $pdf->ezTable($data, "", $title, $opts);
259 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________","",array('justification' => 'right'));
261 $pdf->ezStream();
263 } # end pdf print