Esempio n. 1
0
        public void Setup()
        {
            var assembly      = Assembly.GetExecutingAssembly();
            var location      = new Uri(assembly.GetName().CodeBase);
            var directoryInfo = new FileInfo(location.AbsolutePath).Directory;

            Debug.Assert(directoryInfo != null, "directoryInfo != null");
            Debug.Assert(directoryInfo.FullName != null, "directoryInfo.FullName != null");

            var structureDefinitions  = directoryInfo.FullName + @"\Resources\StructureDefinitions";
            var includeSubDirectories = new DirectorySourceSettings {
                IncludeSubDirectories = true
            };
            var directorySource = new DirectorySource(structureDefinitions, includeSubDirectories);

            var cachedResolver = new CachedResolver(directorySource);
            var coreSource     = new CachedResolver(ZipSource.CreateValidationSource());
            var combinedSource = new MultiResolver(cachedResolver, coreSource);
            var settings       = new ValidationSettings
            {
                EnableXsdValidation = true,
                GenerateSnapshot    = true,
                Trace                    = true,
                ResourceResolver         = combinedSource,
                ResolveExteralReferences = true,
                SkipConstraintValidation = false
            };
            var validator = new Validator(settings);

            _profileValidator = new ProfileValidator(validator);
        }
 static SnapshotGenerator GetSnapshotGenerator()
 {
     if (_snapshotGenerator == null)
     {
         var src = new MultiResolver(_cachedCoreSource, _cachedDirSource);
         _snapshotGenerator = new SnapshotGenerator(src);
     }
     return(_snapshotGenerator);
 }
Esempio n. 3
0
        public void RetrieveArtifactMulti()
        {
            var resolver = new MultiResolver(source, new WebResolver());

            var vs = resolver.ResolveByCanonicalUri("http://hl7.org/fhir/ValueSet/v2-0292");
            Assert.IsNotNull(vs);
            Assert.IsTrue(vs is ValueSet);

            var artifact = resolver.ResolveByUri("http://fhir2.healthintersections.com.au/open/StructureDefinition/flag");

            Assert.IsNotNull(artifact);
            Assert.IsTrue(artifact is StructureDefinition);
            Assert.AreEqual("Flag", ((StructureDefinition)artifact).Name);
        }
Esempio n. 4
0
        public void RetrieveArtifactMulti()
        {
            var resolver = new MultiResolver(source, new WebResolver());

            var vs = resolver.ResolveByCanonicalUri("http://hl7.org/fhir/ValueSet/v2-0292");

            Assert.IsNotNull(vs);
            Assert.IsTrue(vs is ValueSet);

            var artifact = resolver.ResolveByUri("http://test.fhir.org/r2/StructureDefinition/Patient");

            Assert.IsNotNull(artifact);
            Assert.IsTrue(artifact is StructureDefinition);
            Assert.AreEqual("Patient", ((StructureDefinition)artifact).Name);
        }
Esempio n. 5
0
        public FhirValidationSupport(ICommonFactory ICommonFactory)
        {
            this.ICommonFactory = ICommonFactory;

            // Ensure the FHIR extensions are registered
            Hl7.Fhir.FhirPath.ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();

            // Ensure the FHIR extensions are registered
            //Hl7.Fhir.FhirPath.PocoNavigatorExtensions.PrepareFhirSymbolTableFunctions();

            var MultiResolver = new MultiResolver();

            //Load all the ResourceResolvers from the DI injection, current list in order is:
            //InternalServerProfileResolver
            //AustralianFhirProfileResolver
            //ZipSourceResolver
            foreach (IResourceResolver ResourceResolver in ICommonFactory.CreateResourceResolverList())
            {
                MultiResolver.AddSource(ResourceResolver);
            }

            //Below are manual loads for debugging

            //FHIR Specification.zip Zip file
            //MultiResolver.AddSource(new ZipSourceResolver());

            // Try using the fixed content
            //MultiResolver.AddSource(new AustralianFhirProfileResolver());

            // A specific FHIR Registry Server on the web
            //MultiResolver.AddSource(new WebResolver(id => new FhirClient("http://someonesfhirserver.com/fhir")));

            //Look in this Pyro server's Resource
            //MultiResolver.AddSource(new InternalServerProfileResolver());

            //for Debugging look somewhere?
            //MultiResolver.AddSource(new WebResolver(id => new FhirClient("http://localhost:50579/fhir")));

            // Prepare the artefact resolvers (cache to reduce complexity)
            ResourceResolver = new CachedResolver(MultiResolver);
        }
Esempio n. 6
0
        public Validator GetValidator()
        {
            if (!IsValidationOn())
            {
                return(null);
            }

            var zipSource      = ZipSource.CreateValidationSource();
            var coreSource     = new CachedResolver(zipSource);
            var combinedSource = new MultiResolver(GetResourceResolver(), coreSource);
            var settings       = new ValidationSettings
            {
                EnableXsdValidation = true,
                GenerateSnapshot    = true,
                Trace                    = true,
                ResourceResolver         = combinedSource,
                ResolveExteralReferences = true,
                SkipConstraintValidation = false
            };

            return(new Validator(settings));
        }
Esempio n. 7
0
        public ProfileValidator(bool validateXsd, bool showTrace, bool reloadValidator, string profileFolder)
        {
            if (_validator != null && !reloadValidator)
            {
                return;
            }
            var coreSource     = new CachedResolver(ZipSource.CreateValidationSource());
            var cachedResolver = new CachedResolver(new DirectorySource(profileFolder, new DirectorySourceSettings {
                IncludeSubDirectories = true
            }));
            var combinedSource = new MultiResolver(cachedResolver, coreSource);
            var settings       = new ValidationSettings
            {
                EnableXsdValidation = validateXsd,
                GenerateSnapshot    = true,
                Trace                    = showTrace,
                ResourceResolver         = combinedSource,
                ResolveExteralReferences = true,
                SkipConstraintValidation = false
            };

            _validator = new Validator(settings);
        }
Esempio n. 8
0
        public async Task TestAsyncSyncMultiResolver()
        {
            var(sr, ar, sar) = (new SyncResolver(), new AsyncResolver(), new SyncAsyncResolver());
            var multi = new MultiResolver(sr, ar, sar);

            // calling *any* kind of resolve will involve all child resolvers, since they all return null.
            _ = await multi.ResolveByUriAsync("");

#pragma warning disable CS0618 // Type or member is obsolete
            _ = multi.ResolveByCanonicalUri("");
#pragma warning restore CS0618 // Type or member is obsolete

            Assert.AreEqual(1, sr.ByUri);
            Assert.AreEqual(1, sr.ByCanonical);

            Assert.AreEqual(1, ar.ByUriAsync);
            Assert.AreEqual(1, ar.ByCanonicalAsync);

            Assert.AreEqual(0, sar.ByUri);       // multi will always prefer the async
            Assert.AreEqual(0, sar.ByCanonical); // multi will always prefer the async
            Assert.AreEqual(1, sar.ByUriAsync);
            Assert.AreEqual(1, sar.ByCanonicalAsync);
        }
        public static Validator GetValidator()
        {
            var structureDefinitions  = GetStructureDefinitionsPath();
            var includeSubDirectories = new DirectorySourceSettings {
                IncludeSubDirectories = true
            };
            var directorySource = new DirectorySource(structureDefinitions, includeSubDirectories);

            var cachedResolver = new CachedResolver(directorySource);
            var coreSource     = new CachedResolver(ZipSource.CreateValidationSource());
            var combinedSource = new MultiResolver(cachedResolver, coreSource);
            var settings       = new ValidationSettings
            {
                EnableXsdValidation = true,
                GenerateSnapshot    = true,
                Trace                     = true,
                ResourceResolver          = combinedSource,
                ResolveExternalReferences = true,
                SkipConstraintValidation  = false
            };
            var validator = new Validator(settings);

            return(validator);
        }