public OperationOutcome ValidateCode(string canonical = null, string context = null, ValueSet valueSet = null, string code = null, string system = null, string version = null, string display = null, Coding coding = null, CodeableConcept codeableConcept = null, FhirDateTime date = null, bool? @abstract = default(bool?), string displayLanguage = null) { try { // First, try the local service return(_localService.ValidateCode(canonical, context, valueSet, code, system, version, display, coding, codeableConcept, date, @abstract, displayLanguage)); } catch (TerminologyServiceException) { // If that fails, call the fallback try { return(_fallbackService.ValidateCode(canonical, context, valueSet, code, system, version, display, coding, codeableConcept, date, @abstract, displayLanguage)); } catch (ValueSetUnknownException vse) { // The fall back service does not know the valueset. If our local service // does, try get the VS from there, and retry by sending the vs inline valueSet = _localService.FindValueset(canonical); if (valueSet == null) { throw vse; } return(_fallbackService.ValidateCode(null, context, valueSet, code, system, version, display, coding, codeableConcept, date, @abstract, displayLanguage)); } } }
private void testService(ITerminologyService svc) { var vsUrl = "http://hl7.org/fhir/ValueSet/data-absent-reason"; var result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason"); Assert.True(result.Success); result = svc.ValidateCode(vsUrl, code: "NaNX", system: "http://hl7.org/fhir/data-absent-reason"); Assert.False(result.Success); result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason", display: "Not a Number"); Assert.True(result.Success); // The spec is not clear on the behaviour of incorrect displays - so don't test it here //result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason", // display: "Not any Number"); //Assert.True(result.Success); result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/v3-AcknowledgementDetailCode", code: "_AcknowledgementDetailNotSupportedCode", system: "http://hl7.org/fhir/v3/AcknowledgementDetailCode"); Assert.True(result.Success); Assert.Throws <ValueSetUnknownException>(() => svc.ValidateCode("http://hl7.org/fhir/ValueSet/crappy", code: "4322002", system: "http://snomed.info/sct")); var coding = new Coding("http://hl7.org/fhir/data-absent-reason", "NaN"); result = svc.ValidateCode(vsUrl, coding: coding); Assert.True(result.Success); coding.Display = "Not a Number"; result = svc.ValidateCode(vsUrl, coding: coding); Assert.True(result.Success); coding.Code = "NaNX"; result = svc.ValidateCode(vsUrl, coding: coding); Assert.False(result.Success); coding.Code = "NaN"; var cc = new CodeableConcept("http://hl7.org/fhir/data-absent-reason", "NaNX", "Not a Number"); result = svc.ValidateCode(vsUrl, codeableConcept: cc); Assert.False(result.Success); cc.Coding.Add(new Coding("http://hl7.org/fhir/data-absent-reason", "asked")); result = svc.ValidateCode(vsUrl, codeableConcept: cc); DebugDumpOutputXml(result); Assert.True(result.Success); }
private OperationOutcome callService(string code, string system, string display, string uri, BindingStrength?strength, string path) { var outcome = new OperationOutcome(); OperationOutcome validateResult = _service.ValidateCode(uri, code, system, display, abstractAllowed: false); var codeLabel = $"Code '{code}' from system '{system}'"; if (display != null) { codeLabel += $" with display '{display}'"; } if (validateResult.Where(type: OperationOutcome.IssueType.NotSupported).Any()) { if (strength != BindingStrength.Example) { outcome.AddIssue($"The terminology service is incapable of validating {codeLabel} (valueset '{uri}').", Issue.UNSUPPORTED_BINDING_NOT_SUPPORTED_BY_SERVICE, path); validateResult.MakeInformational(); outcome.Include(validateResult); } return(outcome); } if (!validateResult.Success) { if (strength == BindingStrength.Required) { outcome.AddIssue($"{codeLabel} is not valid for required binding to valueset '{uri}'", Issue.CONTENT_INVALID_FOR_REQUIRED_BINDING, path); } else if (strength != BindingStrength.Example) { outcome.AddIssue($"{codeLabel} is not valid for non-required binding to valueset '{uri}'", Issue.CONTENT_INVALID_FOR_NON_REQUIRED_BINDING, path); } validateResult.MakeInformational(); } outcome.Include(validateResult); return(outcome); }
private OperationOutcome callService(string canonical, string code = null, string system = null, string display = null, Coding coding = null, CodeableConcept cc = null, bool?abstractAllowed = null) { var outcome = new OperationOutcome(); try { outcome = _service.ValidateCode(canonical: canonical, code: code, system: system, display: display, coding: coding, codeableConcept: cc, @abstract: abstractAllowed); foreach (var issue in outcome.Issue) { issue.Location = new string[] { _path } } ; } catch (TerminologyServiceException tse) { outcome.AddIssue($"Terminology service failed while validating code '{code}' (system '{system}'): {tse.Message}", Issue.TERMINOLOGY_SERVICE_FAILED, _path); } return(outcome); }