simple fix for hylafax
[openemr.git] / ccdaservice / ccda_gateway.php
blob3cd3a65a17d9e5915abdbe855223781190596c50
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']);
32 else {
33 session_destroy();
34 $ignoreAuth = false;
35 require_once ( dirname( __FILE__ ) . "/../interface/globals.php" );
36 if ( ! isset($_SESSION['authUserID']) ){
37 $landingpage = "index.php";
38 header('Location: '.$landingpage);
39 exit;
41 define('IS_DASHBOARD', $_SESSION['authUserID']);
42 define('IS_PORTAL', false);
44 // give me something to do.
45 $dowhat = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
46 if( $dowhat && $GLOBALS['ccda_alt_service_enable'] >= 1 ){ // do I need this?
47 require_once ("./../ccdaservice/ssmanager.php");
48 if(!runCheck()){ // woops, try again
49 if(!runCheck())
50 die("Document service start failed. Click back to return home."); // nuts! give up
53 else{
54 // maybe next time
55 die("Cda generation service turned off: Verify in Administration->Globals! Click back to return home."); // Die an honorable death!!
58 //eventually below will qualify what document to fetch
59 $parameterArray = array();
60 $parameterArray ['encounter'];
61 $parameterArray ['combination'] = $pid;
62 $parameterArray ['components']; // = 'progress_note|consultation_note|continuity_care_document|diagnostic_image_reporting|discharge_summary|history_physical_note|operative_note|procedure_note|unstructured_document';
63 $parameterArray ['sections']; // = 'allergies|medications|problems|immunizations|procedures|results|plan_of_care|vitals|social_history|encounters|functional_status|referral|instructions';
64 $parameterArray ['downloadccda']=1;
65 $parameterArray ['sent_by'];
66 $parameterArray ['send'];
67 $parameterArray ['view'] = 1;
68 $parameterArray ['recipients'] = 'patient'; // emr_direct or hie else if not set $_SESSION['authUserID']
69 $parameterArray [0] [6] = $_SESSION ['portal_username']; // set to an onsite portal user
71 if(!isset($_SESSION ['site_id'])) $_SESSION ['site_id'] = 'default'; // do believe globals does this but I go rogue at times.
72 $server_url = 'http://localhost'. $GLOBALS['webroot']; // I alias into openemr directory on my sights causing webroot to be empty.
73 //I've have actually seen this return 'default' due to apache config'ed with localhost alias on more than one virtual host?? Watch
74 //global $server_url; // can't find where this is defined!
75 // CCM returns entire cda with service doing templates
76 $ccdaxml = portalccdafetching($pid, $server_url, $parameterArray);
77 // disposal decisions will be here.
78 $h='';
79 if (!$parameterArray ['view']){
80 header ( 'Content-Type: application/xml' );
82 else $h='<a href="./../portal/home.php" </a><button style="color: red; background: white;" >' . xlt("Return Home") .'</button><br>';
83 print_r ( $h.$ccdaxml.$h );
84 //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
85 exit;
87 function portalccdafetching($pid, $server_url, $parameterArray){
89 session_write_close();
90 $site_id = $_SESSION ['site_id'];
91 $parameters = http_build_query($parameterArray); // future use
92 try {
93 $ch = curl_init();
94 $url = $server_url . "/interface/modules/zend_modules/public/encounterccdadispatch/index?site=$site_id&me=".session_id()."&param=1&view=1&combination=$pid&recipient=patient";
95 curl_setopt($ch, CURLOPT_URL, $url);
96 curl_setopt($ch, CURLOPT_HEADER, 0); // set true for look see
97 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
98 curl_setopt($ch, CURLOPT_COOKIESESSION, true);
99 curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
100 curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie");
101 //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.
102 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
103 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
105 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
106 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
107 $result = curl_exec($ch) or die(curl_error($ch));
108 curl_close($ch);
110 catch (Exception $e) {
111 return false;
113 return $result;
115 return 0;