Multiple improvements from IPPF related to layouts. (#1081)
[openemr.git] / interface / patient_file / summary / demographics_print.php
blob7545f9cd2ebd509af214a4dd437462a3d34a0cf5
1 <?php
2 /**
3 * This will print a blank form, and if "patientid" is specified then
4 * any existing data for the specified patient is included.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @copyright Copyright (c) 2009-2015 Rod Roark <rod@sunsetsystems.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../../globals.php");
15 // Option to substitute a custom version of this script.
16 if (!empty($GLOBALS['gbl_rapid_workflow']) &&
17 $GLOBALS['gbl_rapid_workflow'] == 'LBFmsivd' &&
18 file_exists('../../../custom/demographics_print.php')) {
19 include('../../../custom/demographics_print.php');
20 exit();
23 require_once("$srcdir/acl.inc");
24 require_once("$srcdir/options.inc.php");
25 require_once("$srcdir/patient.inc");
27 $patientid = empty($_REQUEST['patientid']) ? 0 : 0 + $_REQUEST['patientid'];
28 if ($patientid < 0) {
29 $patientid = 0 + $pid; // -1 means current pid
32 // True if to display as a form to complete, false to display as information.
33 $isform = empty($_REQUEST['isform']) ? 0 : 1;
35 // Html2pdf fails to generate checked checkboxes properly, so write plain HTML
36 // if we are doing a patient-specific complete form.
37 $PDF_OUTPUT = ($patientid && $isform) ? false : true;
39 if ($PDF_OUTPUT) {
40 require_once("$srcdir/html2pdf/vendor/autoload.php");
41 $pdf = new HTML2PDF('P', 'Letter', 'en');
42 $pdf->setTestTdInOnePage(false); // Turn off error message for TD contents too big.
43 $pdf->pdf->SetDisplayMode('real');
44 ob_start();
47 $CPR = 4; // cells per row
49 $prow = array();
50 $erow = array();
51 $irow = array();
53 if ($patientid) {
54 $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
55 $erow = getEmployerData($pid);
56 // Check authorization.
57 $thisauth = acl_check('patients', 'demo');
58 if (!$thisauth) {
59 die(xl('Demographics not authorized'));
61 if ($prow['squad'] && ! acl_check('squads', $prow['squad'])) {
62 die(xl('You are not authorized to access this squad'));
64 // $irow = getInsuranceProviders(); // needed?
67 // Load array of properties for this layout and its groups.
68 $grparr = array();
69 getLayoutProperties('DEM', $grparr);
71 $fres = sqlStatement("SELECT * FROM layout_options " .
72 "WHERE form_id = 'DEM' AND uor > 0 " .
73 "ORDER BY group_id, seq");
76 <?php if (!$PDF_OUTPUT) { ?>
77 <html>
78 <head>
79 <?php html_header_show();?>
80 <?php } ?>
82 <style>
84 <?php if ($PDF_OUTPUT) { ?>
85 td {
86 font-family: Arial;
87 font-weight: normal;
88 font-size: 9pt;
90 <?php } else { ?>
91 body, td {
92 font-family: Arial, Helvetica, sans-serif;
93 font-weight: normal;
94 font-size: 9pt;
96 body {
97 padding: 5pt 5pt 5pt 5pt;
99 <?php } ?>
101 p.grpheader {
102 font-family: Arial;
103 font-weight: bold;
104 font-size: 12pt;
105 margin-bottom: 4pt;
108 div.section {
109 width: 98%;
110 <?php
111 // html2pdf screws up the div borders when a div overflows to a second page.
112 // Our temporary solution is to turn off the borders in the case where this
113 // is likely to happen (i.e. where all form options are listed).
114 if (!$isform) {
116 border-style: solid;
117 border-width: 1px;
118 border-color: #000000;
119 <?php } ?>
120 padding: 5pt;
122 div.section table {
123 width: 100%;
125 div.section td.stuff {
126 vertical-align: bottom;
127 height: 16pt;
130 td.lcols1 { width: 20%; }
131 td.lcols2 { width: 50%; }
132 td.lcols3 { width: 70%; }
133 td.dcols1 { width: 30%; }
134 td.dcols2 { width: 50%; }
135 td.dcols3 { width: 80%; }
137 .mainhead {
138 font-weight: bold;
139 font-size: 14pt;
140 text-align: center;
143 .under {
144 border-style: solid;
145 border-width: 0 0 1px 0;
146 border-color: #999999;
149 .ftitletable {
150 width: 100%;
151 margin: 0 0 8pt 0;
153 .ftitlecell1 {
154 width: 33%;
155 vertical-align: top;
156 text-align: left;
157 font-size: 14pt;
158 font-weight: bold;
160 .ftitlecell2 {
161 width: 33%;
162 vertical-align: top;
163 text-align: right;
164 font-size: 9pt;
166 .ftitlecellm {
167 width: 34%;
168 vertical-align: top;
169 text-align: center;
170 font-size: 9pt;
171 font-weight: bold;
174 </style>
175 </head>
177 <body bgcolor='#ffffff'>
178 <form>
180 <?php
181 // Generate header with optional logo.
182 $logo = '';
183 $ma_logo_path = "sites/" . $_SESSION['site_id'] . "/images/ma_logo.png";
184 if (is_file("$webserver_root/$ma_logo_path")) {
185 $logo = "<img src='$web_root/$ma_logo_path' style='height:" . round(9 * 5.14) . "pt' />";
186 } else {
187 $logo = "<!-- '$ma_logo_path' does not exist. -->";
189 echo genFacilityTitle(xl('Registration Form'), -1, $logo);
191 function end_cell()
193 global $item_count, $cell_count;
194 if ($item_count > 0) {
195 echo "</td>";
196 $item_count = 0;
200 function end_row()
202 global $cell_count, $CPR;
203 end_cell();
204 if ($cell_count > 0) {
205 for (; $cell_count < $CPR;
206 ++$cell_count) {
207 echo "<td></td>";
210 echo "</tr>\n";
211 $cell_count = 0;
215 function end_group()
217 global $last_group;
218 if (strlen($last_group) > 0) {
219 end_row();
220 echo " </table>\n";
221 echo "</div>\n";
225 function getContent()
227 global $web_root, $webserver_root;
228 $content = ob_get_clean();
229 // Fix a nasty html2pdf bug - it ignores document root!
230 $i = 0;
231 $wrlen = strlen($web_root);
232 $wsrlen = strlen($webserver_root);
233 while (true) {
234 $i = stripos($content, " src='/", $i + 1);
235 if ($i === false) {
236 break;
238 if (substr($content, $i+6, $wrlen) === $web_root &&
239 substr($content, $i+6, $wsrlen) !== $webserver_root) {
240 $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen);
243 return $content;
246 $last_group = '';
247 $cell_count = 0;
248 $item_count = 0;
250 while ($frow = sqlFetchArray($fres)) {
251 $this_group = $frow['group_id'];
252 $titlecols = $frow['titlecols'];
253 $datacols = $frow['datacols'];
254 $data_type = $frow['data_type'];
255 $field_id = $frow['field_id'];
256 $list_id = $frow['list_id'];
257 $currvalue = '';
259 if (strpos($field_id, 'em_') === 0) {
260 $tmp = substr($field_id, 3);
261 if (isset($erow[$tmp])) {
262 $currvalue = $erow[$tmp];
264 } else {
265 if (isset($prow[$field_id])) {
266 $currvalue = $prow[$field_id];
270 // Handle a data category (group) change.
271 if (strcmp($this_group, $last_group) != 0) {
272 end_group();
274 // if (strlen($last_group) > 0) echo "<br />\n";
276 // This replaces the above statement and is an attempt to work around a
277 // nasty html2pdf bug. When a table overflows to the next page, vertical
278 // positioning for whatever follows it is off and can cause overlap.
279 if (strlen($last_group) > 0) {
280 echo "</nobreak><br /><div><table><tr><td>&nbsp;</td></tr></table></div><br />\n";
283 // This is also for html2pdf. Telling it that the following stuff should
284 // start on a new page if there is not otherwise room for it on this page.
285 echo "<nobreak>\n"; // grasping
287 $group_name = $grparr[$this_group]['grp_title'];
288 $last_group = $this_group;
289 echo "<p class='grpheader'>" . xl_layout_label($group_name) . "</p>\n";
290 echo "<div class='section'>\n";
291 echo " <table border='0' cellpadding='0'>\n";
292 echo " <tr><td class='lcols1'></td><td class='dcols1'></td><td class='lcols1'></td><td class='dcols1'></td></tr>\n";
295 // Handle starting of a new row.
296 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
297 end_row();
298 echo " <tr>";
301 if ($item_count == 0 && $titlecols == 0) {
302 $titlecols = 1;
305 // Handle starting of a new label cell.
306 if ($titlecols > 0) {
307 end_cell();
308 echo "<td colspan='$titlecols' ";
309 echo "class='lcols$titlecols stuff " . (($frow['uor'] == 2) ? "required'" : "bold'");
310 if ($cell_count == 2) {
311 echo " style='padding-left:10pt'";
313 echo " nowrap>";
314 $cell_count += $titlecols;
317 ++$item_count;
319 echo "<b>";
321 if ($frow['title']) {
322 echo (xl_layout_label($frow['title']) . ":");
323 } else {
324 echo "&nbsp;";
327 echo "</b>";
329 // Handle starting of a new data cell.
330 if ($datacols > 0) {
331 end_cell();
332 echo "<td colspan='$datacols' class='dcols$datacols stuff under'";
333 /*****************************************************************
334 // Underline is wanted only for fill-in-the-blank data types.
335 if ($data_type < 21 && $data_type != 1 && $data_type != 3) {
336 echo " class='under'";
338 *****************************************************************/
339 if ($cell_count > 0) {
340 echo " style='padding-left:5pt;'";
342 echo ">";
343 $cell_count += $datacols;
346 ++$item_count;
348 if ($isform) {
349 generate_print_field($frow, $currvalue);
350 } else {
351 $s = generate_display_field($frow, $currvalue);
352 if ($s === '') {
353 $s = '&nbsp;';
355 echo $s;
359 end_group();
361 // Ending the last nobreak section for html2pdf.
362 if (strlen($last_group) > 0) {
363 echo "</nobreak>\n";
367 </form>
369 <?php
370 if ($PDF_OUTPUT) {
371 $content = getContent();
372 // $pdf->setDefaultFont('Arial');
373 $pdf->writeHTML($content, false);
374 $pdf->Output('Demographics_form.pdf', 'D'); // D = Download, I = Inline
375 } else {
377 <!-- This should really be in the onload handler but that seems to be unreliable and can crash Firefox 3. -->
378 <script language='JavaScript'>
379 opener.top.printLogPrint(window);
380 </script>
381 </body>
382 </html><?php } ?>