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 TermServiceLoopupTest() { var svc = new LocalTerminologyServer(_resolver); var result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/data-absent-reason", "NaN", "http://hl7.org/fhir/data-absent-reason"); Assert.True(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/data-absent-reason", "NaNX", "http://hl7.org/fhir/data-absent-reason"); Assert.False(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/data-absent-reason", "NaN", "http://hl7.org/fhir/data-absent-reason", display: "Not a Number"); Assert.True(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/data-absent-reason", "NaN", "http://hl7.org/fhir/data-absent-reason", display: "Not any Number"); Assert.False(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/v3-AcknowledgementDetailCode", "_AcknowledgementDetailNotSupportedCode", "http://hl7.org/fhir/v3/AcknowledgementDetailCode"); Assert.False(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/v3-AcknowledgementDetailCode", "_AcknowledgementDetailNotSupportedCode", "http://hl7.org/fhir/v3/AcknowledgementDetailCode", abstractAllowed: true); Assert.True(result.Success); // This is a valueset with a compose, but it has been expanded in the zip, so this will work result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/yesnodontknow", "Y", "http://hl7.org/fhir/v2/0136"); Assert.True(result.Success); // But this won't, it's also a composition, but without expansion - the local term server won't help you here result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/allergyintolerance-substance-code", "160244002", "http://snomed.info/sct"); Assert.False(result.Success); Assert.Single(result.Where(type: OperationOutcome.IssueType.NotSupported)); }