Beispiel #1
0
        public void FallbackServiceValidateCodeTest()
        {
            var client   = new FhirClient("http://ontoserver.csiro.au/dstu2_1");
            var external = new ExternalTerminologyService(client);
            var local    = new LocalTerminologyService(_resolver);
            var svc      = new FallbackTerminologyService(local, external);

            testService(svc);

            // Now, this should fall back
            var result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/substance-code", code: "1166006", system: "http://snomed.info/sct");

            Assert.True(result.Success);
        }
Beispiel #2
0
        public void LocalTSDisplayIncorrectAsWarning()
        {
            var svc = new LocalTerminologyService(_resolver);

            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",
                                          display: "Not a Number");

            Assert.True(result.Success);
            Assert.Equal(0, result.Warnings);

            result = svc.ValidateCode(vsUrl, code: "NaN", system: "http://hl7.org/fhir/data-absent-reason",
                                      display: "Certainly Not a Number");
            Assert.True(result.Success);
            Assert.Equal(1, result.Warnings);
        }
Beispiel #3
0
        public void FallbackServiceValidateCodeTestWithVS()
        {
            var client  = new FhirClient("http://ontoserver.csiro.au/dstu2_1");
            var service = new ExternalTerminologyService(client);
            var vs      = _resolver.FindValueSet("http://hl7.org/fhir/ValueSet/substance-code");

            Assert.NotNull(vs);

            // Override the canonical with something the remote server cannot know
            vs.Url = "http://furore.com/fhir/ValueSet/testVS";
            var local    = new LocalTerminologyService(new IKnowOnlyMyTestVSResolver(vs));
            var fallback = new FallbackTerminologyService(local, service);

            // Now, this should fall back to external + send our vs (that the server cannot know about)
            var result = fallback.ValidateCode("http://furore.com/fhir/ValueSet/testVS", code: "1166006", system: "http://snomed.info/sct");

            Assert.True(result.Success);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public void LocalTermServiceValidateCodeTest()
        {
            var svc = new LocalTerminologyService(_resolver);

            // Do common tests for service
            testService(svc);

            // This is a valueset with a compose - not supported locally normally, but it has been expanded in the zip, so this will work
            var result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/yesnodontknow", code: "Y", system: "http://hl7.org/fhir/v2/0136");

            Assert.True(result.Success);

            // This test is not always correctly done by the external services, so copied here instead
            result = svc.ValidateCode("http://hl7.org/fhir/ValueSet/v3-AcknowledgementDetailCode", code: "_AcknowledgementDetailNotSupportedCode",
                                      system: "http://hl7.org/fhir/v3/AcknowledgementDetailCode", @abstract: false);
            Assert.False(result.Success);

            // And one that will specifically fail on the local service, since it's too complex too expand - the local term server won't help you here
            Assert.Throws <ValueSetExpansionTooComplexException>(
                () => svc.ValidateCode("http://hl7.org/fhir/ValueSet/substance-code", code: "1166006", system: "http://snomed.info/sct"));
        }