Search in sources :

Example 86 with Parameters

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

the class FHIRToolingClient method expandValueset.

public ValueSet expandValueset(ValueSet source, Parameters expParams, Map<String, String> params) {
    List<Header> headers = null;
    Parameters p = expParams == null ? new Parameters() : expParams.copy();
    p.addParameter().setName("valueSet").setResource(source);
    for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n)));
    ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4);
    // gone
    result.addErrorStatus(410);
    // unknown
    result.addErrorStatus(404);
    result.addErrorStatus(405);
    // Unprocessable Entity
    result.addErrorStatus(422);
    result.addSuccessStatus(200);
    result.addSuccessStatus(201);
    if (result.isUnsuccessfulRequest()) {
        throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
    }
    return (ValueSet) result.getPayload();
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters) Header(org.apache.http.Header) StringType(org.hl7.fhir.dstu2.model.StringType) Resource(org.hl7.fhir.dstu2.model.Resource) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Example 87 with Parameters

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

the class FHIRToolingClient method updateClosure.

public ConceptMap updateClosure(String name, Coding coding) {
    Parameters params = new Parameters();
    params.addParameter().setName("name").setValue(new StringType(name));
    params.addParameter().setName("concept").setValue(coding);
    List<Header> headers = null;
    ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION);
    // gone
    result.addErrorStatus(410);
    // unknown
    result.addErrorStatus(404);
    result.addErrorStatus(405);
    // Unprocessable Entity
    result.addErrorStatus(422);
    result.addSuccessStatus(200);
    result.addSuccessStatus(201);
    if (result.isUnsuccessfulRequest()) {
        throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
    }
    return (ConceptMap) result.getPayload();
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters) Header(org.apache.http.Header) StringType(org.hl7.fhir.dstu2.model.StringType) HashMap(java.util.HashMap) Resource(org.hl7.fhir.dstu2.model.Resource) ConceptMap(org.hl7.fhir.dstu2.model.ConceptMap)

Example 88 with Parameters

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

the class RdfParser method composeParametersParametersParameterComponent.

protected void composeParametersParametersParameterComponent(Complex parent, String parentType, String name, Parameters.ParametersParameterComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "parameter", name, element, index);
    if (element.hasNameElement())
        composeString(t, "Parameters", "name", element.getNameElement(), -1);
    if (element.hasValue())
        composeType(t, "Parameters", "value", element.getValue(), -1);
    if (element.hasResource())
        composeResource(t, "Parameters", "resource", element.getResource(), -1);
    for (int i = 0; i < element.getPart().size(); i++) composeParametersParametersParameterComponent(t, "Parameters", "part", element.getPart().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 89 with Parameters

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

the class FHIRToolingClient method operateType.

// 
// public <T extends Resource> boolean delete(Class<T> resourceClass, String id) {
// try {
// return utils.issueDeleteRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), proxy);
// } catch(Exception e) {
// throw new EFhirClientException("An error has occurred while trying to delete this resource", e);
// }
// 
// }
// 
// public <T extends Resource> OperationOutcome create(Class<T> resourceClass, T resource) {
// ResourceRequest<T> resourceRequest = null;
// try {
// List<Header> headers = null;
// resourceRequest = utils.issuePostRequest(resourceAddress.resolveGetUriFromResourceClass(resourceClass),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, proxy);
// resourceRequest.addSuccessStatus(201);
// if(resourceRequest.isUnsuccessfulRequest()) {
// throw new EFhirClientException("Server responded with HTTP error code " + resourceRequest.getHttpStatus(), (OperationOutcome)resourceRequest.getPayload());
// }
// } catch(Exception e) {
// handleException("An error has occurred while trying to create this resource", e);
// }
// OperationOutcome operationOutcome = null;;
// try {
// operationOutcome = (OperationOutcome)resourceRequest.getPayload();
// ResourceAddress.ResourceVersionedIdentifier resVersionedIdentifier =
// ResourceAddress.parseCreateLocation(resourceRequest.getLocation());
// OperationOutcomeIssueComponent issue = operationOutcome.addIssue();
// issue.setSeverity(IssueSeverity.INFORMATION);
// issue.setUserData(ResourceAddress.ResourceVersionedIdentifier.class.toString(),
// resVersionedIdentifier);
// return operationOutcome;
// } catch(ClassCastException e) {
// // some server (e.g. grahams) returns the resource directly
// operationOutcome = new OperationOutcome();
// OperationOutcomeIssueComponent issue = operationOutcome.addIssue();
// issue.setSeverity(IssueSeverity.INFORMATION);
// issue.setUserData(ResourceRequest.class.toString(),
// resourceRequest.getPayload());
// return operationOutcome;
// }
// }
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate, Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// public <T extends Resource> Bundle history(Date lastUpdate, Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate, Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Date lastUpdate, Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Date lastUpdate) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history() {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle search(Class<T> resourceClass, Map<String, String> parameters) {
// Bundle searchResults = null;
// try {
// searchResults = utils.issueGetFeedRequest(resourceAddress.resolveSearchUri(resourceClass, parameters), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("Error performing search with parameters " + parameters, e);
// }
// return searchResults;
// }
// 
// 
// public <T extends Resource> Bundle searchPost(Class<T> resourceClass, T resource, Map<String, String> parameters) {
// Bundle searchResults = null;
// try {
// searchResults = utils.issuePostFeedRequest(resourceAddress.resolveSearchUri(resourceClass, new HashMap<String, String>()), parameters, "src", resource, getPreferredResourceFormat());
// } catch (Exception e) {
// handleException("Error performing search with parameters " + parameters, e);
// }
// return searchResults;
// }
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);
    Parameters searchResults = null;
    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;
        if (complex)
            result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG);
        else
            result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG);
        // gone
        result.addErrorStatus(410);
        // unknown
        result.addErrorStatus(404);
        // Only one for now
        result.addSuccessStatus(200);
        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 2b operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
    }
    return null;
}
Also used : Parameters(org.hl7.fhir.dstu2016may.model.Parameters) OperationOutcome(org.hl7.fhir.dstu2016may.model.OperationOutcome) PrimitiveType(org.hl7.fhir.dstu2016may.model.PrimitiveType) URISyntaxException(java.net.URISyntaxException) ParametersParameterComponent(org.hl7.fhir.dstu2016may.model.Parameters.ParametersParameterComponent)

Example 90 with Parameters

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

the class FHIRToolingClient method initializeClosure.

public ConceptMap initializeClosure(String name) {
    Parameters params = new Parameters();
    params.addParameter().setName("name").setValue(new StringType(name));
    List<Header> headers = null;
    ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL);
    // gone
    result.addErrorStatus(410);
    // unknown
    result.addErrorStatus(404);
    result.addErrorStatus(405);
    // Unprocessable Entity
    result.addErrorStatus(422);
    result.addSuccessStatus(200);
    result.addSuccessStatus(201);
    if (result.isUnsuccessfulRequest()) {
        throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
    }
    return (ConceptMap) result.getPayload();
}
Also used : Parameters(org.hl7.fhir.dstu2016may.model.Parameters) Header(org.apache.http.Header) StringType(org.hl7.fhir.dstu2016may.model.StringType) HashMap(java.util.HashMap) Resource(org.hl7.fhir.dstu2016may.model.Resource) ConceptMap(org.hl7.fhir.dstu2016may.model.ConceptMap)

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)105 Test (org.junit.jupiter.api.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)71 StringType (org.hl7.fhir.r4.model.StringType)68 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)61 HashMap (java.util.HashMap)58 ArrayList (java.util.ArrayList)53 FHIRException (org.hl7.fhir.exceptions.FHIRException)48 IOException (java.io.IOException)44 Parameters (org.hl7.fhir.dstu3.model.Parameters)41 Bundle (org.hl7.fhir.r4.model.Bundle)34 Measure (org.hl7.fhir.r4.model.Measure)31 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)25 Patient (org.hl7.fhir.r4.model.Patient)25 FileNotFoundException (java.io.FileNotFoundException)24 List (java.util.List)24 JsonObject (javax.json.JsonObject)23 GET (javax.ws.rs.GET)23 ExtraParameters (org.apache.camel.component.fhir.api.ExtraParameters)23