forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_order_results.php
143 lines (132 loc) · 4.9 KB
/
single_order_results.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Script to display results for a given procedure order.
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Rod Roark <[email protected]>
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2013-2015 Rod Roark <[email protected]>
* @copyright Copyright (c) 2019 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once(dirname(__FILE__) . '/../globals.php');
require_once($GLOBALS["include_root"] . "/orders/single_order_results.inc.php");
use Mpdf\Mpdf;
use OpenEMR\Common\Acl\AclMain;
use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Core\Header;
// Check authorization.
$thisauth = AclMain::aclCheckCore('patients', 'med');
if (!$thisauth) {
echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Order Results")]);
exit;
}
$orderid = intval($_GET['orderid']);
$finals_only = empty($_POST['form_showall']);
if (!empty($_POST['form_sign']) && !empty($_POST['form_sign_list'])) {
if (!AclMain::aclCheckCore('patients', 'sign')) {
die(xlt('Not authorized to sign results'));
}
// When signing results we are careful to sign only those reports that were
// in the sending form. While this will usually be all the reports linked to
// the order it's possible for a new report to come in while viewing these,
// and it would be very bad to sign results that nobody has seen!
$arrSign = explode(',', $_POST['form_sign_list']);
foreach ($arrSign as $id) {
sqlStatement("UPDATE procedure_report SET " .
"review_status = 'reviewed' WHERE " .
"procedure_report_id = ?", array($id));
}
if ($orderid) {
sqlStatement("UPDATE procedure_order SET " .
"order_status = 'complete' WHERE " .
"procedure_order_id = ?", array($orderid));
}
}
// This mess generates a PDF report and sends it to the patient.
if (!empty($_POST['form_send_to_portal'])) {
// Borrowing the general strategy here from custom_report.php.
// See also: http:https://wiki.spipu.net/doku.php?id=html2pdf:en:v3:output
require_once($GLOBALS["include_root"] . "/cmsportal/portal.inc.php");
$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();
echo "<link rel='stylesheet' type='text/css' href='$webserver_root/interface/themes/style_pdf.css'>\n";
echo "<link rel='stylesheet' type='text/css' href='$webserver_root/library/ESign/css/esign_report.css'>\n";
$GLOBALS['PATIENT_REPORT_ACTIVE'] = true;
generate_order_report($orderid, false, true, $finals_only);
$GLOBALS['PATIENT_REPORT_ACTIVE'] = false;
// echo ob_get_clean(); exit(); // debugging
$pdf->writeHTML(ob_get_clean());
$contents = $pdf->Output('', true);
// Send message with PDF as attachment.
$result = cms_portal_call(array(
'action' => 'putmessage',
'user' => $_POST['form_send_to_portal'],
'title' => xl('Your Lab Results'),
'message' => xl('Please see the attached PDF.'),
'filename' => 'results.pdf',
'mimetype' => 'application/pdf',
'contents' => base64_encode($contents),
));
if ($result['errmsg']) {
die(text($result['errmsg']));
}
}
?>
<html>
<head>
<?php Header::setupHeader(); ?>
<title><?php echo xlt('Order Results'); ?></title>
<style>
body {
margin: 9pt;
font-family: sans-serif;
font-size: 1em;
}
</style>
<script src="../../library/topdialog.js"></script>
<script>
<?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
</script>
</head>
<body>
<?php if (empty($_POST['form_sign'])) {
generate_order_report($orderid, true, true, $finals_only);
} else { ?>
<script>
if (opener.document.forms && opener.document.forms[0]) {
// Opener should be list_reports.php. Make it refresh.
var f = opener.document.forms[0];
if (f.form_external_refresh) {
f.form_external_refresh.value = '1';
f.submit();
}
}
let stayHere = './single_order_results.php?orderid=' + <?php echo js_escape($orderid); ?>;
window.location.assign(stayHere);
</script>
<?php } ?>
</body>
</html>