From 5781080917498655913e9137ba9eec3fdbb337d6 Mon Sep 17 00:00:00 2001 From: Jerry Padgett Date: Tue, 20 Jul 2021 00:26:07 -0400 Subject: [PATCH] Dynamically resolve host domain Uri for API's and CCDA (#4535) * Dynamically resolve host domain uri for API's and CCDA - fixes for prior PR * change site address to empty * Convert ccda_gateway to use new CDADocumentService New CDADocumentService * syntax * implement new ccd in reports arbitrate sessions in CCM api. * forgot to remove test session start --- ccdaservice/ccda_gateway.php | 248 ++++++++--------------- interface/globals.php | 48 ++++- interface/modules/zend_modules/public/index.php | 11 +- interface/patient_file/report/patient_report.php | 19 ++ library/globals.inc.php | 6 +- portal/patient/_machine_config.php | 35 +--- src/Services/CDADocumentService.php | 177 ++++++++++++++++ 7 files changed, 339 insertions(+), 205 deletions(-) rewrite ccdaservice/ccda_gateway.php (65%) create mode 100644 src/Services/CDADocumentService.php diff --git a/ccdaservice/ccda_gateway.php b/ccdaservice/ccda_gateway.php dissimilarity index 65% index 6f2abd770..075d3841c 100644 --- a/ccdaservice/ccda_gateway.php +++ b/ccdaservice/ccda_gateway.php @@ -1,161 +1,87 @@ - - * @author Brady Miller - * @copyright Copyright (c) 2016-2021 Jerry Padgett - * @copyright Copyright (c) 2019 Brady Miller - * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 - */ - -//authenticate for portal or main- never know where it gets used - -// Will start the (patient) portal OpenEMR session/cookie. - -use OpenEMR\Common\Csrf\CsrfUtils; - -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(); -} - -$dowhat = $_REQUEST['action'] ?? ''; -if ((!$GLOBALS['ccda_alt_service_enable']) > 0) { - 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(); - -$parameterArray = array(); -//$parameterArray['encounter']; -$parameterArray['combination'] = $pid; -$parameterArray['components'] = 'allergies|medications|problems|immunizations|procedures|results|plan_of_care|vitals|social_history|encounters|functional_status|referral|instructions|medical_devices|goals'; -//$parameterArray['sections']; -$parameterArray['downloadccda'] = "download_ccda"; -$parameterArray['latestccda'] = '0'; -$parameterArray['send_to'] = 'download_all'; -$parameterArray['sent_by_app'] = 'portal'; -$parameterArray['downloadformat'] = 'ccda'; -$parameterArray['ccda_pid'][] = $pid; -//$parameterArray['me'] = urlencode(session_id()); -$parameterArray['view'] = 0; -$parameterArray['recipient'] = 'patient'; // emr_direct or hie -$parameterArray['site'] = $_SESSION ['site_id']; // set to an onsite portal user - - -$server_url = resolveHost(); -// CCM returns viewable CCD html file or -// zip containing a CCDA.xml, CCDA.html and cda.xsl -$ccdaxml = portalccdafetching($pid, $server_url, $parameterArray, $dowhat); - -if ($dowhat === 'dl') { - header("Cache-Control: public"); - header("Content-Description: File Transfer"); - header("Content-Disposition: attachment; filename=SummaryofCare.zip"); - header("Content-Type: application/download"); - header("Content-Transfer-Encoding: binary"); - echo $ccdaxml; - exit; -} - -echo($ccdaxml); - -exit; - -function portalccdafetching($pid, $server_url, $parameterArray = [], $action = 'view') -{ - $parameters = ''; - $site_id = $_SESSION['site_id']; - $url = $server_url . "/interface/modules/zend_modules/public/encounterccdadispatch/index?site=" . - urlencode($site_id) . "&me=" . urlencode(session_id()) . - "¶m=1&view=1&combination=" . urlencode($pid) . "&recipient=patient"; - if ($action === 'dl') { - $parameters = http_build_query($parameterArray); - $url = $server_url . "/interface/modules/zend_modules/public/encounterccdadispatch/index?me=" . urlencode(session_id()); - } - try { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); - curl_setopt($ch, CURLOPT_HEADER, 0); // set true for look see - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_COOKIESESSION, true); - curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie"); - curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_COOKIE, 'XDEBUG_SESSION=1'); // debug break on first line in public/index.php - - $result = curl_exec($ch) or die(curl_error($ch)); - curl_close($ch); - } catch (Exception $e) { - die($e->getMessage()); - } - - return $result; -} - -function resolveHost(): string -{ - if (!empty($GLOBALS['site_addr_oath'])) { - $host = rtrim(trim($GLOBALS['site_addr_oath']), "/"); - return rtrim(trim($host . $GLOBALS['webroot']), "/"); - } - $scheme = $_SERVER['REQUEST_SCHEME'] . "://"; - $possibleHostSources = array('HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR'); - $sourceTransformations = array( - "HTTP_X_FORWARDED_HOST" => function ($value) { - $elements = explode(',', $value); - return trim(end($elements)); - } - ); - $host = ''; - foreach ($possibleHostSources as $source) { - if (!empty($host)) { - break; - } - if (empty($_SERVER[$source])) { - continue; - } - $host = $_SERVER[$source]; - if (array_key_exists($source, $sourceTransformations)) { - $host = $sourceTransformations[$source]($host); - } - } - // remove port - $host = preg_replace('/:\d+$/', '', trim($host)); - - return rtrim(trim($scheme . $host . $GLOBALS['webroot']), "/"); -} + + * @author Brady Miller + * @copyright Copyright (c) 2016-2021 Jerry Padgett + * @copyright Copyright (c) 2019 Brady Miller + * @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 ((!$GLOBALS['ccda_alt_service_enable']) > 0) { + 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; +} +die(xlt("Error. Nothing to do.")); diff --git a/interface/globals.php b/interface/globals.php index 215fa1a8d..8f27e7ab5 100644 --- a/interface/globals.php +++ b/interface/globals.php @@ -21,6 +21,7 @@ if ($response !== true) { use OpenEMR\Core\Kernel; use OpenEMR\Core\ModulesApplication; use Dotenv\Dotenv; +use OpenEMR\Services\VersionService; // Throw error if the php openssl module is not installed. if (!(extension_loaded('openssl'))) { @@ -86,6 +87,31 @@ if (preg_match("/^[^\/]/", $web_root)) { // $webserver_root = "/var/www/openemr"; // $web_root = "/openemr"; +$ResolveServerHost = static function () { + $scheme = $_SERVER['REQUEST_SCHEME'] . "://"; + $possibleHostSources = array('HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR'); + $sourceTransformations = array( + "HTTP_X_FORWARDED_HOST" => function ($value) { + $elements = explode(',', $value); + return trim(end($elements)); + } + ); + $host = ''; + foreach ($possibleHostSources as $source) { + if (!empty($host)) { + break; + } + if (empty($_SERVER[$source])) { + continue; + } + $host = $_SERVER[$source]; + if (array_key_exists($source, $sourceTransformations)) { + $host = $sourceTransformations[$source]($host); + } + } + return rtrim(trim($scheme . $host), "/"); +}; + // Debug function. Can expand for longer trace or file info. function GetCallingScriptName() { @@ -227,16 +253,29 @@ $GLOBALS['edi_271_file_path'] = $GLOBALS['OE_SITE_DIR'] . "/documents/edi/"; // Check necessary writable paths (add them if do not exist) if (! is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/gacl')) { - mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/gacl', 0755, true); + if (!mkdir($concurrentDirectory = $GLOBALS['OE_SITE_DIR'] . '/documents/smarty/gacl', 0755, true) && !is_dir($concurrentDirectory)) { + throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); + } } if (! is_dir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/main')) { - mkdir($GLOBALS['OE_SITE_DIR'] . '/documents/smarty/main', 0755, true); + if (!mkdir($concurrentDirectory = $GLOBALS['OE_SITE_DIR'] . '/documents/smarty/main', 0755, true) && !is_dir($concurrentDirectory)) { + throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); + } } // Set and check that necessary writeable path exist for mPDF tool $GLOBALS['MPDF_WRITE_DIR'] = $GLOBALS['OE_SITE_DIR'] . '/documents/mpdf/pdf_tmp'; if (! is_dir($GLOBALS['MPDF_WRITE_DIR'])) { - mkdir($GLOBALS['MPDF_WRITE_DIR'], 0755, true); + if (!mkdir($concurrentDirectory = $GLOBALS['MPDF_WRITE_DIR'], 0755, true) && !is_dir($concurrentDirectory)) { + throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); + } +} + +if (empty($GLOBALS['site_addr_oath'])) { + $GLOBALS['site_addr_oath'] = $ResolveServerHost(); +} +if (empty($GLOBALS['qualified_site_addr'])) { + $GLOBALS['qualified_site_addr'] = rtrim($GLOBALS['site_addr_oath'] . trim($GLOBALS['webroot']), "/"); } // Includes composer autoload @@ -525,8 +564,7 @@ $tmore = xl('(More)'); // -if you don't want it translated, then strip the xl function away $tback = xl('(Back)'); -$versionService = new \OpenEMR\Services\VersionService(); -$version = $versionService->fetch(); +$version = (new VersionService())->fetch(); if (!empty($version)) { //Version tag diff --git a/interface/modules/zend_modules/public/index.php b/interface/modules/zend_modules/public/index.php index 6dc66fb96..fbe53813a 100644 --- a/interface/modules/zend_modules/public/index.php +++ b/interface/modules/zend_modules/public/index.php @@ -18,7 +18,7 @@ use Laminas\Console\Request as ConsoleRequest; //fetching controller name and action name from the SOAP request -$urlArray = explode('/', $_SERVER['REQUEST_URI']); +$urlArray = explode('/', ($_SERVER['REQUEST_URI'] ?? '')); $countUrlArray = count($urlArray); preg_match('/\/(\w*)\?/', $_SERVER['REQUEST_URI'], $matches); $actionName = $matches[1] ?? ''; @@ -32,12 +32,18 @@ if (!empty($_REQUEST['recipient']) && ($_REQUEST['recipient'] === 'patient') && session_id($_REQUEST['me']); session_start(); } - if ($_SESSION['pid'] && $_SESSION['sessionUser'] == '-patient-' && $_SESSION['portal_init']) { + if ($_SESSION['pid'] && $_SESSION['sessionUser'] === '-patient-' && $_SESSION['portal_init']) { // Onsite portal was validated and patient authorized and re-validated via forwarded session. $ignoreAuth_onsite_portal = true; } } +if (!empty($_REQUEST['me']) && $_REQUEST['sent_by_app'] === 'core_api') { + // pick up already running session from api's + session_id($_REQUEST['me']); + session_start(); +} + if (php_sapi_name() === 'cli' && count($argv) != 0) { $ignoreAuth = true; $siteDefault = 'default'; @@ -50,6 +56,7 @@ if (php_sapi_name() === 'cli' && count($argv) != 0) { // Since from command line, set $sessionAllowWrite since need to set site_id session and no benefit to set to false $sessionAllowWrite = true; } + require_once(__DIR__ . "/../../../globals.php"); require_once(__DIR__ . "/../../../../library/forms.inc"); require_once(__DIR__ . "/../../../../library/options.inc.php"); diff --git a/interface/patient_file/report/patient_report.php b/interface/patient_file/report/patient_report.php index c87167cef..68615ae25 100644 --- a/interface/patient_file/report/patient_report.php +++ b/interface/patient_file/report/patient_report.php @@ -20,6 +20,7 @@ require_once("$srcdir/forms.inc"); require_once("$srcdir/patient.inc"); use OpenEMR\Common\Acl\AclMain; +use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Core\Header; use OpenEMR\Events\PatientReport\PatientReportEvent; use OpenEMR\Menu\PatientMenuRole; @@ -170,6 +171,7 @@ $oemr_ui = new OemrUI($arrOeUiSettings);

+ @@ -620,6 +622,23 @@ $(function () { top.restoreSession(); $("#ccr_form").submit(); }); + $(".viewNewCCD").click(function() { + // there's a lot of ways to do this but for now, we'll go with this! + top.restoreSession(); + let url = './../../../ccdaservice/ccda_gateway.php?action=report_ccd_view&csrf_token_form=' + + encodeURIComponent(""); + fetch(url, { + credentials: 'same-origin', + method: 'GET', + }) + .then(response => response.text()) + .then(response => { + let view = window.open('about:blank', '_blank'); + view.document.write(response); + view.document.close(); + return false; + }) + }); $(".viewCCD").click(function() { var ccrAction = document.getElementsByName('ccrAction'); ccrAction[0].value = 'viewccd'; diff --git a/library/globals.inc.php b/library/globals.inc.php index e068b1245..f8a03d6f1 100644 --- a/library/globals.inc.php +++ b/library/globals.inc.php @@ -2974,10 +2974,10 @@ $GLOBALS_METADATA = array( 'Connectors' => array( 'site_addr_oath' => array( - xl('Site Address (required for OAuth2, FHIR and CCDA)'), + xl('Site Address Override (if needed for OAuth2, FHIR or CCDA)'), 'text', - 'https://' . $_SERVER['HTTP_HOST'] . $GLOBALS['webroot'], - xl('Site Address (required for OAuth2, FHIR and CCDA). Example is') . ' https://localhost:8300 .' + '', + xl('Only need to set this if the server is not providing the correct host for OAuth2, FHIR or CCDA. Example is') . ' https://localhost:8300 .' ), 'rest_api' => array( diff --git a/portal/patient/_machine_config.php b/portal/patient/_machine_config.php index 1dc57f696..e13960c64 100644 --- a/portal/patient/_machine_config.php +++ b/portal/patient/_machine_config.php @@ -68,7 +68,7 @@ GlobalConfig::$CONNECTION_SETTING->BootstrapSQL = "SET sql_mode = '', time_zone * the root url of the application with trailing slash, for example http://localhost/patient/ * default is relative base address */ -GlobalConfig::$WEB_ROOT = resolveHost(); +GlobalConfig::$WEB_ROOT = $GLOBALS['qualified_site_addr']; if ($GLOBALS['portal_onsite_two_basepath']) { GlobalConfig::$ROOT_URL = GlobalConfig::$WEB_ROOT . '/portal/patient/'; } else { @@ -86,36 +86,3 @@ if ($GLOBALS['portal_onsite_two_basepath']) { if (GlobalConfig::$CONNECTION_SETTING->Multibyte && !function_exists('mb_strlen')) { die('Multibyte extensions are not installed but Multibyte is set to true in _machine_config.php'); } - -function resolveHost(): string -{ - if (!empty($GLOBALS['site_addr_oath'])) { - $host = rtrim(trim($GLOBALS['site_addr_oath']), "/"); - return rtrim(trim($host . $GLOBALS['webroot']), "/"); - } - $scheme = $_SERVER['REQUEST_SCHEME'] . "://"; - $possibleHostSources = array('HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR'); - $sourceTransformations = array( - "HTTP_X_FORWARDED_HOST" => function ($value) { - $elements = explode(',', $value); - return trim(end($elements)); - } - ); - $host = ''; - foreach ($possibleHostSources as $source) { - if (!empty($host)) { - break; - } - if (empty($_SERVER[$source])) { - continue; - } - $host = $_SERVER[$source]; - if (array_key_exists($source, $sourceTransformations)) { - $host = $sourceTransformations[$source]($host); - } - } - // remove port - $host = preg_replace('/:\d+$/', '', trim($host)); - - return rtrim(trim($scheme . $host . $GLOBALS['webroot']), "/"); -} diff --git a/src/Services/CDADocumentService.php b/src/Services/CDADocumentService.php new file mode 100644 index 000000000..a4f26d57d --- /dev/null +++ b/src/Services/CDADocumentService.php @@ -0,0 +1,177 @@ + + * @copyright Copyright (c) 2021 Jerry Padgett + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +namespace OpenEMR\Services; + +use CouchDB; +use OpenEMR\Common\Crypto\CryptoGen; +use OpenEMR\Common\Uuid\UuidRegistry; +use Symfony\Component\HttpClient\HttpClient; + +/** + * Class CDADocumentService + * + * @package OpenEMR\Services + * + * See interface/modules/zend_modules/module/Carecoordination/src/Carecoordination/Controller/EncounterccdadispatchController.php + * indexAction() and interface/modules/zend_modules/public/index.php + */ +class CDADocumentService extends BaseService +{ + const TABLE_NAME = "ccda"; + protected $serverUrl; + + public function __construct() + { + parent::__construct(self::TABLE_NAME); + UuidRegistry::createMissingUuidsForTables([self::TABLE_NAME]); + $this->serverUrl = $GLOBALS['qualified_site_addr']; + } + + public function getLastCdaMeta($pid) + { + $query = "SELECT cc.uuid, cc.date, pd.fname, pd.lname, pd.pid FROM ccda AS cc + LEFT JOIN patient_data AS pd ON pd.pid=cc.pid + WHERE cc.pid = ? + ORDER BY cc.id DESC LIMIT 1"; + + return sqlQuery($query, array($pid)); + } + + public function getFile($id) + { + $query = "select couch_docid, couch_revid, ccda_data, encrypted from ccda where uuid=?"; + $row = sqlQuery($query, array($id)); + $content = ''; + if (!empty($row)) { + if (!empty($row['couch_docid'])) { + $couch = new CouchDB(); + $resp = $couch->retrieve_doc($row['couch_docid']); + if ($row['encrypted']) { + $cryptoGen = new CryptoGen(); + $content = $cryptoGen->decryptStandard($resp->data, null, 'database'); + } else { + $content = base64_decode($resp->data); + } + } elseif (!empty($row['ccda_data'])) { + $fccda = fopen($row['ccda_data'], "r"); + if ($row['encrypted']) { + $cryptoGen = new CryptoGen(); + $content = $cryptoGen->decryptStandard(fread($fccda, filesize($row['ccda_data'])), null, 'database'); + } else { + $content = fread($fccda, filesize($row['ccda_data'])); + } + fclose($fccda); + } + } + + return $content; + } + + public function generateCCDHtml($pid): string + { + $url = $this->serverUrl . "/interface/modules/zend_modules/public/encounterccdadispatch"; + $httpClient = HttpClient::create([ + "verify_peer" => false, + "verify_host" => false + ]); + $response = $httpClient->request('GET', $url, [ + 'query' => [ + 'combination' => $pid, + 'recipient' => 'self', + 'view' => '1', + 'site' => $_SESSION ['site_id'], + 'sent_by_app' => 'core_api', + 'me' => session_id(), + 'XDEBUG_SESSION' => '1' + ] + ]); + + $status = $response->getStatusCode(); // @todo validate + + return $response->getContent(); + } + + public function generateCCDXml($pid): string + { + $url = $this->serverUrl . "/interface/modules/zend_modules/public/encounterccdadispatch"; + $httpClient = HttpClient::create([ + "verify_peer" => false, + "verify_host" => false + ]); + $response = $httpClient->request('GET', $url, [ + 'query' => [ + 'combination' => $pid, + 'recipient' => 'patient', + 'view' => '0', + 'hiehook' => '1', + 'sent_by_app' => 'core_api', + 'me' => session_id() + ] + ]); + + $status = $response->getStatusCode(); // @todo validate + + return $response->getContent(); + } + + public function portalGenerateCCD($pid): string + { + $url = $this->serverUrl . "/interface/modules/zend_modules/public/encounterccdadispatch"; + $httpClient = HttpClient::create([ + "verify_peer" => false, + "verify_host" => false + ]); + $response = $httpClient->request('GET', $url, [ + 'query' => [ + 'combination' => $pid, + 'recipient' => 'patient', + 'view' => '1', + 'me' => session_id(),// to authenticate in CCM. Portal only. + 'site' => $_SESSION ['site_id'] + ] + ]); + + $status = $response->getStatusCode(); // @todo validate + + return $response->getContent(); + } + + public function portalGenerateCCDZip($pid): string + { + $parameterArray = array( + 'combination' => $pid, + 'components' => 'allergies|medications|problems|immunizations|procedures|results|plan_of_care|vitals|social_history|encounters|functional_status|referral|instructions|medical_devices|goals', + 'downloadccda' => 'download_ccda', + 'latestccda' => '0', + 'send_to' => 'download_all', + 'sent_by_app' => 'portal', + 'ccda_pid' => [0 => $pid], + 'view' => 0, + 'recipient' => 'patient', + 'site' => $_SESSION ['site_id'], + ); + $url = $this->serverUrl . "/interface/modules/zend_modules/public/encounterccdadispatch"; + $httpClient = HttpClient::create([ + "verify_peer" => false, + "verify_host" => false + ]); + $response = $httpClient->request('POST', $url, [ + 'query' => ['me' => session_id()], // to authenticate in CCM. Portal only. + 'body' => $parameterArray + ]); + + $status = $response->getStatusCode(); // @todo validate + + return $response->getContent(); + } +} -- 2.11.4.GIT