add yet another mariadb short term release to ci (#6004)
[openemr.git] / ccdaservice / ccda_gateway.php
blob9729cf45a71dff1d1d9abd982291a8771941eb23
1 <?php
3 /**
4 * ccda_gateway.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2016-2022 Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 use OpenEMR\Common\Csrf\CsrfUtils;
16 use OpenEMR\Services\CDADocumentService;
18 // authenticate for portal or main- never know where it gets used
19 // Will start the (patient) portal OpenEMR session/cookie.
20 require_once(__DIR__ . "/../src/Common/Session/SessionUtil.php");
21 OpenEMR\Common\Session\SessionUtil::portalSessionStart();
23 $sessionAllowWrite = true;
24 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
25 $pid = $_SESSION['pid'];
26 $ignoreAuth = true;
27 require_once(__DIR__ . "/../interface/globals.php");
28 define('IS_DASHBOARD', false);
29 define('IS_PORTAL', $_SESSION['pid']);
30 } else {
31 OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
32 $ignoreAuth = false;
33 require_once(__DIR__ . "/../interface/globals.php");
34 if (!isset($_SESSION['authUserID'])) {
35 $landingpage = "index.php";
36 header('Location: ' . $landingpage);
37 exit;
39 define('IS_DASHBOARD', $_SESSION['authUserID']);
40 define('IS_PORTAL', false);
43 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
44 CsrfUtils::csrfNotVerified();
47 if (empty($GLOBALS['ccda_alt_service_enable'])) {
48 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
50 if (IS_PORTAL && $GLOBALS['ccda_alt_service_enable'] < 2) {
51 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
53 if (IS_DASHBOARD && ($GLOBALS['ccda_alt_service_enable'] != 1 && $GLOBALS['ccda_alt_service_enable'] != 3)) {
54 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
57 if (!isset($_SESSION['site_id'])) {
58 $_SESSION ['site_id'] = 'default';
61 session_write_close();
63 $cdaService = new CDADocumentService();
65 if ($_REQUEST['action'] === 'dl') {
66 $ccda_xml = $cdaService->portalGenerateCCDZip($pid);
67 // download zip containing CCDA.xml, CCDA.html and cda.xsl files
68 header("Cache-Control: public");
69 header("Content-Description: File Transfer");
70 header("Content-Disposition: attachment; filename=SummaryofCare.zip");
71 header("Content-Type: application/zip");
72 header("Content-Transfer-Encoding: binary");
73 echo $ccda_xml;
74 exit;
76 if ($_REQUEST['action'] === 'view') {
77 $ccda_xml = $cdaService->portalGenerateCCD($pid);
78 // CCM returns viewable CCD html file
79 // that displays to new tab opened from home
80 echo $ccda_xml;
81 exit;
83 if ($_REQUEST['action'] === 'report_ccd_view') {
84 $ccda_xml = $cdaService->generateCCDHtml($pid);
85 if (stripos($ccda_xml, '/interface/login_screen.php') !== false) {
86 echo(xlt("Error. Not Authorized."));
87 exit;
89 echo $ccda_xml;
91 exit;
93 if ($_REQUEST['action'] === 'report_ccd_download') {
94 $ccda_xml = $cdaService->generateCCDZip($pid);
95 // download zip containing CCDA.xml, CCDA.html and cda.xsl files
96 header("Cache-Control: public");
97 header("Content-Description: File Transfer");
98 header("Content-Disposition: attachment; filename=SummaryofCare.zip");
99 header("Content-Type: application/zip");
100 header("Content-Transfer-Encoding: binary");
101 echo $ccda_xml;
102 exit;
104 die(xlt("Error. Nothing to do."));