Search in sources :

Example 56 with ParametersParameterComponent

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

the class BaseWorkerContext method serverValidateCode.

private ValidationResult serverValidateCode(Parameters pin, boolean doCache) throws Exception {
    if (noTerminologyServer) {
        return new ValidationResult(null, null, TerminologyServiceErrorClass.NOSERVICE);
    }
    String cacheName = doCache ? generateCacheName(pin) : null;
    ValidationResult res = loadFromCache(cacheName);
    if (res != null) {
        return res;
    }
    tlog("Terminology Server: $validate-code " + describeValidationParameters(pin));
    for (ParametersParameterComponent pp : pin.getParameter()) {
        if (pp.getName().equals("profile")) {
            throw new Error("Can only specify profile in the context");
        }
    }
    if (expProfile == null) {
        throw new Exception("No ExpansionProfile provided");
    }
    pin.addParameter().setName("profile").setResource(expProfile);
    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    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();
        } 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.NOTSUPPORTED) {
                    err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
                }
            } catch (FHIRException e) {
            }
        }
    }
    if (!ok) {
        res = new ValidationResult(IssueSeverity.ERROR, message, err);
    } else if (display != null) {
        res = new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    } else {
        res = new ValidationResult(new ConceptDefinitionComponent());
    }
    saveToCache(res, cacheName);
    return res;
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.dstu3.terminologies.ValueSetExpander.TerminologyServiceErrorClass) Parameters(org.hl7.fhir.dstu3.model.Parameters) StringType(org.hl7.fhir.dstu3.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 57 with ParametersParameterComponent

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

the class ValueSetExpanderSimple method doExpand.

public ValueSetExpansionOutcome doExpand(ValueSet source, Parameters expParams) throws FHIRException, ETooCostly, FileNotFoundException, IOException {
    if (expParams == null)
        expParams = makeDefaultExpansion();
    source.checkNoModifiers("ValueSet", "expanding");
    focus = source.copy();
    focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
    focus.getExpansion().setTimestampElement(DateTimeType.now());
    focus.getExpansion().setIdentifier(Factory.createUUID());
    for (ParametersParameterComponent p : expParams.getParameter()) {
        if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested"))
            focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
    }
    if (source.hasCompose())
        handleCompose(source.getCompose(), focus.getExpansion().getParameter(), expParams, source.getUrl());
    if (canBeHeirarchy) {
        for (ValueSetExpansionContainsComponent c : roots) {
            focus.getExpansion().getContains().add(c);
        }
    } else {
        for (ValueSetExpansionContainsComponent c : codes) {
            if (map.containsKey(key(c)) && !c.getAbstract()) {
                // we may have added abstract codes earlier while we still thought it might be heirarchical, but later we gave up, so now ignore them
                focus.getExpansion().getContains().add(c);
                // make sure any heirarchy is wiped
                c.getContains().clear();
            }
        }
    }
    if (total > 0) {
        focus.getExpansion().setTotal(total);
    }
    return new ValueSetExpansionOutcome(focus);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 58 with ParametersParameterComponent

use of org.hl7.fhir.r4b.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.dstu2016may.model.Parameters) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.dstu2016may.model.StringType) ParametersParameterComponent(org.hl7.fhir.dstu2016may.model.Parameters.ParametersParameterComponent)

Example 59 with ParametersParameterComponent

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

the class FHIRToolingClient method operateType.

public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
    boolean complex = false;
    for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
    String ps = "";
    try {
        if (!complex)
            for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
                ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
        ResourceRequest<T> result;
        URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
        if (complex) {
            byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
            if (client.getLogger() != null) {
                client.getLogger().logRequest("POST", url.toString(), null, body);
            }
            result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        } else {
            if (client.getLogger() != null) {
                client.getLogger().logRequest("GET", url.toString(), null, null);
            }
            result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        }
        if (result.isUnsuccessfulRequest()) {
            throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
        }
        if (result.getPayload() instanceof Parameters) {
            return (Parameters) result.getPayload();
        } else {
            Parameters p_out = new Parameters();
            p_out.addParameter().setName("return").setResource(result.getPayload());
            return p_out;
        }
    } catch (Exception e) {
        handleException("Error performing tx3 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
    }
    return null;
}
Also used : URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 60 with ParametersParameterComponent

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

the class ValueSetExpanderSimple method doExpand.

public ValueSetExpansionOutcome doExpand(ValueSet source, Parameters expParams) throws FHIRException, ETooCostly, FileNotFoundException, IOException {
    if (expParams == null)
        expParams = makeDefaultExpansion();
    source.checkNoModifiers("ValueSet", "expanding");
    focus = source.copy();
    focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
    focus.getExpansion().setTimestampElement(DateTimeType.now());
    focus.getExpansion().setIdentifier(Factory.createUUID());
    for (ParametersParameterComponent p : expParams.getParameter()) {
        if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested"))
            focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
    }
    if (source.hasCompose())
        handleCompose(source.getCompose(), focus.getExpansion(), expParams, source.getUrl(), focus.getExpansion().getExtension());
    if (canBeHeirarchy) {
        for (ValueSetExpansionContainsComponent c : roots) {
            focus.getExpansion().getContains().add(c);
        }
    } else {
        for (ValueSetExpansionContainsComponent c : codes) {
            if (map.containsKey(key(c)) && (includeAbstract || !c.getAbstract())) {
                // we may have added abstract codes earlier while we still thought it might be heirarchical, but later we gave up, so now ignore them
                focus.getExpansion().getContains().add(c);
                // make sure any heirarchy is wiped
                c.getContains().clear();
            }
        }
    }
    if (total > 0) {
        focus.getExpansion().setTotal(total);
    }
    return new ValueSetExpansionOutcome(focus);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionComponent(org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionComponent) ValueSet(org.hl7.fhir.r4b.model.ValueSet) 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