Search in sources :

Example 11 with ParametersParameterComponent

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

the class BaseWorkerContext method validateOnServer.

private ValidationResult validateOnServer(ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException {
    boolean cache = false;
    if (vs != null) {
        for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
            codeSystemsUsed.add(inc.getSystem());
        }
        for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
            codeSystemsUsed.add(inc.getSystem());
        }
    }
    if (vs != null) {
        if (isTxCaching && cacheId != null && vs.getUrl() != null && cached.contains(vs.getUrl() + "|" + vs.getVersion())) {
            pin.addParameter().setName("url").setValue(new UriType(vs.getUrl() + (vs.hasVersion() ? "|" + vs.getVersion() : "")));
        } else if (options.getVsAsUrl()) {
            pin.addParameter().setName("url").setValue(new StringType(vs.getUrl()));
        } else {
            pin.addParameter().setName("valueSet").setResource(vs);
            if (vs.getUrl() != null) {
                cached.add(vs.getUrl() + "|" + vs.getVersion());
            }
        }
        cache = true;
        addDependentResources(pin, vs);
    }
    if (cache) {
        pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
    }
    for (ParametersParameterComponent pp : pin.getParameter()) {
        if (pp.getName().equals("profile")) {
            throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));
        }
    }
    if (expParameters == null) {
        throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED));
    }
    pin.addParameter().setName("profile").setResource(expParameters);
    if (txLog != null) {
        txLog.clearLastId();
    }
    if (txClient == null) {
        throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
    }
    Parameters pOut;
    if (vs == null) {
        pOut = txClient.validateCS(pin);
    } else {
        pOut = txClient.validateVS(pin);
    }
    return processValidationResult(pOut);
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) Parameters(org.hl7.fhir.r4b.model.Parameters) StringType(org.hl7.fhir.r4b.model.StringType) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r4b.model.UriType) ParametersParameterComponent(org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent)

Example 12 with ParametersParameterComponent

use of org.hl7.fhir.r4.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()));
            result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        } else {
            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 tx5 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
    }
    return null;
}
Also used : URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent)

Example 13 with ParametersParameterComponent

use of org.hl7.fhir.r4.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.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.r5.model.StringType) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) BooleanType(org.hl7.fhir.r5.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 14 with ParametersParameterComponent

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

the class BaseWorkerContext method validateOnServer.

protected ValidationResult validateOnServer(ValueSet vs, Parameters pin, ValidationOptions options) throws FHIRException {
    boolean cache = false;
    if (vs != null) {
        for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
            codeSystemsUsed.add(inc.getSystem());
        }
        for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
            codeSystemsUsed.add(inc.getSystem());
        }
    }
    if (vs != null) {
        if (isTxCaching && cacheId != null && vs.getUrl() != null && cached.contains(vs.getUrl() + "|" + vs.getVersion())) {
            pin.addParameter().setName("url").setValue(new UriType(vs.getUrl() + (vs.hasVersion() ? "|" + vs.getVersion() : "")));
        } else if (options.getVsAsUrl()) {
            pin.addParameter().setName("url").setValue(new StringType(vs.getUrl()));
        } else {
            pin.addParameter().setName("valueSet").setResource(vs);
            if (vs.getUrl() != null) {
                cached.add(vs.getUrl() + "|" + vs.getVersion());
            }
        }
        cache = true;
        addDependentResources(pin, vs);
    }
    if (cache) {
        pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
    }
    for (ParametersParameterComponent pp : pin.getParameter()) {
        if (pp.getName().equals("profile")) {
            throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));
        }
    }
    if (expParameters == null) {
        throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED));
    }
    pin.addParameter().setName("profile").setResource(expParameters);
    if (txLog != null) {
        txLog.clearLastId();
    }
    if (txClient == null) {
        throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
    }
    Parameters pOut;
    if (vs == null) {
        pOut = txClient.validateCS(pin);
    } else {
        pOut = txClient.validateVS(pin);
    }
    return processValidationResult(pOut);
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) Parameters(org.hl7.fhir.r5.model.Parameters) StringType(org.hl7.fhir.r5.model.StringType) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r5.model.UriType) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 15 with ParametersParameterComponent

use of org.hl7.fhir.r4.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(), source);
    }
    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.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) ParametersParameterComponent(org.hl7.fhir.r5.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