Exemplo n.º 1
0
        static bool isValidTypeProfile(this IResourceResolver resolver, HashSet <string> recursionStack, FHIRDefinedType?type, StructureDefinition profile)
        {
            // Recursively walk up the base profile hierarchy until we find a profile on baseType
            if (type == null)
            {
                return(true);
            }
            if (profile == null)
            {
                return(true);
            }

            // DSTU2: sd.ConstrainedType is empty for core definitions => resolve from sd.Name
            // STU3: sd.Type is always specified, including for core definitions
            var sdType = profile.ConstrainedType ?? ModelInfo.FhirTypeNameToFhirType(profile?.Name);

            if (sdType == null)
            {
                return(false);
            }

            if (sdType == type)
            {
                return(true);
            }
            if (profile.Base == null)
            {
                return(false);
            }
            var sdBase = resolver.FindStructureDefinition(profile.Base);

            if (sdBase == null)
            {
                return(false);
            }
            if (sdBase.Url == null)
            {
                return(false);
            }                                         // Shouldn't happen...

            // Detect/prevent endless recursion... e.g. X.Base = Y and Y.Base = X
            if (!recursionStack.Add(sdBase.Url))
            {
                throw Error.InvalidOperation(
                          $"Recursive profile dependency detected. Base profile hierarchy:\r\n{string.Join("\r\n", recursionStack)}"
                          );
            }

            return(isValidTypeProfile(resolver, recursionStack, type, sdBase));
        }
        private IBucket createSliceDefs()
        {
            var sd = _resolver.FindStructureDefinition("http://example.com/StructureDefinition/patient-telecom-reslice-ek");

            Assert.NotNull(sd);
            var snapgen = new SnapshotGenerator(_resolver);

            snapgen.Update(sd);

            // sd.Snapshot.Element.Where(e => e.Path.EndsWith(".telecom")).Select(e=>e.Path + " : " + e.Name ?? "").ToArray()

            var nav     = new ElementDefinitionNavigator(sd);
            var success = nav.JumpToFirst("Patient.telecom");

            Assert.True(success);
            //var xml = FhirSerializer.SerializeResourceToXml(sd);
            //File.WriteAllText(@"c:\temp\sdout.xml", xml);

            return(BucketFactory.CreateRoot(nav, _validator));
        }
        public IStructureDefinitionSummary Provide(string canonical)
        {
            var    isLocalType     = !canonical.Contains("/");
            string mappedCanonical = canonical;

            if (isLocalType)
            {
                var mapSuccess = _typeNameMapper(canonical, out mappedCanonical);
                if (!mapSuccess)
                {
                    return(null);
                }
            }

            var sd = _resolver.FindStructureDefinition(mappedCanonical, requireSnapshot: true);

            if (sd == null)
            {
                return(null);
            }

            return(new StructureDefinitionComplexTypeSerializationInfo(ElementDefinitionNavigator.ForSnapshot(sd)));
        }
Exemplo n.º 4
0
        public static StructureDefinition FindStructureDefinitionForCoreType(this IResourceResolver resolver, string typename)
        {
            var url = ModelInfo.CanonicalUriForFhirCoreType(typename);

            return(resolver.FindStructureDefinition(url));
        }
Exemplo n.º 5
0
 private StructureDefinition resolve(string uri) => _resolver.FindStructureDefinition(uri);