Search in sources :

Example 16 with ParametersParameterComponent

use of org.hl7.fhir.r5.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) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 17 with ParametersParameterComponent

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

the class BaseWorkerContext method validateOnServer.

private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
    if (vs != null)
        pin.addParameter().setName("valueSet").setResource(vs);
    for (ParametersParameterComponent pp : pin.getParameter()) if (pp.getName().equals("profile"))
        throw new Error("Can only specify profile in the context");
    if (expParameters == null)
        throw new Error("No ExpansionProfile provided");
    pin.addParameter().setName("profile").setResource(expParameters);
    txLog.clearLastId();
    Parameters pOut;
    if (vs == null)
        pOut = txClient.validateCS(pin);
    else
        pOut = txClient.validateVS(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)
        return new ValidationResult(IssueSeverity.ERROR, message, err).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (message != null && !message.equals("No Message returned"))
        return new ValidationResult(IssueSeverity.WARNING, message, new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (display != null)
        return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else
        return new ValidationResult(new ConceptDefinitionComponent()).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 18 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project snowstorm by IHTSDO.

the class AbstractFHIRTest method toString.

protected String toString(ParametersParameterComponent p, String indent) {
    StringBuffer sb = new StringBuffer();
    sb.append(p.getName() + " (" + p.fhirType() + ")");
    if (p.getValue() != null) {
        sb.append(": " + toString(p.getValue()));
    }
    if (p.getResource() != null) {
        sb.append(": " + p.getResource());
    }
    for (ParametersParameterComponent part : p.getPart()) {
        sb.append("\n" + toString(part, indent + "  "));
    }
    return sb.toString();
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 19 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project snowstorm by IHTSDO.

the class AbstractFHIRTest method populatePropertyMap.

private void populatePropertyMap(Map<String, Type> propertyMap, List<ParametersParameterComponent> parts) {
    String key = null;
    Type value = null;
    for (ParametersParameterComponent part : parts) {
        if (part.getName().equals("code")) {
            key = part.getValue().castToString(part.getValue()).asStringValue();
        } else {
            value = part.getValue();
        }
    }
    propertyMap.put(key, value);
}
Also used : IssueType(org.hl7.fhir.r4.model.OperationOutcome.IssueType) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 20 with ParametersParameterComponent

use of org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent in project snowstorm by IHTSDO.

the class CodeSystemProviderLookupTest method testSinglePropertiesRecovery.

@Test
void testSinglePropertiesRecovery() throws FHIROperationException {
    String url = "http://localhost:" + port + "/fhir/CodeSystem/$lookup?system=http://snomed.info/sct&code=" + sampleSCTID + "&property=normalForm&_format=json";
    Parameters p = getParameters(url);
    /*for (ParametersParameterComponent parameter : p.getParameter()) {
			logger.info(toString(parameter, ""));
		}*/
    String normalFormProperty = toString(getProperty(p, "normalForm"));
    assertNotNull(normalFormProperty);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) Test(org.junit.jupiter.api.Test)

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