/// <summary>
        /// Turn a relative reference into an absolute url, based on the fullUrl of the parent resource
        /// </summary>
        /// <param name="nav"></param>
        /// <param name="identity"></param>
        /// <returns></returns>
        /// <remarks>See https://www.hl7.org/fhir/bundle.html#references for more information</remarks>
        public static ResourceIdentity MakeAbsolute(this ScopedNavigator nav, ResourceIdentity identity)
        {
            if (identity.IsRelativeRestUrl)
            {
                // Relocate the relative url on the base given in the fullUrl of the entry (if applicable)
                var fullUrl = nav.FullUrl();

                if (fullUrl != null)
                {
                    var parentIdentity = new ResourceIdentity(fullUrl);

                    if (parentIdentity.IsAbsoluteRestUrl)
                    {
                        identity = identity.WithBase(parentIdentity.BaseUri);
                    }
                    else if (parentIdentity.IsUrn)
                    {
                        identity = new ResourceIdentity($"{parentIdentity}/{identity.Id}");
                    }
                }

                // Return the identity - will remain relative if we did not find a fullUrl
            }

            return(identity);
        }
Exemplo n.º 2
0
        public IElementNavigator Resolve(IElementNavigator instance, string reference)
        {
            var identity = new ResourceIdentity(reference);

            if (identity.Form == ResourceIdentityForm.RelativeRestUrl)
            {
                // Relocate the relative url on the base given in the fullUrl of the entry (if applicable)
                var fullUrl = ContextFullUrl(instance);

                if (fullUrl != null)
                {
                    var parentIdentity = new ResourceIdentity(fullUrl);
                    if (parentIdentity.BaseUri != null)
                    {
                        identity = identity.WithBase(parentIdentity.BaseUri);
                    }
                }
            }

            IElementNavigator referencedResource = null;

            if (identity.Form == ResourceIdentityForm.Local || identity.Form == ResourceIdentityForm.AbsoluteRestUrl || identity.Form == ResourceIdentityForm.Urn)
            {
                referencedResource = findUri(instance, identity.ToString());
            }

            return(referencedResource);
        }
Exemplo n.º 3
0
        public void WithBase()
        {
            var id  = new ResourceIdentity("http://localhost/services/fhir/v012/Patient/3");
            var id1 = id.WithBase("http://nu.nl/fhir");

            Assert.AreEqual("http://nu.nl/fhir/Patient/3", id1.ToString());

            var id2 = new ResourceIdentity("Patient/3").WithBase("http://nu.nl/fhir");

            Assert.AreEqual("http://nu.nl/fhir/Patient/3", id2.ToString());

            var id3 = id2.MakeRelative();

            Assert.AreEqual("Patient/3", id3.ToString());
        }