Openemr fhir search (#4349)
[openemr.git] / src / Services / FHIR / FhirUrlResolver.php
blob20438ce623bbb4403c8ccdb53bacec66e2f5f9fd
1 <?php
3 /**
4 * FhirURLResolver is a simple class that takes in a FHIR base server url and can be used to extract pieces of the URL
5 * that are needed within the FHIR system such as a resource's relative URI
6 * @package openemr
7 * @link http://www.open-emr.org
8 * @author Stephen Nielson <stephen@nielson.org>
9 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Services\FHIR;
15 class FhirUrlResolver
17 private $fhirBaseURL;
19 private $baseUrlLength;
21 public function __construct($baseURL)
23 $this->fhirBaseURL = $baseURL;
24 $this->baseUrlLength = strlen($baseURL);
27 public function getRelativeUrl($url): ?string
29 // extracts everything but the resource/:id portion of a URL from the base url.
30 // if the URI passed in does not match the base fhir URI we do nothing with it
31 if (strstr($url, $this->fhirBaseURL) === false) {
32 return null;
33 } else {
34 // grab everything from our string onwards...
35 $relativeUrl = substr($url, $this->baseUrlLength - 1);
36 return $relativeUrl !== false ? $relativeUrl : null;