Dynamically resolve host domain Uri for API's and CCDA (#4535)
[openemr.git] / ccdaservice / ccda_gateway.php
blob075d3841c9b512eb057df139053340d071c43fa7
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-2021 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 ((!$GLOBALS['ccda_alt_service_enable']) > 0) {
48 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
51 if (!isset($_SESSION['site_id'])) {
52 $_SESSION ['site_id'] = 'default';
55 session_write_close();
57 $cdaService = new CDADocumentService();
59 if ($_REQUEST['action'] === 'dl') {
60 $ccda_xml = $cdaService->portalGenerateCCDZip($pid);
61 // download zip containing CCDA.xml, CCDA.html and cda.xsl files
62 header("Cache-Control: public");
63 header("Content-Description: File Transfer");
64 header("Content-Disposition: attachment; filename=SummaryofCare.zip");
65 header("Content-Type: application/zip");
66 header("Content-Transfer-Encoding: binary");
67 echo $ccda_xml;
68 exit;
70 if ($_REQUEST['action'] === 'view') {
71 $ccda_xml = $cdaService->portalGenerateCCD($pid);
72 // CCM returns viewable CCD html file
73 // that displays to new tab opened from home
74 echo $ccda_xml;
75 exit;
77 if ($_REQUEST['action'] === 'report_ccd_view') {
78 $ccda_xml = $cdaService->generateCCDHtml($pid);
79 if (stripos($ccda_xml, '/interface/login_screen.php') !== false) {
80 echo(xlt("Error. Not Authorized."));
81 exit;
83 echo $ccda_xml;
85 exit;
87 die(xlt("Error. Nothing to do."));