Search in sources :

Example 1 with ResourceEntity

use of ca.uhn.fhir.rest.client.apache.ResourceEntity in project geoprism-registry by terraframe.

the class FhirBulkDataImporter method initiateBulkExport.

private String initiateBulkExport(CloseableHttpClient myClient, FhirContext ctx) {
    try {
        Parameters params = new Parameters();
        params.addParameter().setName("_type").setValue(new StringType("Organization,Location"));
        HttpPost post = new HttpPost(system.getUrl() + "/" + "$export");
        post.addHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_RESPOND_ASYNC);
        post.setEntity(new ResourceEntity(ctx, params));
        try (CloseableHttpResponse response = myClient.execute(post)) {
            if (response.getStatusLine().getStatusCode() == 202) {
                return response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue();
            } else {
                System.out.println(response.getStatusLine().getStatusCode());
                StringWriter writer = new StringWriter();
                IOUtils.copy(response.getEntity().getContent(), writer, "utf-8");
                String message = writer.toString();
                throw new ProgrammingErrorException(message);
            }
        }
    } catch (IOException e) {
        throw new ProgrammingErrorException(e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Parameters(org.hl7.fhir.r4.model.Parameters) StringWriter(java.io.StringWriter) StringType(org.hl7.fhir.r4.model.StringType) ResourceEntity(ca.uhn.fhir.rest.client.apache.ResourceEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException)

Aggregations

ResourceEntity (ca.uhn.fhir.rest.client.apache.ResourceEntity)1 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 Parameters (org.hl7.fhir.r4.model.Parameters)1 StringType (org.hl7.fhir.r4.model.StringType)1