Merge pull request #1024 for XSS remediation in prescription module
[openemr.git] / ccdaservice / ccda_gateway.php
blob69e9018c047ca501f04d373a661210204d65ac59
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @package OpenEMR
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
23 //authencate for portal or main- never know where it gets used
24 session_start();
25 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
26 $pid = $_SESSION['pid'];
27 $ignoreAuth = true;
28 require_once(dirname(__FILE__) . "/../interface/globals.php");
29 define('IS_DASHBOARD', false);
30 define('IS_PORTAL', $_SESSION['pid']);
31 } else {
32 session_destroy();
33 $ignoreAuth = false;
34 require_once(dirname(__FILE__) . "/../interface/globals.php");
35 if (! isset($_SESSION['authUserID'])) {
36 $landingpage = "index.php";
37 header('Location: '.$landingpage);
38 exit;
41 define('IS_DASHBOARD', $_SESSION['authUserID']);
42 define('IS_PORTAL', false);
45 // give me something to do.
46 $dowhat = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
47 if ($dowhat && $GLOBALS['ccda_alt_service_enable'] >= 1) { // do I need this?
48 require_once("./../ccdaservice/ssmanager.php");
49 if (!runCheck()) { // woops, try again
50 if (!runCheck()) {
51 die("Document service start failed. Click back to return home."); // nuts! give up
54 } else {
55 // maybe next time
56 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
59 //eventually below will qualify what document to fetch
60 $parameterArray = array();
61 $parameterArray ['encounter'];
62 $parameterArray ['combination'] = $pid;
63 $parameterArray ['components']; // = 'progress_note|consultation_note|continuity_care_document|diagnostic_image_reporting|discharge_summary|history_physical_note|operative_note|procedure_note|unstructured_document';
64 $parameterArray ['sections']; // = 'allergies|medications|problems|immunizations|procedures|results|plan_of_care|vitals|social_history|encounters|functional_status|referral|instructions';
65 $parameterArray ['downloadccda']=1;
66 $parameterArray ['sent_by'];
67 $parameterArray ['send'];
68 $parameterArray ['view'] = 1;
69 $parameterArray ['recipients'] = 'patient'; // emr_direct or hie else if not set $_SESSION['authUserID']
70 $parameterArray [0] [6] = $_SESSION ['portal_username']; // set to an onsite portal user
72 if (!isset($_SESSION ['site_id'])) {
73 $_SESSION ['site_id'] = 'default'; // do believe globals does this but I go rogue at times.
76 $server_url = 'http://localhost'. $GLOBALS['webroot']; // I alias into openemr directory on my sights causing webroot to be empty.
77 //I've have actually seen this return 'default' due to apache config'ed with localhost alias on more than one virtual host?? Watch
78 //global $server_url; // can't find where this is defined!
79 // CCM returns entire cda with service doing templates
80 $ccdaxml = portalccdafetching($pid, $server_url, $parameterArray);
81 // disposal decisions will be here.
82 $h='';
83 if (!$parameterArray ['view']) {
84 header('Content-Type: application/xml');
85 } else {
86 $h='<a href="./../portal/home.php" </a><button style="color: red; background: white;" >' . xlt("Return Home") .'</button><br>';
89 print_r($h.$ccdaxml.$h);
90 //service_shutdown(1); //In ssmanager 0= terminate and disable 1 = soft=terminate but still active w/no restart, > 1 just restart based on B.S timer
91 exit;
93 function portalccdafetching($pid, $server_url, $parameterArray)
96 session_write_close();
97 $site_id = $_SESSION ['site_id'];
98 $parameters = http_build_query($parameterArray); // future use
99 try {
100 $ch = curl_init();
101 $url = $server_url . "/interface/modules/zend_modules/public/encounterccdadispatch/index?site=$site_id&me=".session_id()."&param=1&view=1&combination=$pid&recipient=patient";
102 curl_setopt($ch, CURLOPT_URL, $url);
103 curl_setopt($ch, CURLOPT_HEADER, 0); // set true for look see
104 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
105 curl_setopt($ch, CURLOPT_COOKIESESSION, true);
106 curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
107 curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie");
108 //curl_setopt ($ch, CURLOPT_COOKIE, 'XDEBUG_SESSION=1'); // break on first line in public/index.php - uncomment and start any xdebug session and fetch a ccda in app.
109 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
110 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
112 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
113 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
114 $result = curl_exec($ch) or die(curl_error($ch));
115 curl_close($ch);
116 } catch (Exception $e) {
117 return false;
120 return $result;
122 return 0;