Example #1
0
        public void QuantityElement()
        {
            var assertion = new ProfileAssertion("Patient.name[0]", resolve);

            assertion.SetInstanceType(FHIRDefinedType.Quantity);
            assertion.SetDeclaredType(FHIRDefinedType.Age);

            Assert.True(assertion.Validate().Success);
            Assert.Single(assertion.MinimalProfiles, assertion.DeclaredType);

            assertion.SetInstanceType(FHIRDefinedType.Identifier);
            var report = assertion.Validate();

            Assert.False(report.Success);
            Assert.Contains("is incompatible with that of the instance", report.ToString());
        }
Example #2
0
        public void ProfiledElement()
        {
            var assertion = new ProfileAssertion("Patient.identifier[0]", resolve);

            assertion.SetDeclaredType("http://validationtest.org/fhir/StructureDefinition/IdentifierWithBSN");
            Assert.True(assertion.Validate().Success);

            assertion.SetInstanceType(FHIRDefinedType.Identifier);
            Assert.True(assertion.Validate().Success);
            Assert.Single(assertion.MinimalProfiles, assertion.DeclaredType);

            assertion.SetInstanceType(FHIRDefinedType.HumanName);
            var report = assertion.Validate();

            Assert.False(report.Success);
            Assert.Contains("is incompatible with that of the instance", report.ToString());
        }
Example #3
0
        public ProfilePreprocessor(Func <string, StructureDefinition> profileResolver, Action <StructureDefinition> snapshotGenerator,
                                   IElementNavigator instance, string declaredTypeProfile,
                                   IEnumerable <StructureDefinition> additionalProfiles, IEnumerable <string> additionalCanonicals)
        {
            _profileResolver   = profileResolver;
            _snapshotGenerator = snapshotGenerator;
            _path = instance.Location;

            _profiles = new ProfileAssertion(_path, _profileResolver);

            if (instance.Type != null)
            {
                _profiles.SetInstanceType(ModelInfo.CanonicalUriForFhirCoreType(instance.Type));
            }
            if (declaredTypeProfile != null)
            {
                _profiles.SetDeclaredType(declaredTypeProfile);
            }

            // This is only for resources, but I don't bother checking, since this will return empty anyway
            _profiles.AddStatedProfile(instance.Children("meta").Children("profile").Select(p => p.Value).Cast <string>());

            //Almost identically, extensions can declare adherance to a profile using the 'url' attribute
            if (declaredTypeProfile == ModelInfo.CanonicalUriForFhirCoreType(FHIRDefinedType.Extension))
            {
                var urlDeclaration = instance.Children("url").FirstOrDefault()?.Value as string;

                if (urlDeclaration != null && urlDeclaration.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
                {
                    _profiles.AddStatedProfile(urlDeclaration);
                }
            }

            if (additionalProfiles != null)
            {
                _profiles.AddStatedProfile(additionalProfiles);
            }
            if (additionalCanonicals != null)
            {
                _profiles.AddStatedProfile(additionalCanonicals);
            }
        }
Example #4
0
        public void ContainedResource()
        {
            var assertion = new ProfileAssertion("Bundle.entry.resource[0]", resolve);

            assertion.SetDeclaredType(FHIRDefinedType.Resource);
            Assert.True(assertion.Validate().Success);

            assertion.SetInstanceType(FHIRDefinedType.Patient);
            Assert.True(assertion.Validate().Success);

            assertion.SetDeclaredType(FHIRDefinedType.DomainResource);
            Assert.True(assertion.Validate().Success);

            Assert.Single(assertion.MinimalProfiles, assertion.InstanceType);

            assertion.SetInstanceType(FHIRDefinedType.Binary);
            var report = assertion.Validate();

            Assert.False(report.Success);
            Assert.Contains("is incompatible with that of the instance", report.ToString());
        }
Example #5
0
        public void InitializationAndResolution()
        {
            var sd = _resolver.FindStructureDefinitionForCoreType(FHIRDefinedType.ValueSet);

            var assertion = new ProfileAssertion("Patient.name[0]", resolve);

            assertion.SetInstanceType(FHIRDefinedType.ValueSet);
            assertion.SetDeclaredType(FHIRDefinedType.ValueSet);
            assertion.AddStatedProfile("http://hl7.org/fhir/StructureDefinition/shareablevalueset");

            Assert.Equal(2, assertion.AllProfiles.Count());
            Assert.Equal(2, assertion.AllProfiles.Count(p => p.Status == null));    // status == null is only true for unresolved resources

            assertion.AddStatedProfile(sd);

            Assert.Equal(2, assertion.AllProfiles.Count());                      // Adding a ValueSet SD that was already there does not increase the profile count
            Assert.Equal(1, assertion.AllProfiles.Count(p => p.Status == null)); // but now there's 1 unresolved profile less
            Assert.True(assertion.AllProfiles.Contains(sd));                     // the other being the Sd we just added

            Assert.Equal(sd, assertion.InstanceType);
            Assert.Equal(sd, assertion.DeclaredType);

            var outcome = assertion.Resolve();

            Assert.True(outcome.Success);
            Assert.Equal(2, assertion.AllProfiles.Count());                      // We should still have 2 distinct SDs
            Assert.Equal(0, assertion.AllProfiles.Count(p => p.Status == null)); // none remain unresolved
            Assert.True(assertion.AllProfiles.Contains(sd));                     // one still being the Sd we manually added

            assertion.AddStatedProfile("http://hl7.org/fhir/StructureDefinition/unresolvable");

            outcome = assertion.Resolve();
            Assert.False(outcome.Success);
            Assert.Equal(3, assertion.AllProfiles.Count());                      // We should still have 3 distinct SDs
            Assert.Equal(1, assertion.AllProfiles.Count(p => p.Status == null)); // one remains unresolved
            Assert.True(assertion.AllProfiles.Contains(sd));                     // one still being the Sd we manually added
        }
Example #6
0
        public void ResourceWithStatedProfiles()
        {
            var assertion = new ProfileAssertion("Observation", resolve);

            assertion.SetDeclaredType(FHIRDefinedType.Observation);

            Assert.True(assertion.Validate().Success);

            assertion.AddStatedProfile(ModelInfo.CanonicalUriForFhirCoreType(FHIRDefinedType.Observation));
            assertion.AddStatedProfile("http://validationtest.org/fhir/StructureDefinition/WeightHeightObservation");
            assertion.AddStatedProfile("http://hl7.org/fhir/StructureDefinition/devicemetricobservation");

            var report = assertion.Validate();

            Assert.True(report.Success);
            Assert.Equal(2, assertion.MinimalProfiles.Count());
            Assert.Equal(assertion.MinimalProfiles, assertion.StatedProfiles.Skip(1));

            assertion.SetDeclaredType(FHIRDefinedType.Procedure);
            report = assertion.Validate();

            Assert.False(report.Success);
            Assert.Contains("is incompatible with the declared type", report.ToString());
        }