Пример #1
0
        public void GenerateLipidSnapshot()
        {
            var sd = _source.GetStructureDefinition("http://hl7.org/fhir/StructureDefinition/lipidprofile");

            Assert.IsNotNull(sd);

            generateSnapshotAndCompare(sd, _source);
        }
Пример #2
0
        public void GenerateSingleSnapshot()
        {
            var sd = _testSource.GetStructureDefinition("http://hl7.org/fhir/StructureDefinition/genetics");

            Assert.IsNotNull(sd);

            generateSnapshotAndCompare(sd, _testSource);
        }
        public void ResolveStructures()
        {
            var extDefn = source.GetStructureDefinition("http://hl7.org/fhir/StructureDefinition/data-absent-reason");
            Assert.IsNotNull(extDefn);
            Assert.IsInstanceOfType(extDefn, typeof(StructureDefinition));

            extDefn = source.GetStructureDefinition("http://hl7.org/fhir/StructureDefinition/Patient");
            Assert.IsNotNull(extDefn);
            Assert.IsInstanceOfType(extDefn, typeof(StructureDefinition));
        }
Пример #4
0
        public void Generate(StructureDefinition structure)
        {
            if (structure.Differential == null)
            {
                throw Error.Argument("structure", "structure does not contain a differential specification");
            }

            // [WMR 20160718] Also accept extension definitions (IsConstraint == false)
            if (!structure.IsConstraint && !structure.IsExtension)
            {
                throw Error.Argument("structure", "structure is not a constraint or extension");
            }

            if (structure.Base == null)
            {
                throw Error.Argument("structure", "structure is a constraint, but no base has been specified");
            }

            var differential = structure.Differential;

            var baseStructure = _resolver.GetStructureDefinition(structure.Base);

            if (baseStructure == null)
            {
                throw Error.InvalidOperation("Could not locate the base StructureDefinition for url " + structure.Base);
            }
            if (baseStructure.Snapshot == null)
            {
                throw Error.InvalidOperation("Snapshot generator required the base at '{0}' to have a snapshot representation", structure.Base);
            }

            var snapshot = (StructureDefinition.SnapshotComponent)baseStructure.Snapshot.DeepCopy();

            generateBaseElements(snapshot.Element);
            var snapNav = new ElementNavigator(snapshot.Element);

            // Fill out the gaps (mostly missing parents) in the differential representation
            var fullDifferential = new DifferentialTreeConstructor(differential.Element).MakeTree();
            var diffNav          = new ElementNavigator(fullDifferential);

            merge(snapNav, diffNav);

            structure.Snapshot = new StructureDefinition.SnapshotComponent()
            {
                Element = snapNav.ToListOfElements()
            };
        }
        //[Ignore]
        public void GenerateExtensionSnapshot()
        {
            var sd = _testSource.GetStructureDefinition(@"http://example.org/fhir/StructureDefinition/string-translation");

            Assert.IsNotNull(sd);

            generateSnapshotAndCompare(sd, _testSource);
        }
Пример #6
0
        public void GenerateNorwegianSnapshots()
        {
            var mySource  = new FileDirectoryArtifactSource(@"C:\Git\helsenord.ig\Source\Chapter.3.Package", includeSubdirectories: false);
            var stdSource = ZipArtifactSource.CreateValidationSource();
            var resolver  = new ArtifactResolver(new MultiArtifactSource(mySource, stdSource));

            var sources = new[] { "noHealthcareService", "noHealthcareServiceLocation", "noOrganization", "noPractitioner", "acronym" };

            var generator = new SnapshotGenerator(resolver, markChanges: false);

            foreach (var source in sources)
            {
                var sd = resolver.GetStructureDefinition("http://hl7.no/fhir/StructureDefinition/" + source);
                Assert.IsNotNull(sd, "Cannot find SD " + sd.Url);

                generator.Generate(sd);
                File.WriteAllText(@"C:\Git\helsenord.ig\Source\Chapter.3.Package\structure." + source + ".xml", FhirSerializer.SerializeResourceToXml(sd));
            }
        }
Пример #7
0
        internal static bool expandElement(ElementNavigator nav, ArtifactResolver resolver, SnapshotGeneratorSettings settings)
        {
            if (resolver == null)
            {
                throw Error.ArgumentNull("source");
            }
            if (nav.Current == null)
            {
                throw Error.ArgumentNull("Navigator is not positioned on an element");
            }

            if (nav.HasChildren)
            {
                return(true);                     // already has children, we're not doing anything extra
            }
            var defn = nav.Current;

            if (!String.IsNullOrEmpty(defn.NameReference))
            {
                var sourceNav = new ElementNavigator(nav);
                var success   = sourceNav.JumpToNameReference(defn.NameReference);

                if (!success)
                {
                    throw Error.InvalidOperation("Trying to navigate down a node that has a nameReference of '{0}', which cannot be found in the StructureDefinition".FormatWith(defn.NameReference));
                }

                nav.CopyChildren(sourceNav);
            }
            else if (defn.Type != null && defn.Type.Count > 0)
            {
                if (defn.Type.Count > 1)
                {
                    throw new NotSupportedException("Element at path '{0}' has a choice of types, cannot expand".FormatWith(nav.Path));
                }
                else
                {
                    // [WMR 20160720] Handle custom type profiles (GForge #9791)
                    // var coreType = resolver.GetStructureDefinitionForCoreType(defn.Type[0].Code.Value);
                    var primaryType = defn.Type[0];
                    var typeProfile = primaryType.Profile.FirstOrDefault();
                    StructureDefinition coreType = null;
                    if (!defn.IsExtension() && !defn.IsReference() && !string.IsNullOrEmpty(typeProfile) && settings.ExpandTypeProfiles)
                    {
                        coreType = resolver.GetStructureDefinition(typeProfile);
                        if ((coreType == null || coreType.Snapshot == null) && settings.IgnoreMissingTypeProfiles)
                        {
                            coreType = resolver.GetStructureDefinitionForCoreType(primaryType.Code.Value);
                        }
                    }
                    else
                    {
                        coreType = resolver.GetStructureDefinitionForCoreType(primaryType.Code.Value);
                    }

                    if (coreType == null)
                    {
                        throw Error.NotSupported("Trying to navigate down a node that has a declared base type of '{0}', which is unknown".FormatWith(defn.Type[0].Code));
                    }
                    if (coreType.Snapshot == null)
                    {
                        throw Error.NotSupported("Found definition of base type '{0}', but is does not contain a snapshot representation".FormatWith(defn.Type[0].Code));
                    }

                    generateBaseElements(coreType.Snapshot.Element);
                    var sourceNav = new ElementNavigator(coreType.Snapshot.Element);
                    sourceNav.MoveToFirstChild();
                    nav.CopyChildren(sourceNav);
                }
            }

            return(true);
        }