3 * oeFHIRHttpClient class
6 * @link http://www.open-emr.org
7 * @author Jerry Padgett <sjpadgett@gmail.com>
8 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
9 * @license https://www.gnu.org/licenses/agpl-3.0.en.html GNU Affero General Public License 3
14 use GuzzleHttp\Client
;
16 class oeFHIRHttpClient
19 private $settings = [];
21 // @TODO Create exceptions catch for recovery and display.
23 public function setSettings()
25 //$url = 'http://localhost:8076/dstu3/open/'; //Smart on FHIR (multi-tenant stu3, port 8075 is for dstu2)
26 //$url = 'http://localhost:8080/hapi-fhir-jpaserver-example/baseStu3/';
27 $url = trim($GLOBALS['fhir_base_url']);
28 $url = substr($url, -1) == '/' ?
$url : $url . '/';
29 $this->settings
= array(
30 'base_uri' => $url, // http/https ssl cert verify is currently off
31 'verify' => false, // @TODO force/add client cert check and/or endpoint cert verify
32 'http_errors' => false);
35 public function __construct()
38 $this->client
= new Client($this->settings
);
41 public function sendResource($type = 'Patient', $id = '', $data = '')
43 $uri = $type . '/' . $id;
44 $returned = $this->client
->request('PUT', $uri, ['body' => $data]);
45 $head = '<strong>Transaction Status: ' . $returned->getStatusCode() . ' ' . $returned->getReasonPhrase() . '</strong><br/>';
46 foreach ($returned->getHeaders() as $name => $values) {
47 $head .= $name . ': ' . implode(', ', $values) . "<br/>";
53 public function requestResource($type = 'Patient', $id = '', $action = '')
55 $actionIs = $action == 'history' ?
'/_history' : ''; // no action = read latest version
56 $uri = $type . '/' . $id . $actionIs . '?_format=json';
57 $returned = $this->client
->request('GET', $uri);
58 $body = $returned->getBody()->getContents();
63 // @todo for now search for type by patient
64 public function searchResource($type = 'Patient', $id = '', $search = '')
66 $uri = $type . '?patient=' . $id . '&_format=json&_pretty=true';
67 $returned = $this->client
->request('GET', $uri);
68 $body = $returned->getBody()->getContents();