forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccda_gateway.php
104 lines (93 loc) · 3.69 KB
/
ccda_gateway.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
<?php
/**
* ccda_gateway.php
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Jerry Padgett <[email protected]>
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2016-2022 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2019 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Services\CDADocumentService;
// authenticate for portal or main- never know where it gets used
// Will start the (patient) portal OpenEMR session/cookie.
require_once(__DIR__ . "/../src/Common/Session/SessionUtil.php");
OpenEMR\Common\Session\SessionUtil::portalSessionStart();
$sessionAllowWrite = true;
if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
$pid = $_SESSION['pid'];
$ignoreAuth = true;
require_once(__DIR__ . "/../interface/globals.php");
define('IS_DASHBOARD', false);
define('IS_PORTAL', $_SESSION['pid']);
} else {
OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
$ignoreAuth = false;
require_once(__DIR__ . "/../interface/globals.php");
if (!isset($_SESSION['authUserID'])) {
$landingpage = "index.php";
header('Location: ' . $landingpage);
exit;
}
define('IS_DASHBOARD', $_SESSION['authUserID']);
define('IS_PORTAL', false);
}
if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}
if (empty($GLOBALS['ccda_alt_service_enable'])) {
die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
}
if (IS_PORTAL && $GLOBALS['ccda_alt_service_enable'] < 2) {
die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
}
if (IS_DASHBOARD && ($GLOBALS['ccda_alt_service_enable'] != 1 && $GLOBALS['ccda_alt_service_enable'] != 3)) {
die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
}
if (!isset($_SESSION['site_id'])) {
$_SESSION ['site_id'] = 'default';
}
session_write_close();
$cdaService = new CDADocumentService();
if ($_REQUEST['action'] === 'dl') {
$ccda_xml = $cdaService->portalGenerateCCDZip($pid);
// download zip containing CCDA.xml, CCDA.html and cda.xsl files
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=SummaryofCare.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
echo $ccda_xml;
exit;
}
if ($_REQUEST['action'] === 'view') {
$ccda_xml = $cdaService->portalGenerateCCD($pid);
// CCM returns viewable CCD html file
// that displays to new tab opened from home
echo $ccda_xml;
exit;
}
if ($_REQUEST['action'] === 'report_ccd_view') {
$ccda_xml = $cdaService->generateCCDHtml($pid);
if (stripos($ccda_xml, '/interface/login_screen.php') !== false) {
echo(xlt("Error. Not Authorized."));
exit;
}
echo $ccda_xml;
exit;
}
if ($_REQUEST['action'] === 'report_ccd_download') {
$ccda_xml = $cdaService->generateCCDZip($pid);
// download zip containing CCDA.xml, CCDA.html and cda.xsl files
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=SummaryofCare.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
echo $ccda_xml;
exit;
}
die(xlt("Error. Nothing to do."));