예제 #1
0
        private GenericBundle CreateEmptyBundle()
        {
            var bundleResourceNode = SourceNode.Resource("Bundle", "Bundle", SourceNode.Valued("type", "searchset"));

            var identifier = SourceNode.Node("identifier");

            identifier.Add(SourceNode.Valued("system", "urn:ietf:rfc:3986"));
            identifier.Add(SourceNode.Valued("value", Guid.NewGuid().ToString()));
            bundleResourceNode.Add(identifier);

            var documentBundle = GenericBundle.FromBundle(bundleResourceNode);

            documentBundle = documentBundle.Meta(Guid.NewGuid().ToString(), DateTimeOffset.Now);

            return(documentBundle);
        }
예제 #2
0
 private void SendCreatedBundle(IVonkContext vonkContext, GenericBundle searchBundle)
 {
     vonkContext.Response.Payload    = searchBundle.ToIResource(vonkContext.InformationModel);
     vonkContext.Response.HttpResult = 200;
     vonkContext.Response.Headers.Add(VonkResultHeader.Location, "Bundle/" + vonkContext.Response.Payload.Id);
 }
예제 #3
0
        /// <summary>
        /// Overloaded method for recursive use.
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="everythingBundle"></param>
        /// <param name="includedReferences">Remember which resources were already added to the search bundle</param>
        /// <returns></returns>
        private async Task <(bool success, GenericBundle everythingBundle, VonkIssue error)> IncludeReferencesInBundle(IResource resource, GenericBundle everythingBundle, HashSet <string> includedReferences)
        {
            // Get references of given resource
            var allReferencesInResourceQuery = "$this.descendants().where($this is Reference).reference";
            var references = resource.ToTypedElement(_schemaProvider).Select(allReferencesInResourceQuery);

            // Resolve references
            // Skip the following resources:
            //    - Contained resources as they are already included through their parents
            //    - Resources that are already included in the search bundle
            (bool successfulResolve, IResource resolvedResource, VonkIssue error) = (true, null, null);
            foreach (var reference in references)
            {
                var referenceValue = reference.Value.ToString();
                if (!referenceValue.StartsWith("#", StringComparison.Ordinal) && !includedReferences.Contains(referenceValue))
                {
                    (successfulResolve, resolvedResource, error) = await ResolveResource(referenceValue);

                    if (successfulResolve)
                    {
                        if (resource.InformationModel != resolvedResource.InformationModel)
                        {
                            return(false, everythingBundle, WrongInformationModel(resource.InformationModel, resolvedResource));
                        }

                        everythingBundle = everythingBundle.AddEntry(resolvedResource, referenceValue);
                        includedReferences.Add(referenceValue);
                    }
                    else
                    {
                        break;
                    }

                    // Recursively resolve all references in the included resource
                    (successfulResolve, everythingBundle, error) = await IncludeReferencesInBundle(resolvedResource, everythingBundle, includedReferences);

                    if (!successfulResolve)
                    {
                        break;
                    }
                }
            }
            return(successfulResolve, everythingBundle, error);
        }
예제 #4
0
        /// <summary>
        /// Include all resources found through references in a resource in a search bundle.
        /// This function traverses recursively through all references until no new references are found.
        /// No depth-related limitations.
        /// </summary>
        /// <param name="startResource">First resource which potentially contains references that need to be included in the document</param>
        /// <param name="searchBundle">FHIR Search Bundle to which the resolved resources shall be added as includes</param>
        /// <returns>
        /// - success describes if all references could recursively be found, starting from the given resource
        /// - failedReference contains the first reference that could not be resolved, empty if all resources can be resolved
        /// </returns>
        private async Task <(bool success, GenericBundle everythingBundle, VonkIssue error)> IncludeReferencesInBundle(IResource startResource, GenericBundle searchBundle)
        {
            var includedReferences = new HashSet <string>();

            return(await IncludeReferencesInBundle(startResource, searchBundle, includedReferences));
        }