// Create default SnapshotGeneratorSettings, apply the specified regenerate flag
        static SnapshotGeneratorSettings createSettings(bool regenerate)
        {
            var settings = SnapshotGeneratorSettings.CreateDefault();

            settings.ForceRegenerateSnapshots = regenerate;
            return(settings);
        }
 public ElementVerifier(IList <ElementDefinition> elements, SnapshotGeneratorSettings settings)
 {
     _settings = settings;
     _elements = elements;
     _settings = settings;
     _pos      = 0;
 }
 public ElementVerifier(StructureDefinition sd, SnapshotGeneratorSettings settings)
 {
     Assert.IsNotNull(sd);
     Assert.IsTrue(sd.HasSnapshot);
     _settings = settings;
     _elements = sd.Snapshot.Element;
     _pos      = 0;
     // var ann = sd.Annotation<OriginAnnotation>();
     // Debug.Print($"Assert structure: url = '{sd.Url}' - origin = '{ann.Origin}'");
     Debug.Print($"Assert structure: url = '{sd.Url}' - origin = '{sd.GetOrigin()}'");
 }
Esempio n. 4
0
        public static void Create(StructureDefinition structDef)
        {
            if (structDef is null)
            {
                throw new ArgumentNullException(nameof(structDef));
            }

            structDef.Snapshot = new StructureDefinition.SnapshotComponent();

            // Generate StructureDefinition.Snapshot using c# API.
            SnapshotGeneratorSettings settings  = SnapshotGeneratorSettings.CreateDefault();
            SnapshotGenerator         generator = new SnapshotGenerator(ZipFhirSource.Source, settings);

            generator.Update(structDef);
        }
Esempio n. 5
0
        // Note: this modifies an SD that is passed to us and will alter a possibly cached
        // object shared amongst other threads. This is generally useful and saves considerable
        // time when the same snapshot is needed again, but may result in side-effects
        private OperationOutcome snapshotGenerationNeeded(StructureDefinition definition)
        {
            if (!Settings.GenerateSnapshot)
            {
                return(new OperationOutcome());
            }

            // Default implementation: call event
            if (OnSnapshotNeeded != null)
            {
                var eventData = new OnSnapshotNeededEventArgs(definition, Settings.ResourceResolver);
                OnSnapshotNeeded(this, eventData);
                return(eventData.Result);
            }

            // Else, expand, depending on our configuration
#if REUSE_SNAPSHOT_GENERATOR
            var generator = this.SnapshotGenerator;
            if (generator != null)
            {
                generator.Update(definition);

#if DEBUG
                string xml  = (new FhirXmlSerializer()).SerializeToString(definition);
                string name = definition.Id ?? definition.Name.Replace(" ", "").Replace("/", "");
                var    dir  = Path.Combine(Path.GetTempPath(), "validation");

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                File.WriteAllText(Path.Combine(dir, name) + ".StructureDefinition.xml", xml);
#endif


                return(generator.Outcome ?? new OperationOutcome());
#else
            if (Settings.ResourceResolver != null)
            {
                SnapshotGeneratorSettings settings = Settings.GenerateSnapshotSettings ?? SnapshotGeneratorSettings.Default;
                (new SnapshotGenerator(Settings.ResourceResolver, settings)).Update(definition);
#endif
            }

            return(new OperationOutcome());
        }
    }
        private void forDoc()
        {
            FhirXmlParser parser = new FhirXmlParser(new ParserSettings {
                AcceptUnknownMembers = true
            });
            IFhirReader xmlWithPatientData = null;
            var         patient            = parser.Parse <Patient>(xmlWithPatientData);

            // -----

            ArtifactResolver source = ArtifactResolver.CreateCachedDefault();
            var settings            = new SnapshotGeneratorSettings {
                IgnoreMissingTypeProfiles = true
            };
            StructureDefinition profile = null;

            var generator = new SnapshotGenerator(source, _settings);

            generator.Generate(profile);
        }
Esempio n. 7
0
        // Note: this modifies an SD that is passed to us and will alter a possibly cached
        // object shared amongst other threads. This is generally useful and saves considerable
        // time when the same snapshot is needed again, but may result in side-effects
        private OperationOutcome snapshotGenerationNeeded(StructureDefinition definition)
        {
            if (!Settings.GenerateSnapshot)
            {
                return(new OperationOutcome());
            }

            // Default implementation: call event
            if (OnSnapshotNeeded != null)
            {
                var eventData = new OnSnapshotNeededEventArgs(definition, Settings.ResourceResolver);
                OnSnapshotNeeded(this, eventData);
                return(eventData.Result);
            }

            // Else, expand, depending on our configuration
#if REUSE_SNAPSHOT_GENERATOR
            var generator = this.SnapshotGenerator;
            if (generator != null)
            {
                generator.Update(definition);
#if DUMP_SNAPSHOTS
                string xml  = FhirSerializer.SerializeResourceToXml(definition);
                string name = definition.Id ?? definition.Name.Replace(" ", "");

                File.WriteAllText(@"c:\temp\validation\" + name + ".StructureDefinition.xml", xml);
#endif


                return(generator.Outcome ?? new OperationOutcome());
#else
            if (Settings.ResourceResolver != null)
            {
                SnapshotGeneratorSettings settings = Settings.GenerateSnapshotSettings ?? SnapshotGeneratorSettings.Default;
                (new SnapshotGenerator(Settings.ResourceResolver, settings)).Update(definition);
#endif
            }

            return(new OperationOutcome());
        }
    }
 /// <summary>Creates a new instance of the <see cref="SnapshotSource"/> for the specified internal resolver.</summary>
 /// <param name="source">An internal <see cref="IResourceResolver"/> instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory.</param>
 public SnapshotSource(IResourceResolver source)
     : this(source, SnapshotGeneratorSettings.CreateDefault())
 {
 }
 /// <summary>Creates a new instance of the <see cref="SnapshotSource"/> for the specified internal resolver.</summary>
 /// <param name="source">An internal <see cref="IResourceResolver"/> instance. The implementation should be idempotent (i.e. cached), so the generated snapshots are persisted in memory.</param>
 /// <param name="settings">Configuration settings for the snapshot generator.</param>
 public SnapshotSource(IResourceResolver source, SnapshotGeneratorSettings settings)
 {
     // SnapshotGenerator ctor will throw if source or settings are null
     Generator = new SnapshotGenerator(source, settings);
 }