minor changes and internationalization for prior commit
[openemr.git] / ccdaservice / ccda_gateway.php
blob3741b2cf37be67b98647b1a5a9398e4e53bb291a
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 $sanitize_all_escapes = true;
29 $fake_register_globals = false;
30 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
31 define('IS_DASHBOARD', false);
32 define('IS_PORTAL', $_SESSION['pid']);
34 else {
35 session_destroy();
36 $ignoreAuth = false;
37 $sanitize_all_escapes = true;
38 $fake_register_globals = false;
39 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
40 if ( ! isset($_SESSION['authUserID']) ){
41 $landingpage = "index.php";
42 header('Location: '.$landingpage);
43 exit;
45 define('IS_DASHBOARD', $_SESSION['authUserID']);
46 define('IS_PORTAL', false);
48 // give me something to do.
49 $dowhat = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
50 if( $dowhat && $GLOBALS['ccda_alt_service_enable'] >= 1 ){ // do I need this?
51 require_once ("./../ccdaservice/ssmanager.php");
52 if(!runCheck()){ // woops, try again
53 if(!runCheck())
54 die("Document service start failed. Click back to return home."); // nuts! give up
57 else{
58 // maybe next time
59 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
62 //eventually below will qualify what document to fetch
63 $parameterArray = array();
64 $parameterArray ['encounter'];
65 $parameterArray ['combination'] = $pid;
66 $parameterArray ['components']; // = 'progress_note|consultation_note|continuity_care_document|diagnostic_image_reporting|discharge_summary|history_physical_note|operative_note|procedure_note|unstructured_document';
67 $parameterArray ['sections']; // = 'allergies|medications|problems|immunizations|procedures|results|plan_of_care|vitals|social_history|encounters|functional_status|referral|instructions';
68 $parameterArray ['downloadccda']=1;
69 $parameterArray ['sent_by'];
70 $parameterArray ['send'];
71 $parameterArray ['view'] = 1;
72 $parameterArray ['recipients'] = 'patient'; // emr_direct or hie else if not set $_SESSION['authUserID']
73 $parameterArray [0] [6] = $_SESSION ['portal_username']; // set to an onsite portal user
75 if(!isset($_SESSION ['site_id'])) $_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' );
86 else $h='<a href="./../portal/home.php" </a><button style="color: red; background: white;" >' . xlt("Return Home") .'</button><br>';
87 print_r ( $h.$ccdaxml.$h );
88 //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
89 exit;
91 function portalccdafetching($pid, $server_url, $parameterArray){
93 session_write_close();
94 $site_id = $_SESSION ['site_id'];
95 $parameters = http_build_query($parameterArray); // future use
96 try {
97 $ch = curl_init();
98 $url = $server_url . "/interface/modules/zend_modules/public/encounterccdadispatch/index?site=$site_id&me=".session_id()."&param=1&view=1&combination=$pid&recipient=patient";
99 curl_setopt($ch, CURLOPT_URL, $url);
100 curl_setopt($ch, CURLOPT_HEADER, 0); // set true for look see
101 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
102 curl_setopt($ch, CURLOPT_COOKIESESSION, true);
103 curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
104 curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie");
105 //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.
106 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
107 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
109 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
110 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
111 $result = curl_exec($ch) or die(curl_error($ch));
112 curl_close($ch);
114 catch (Exception $e) {
115 return false;
117 return $result;
119 return 0;