Exemplo n.º 1
0
        public ICapabilityStatementBuilder ApplyToResource(string resourceType, Action <ListedResourceComponent> action)
        {
            EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType));
            EnsureArg.IsNotNull(action, nameof(action));
            EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType));

            ListedRestComponent     listedRestComponent = _statement.Rest.Server();
            ListedResourceComponent resourceComponent   = listedRestComponent.Resource.SingleOrDefault(x => string.Equals(x.Type, resourceType, StringComparison.OrdinalIgnoreCase));

            if (resourceComponent == null)
            {
                resourceComponent = new ListedResourceComponent
                {
                    Type    = resourceType,
                    Profile = new ReferenceComponent
                    {
                        Reference = $"http://hl7.org/fhir/StructureDefinition/{resourceType}",
                    },
                };

                listedRestComponent.Resource.Add(resourceComponent);
            }

            action(resourceComponent);

            return(this);
        }
        public static MockModelInfoProviderBuilder Create(FhirSpecification version)
        {
            IModelInfoProvider provider = Substitute.For <IModelInfoProvider>();

            provider.Version.Returns(version);

            // Adds normative types by default
            var seenTypes = new HashSet <string>
            {
                "Binary", "Bundle", "CapabilityStatement", "CodeSystem", "Observation", "OperationOutcome", "Patient", "StructureDefinition", "ValueSet",
            };

            provider.GetResourceTypeNames().Returns(_ => seenTypes.Where(x => !string.IsNullOrEmpty(x)).ToArray());
            provider.IsKnownResource(Arg.Any <string>()).Returns(x => provider.GetResourceTypeNames().Contains(x[0]));

            // Simulate inherited behavior
            // Some code depends on "InheritedResource".BaseType
            // This adds the ability to resolve "Resource" as the base type
            provider.GetTypeForFhirType(Arg.Any <string>()).Returns(p => p.ArgAt <string>(0) == "Resource" ? typeof(ResourceObj) : typeof(InheritedResourceObj));
            provider.GetFhirTypeNameForType(Arg.Any <Type>()).Returns(p => p.ArgAt <Type>(0) == typeof(ResourceObj) ? "Resource" : null);

            // IStructureDefinitionSummaryProvider allows the execution of FHIRPath queries
            provider.ToTypedElement(Arg.Any <ISourceNode>())
            .Returns(p => p.ArgAt <ISourceNode>(0).ToTypedElement(new MockStructureDefinitionSummaryProvider(p.ArgAt <ISourceNode>(0), seenTypes)));

            return(new MockModelInfoProviderBuilder(provider, seenTypes));
        }
Exemplo n.º 3
0
        public ICapabilityStatementBuilder UpdateRestResourceComponent(string resourceType, Action <ListedResourceComponent> action)
        {
            EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType));
            EnsureArg.IsNotNull(action, nameof(action));
            EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType));

            ListedRestComponent     listedRestComponent = _statement.Rest.Server();
            ListedResourceComponent resourceComponent   = listedRestComponent.Resource.SingleOrDefault(x => string.Equals(x.Type, resourceType, StringComparison.OrdinalIgnoreCase));

            if (resourceComponent == null)
            {
                resourceComponent = new ListedResourceComponent
                {
                    Type = resourceType,
                };
                listedRestComponent.Resource.Add(resourceComponent);
            }

            action(resourceComponent);

            return(this);
        }
        public ITypedElement Resolve(string reference)
        {
            if (string.IsNullOrWhiteSpace(reference))
            {
                return(null);
            }

            ReferenceSearchValue parsed = _referenceParser.Parse(reference);

            if (parsed == null || !_modelInfoProvider.IsKnownResource(parsed.ResourceType))
            {
                return(null);
            }

            ISourceNode node = FhirJsonNode.Create(
                JObject.FromObject(
                    new
            {
                resourceType = parsed.ResourceType,
                id           = parsed.ResourceId,
            }));

            return(node.ToTypedElement(_modelInfoProvider.StructureDefinitionSummaryProvider));
        }
Exemplo n.º 5
0
 public static bool IsKnownResource(string name)
 {
     EnsureProvider();
     return(_modelInfoProvider.IsKnownResource(name));
 }