Skip to content

Commit

Permalink
Merge pull request #73 from IBM/master
Browse files Browse the repository at this point in the history
ttest
  • Loading branch information
albertwang-ibm committed Sep 15, 2019
2 parents 3c8acdc + 9565105 commit 3af3a7a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.ws.rs.core.Response;

import com.ibm.watson.health.fhir.client.impl.FHIRBasicAuthenticator;
import com.ibm.watson.health.fhir.config.FHIRRequestContext;
import com.ibm.watson.health.fhir.exception.FHIROperationException;
import com.ibm.watson.health.fhir.model.type.Instant;
import com.ibm.watson.health.fhir.operation.bullkdata.config.BulkDataConfigUtil;
Expand Down Expand Up @@ -140,6 +141,8 @@ public String submit(MediaType outputFormat, Instant since, List<String> types,

// Need to push this into a property.
WebTarget target = getWebTarget(properties.get(BulkDataConfigUtil.BATCH_URL));

System.out.println("-> " + properties.get(BulkDataConfigUtil.BATCH_URL));

BulkExportJobInstanceRequest.Builder builder = BulkExportJobInstanceRequest.builder();
builder.applicationName(properties.get(BulkDataConfigUtil.APPLICATION_NAME));
Expand All @@ -152,7 +155,13 @@ public String submit(MediaType outputFormat, Instant since, List<String> types,
builder.cosCredentialIbm(properties.get(BulkDataConfigUtil.JOB_PARAMETERS_IBM));
builder.cosApiKey(properties.get(BulkDataConfigUtil.JOB_PARAMETERS_KEY));
builder.cosSrvInstId(properties.get(BulkDataConfigUtil.JOB_PARAMETERS_ENDPOINT));


String fhirTenant = FHIRRequestContext.get().getTenantId();
builder.fhirTenant(fhirTenant);

String fhirDataStoreId = FHIRRequestContext.get().getDataStoreId();
builder.fhirDataStoreId(fhirDataStoreId);

String resourceType = types.get(0);
builder.fhirResourceType(resourceType);

Expand All @@ -169,8 +178,8 @@ public String submit(MediaType outputFormat, Instant since, List<String> types,
String responseStr = r.readEntity(String.class);

// Debug / Dev only
if (log.isLoggable(Level.FINE)) {
log.fine("JSON -> \n" + responseStr);
if (log.isLoggable(Level.WARNING)) {
log.warning("JSON -> \n" + responseStr);
}

BulkExportJobInstanceResponse response =
Expand All @@ -179,7 +188,7 @@ public String submit(MediaType outputFormat, Instant since, List<String> types,
// From the response
String jobId = Integer.toString(response.getInstanceId());

return "/fhir-server/api/v4/$export-status?job=" + jobId;
return "/wh-fhir-dev/api/v4/$export-status?job=" + jobId;
}

/**
Expand Down Expand Up @@ -213,8 +222,8 @@ public PollingLocationResponse status(String job) throws Exception {
BulkExportJobExecutionResponse response =
BulkExportJobExecutionResponse.Parser.parse(responseStr);

if (log.isLoggable(Level.FINE)) {
log.fine("Logging the BulkExportJobExecutionResponse Details -> \n "
if (log.isLoggable(Level.WARNING)) {
log.warning("Logging the BulkExportJobExecutionResponse Details -> \n "
+ BulkExportJobExecutionResponse.Writer.generate(response, false));
}

Expand All @@ -224,7 +233,7 @@ public PollingLocationResponse status(String job) throws Exception {
} else if (SUCCESS_STATUS.contains(batchStatus)) {
result = process(response);
} else if (FAILED_STATUS.contains(batchStatus)) {
throw BulkDataUtil.buildOperationException("batch status check is null");
throw BulkDataUtil.buildOperationException("batch status check is failed");
}

} catch (FHIROperationException fe) {
Expand All @@ -251,7 +260,7 @@ private PollingLocationResponse process(BulkExportJobExecutionResponse response)
String baseCosUrl = properties.get(BulkDataConfigUtil.JOB_PARAMETERS_ENDPOINT);
String bucket = properties.get(BulkDataConfigUtil.JOB_PARAMETERS_BUCKET);
String downloadUrl =
baseCosUrl + "/" + bucket + "/job" + jobId + "_" + resourceType + "_0.ndjson";
baseCosUrl + "/" + bucket + "/job" + jobId + "/" + resourceType + "_0.ndjson";

// Request
String request = "/$export?_type=" + resourceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public static class JobParameter {

String fhirResourceType;
String fhirSearchFromDate;

String fhirTenant;
String fhirDataStoreId;

String cosBucketName;
String cosLocation;
String cosEndpointUrl;
Expand Down Expand Up @@ -160,6 +162,22 @@ public void setCosSrvInstId(String cosSrvInstId) {
this.cosSrvInstId = cosSrvInstId;
}

public String getFhirTenant() {
return fhirTenant;
}

public void setFhirTenant(String fhirTenant) {
this.fhirTenant = fhirTenant;
}

public String getFhirDataStoreId() {
return fhirDataStoreId;
}

public void setFhirDataStoreId(String fhirDataStoreId) {
this.fhirDataStoreId = fhirDataStoreId;
}

}

/**
Expand Down Expand Up @@ -231,6 +249,16 @@ public Builder cosSrvInstId(String cosSrvInstId) {
jobParameter.setCosSrvInstId(cosSrvInstId);
return this;
}

public Builder fhirTenant(String fhirTenant) {
jobParameter.setFhirTenant(fhirTenant);
return this;
}

public Builder fhirDataStoreId(String fhirDataStoreId) {
jobParameter.setFhirDataStoreId(fhirDataStoreId);
return this;
}

public BulkExportJobInstanceRequest build() {
request.setJobParameters(jobParameter);
Expand Down Expand Up @@ -322,6 +350,16 @@ public static BulkExportJobInstanceRequest parse(InputStream in)
if (cosSrvinstId != null) {
builder.cosSrvInstId(cosSrvinstId);
}

String fhirTenant = obj.getString("fhir.tenant");
if (fhirTenant != null) {
builder.fhirTenant(fhirTenant);
}

String fhirDataStoreId = obj.getString("fhir.datastoreid");
if (fhirDataStoreId != null) {
builder.fhirDataStoreId(fhirDataStoreId);
}
}

return builder.build();
Expand Down Expand Up @@ -415,6 +453,14 @@ public static String generate(BulkExportJobInstanceRequest obj, boolean withSens
if (parameter.getFhirSearchFromDate() != null) {
generator.write("fhir.search.fromdate", parameter.getFhirSearchFromDate());
}

if (parameter.getFhirTenant() != null) {
generator.write("fhir.tenant", parameter.getFhirTenant());
}

if (parameter.getFhirDataStoreId() != null) {
generator.write("fhir.datastoreid", parameter.getFhirDataStoreId());
}

generator.writeEnd();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ExportOperationTest extends FHIRServerTestBase {

public static final String FORMAT = "application/fhir+ndjson";

public static final boolean ON = false;
public static final boolean ON = true;

@Test(groups = { TEST_GROUP_NAME }, enabled = ON)
public void testBaseExport() throws FHIRGeneratorException, IOException {
Expand Down

0 comments on commit 3af3a7a

Please sign in to comment.