Feat openemr fix 7480 7494 email prescription (#7495)
[openemr.git] / interface / patient_file / summary / demographics_print.php
blob17fc12c9e29d25b9f3ecfc85b0893bf334e1b00c
1 <?php
3 /**
4 * This will print a blank form, and if "patientid" is specified then
5 * any existing data for the specified patient is included.
7 * @package OpenEMR
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2009-2015 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../../globals.php");
18 // Option to substitute a custom version of this script.
19 if (
20 !empty($GLOBALS['gbl_rapid_workflow']) &&
21 $GLOBALS['gbl_rapid_workflow'] == 'LBFmsivd' &&
22 file_exists('../../../custom/demographics_print.php')
23 ) {
24 include('../../../custom/demographics_print.php');
25 exit();
28 require_once("$srcdir/options.inc.php");
29 require_once("$srcdir/patient.inc.php");
31 use Mpdf\Mpdf;
32 use OpenEMR\Common\Acl\AclMain;
33 use OpenEMR\Pdf\Config_Mpdf;
35 $patientid = empty($_REQUEST['patientid']) ? 0 : 0 + $_REQUEST['patientid'];
36 if ($patientid < 0) {
37 $patientid = (int) $pid; // -1 means current pid
40 // True if to display as a form to complete, false to display as information.
41 $isform = empty($_REQUEST['isform']) ? 0 : 1;
43 $PDF_OUTPUT = ($patientid && $isform) ? false : true;
45 if ($PDF_OUTPUT) {
46 $config_mpdf = Config_Mpdf::getConfigMpdf();
47 $pdf = new mPDF($config_mpdf);
48 if ($_SESSION['language_direction'] == 'rtl') {
49 $pdf->SetDirectionality('rtl');
51 ob_start();
54 $CPR = 4; // cells per row
56 $prow = array();
57 $erow = array();
58 $irow = array();
60 if ($patientid) {
61 $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
62 $erow = getEmployerData($pid);
63 // Check authorization.
64 $thisauth = AclMain::aclCheckCore('patients', 'demo');
65 if (!$thisauth) {
66 die(xlt('Demographics not authorized'));
68 if ($prow['squad'] && ! AclMain::aclCheckCore('squads', $prow['squad'])) {
69 die(xlt('You are not authorized to access this squad'));
71 // $irow = getInsuranceProviders(); // needed?
74 // Load array of properties for this layout and its groups.
75 $grparr = array();
76 getLayoutProperties('DEM', $grparr);
78 $fres = sqlStatement("SELECT * FROM layout_options " .
79 "WHERE form_id = 'DEM' AND uor > 0 " .
80 "ORDER BY group_id, seq");
83 <?php if (!$PDF_OUTPUT) { ?>
84 <html>
85 <head>
86 <?php } ?>
88 <style>
90 <?php if ($PDF_OUTPUT) { ?>
91 td {
92 font-family: Arial;
93 font-weight: normal;
94 font-size: 9pt;
96 <?php } else { ?>
97 body, td {
98 font-family: Arial, Helvetica, sans-serif;
99 font-weight: normal;
100 font-size: 9pt;
102 body {
103 padding: 5pt 5pt 5pt 5pt;
105 <?php } ?>
107 p.grpheader {
108 font-family: Arial;
109 font-weight: bold;
110 font-size: 12pt;
111 margin-bottom: 4pt;
114 div.section {
115 width: 98%;
116 <?php
117 // html2pdf screws up the div borders when a div overflows to a second page.
118 // Our temporary solution is to turn off the borders in the case where this
119 // is likely to happen (i.e. where all form options are listed).
120 // TODO - now use mPDF, so should test if still need this fix
121 if (!$isform) {
123 border-style: solid;
124 border-width: 1px;
125 border-color: #000000;
126 <?php } ?>
127 padding: 5pt;
129 div.section table {
130 width: 100%;
132 div.section td.stuff {
133 vertical-align: bottom;
134 height: 16pt;
137 td.lcols1 { width: 20%; }
138 td.lcols2 { width: 50%; }
139 td.lcols3 { width: 70%; }
140 td.dcols1 { width: 30%; }
141 td.dcols2 { width: 50%; }
142 td.dcols3 { width: 80%; }
144 .mainhead {
145 font-weight: bold;
146 font-size: 14pt;
147 text-align: center;
150 .under {
151 border-style: solid;
152 border-width: 0 0 1px 0;
153 border-color: #999999;
156 .ftitletable {
157 width: 100%;
158 margin: 0 0 8pt 0;
160 .ftitlecell1 {
161 width: 33%;
162 vertical-align: top;
163 text-align: left;
164 font-size: 14pt;
165 font-weight: bold;
167 .ftitlecell2 {
168 width: 33%;
169 vertical-align: top;
170 text-align: right;
171 font-size: 9pt;
173 .ftitlecellm {
174 width: 34%;
175 vertical-align: top;
176 text-align: center;
177 font-size: 9pt;
178 font-weight: bold;
181 </style>
182 </head>
184 <body bgcolor='#ffffff'>
185 <form>
187 <?php
188 // Generate header with optional logo.
189 $logo = '';
190 $ma_logo_path = "sites/" . $_SESSION['site_id'] . "/images/ma_logo.png";
191 if (is_file("$webserver_root/$ma_logo_path")) {
192 $logo = "$web_root/$ma_logo_path";
195 echo genFacilityTitle(xl('Registration Form'), -1, $logo);
197 function end_cell()
199 global $item_count, $cell_count;
200 if ($item_count > 0) {
201 echo "</td>";
202 $item_count = 0;
206 function end_row()
208 global $cell_count, $CPR;
209 end_cell();
210 if ($cell_count > 0) {
211 for (; $cell_count < $CPR; ++$cell_count) {
212 echo "<td></td>";
215 echo "</tr>\n";
216 $cell_count = 0;
220 function end_group()
222 global $last_group;
223 if (strlen($last_group) > 0) {
224 end_row();
225 echo " </table>\n";
226 echo "</div>\n";
230 function getContent()
232 $content = ob_get_clean();
233 return $content;
236 $last_group = '';
237 $cell_count = 0;
238 $item_count = 0;
240 while ($frow = sqlFetchArray($fres)) {
241 $this_group = $frow['group_id'];
242 $titlecols = $frow['titlecols'];
243 $datacols = $frow['datacols'];
244 $data_type = $frow['data_type'];
245 $field_id = $frow['field_id'];
246 $list_id = $frow['list_id'];
247 $currvalue = '';
249 if (strpos($field_id, 'em_') === 0) {
250 $tmp = substr($field_id, 3);
251 if (isset($erow[$tmp])) {
252 $currvalue = $erow[$tmp];
254 } else {
255 if (isset($prow[$field_id])) {
256 $currvalue = $prow[$field_id];
260 // Handle a data category (group) change.
261 if (strcmp($this_group, $last_group) != 0) {
262 end_group();
264 // if (strlen($last_group) > 0) echo "<br />\n";
266 // This replaces the above statement and is an attempt to work around a
267 // nasty html2pdf bug. When a table overflows to the next page, vertical
268 // positioning for whatever follows it is off and can cause overlap.
269 // TODO - now use mPDF, so should test if still need this fix
270 if (strlen($last_group) > 0) {
271 echo "</nobreak><br /><div><table><tr><td>&nbsp;</td></tr></table></div><br />\n";
274 // This is also for html2pdf. Telling it that the following stuff should
275 // start on a new page if there is not otherwise room for it on this page.
276 // TODO - now use mPDF, so should test if still need this fix
277 echo "<nobreak>\n"; // grasping
279 $group_name = $grparr[$this_group]['grp_title'];
280 $last_group = $this_group;
281 echo "<p class='grpheader'>" . text(xl_layout_label($group_name)) . "</p>\n";
282 echo "<div class='section'>\n";
283 echo " <table border='0' cellpadding='0'>\n";
284 echo " <tr><td class='lcols1'></td><td class='dcols1'></td><td class='lcols1'></td><td class='dcols1'></td></tr>\n";
287 // Handle starting of a new row.
288 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
289 end_row();
290 echo " <tr>";
293 if ($item_count == 0 && $titlecols == 0) {
294 $titlecols = 1;
297 // Handle starting of a new label cell.
298 if ($titlecols > 0) {
299 end_cell();
300 echo "<td colspan='" . attr($titlecols) . "' ";
301 echo "class='lcols" . attr($titlecols) . " stuff " . (($frow['uor'] == 2) ? "required'" : "bold'");
302 if ($cell_count == 2) {
303 echo " style='padding-left:10pt'";
305 echo " nowrap>";
306 $cell_count += $titlecols;
309 ++$item_count;
311 echo "<b>";
313 if ($frow['title']) {
314 echo text((xl_layout_label($frow['title'])) . ":");
315 } else {
316 echo "&nbsp;";
319 echo "</b>";
321 // Handle starting of a new data cell.
322 if ($datacols > 0) {
323 end_cell();
324 echo "<td colspan='" . attr($datacols) . "' class='dcols" . attr($datacols) . " stuff under'";
325 /*****************************************************************
326 // Underline is wanted only for fill-in-the-blank data types.
327 if ($data_type < 21 && $data_type != 1 && $data_type != 3) {
328 echo " class='under'";
330 *****************************************************************/
331 if ($cell_count > 0) {
332 echo " style='padding-left:5pt;'";
334 echo ">";
335 $cell_count += $datacols;
338 ++$item_count;
340 if ($isform) {
341 generate_print_field($frow, $currvalue);
342 } else {
343 $s = generate_display_field($frow, $currvalue);
344 if ($s === '') {
345 $s = '&nbsp;';
347 echo $s;
351 end_group();
353 // Ending the last nobreak section for html2pdf.
354 // TODO - now use mPDF, so should test if still need this fix
355 if (strlen($last_group) > 0) {
356 echo "</nobreak>\n";
360 </form>
362 <?php
363 if ($PDF_OUTPUT) {
364 $content = getContent();
365 $pdf->writeHTML($content);
366 $pdf->Output('Demographics_form.pdf', 'D'); // D = Download, I = Inline
367 } else {
369 <!-- This should really be in the onload handler but that seems to be unreliable and can crash Firefox 3. -->
370 <script>
371 opener.top.printLogPrint(window);
372 </script>
373 </body>
374 </html>
375 <?php } ?>