예제 #1
0
        /// <summary>
        /// Creates a default cached ArtifactResolver
        /// Default only searches in the executable directory files and the core zip.
        /// </summary>
        public static ArtifactResolver CreateCachedDefault()
        {
            var resolver = ArtifactResolver.CreateDefault();

            // Wrap a cache around the default source
            resolver.Source = new CachedArtifactSource(resolver.Source);

            return(resolver);
        }
        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));
            }           
        }
예제 #3
0
        private static void generateSnapshotAndCompare(StructureDefinition original, ArtifactResolver source)
        {
            var generator = new SnapshotGenerator(source, markChanges: false);        

            var expanded = (StructureDefinition)original.DeepCopy();
            Assert.IsTrue(original.IsExactly(expanded));

            generator.Generate(expanded);
           
            var areEqual = original.IsExactly(expanded);

            if (!areEqual)
            {
                File.WriteAllText("c:\\temp\\snapshotgen-source.xml", FhirSerializer.SerializeResourceToXml(original));
                File.WriteAllText("c:\\temp\\snapshotgen-dest.xml", FhirSerializer.SerializeResourceToXml(expanded));
            }

            Assert.IsTrue(areEqual);
        }
        private static void generateSnapshotAndCompare(StructureDefinition original, ArtifactResolver source)
        {
            var generator = new SnapshotGenerator(source, markChanges: false);        

            var expanded = (StructureDefinition)original.DeepCopy();
            Assert.IsTrue(original.IsExactly(expanded));

            generator.Generate(expanded);

            // Simulate bug in Grahame's expander
            if (original.Snapshot.Element.Count == expanded.Snapshot.Element.Count)
            {
                for (var ix = 0; ix < expanded.Snapshot.Element.Count; ix++)
                {
                    if (original.Snapshot.Element[ix].Path == expanded.Snapshot.Element[ix].Path)
                    {
                        expanded.Snapshot.Element[ix].Min = original.Snapshot.Element[ix].Min;
                        expanded.Snapshot.Element[ix].MustSupport = original.Snapshot.Element[ix].MustSupport;
                    }
                }
            }
            
            var areEqual = original.IsExactly(expanded);

            if (!areEqual)
            {
                File.WriteAllText("c:\\temp\\snapshotgen-source.xml", FhirSerializer.SerializeResourceToXml(original));
                File.WriteAllText("c:\\temp\\snapshotgen-dest.xml", FhirSerializer.SerializeResourceToXml(expanded));
            }

            Assert.IsTrue(areEqual);
        }
 public void Setup()
 {
     _source = ArtifactResolver.CreateOffline();
 }
        public static bool ExpandElement(this ElementNavigator nav, ArtifactResolver source)
        {
            if (source == 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
                {
                    var coreType = source.GetStructureDefinitionForCoreType(defn.Type[0].Code);
                    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));

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

            return true;
        }
예제 #7
0
 public void Setup()
 {
     _testSource = new ArtifactResolver(new CachedArtifactSource(new FileDirectoryArtifactSource("TestData/snapshot-test")));
 }
예제 #8
0
 public SnapshotGenerator(ArtifactResolver resolver, bool markChanges=false)
 {
     _resolver = resolver;
     _markChanges = markChanges;
 }