* @author Brady Miller * @copyright Copyright (c) 2009-2015 Rod Roark * @copyright Copyright (c) 2018 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once("../../globals.php"); // Option to substitute a custom version of this script. if ( !empty($GLOBALS['gbl_rapid_workflow']) && $GLOBALS['gbl_rapid_workflow'] == 'LBFmsivd' && file_exists('../../../custom/demographics_print.php') ) { include('../../../custom/demographics_print.php'); exit(); } require_once("$srcdir/options.inc.php"); require_once("$srcdir/patient.inc"); use Mpdf\Mpdf; use OpenEMR\Common\Acl\AclMain; $patientid = empty($_REQUEST['patientid']) ? 0 : 0 + $_REQUEST['patientid']; if ($patientid < 0) { $patientid = (int) $pid; // -1 means current pid } // True if to display as a form to complete, false to display as information. $isform = empty($_REQUEST['isform']) ? 0 : 1; // Html2pdf fails to generate checked checkboxes properly, so write plain HTML // if we are doing a patient-specific complete form. // TODO - now use mPDF, so should test if still need this fix $PDF_OUTPUT = ($patientid && $isform) ? false : true; if ($PDF_OUTPUT) { $config_mpdf = array( 'tempDir' => $GLOBALS['MPDF_WRITE_DIR'], 'mode' => $GLOBALS['pdf_language'], 'format' => 'Letter', 'default_font_size' => '9', 'default_font' => 'dejavusans', 'margin_left' => $GLOBALS['pdf_left_margin'], 'margin_right' => $GLOBALS['pdf_right_margin'], 'margin_top' => $GLOBALS['pdf_top_margin'], 'margin_bottom' => $GLOBALS['pdf_bottom_margin'], 'margin_header' => '', 'margin_footer' => '', 'orientation' => 'P', 'shrink_tables_to_fit' => 1, 'use_kwt' => true, 'autoScriptToLang' => true, 'keep_table_proportions' => true ); $pdf = new mPDF($config_mpdf); if ($_SESSION['language_direction'] == 'rtl') { $pdf->SetDirectionality('rtl'); } ob_start(); } $CPR = 4; // cells per row $prow = array(); $erow = array(); $irow = array(); if ($patientid) { $prow = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD"); $erow = getEmployerData($pid); // Check authorization. $thisauth = AclMain::aclCheckCore('patients', 'demo'); if (!$thisauth) { die(xlt('Demographics not authorized')); } if ($prow['squad'] && ! AclMain::aclCheckCore('squads', $prow['squad'])) { die(xlt('You are not authorized to access this squad')); } // $irow = getInsuranceProviders(); // needed? } // Load array of properties for this layout and its groups. $grparr = array(); getLayoutProperties('DEM', $grparr); $fres = sqlStatement("SELECT * FROM layout_options " . "WHERE form_id = 'DEM' AND uor > 0 " . "ORDER BY group_id, seq"); ?>
"; } else { $logo = ""; } echo genFacilityTitle(xl('Registration Form'), -1, $logo); function end_cell() { global $item_count, $cell_count; if ($item_count > 0) { echo ""; $item_count = 0; } } function end_row() { global $cell_count, $CPR; end_cell(); if ($cell_count > 0) { for (; $cell_count < $CPR; ++$cell_count) { echo ""; } echo "\n"; $cell_count = 0; } } function end_group() { global $last_group; if (strlen($last_group) > 0) { end_row(); echo " \n"; echo "\n"; } } function getContent() { global $web_root, $webserver_root; $content = ob_get_clean(); // Fix a nasty html2pdf bug - it ignores document root! // TODO - now use mPDF, so should test if still need this fix $i = 0; $wrlen = strlen($web_root); $wsrlen = strlen($webserver_root); while (true) { $i = stripos($content, " src='/", $i + 1); if ($i === false) { break; } if ( substr($content, $i + 6, $wrlen) === $web_root && substr($content, $i + 6, $wsrlen) !== $webserver_root ) { $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen); } } return $content; } $last_group = ''; $cell_count = 0; $item_count = 0; while ($frow = sqlFetchArray($fres)) { $this_group = $frow['group_id']; $titlecols = $frow['titlecols']; $datacols = $frow['datacols']; $data_type = $frow['data_type']; $field_id = $frow['field_id']; $list_id = $frow['list_id']; $currvalue = ''; if (strpos($field_id, 'em_') === 0) { $tmp = substr($field_id, 3); if (isset($erow[$tmp])) { $currvalue = $erow[$tmp]; } } else { if (isset($prow[$field_id])) { $currvalue = $prow[$field_id]; } } // Handle a data category (group) change. if (strcmp($this_group, $last_group) != 0) { end_group(); // if (strlen($last_group) > 0) echo "
\n"; // This replaces the above statement and is an attempt to work around a // nasty html2pdf bug. When a table overflows to the next page, vertical // positioning for whatever follows it is off and can cause overlap. // TODO - now use mPDF, so should test if still need this fix if (strlen($last_group) > 0) { echo "
 

\n"; } // This is also for html2pdf. Telling it that the following stuff should // start on a new page if there is not otherwise room for it on this page. // TODO - now use mPDF, so should test if still need this fix echo "\n"; // grasping $group_name = $grparr[$this_group]['grp_title']; $last_group = $this_group; echo "

" . text(xl_layout_label($group_name)) . "

\n"; echo "
\n"; echo " \n"; echo " \n"; } // Handle starting of a new row. if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) { end_row(); echo " "; } if ($item_count == 0 && $titlecols == 0) { $titlecols = 1; } // Handle starting of a new label cell. if ($titlecols > 0) { end_cell(); echo "
"; $cell_count += $titlecols; } ++$item_count; echo ""; if ($frow['title']) { echo text((xl_layout_label($frow['title'])) . ":"); } else { echo " "; } echo ""; // Handle starting of a new data cell. if ($datacols > 0) { end_cell(); echo " 0) { echo " style='padding-left:5pt;'"; } echo ">"; $cell_count += $datacols; } ++$item_count; if ($isform) { generate_print_field($frow, $currvalue); } else { $s = generate_display_field($frow, $currvalue); if ($s === '') { $s = ' '; } echo $s; } } end_group(); // Ending the last nobreak section for html2pdf. // TODO - now use mPDF, so should test if still need this fix if (strlen($last_group) > 0) { echo "\n"; } ?> writeHTML($content); $pdf->Output('Demographics_form.pdf', 'I'); // D = Download, I = Inline } else { ?>