Search in sources :

Example 51 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project pathling by aehrc.

the class DefaultTerminologyServiceTest method testTranslateForValidAndInvalidCodings.

@Test
void testTranslateForValidAndInvalidCodings() {
    // Response bundle:
    // [1]  CODING1_VERSION1 -> None
    // [2]  CODING2_VERSION1 -> { equivalent: CODING3_VERSION1, wider: CODING1_VERSION1}
    final Bundle responseBundle = new Bundle().setType(BundleType.BATCHRESPONSE);
    // entry with no mapping
    final Parameters noTranslation = new Parameters().addParameter("result", false);
    responseBundle.addEntry().setResource(noTranslation).getResponse().setStatus("200");
    // entry with two mappings
    final Parameters withTranslation = new Parameters().addParameter("result", true);
    final ParametersParameterComponent equivalentMatch = withTranslation.addParameter().setName("match");
    equivalentMatch.addPart().setName("equivalence").setValue(new CodeType("equivalent"));
    equivalentMatch.addPart().setName("concept").setValue(CODING3_VERSION1.toCoding());
    final ParametersParameterComponent widerMatch = withTranslation.addParameter().setName("match");
    widerMatch.addPart().setName("equivalence").setValue(new CodeType("wider"));
    widerMatch.addPart().setName("concept").setValue(CODING1_VERSION1.toCoding());
    responseBundle.addEntry().setResource(withTranslation).getResponse().setStatus("200");
    when(terminologyClient.batch(any())).thenReturn(responseBundle);
    final ConceptTranslator actualTranslator = terminologyService.translate(Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null), "uuid:concept-map", false, Collections.singletonList(ConceptMapEquivalence.EQUIVALENT));
    assertEquals(ConceptTranslatorBuilder.empty().put(CODING2_VERSION1, CODING3_VERSION1.toCoding()).build(), actualTranslator);
    // expected request bundle
    final Bundle requestBundle = new Bundle().setType(BundleType.BATCH);
    requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING1_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
    requestBundle.addEntry().setResource(new Parameters().addParameter("url", new UriType("uuid:concept-map")).addParameter("reverse", false).addParameter("coding", CODING2_VERSION1.toCoding())).getRequest().setMethod(HTTPVerb.POST).setUrl("ConceptMap/$translate");
    verify(terminologyClient).batch(deepEq(requestBundle));
    verifyNoMoreInteractions(terminologyClient);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) Bundle(org.hl7.fhir.r4.model.Bundle) CodeType(org.hl7.fhir.r4.model.CodeType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent) UriType(org.hl7.fhir.r4.model.UriType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project kindling by HL7.

the class BuildWorkerContext method lookupLoinc.

private String lookupLoinc(String code) throws Exception {
    if (true) {
        // (!triedServer || serverOk) {
        try {
            triedServer = true;
            // for this, we use the FHIR client
            if (txClient == null) {
                txClient = new TerminologyClientR5(tsServer);
                this.txLog = new HTMLClientLogger(null);
            }
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("system", "http://loinc.org");
            Parameters result = txClient.lookupCode(params);
            for (ParametersParameterComponent p : result.getParameter()) {
                if (p.getName().equals("display"))
                    return ((StringType) p.getValue()).asStringValue();
            }
            throw new Exception("Did not find LOINC code in return values");
        } catch (EFhirClientException e) {
            serverOk = true;
            throw e;
        } catch (Exception e) {
            serverOk = false;
            throw e;
        }
    } else
        throw new Exception("Server is not available");
}
Also used : TerminologyClientR5(org.hl7.fhir.convertors.txClient.TerminologyClientR5) Parameters(org.hl7.fhir.r5.model.Parameters) HashMap(java.util.HashMap) HTMLClientLogger(org.hl7.fhir.r5.context.HTMLClientLogger) UcumException(org.fhir.ucum.UcumException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 53 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project redmatch by aehrc.

the class RedmatchGrammarValidator method validateCode.

private ValidationResult validateCode(String code, String path, String message) throws IOException {
    // Special case: codes ending with extension.url
    if (code.endsWith("extension.url")) {
        code = code.substring(0, code.length() - 4);
    }
    Boolean res = null;
    Parameters out = terminologyService.validate(fhirPackage, code);
    for (ParametersParameterComponent param : out.getParameter()) {
        if (param.getName().equals("result")) {
            res = ((BooleanType) param.getValue()).getValue();
        }
    }
    if (res == null) {
        throw new RuntimeException("Unexpected response (has no 'result' out parameter).");
    }
    ValidationResult vr = new ValidationResult(res, code);
    if (!res) {
        vr.getMessages().add(String.format(message, path));
    }
    return vr;
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 54 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method serverValidateCode.

private ValidationResult serverValidateCode(Parameters pin) {
    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    for (ParametersParameterComponent p : pout.getParameter()) {
        if (p.getName().equals("result"))
            ok = ((BooleanType) p.getValue()).getValue().booleanValue();
        else if (p.getName().equals("message"))
            message = ((StringType) p.getValue()).getValue();
        else if (p.getName().equals("display"))
            display = ((StringType) p.getValue()).getValue();
    }
    if (!ok)
        return new ValidationResult(IssueSeverity.ERROR, message);
    else if (display != null)
        return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    else
        return new ValidationResult(null);
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters) ConceptDefinitionComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent) StringType(org.hl7.fhir.dstu2.model.StringType) ParametersParameterComponent(org.hl7.fhir.dstu2.model.Parameters.ParametersParameterComponent)

Example 55 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method processValidationResult.

public ValidationResult processValidationResult(Parameters pOut) {
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    String system = null;
    String code = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pOut.getParameter()) {
        if (p.hasValue()) {
            if (p.getName().equals("result")) {
                ok = ((BooleanType) p.getValue()).getValue().booleanValue();
            } else if (p.getName().equals("message")) {
                message = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("display")) {
                display = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("system")) {
                system = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("code")) {
                code = ((StringType) p.getValue()).getValue();
            } else if (p.getName().equals("cause")) {
                try {
                    IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
                    if (it == IssueType.UNKNOWN) {
                        err = TerminologyServiceErrorClass.UNKNOWN;
                    } else if (it == IssueType.NOTFOUND) {
                        err = TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED;
                    } else if (it == IssueType.NOTSUPPORTED) {
                        err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
                    } else {
                        err = null;
                    }
                } catch (FHIRException e) {
                }
            }
        }
    }
    if (!ok) {
        return new ValidationResult(IssueSeverity.ERROR, message + " (from " + txClient.getAddress() + ")", err).setTxLink(txLog.getLastId());
    } else if (message != null && !message.equals("No Message returned")) {
        return new ValidationResult(IssueSeverity.WARNING, message + " (from " + txClient.getAddress() + ")", system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else if (display != null) {
        return new ValidationResult(system, new ConceptDefinitionComponent().setDisplay(display).setCode(code)).setTxLink(txLog.getLastId());
    } else {
        return new ValidationResult(system, new ConceptDefinitionComponent().setCode(code)).setTxLink(txLog.getLastId());
    }
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4b.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.r4b.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.r4b.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent)

Aggregations

ParametersParameterComponent (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)26 Parameters (org.hl7.fhir.r4.model.Parameters)21 HashMap (java.util.HashMap)18 JsonObject (javax.json.JsonObject)15 GET (javax.ws.rs.GET)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 ExtraParameters (org.apache.camel.component.fhir.api.ExtraParameters)15 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 IOException (java.io.IOException)7 CodeType (org.hl7.fhir.r4.model.CodeType)7 URISyntaxException (java.net.URISyntaxException)6 Nonnull (javax.annotation.Nonnull)6 Parameters (org.hl7.fhir.dstu3.model.Parameters)6 ParametersParameterComponent (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)6 Bundle (org.hl7.fhir.r4.model.Bundle)6 Slf4j (lombok.extern.slf4j.Slf4j)5 Parameters (org.hl7.fhir.dstu2.model.Parameters)5 Parameters (org.hl7.fhir.dstu2016may.model.Parameters)5