use of gov.cms.ab2d.common.dto.StartJobDTO in project ab2d by CMSgov.
the class ApiCommon method checkValidCreateJob.
public StartJobDTO checkValidCreateJob(HttpServletRequest request, String contractNumber, OffsetDateTime since, String resourceTypes, String outputFormat, FhirVersion version) {
PdpClient pdpClient = pdpClientService.getCurrentClient();
contractNumber = checkIfContractAttested(pdpClient.getContract(), contractNumber);
checkIfInMaintenanceMode();
checkIfCurrentClientCanAddJob();
checkResourceTypesAndOutputFormat(resourceTypes, outputFormat);
checkSinceTime(since);
return new StartJobDTO(contractNumber, pdpClient.getOrganization(), resourceTypes, getCurrentUrl(request), outputFormat, since, version);
}
use of gov.cms.ab2d.common.dto.StartJobDTO in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testGetStatusWhileFinished.
@Test
void testGetStatusWhileFinished() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH + "?_type=ExplanationOfBenefit").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andReturn();
String statusUrl = mvcResult.getResponse().getHeader(CONTENT_LOCATION);
assertNotNull(statusUrl);
JobOutput jobOutput = new JobOutput();
jobOutput.setFhirResourceType(EOB);
jobOutput.setFilePath("file.ndjson");
jobOutput.setError(false);
jobOutput.setFileLength(5000L);
jobOutput.setChecksum("file");
jobClientMock.addJobOutputForDownload(jobOutput);
JobOutput errorJobOutput = new JobOutput();
errorJobOutput.setFhirResourceType(OPERATION_OUTCOME);
errorJobOutput.setFilePath("error.ndjson");
errorJobOutput.setFileLength(6000L);
errorJobOutput.setChecksum("error");
errorJobOutput.setError(true);
jobClientMock.addJobOutputForDownload(errorJobOutput);
String jobUuid = jobClientMock.pickAJob();
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
this.mockMvc.perform(get(statusUrl).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(200)).andExpect(buildExpiresMatcher()).andExpect(jsonPath("$.transactionTime", Is.is(new org.hl7.fhir.dstu3.model.DateTimeType(OffsetDateTime.now().toString()).toHumanDisplay()))).andExpect(jsonPath("$.request", Is.is(startJobDTO.getUrl()))).andExpect(jsonPath("$.requiresAccessToken", Is.is(true))).andExpect(jsonPath("$.output[0].type", Is.is(EOB))).andExpect(jsonPath("$.output[0].url", Is.is("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/file.ndjson"))).andExpect(jsonPath("$.output[0].extension[0].url", Is.is(CHECKSUM_STRING))).andExpect(jsonPath("$.output[0].extension[0].valueString", Is.is("sha256:file"))).andExpect(jsonPath("$.output[0].extension[1].url", Is.is(CONTENT_LENGTH_STRING))).andExpect(jsonPath("$.output[0].extension[1].valueDecimal", Is.is(5000))).andExpect(jsonPath("$.error[0].type", Is.is(OPERATION_OUTCOME))).andExpect(jsonPath("$.error[0].url", Is.is("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/error.ndjson"))).andExpect(jsonPath("$.error[0].extension[0].url", Is.is(CHECKSUM_STRING))).andExpect(jsonPath("$.error[0].extension[0].valueString", Is.is("sha256:error"))).andExpect(jsonPath("$.error[0].extension[1].url", Is.is(CONTENT_LENGTH_STRING))).andExpect(jsonPath("$.error[0].extension[1].valueDecimal", Is.is(6000)));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(2, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
ApiRequestEvent requestEvent2 = (ApiRequestEvent) apiRequestEvents.get(1);
if (requestEvent.getUrl().contains("export")) {
assertNull(requestEvent.getJobId());
} else {
assertEquals(jobUuid, requestEvent.getJobId());
}
if (requestEvent2.getUrl().contains("export")) {
assertNull(requestEvent2.getJobId());
} else {
assertEquals(jobUuid, requestEvent2.getJobId());
}
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(2, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
ApiResponseEvent responseEvent2 = (ApiResponseEvent) apiResponseEvents.get(1);
assertEquals(jobUuid, responseEvent.getJobId());
assertEquals(jobUuid, responseEvent2.getJobId());
assertEquals(200, responseEvent2.getResponseCode());
assertTrue(requestEvent.getRequestId().equals(responseEvent.getRequestId()) || requestEvent.getRequestId().equalsIgnoreCase(responseEvent2.getRequestId()));
assertTrue(requestEvent2.getRequestId().equals(responseEvent.getRequestId()) || requestEvent2.getRequestId().equalsIgnoreCase(responseEvent2.getRequestId()));
assertEquals(requestEvent2.getRequestId(), responseEvent2.getRequestId());
// Technically the job status change has 1 entry but should have more because
// it went through the entire process, but because it is done manually here
// events weren't created for it.
assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class)));
}
use of gov.cms.ab2d.common.dto.StartJobDTO in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testPatientExportWithParameters.
@Test
void testPatientExportWithParameters() throws Exception {
final String typeParams = "?_type=ExplanationOfBenefit&_outputFormat=application/fhir+ndjson&since=20191015";
ResultActions resultActions = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/" + PATIENT_EXPORT_PATH + typeParams).header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON));
String jobUuid = jobClientMock.pickAJob();
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
String statusUrl = "http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/$status";
resultActions.andExpect(status().isAccepted()).andExpect(header().string(CONTENT_LOCATION, statusUrl));
assertEquals("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH + typeParams, startJobDTO.getUrl());
assertEquals(EOB, startJobDTO.getResourceTypes());
assertEquals(pdpClientRepository.findByClientId(TEST_PDP_CLIENT).getOrganization(), startJobDTO.getOrganization());
}
use of gov.cms.ab2d.common.dto.StartJobDTO in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testGetStatusWhileFinishedHttps.
@Test
void testGetStatusWhileFinishedHttps() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH + "?_type=ExplanationOfBenefit").header("Authorization", "Bearer " + token).header("X-Forwarded-Proto", "https").contentType(MediaType.APPLICATION_JSON)).andReturn();
String statusUrl = mvcResult.getResponse().getHeader(CONTENT_LOCATION);
assertNotNull(statusUrl);
String jobUuid = jobClientMock.pickAJob();
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
JobOutput jobOutput = new JobOutput();
jobOutput.setFhirResourceType(EOB);
jobOutput.setFilePath("file.ndjson");
jobOutput.setError(false);
jobOutput.setChecksum("ABCD");
jobOutput.setFileLength(10L);
jobClientMock.addJobOutputForDownload(jobOutput);
JobOutput errorJobOutput = new JobOutput();
errorJobOutput.setFhirResourceType(OPERATION_OUTCOME);
errorJobOutput.setFilePath("error.ndjson");
errorJobOutput.setError(true);
errorJobOutput.setChecksum("1010F");
errorJobOutput.setFileLength(20L);
jobClientMock.addJobOutputForDownload(errorJobOutput);
this.mockMvc.perform(get(statusUrl).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(200)).andExpect(buildExpiresMatcher()).andExpect(jsonPath("$.transactionTime", Is.is(new org.hl7.fhir.dstu3.model.DateTimeType(OffsetDateTime.now().toString()).toHumanDisplay()))).andExpect(jsonPath("$.request", Is.is(startJobDTO.getUrl()))).andExpect(jsonPath("$.requiresAccessToken", Is.is(true))).andExpect(jsonPath("$.output[0].type", Is.is(EOB))).andExpect(jsonPath("$.output[0].url", Is.is("https://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/file.ndjson"))).andExpect(jsonPath("$.error[0].type", Is.is(OPERATION_OUTCOME))).andExpect(jsonPath("$.error[0].url", Is.is("https://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/error.ndjson")));
}
use of gov.cms.ab2d.common.dto.StartJobDTO in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testBasicPatientExport.
@Test
void testBasicPatientExport() throws Exception {
ResultActions resultActions = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
assertEquals(1, apiRequestEvents.size());
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(1, apiResponseEvents.size());
assertEquals(HttpStatus.ACCEPTED.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
List<LoggableEvent> jobEvents = loggerEventRepository.load(JobStatusChangeEvent.class);
assertEquals(1, jobEvents.size());
JobStatusChangeEvent jobEvent = (JobStatusChangeEvent) jobEvents.get(0);
assertEquals(SUBMITTED.name(), jobEvent.getNewStatus());
assertNull(jobEvent.getOldStatus());
assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class)));
String jobUuid = jobClientMock.pickAJob();
assertEquals(jobUuid, responseEvent.getJobId());
String statusUrl = "http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/$status";
resultActions.andExpect(status().isAccepted()).andExpect(header().string(CONTENT_LOCATION, statusUrl));
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
assertEquals("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH, startJobDTO.getUrl());
assertEquals(EOB, startJobDTO.getResourceTypes());
assertEquals(pdpClientRepository.findByClientId(TEST_PDP_CLIENT).getOrganization(), startJobDTO.getOrganization());
}
Aggregations