All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.fhir.cql.engine.util.FHIRClientUtil Maven / Gradle / Ivy

There is a newer version: 4.11.1
Show newest version
/*
 * (C) Copyright IBM Corp. 2021
 *
 * SPDX-License-Identifier: Apache-2.0
 */
package com.ibm.fhir.cql.engine.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import javax.ws.rs.core.Response;

import com.ibm.fhir.client.FHIRResponse;
import com.ibm.fhir.cql.engine.exception.BaseServerResponseException;

/**
 * Helper methods for working with the IBM FHIR Server Client and 
 * produced FHIRResponse objects.
 */
public class FHIRClientUtil {

    public static void handleErrorResponse(FHIRResponse response) {
        Response r = null;
        try {
            r = response.getResponse();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }

        handleErrorResponse(r);
    }

    public static void handleErrorResponse(Response response) {
        if (!response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
            throw new BaseServerResponseException(response.getStatus(), response.readEntity(String.class));
        }
    }

    public static String urlencode(String value) {
        try {
            return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy