예제 #1
0
        public void ProfileAssertionHandling()
        {
            ResourceEntry<Patient> p = new ResourceEntry<Patient>();

            var prof1 = new Uri("http://profiles.com/important/profiles/1");
            var prof2 = new Uri("http://profiles.com/important/profiles/2");

            p.AddProfileAssertion(prof1);
            p.AddProfileAssertion(prof2);
            Assert.AreEqual(2, p.Tags.Count());

            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof1));
            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof2));

            p.RemoveProfileAssertion(prof2);
            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof1));
            Assert.IsFalse(p.GetAssertedProfiles().Contains(prof2));
        }
예제 #2
0
        public void ProfileAssertionHandling()
        {
            ResourceEntry <Patient> p = new ResourceEntry <Patient>();

            var prof1 = new Uri("http://profiles.com/important/profiles/1");
            var prof2 = new Uri("http://profiles.com/important/profiles/2");

            p.AddProfileAssertion(prof1);
            p.AddProfileAssertion(prof2);
            Assert.AreEqual(2, p.Tags.Count());

            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof1));
            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof2));

            p.RemoveProfileAssertion(prof2);
            Assert.IsTrue(p.GetAssertedProfiles().Contains(prof1));
            Assert.IsFalse(p.GetAssertedProfiles().Contains(prof2));
        }
예제 #3
0
        public static OperationOutcome ValidateEntry(ResourceEntry entry)
        {
            OperationOutcome result = new OperationOutcome();

            result.Issue = new List <OperationOutcome.OperationOutcomeIssueComponent>();

            ICollection <ValidationResult> vresults = new List <ValidationResult>();


            // Phase 1, validate against low-level rules built into the FHIR datatypes

            // todo: The API no longer seems to have the FhirValidator class.

            /*
             * (!FhirValidator.TryValidate(entry.Resource, vresults, recurse: true))
             * {
             *  foreach (var vresult in vresults)
             *      result.Issue.Add(createValidationResult("[.NET validation] " + vresult.ErrorMessage, vresult.MemberNames));
             * }
             */

            // Phase 2, validate against the XML schema
            var xml = FhirSerializer.SerializeResourceToXml(entry.Resource);
            var doc = XDocument.Parse(xml);

            doc.Validate(SchemaCollection.ValidationSchemaSet, (source, args) => result.Issue.Add(createValidationResult("[XSD validation] " + args.Message, null)));


            // Phase 3, validate against a profile, if present
            var profileTags = entry.GetAssertedProfiles();

            if (profileTags.Count() == 0)
            {
                // If there's no profile specified, at least compare it to the "base" profile
                string baseProfile = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + entry.Resource.GetCollectionName();
                profileTags = new Uri[] { new Uri(baseProfile, UriKind.Absolute) };
            }

            var artifactSource = ArtifactResolver.CreateOffline();
            var specProvider   = new SpecificationProvider(artifactSource);

            foreach (var profileTag in profileTags)
            {
                var specBuilder = new SpecificationBuilder(specProvider);
                specBuilder.Add(StructureFactory.PrimitiveTypes());
                specBuilder.Add(StructureFactory.MetaTypes());
                specBuilder.Add(StructureFactory.NonFhirNamespaces());
                specBuilder.Add(profileTag.ToString());
                specBuilder.Expand();

                string path = Directory.GetCurrentDirectory();

                var spec = specBuilder.ToSpecification();
                var nav  = doc.CreateNavigator();
                nav.MoveToFirstChild();

                Report report = spec.Validate(nav);
                var    errors = report.Errors;
                foreach (var error in errors)
                {
                    result.Issue.Add(createValidationResult("[Profile validator] " + error.Message, null));
                }
            }

            if (result.Issue.Count == 0)
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
예제 #4
0
        public static OperationOutcome ValidateEntry(ResourceEntry entry)
        {
            OperationOutcome result = new OperationOutcome();
            result.Issue = new List<OperationOutcome.OperationOutcomeIssueComponent>();

            ICollection<ValidationResult> vresults = new List<ValidationResult>();

            // Phase 1, validate against low-level rules built into the FHIR datatypes

            // todo: The API no longer seems to have the FhirValidator class.
            /*
            (!FhirValidator.TryValidate(entry.Resource, vresults, recurse: true))
            {
                foreach (var vresult in vresults)
                    result.Issue.Add(createValidationResult("[.NET validation] " + vresult.ErrorMessage, vresult.MemberNames));
            }
            */

            // Phase 2, validate against the XML schema
            var xml = FhirSerializer.SerializeResourceToXml(entry.Resource);
            var doc = XDocument.Parse(xml);
            doc.Validate(SchemaCollection.ValidationSchemaSet, (source, args) => result.Issue.Add( createValidationResult("[XSD validation] " + args.Message,null) ));

            // Phase 3, validate against a profile, if present
            var profileTags = entry.GetAssertedProfiles();
            if (profileTags.Count() == 0)
            {
                // If there's no profile specified, at least compare it to the "base" profile
                string baseProfile = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + entry.Resource.GetCollectionName();
                profileTags = new Uri[] { new Uri(baseProfile, UriKind.Absolute) };
            }

            var artifactSource = ArtifactResolver.CreateOffline();
            var specProvider = new SpecificationProvider(artifactSource);

            foreach (var profileTag in profileTags)
            {
                var specBuilder = new SpecificationBuilder(specProvider);
                specBuilder.Add(StructureFactory.PrimitiveTypes());
                specBuilder.Add(StructureFactory.MetaTypes());
                specBuilder.Add(StructureFactory.NonFhirNamespaces());
                specBuilder.Add(profileTag.ToString());
                specBuilder.Expand();

                string path = Directory.GetCurrentDirectory();

                var spec = specBuilder.ToSpecification();
                var nav = doc.CreateNavigator();
                nav.MoveToFirstChild();

                Report report = spec.Validate(nav);
                var errors = report.Errors;
                foreach (var error in errors)
                {
                    result.Issue.Add(createValidationResult("[Profile validator] " + error.Message, null));
                }
            }

            if(result.Issue.Count == 0)
                return null;
            else
                return result;
        }