public void TestCodeableConceptValidation() { var val = new BindingValidator(_termService, "Demo"); var binding = new ElementDefinition.BindingComponent { ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason"), Strength = BindingStrength.Required }; var cc = new CodeableConcept(); cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "NaN")); cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "not-asked")); var result = val.ValidateBinding(cc, binding); Assert.True(result.Success); cc.Coding.First().Code = "NaNX"; result = val.ValidateBinding(cc, binding); Assert.True(result.Success); cc.Coding.Skip(1).First().Code = "did-ask"; result = val.ValidateBinding(cc, binding); Assert.False(result.Success); //EK 2017-07-6 No longer reports warnings when failing a preferred binding binding.Strength = BindingStrength.Preferred; result = val.ValidateBinding(cc, binding); Assert.True(result.Success); Assert.Equal(0, result.Warnings); }
public void TestCodeableConceptValidation() { var val = new BindingValidator(_termService, "Demo"); var vsUri = "http://hl7.org/fhir/ValueSet/data-absent-reason"; var cc = new CodeableConcept(); cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "NaN")); cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "not-asked")); var result = val.ValidateBinding(cc, vsUri, BindingStrength.Required); Assert.True(result.Success); cc.Coding.First().Code = "NaNX"; result = val.ValidateBinding(cc, vsUri, BindingStrength.Required); Assert.True(result.Success); cc.Coding.Skip(1).First().Code = "did-ask"; result = val.ValidateBinding(cc, vsUri, BindingStrength.Required); Assert.False(result.Success); result = val.ValidateBinding(cc, vsUri); Assert.True(result.Success); Assert.Equal(1, result.Warnings); }
internal OperationOutcome ValidateBinding(ElementDefinition definition, IElementNavigator instance) { var outcome = new OperationOutcome(); var ts = Settings.TerminologyService; if (ts == null) { if (Settings.ResourceResolver == null) { Trace(outcome, $"Cannot resolve binding references since neither TerminologyService nor ResourceResolver is given in the settings", Issue.UNAVAILABLE_TERMINOLOGY_SERVER, instance); return(outcome); } ts = new LocalTerminologyServer(Settings.ResourceResolver); } var bindingValidator = new BindingValidator(ts, instance.Location); try { return(bindingValidator.ValidateBinding(instance, definition)); } catch (Exception e) { Trace(outcome, $"Terminology service failed while validating code X (system Y): {e.Message}", Issue.UNAVAILABLE_VALIDATE_CODE_FAILED, instance); return(outcome); } }
public void TestCodingValidation() { var val = new BindingValidator(_termService, "Demo"); var vsUri = "http://hl7.org/fhir/ValueSet/data-absent-reason"; var c = new Coding("http://hl7.org/fhir/data-absent-reason", "NaN"); var result = val.ValidateBinding(c, vsUri, BindingStrength.Required); Assert.True(result.Success); c.Code = "NaNX"; result = val.ValidateBinding(c, vsUri, BindingStrength.Required); Assert.False(result.Success); result = val.ValidateBinding(c, vsUri); Assert.True(result.Success); c.Code = "NaN"; c.Display = "Not a Number"; result = val.ValidateBinding(c, vsUri, BindingStrength.Required); Assert.True(result.Success); c.Display = "Not a NumberX"; result = val.ValidateBinding(c, vsUri, BindingStrength.Required); Assert.False(result.Success); // But this won't, it's also a composition, but without expansion - the local term server won't help you here c = new Coding("http://snomed.info/sct", "160244002"); result = val.ValidateBinding(c, "http://hl7.org/fhir/ValueSet/allergyintolerance-substance-code"); Assert.True(result.Success); Assert.NotEmpty(result.Where(type: OperationOutcome.IssueType.NotSupported)); }
internal OperationOutcome ValidateBinding(ElementDefinition definition, IElementNavigator instance) { var outcome = new OperationOutcome(); if (definition.Binding == null) { return(outcome); } var ts = Settings.TerminologyService; if (ts == null) { if (Settings.ResourceResolver == null) { Trace(outcome, $"Cannot resolve binding references since neither TerminologyService nor ResourceResolver is given in the settings", Issue.UNAVAILABLE_TERMINOLOGY_SERVER, instance); return(outcome); } ts = new LocalTerminologyService(Settings.ResourceResolver); } var bindingValidator = new BindingValidator(ts, instance.Location); try { Element bindable = instance.ParseBindable(); // If the instance is not bindeable, ignore the Binding specified on the element, // it's simply not applicable if (bindable != null) { return(bindingValidator.ValidateBinding(bindable, definition.Binding)); } } catch (Exception e) { Trace(outcome, $"Terminology service call failed for binding at {definition.Path}: {e.Message}", Issue.TERMINOLOGY_SERVICE_FAILED, instance); } return(outcome); }
public void TestCodingValidation() { var val = new BindingValidator(_termService, "Demo"); var binding = new ElementDefinition.BindingComponent { ValueSet = new ResourceReference("http://hl7.org/fhir/ValueSet/data-absent-reason"), Strength = BindingStrength.Required }; var c = new Coding("http://hl7.org/fhir/data-absent-reason", "NaN"); var result = val.ValidateBinding(c, binding); Assert.True(result.Success); c.Code = "NaNX"; result = val.ValidateBinding(c, binding); Assert.False(result.Success); c.Code = "NaN"; binding.Strength = null; result = val.ValidateBinding(c, binding); Assert.True(result.Success); Assert.Equal(1, result.Warnings); // missing binding strength c.Display = "Not a Number"; binding.Strength = BindingStrength.Required; result = val.ValidateBinding(c, binding); Assert.True(result.Success); c.Display = "Not a NumberX"; result = val.ValidateBinding(c, binding); Assert.False(result.Success); // But this won't, it's also a composition, but without expansion - the local term server won't help you here var binding2 = new ElementDefinition.BindingComponent { ValueSet = new FhirUri("http://hl7.org/fhir/ValueSet/allergyintolerance-substance-code"), Strength = BindingStrength.Required }; c = new Coding("http://snomed.info/sct", "160244002"); result = val.ValidateBinding(c, binding2); Assert.True(result.Success); Assert.NotEmpty(result.Where(type: OperationOutcome.IssueType.NotSupported)); }