/// <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);
        }
Example #2
0
        public bool MoveToFirstChild(string nameFilter = null)
        {
            ScopedNavigator me = null;

            if (this.AtResource)
            {
                me = (ScopedNavigator)this.Clone();

                // Is the current position not a contained resource?
                if (Parent?.ContainedResources().FirstOrDefault() == null)
                {
                    ResourceContext = _wrapped.Clone();
                }
            }

            if (!_wrapped.MoveToFirstChild(nameFilter))
            {
                return(false);
            }

            // If the current position is a resource, we'll be the new _parentScope
            if (me != null)
            {
                Parent = me;
            }

            _cache = new Cache();

            return(true);
        }
Example #3
0
        public bool MoveToFirstChild(string nameFilter = null)
        {
            ScopedNavigator me = null;

            if (this.AtResource)
            {
                me = (ScopedNavigator)this.Clone();
            }

            if (!_wrapped.MoveToFirstChild(nameFilter))
            {
                return(false);
            }

            // If the current position is a resource, we'll be the new _parentScope
            if (me != null)
            {
                Parent = me;
            }

            _cache = new Cache();

            return(true);
        }
 public static string MakeAbsolute(this ScopedNavigator nav, string reference) =>
 nav.MakeAbsolute(new ResourceIdentity(reference)).ToString();