use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class ReportServiceTest method deleteStudyReportRecord.
@Test
public void deleteStudyReportRecord() {
LocalDate startDate = LocalDate.parse("2015-05-05").minusDays(45);
LocalDate endDate = LocalDate.parse("2015-05-05");
DateRangeResourceList<ReportData> emptyResults = new DateRangeResourceList<>(Lists.<ReportData>newArrayList()).withRequestParam("startDate", START_DATE).withRequestParam("endDate", END_DATE);
doReturn(emptyResults).when(mockReportDataDao).getReportData(STUDY_REPORT_DATA_KEY, startDate, endDate);
DateTimeUtils.setCurrentMillisFixed(DateTime.parse("2015-05-05").getMillis());
try {
service.deleteStudyReportRecord(TEST_APP_ID, IDENTIFIER, DATE.toString());
verify(mockReportDataDao).deleteReportDataRecord(STUDY_REPORT_DATA_KEY, DATE.toString());
verify(mockReportDataDao).getReportData(STUDY_REPORT_DATA_KEY, startDate, endDate);
verify(mockReportIndexDao).removeIndex(STUDY_REPORT_DATA_KEY);
} finally {
DateTimeUtils.setCurrentMillisSystem();
}
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postObservationFailsOnInvalidSerumTestValue.
@Test
public void postObservationFailsOnInvalidSerumTestValue() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
String json = makeObservation(INVALID_SERUM_OBSERVATION_JSON);
mockRequestBody(mockRequest, json);
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, OBSERVATION_REPORT, HEALTH_CODE, JAN1, JAN2);
ResponseEntity<StatusMessage> retValue = controller.postObservation();
assertEquals(retValue.getBody().getMessage(), "Observation created.");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAccountService).authenticate(eq(app), signInCaptor.capture());
SignIn capturedSignIn = signInCaptor.getValue();
assertEquals(capturedSignIn.getAppId(), APP_ID);
assertEquals(capturedSignIn.getExternalId(), CUIMC_USERNAME);
assertEquals(capturedSignIn.getPassword(), "dummy-password");
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(OBSERVATION_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
ReportData capturedReport = reportCaptor.getValue();
assertEquals(capturedReport.getDate(), "1970-01-01");
verifySubject(capturedReport.getData());
assertEquals(capturedReport.getStudyIds(), USER_STUDY_IDS);
verify(mockAccountService).updateAccount(accountCaptor.capture());
Account capturedAcct = accountCaptor.getValue();
assertEquals(capturedAcct.getDataGroups(), makeSetOf(CRCController.AccountStates.TESTS_AVAILABLE_TYPE_UNKNOWN, "group1"));
assertEquals(capturedAcct.getAttributes().get(TIMESTAMP_FIELD), TIMESTAMP.toString());
verify(mockHealthDataService).submitHealthData(eq(APP_ID), participantCaptor.capture(), dataCaptor.capture());
HealthDataSubmission healthData = dataCaptor.getValue();
assertEquals(healthData.getAppVersion(), "v1");
assertEquals(healthData.getCreatedOn(), TIMESTAMP);
assertEquals(healthData.getMetadata().toString(), "{\"type\":\"" + OBSERVATION_REPORT + "\"}");
assertEquals(healthData.getData().toString(), json);
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method placeOrderAsParticipant.
@Test
public void placeOrderAsParticipant() {
setupParticipantAuthentication();
setupShippingAddress();
doNothing().when(mockGBFOrderService).placeOrder(any(), eq(true));
ArgumentCaptor<AccountId> accountIdCaptor = ArgumentCaptor.forClass(AccountId.class);
when(mockAccountService.getAccount(accountIdCaptor.capture())).thenReturn(Optional.of(account));
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, SHIPMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
controller.postUserLabShipmentRequest();
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(SHIPMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
verify(controller).internalLabShipmentRequest(any(), any());
ReportData capturedReport = reportCaptor.getValue();
String orderId = capturedReport.getData().get(SHIPMENT_REPORT_KEY_ORDER_ID).asText();
assertTrue(orderId.startsWith(ACCOUNT_ID.getId()));
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method placeOrderForHealthCode.
@Test
public void placeOrderForHealthCode() {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
setupShippingAddress();
ArgumentCaptor<AccountId> accountIdCaptor = ArgumentCaptor.forClass(AccountId.class);
when(mockAccountService.getAccount(accountIdCaptor.capture())).thenReturn(Optional.of(account));
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, SHIPMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
controller.postLabShipmentRequest("healthcode:" + HEALTH_CODE);
verify(mockAccountService).authenticate(any(), any());
verify(mockAccountService, atLeastOnce()).getAccount(accountIdCaptor.capture());
assertTrue(accountIdCaptor.getAllValues().stream().anyMatch(accountId -> accountId.getHealthCode().equals(HEALTH_CODE)));
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(SHIPMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
verify(controller).internalLabShipmentRequest(any(), any());
ReportData capturedReport = reportCaptor.getValue();
String orderId = capturedReport.getData().get(SHIPMENT_REPORT_KEY_ORDER_ID).asText();
assertTrue(orderId.startsWith(ACCOUNT_ID.getId()));
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentCreated.
@Test
public void postAppointmentCreated() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
mockGetLocation(LOCATION_JSON);
// mockGetGeocoding();
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
Appointment appointment = new Appointment();
appointment.setStatus(BOOKED);
// add a wrong participant to verify we go through them all and look for ours
addAppointmentParticipantComponent(appointment, "Location/foo");
addAppointmentSageId(appointment, TEST_USER_ID);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
mockRequestBody(mockRequest, json);
ResponseEntity<StatusMessage> retValue = controller.postAppointment();
assertEquals(retValue.getBody().getMessage(), "Appointment created (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAccountService).authenticate(eq(app), signInCaptor.capture());
SignIn capturedSignIn = signInCaptor.getValue();
assertEquals(capturedSignIn.getAppId(), APP_ID);
assertEquals(capturedSignIn.getExternalId(), CUIMC_USERNAME);
assertEquals(capturedSignIn.getPassword(), "dummy-password");
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(APPOINTMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
ReportData capturedReport = reportCaptor.getValue();
assertEquals(capturedReport.getDate(), "1970-01-01");
verifyParticipant(capturedReport.getData());
assertEquals(capturedReport.getStudyIds(), USER_STUDY_IDS);
verify(mockAccountService).updateAccount(accountCaptor.capture());
Account capturedAcct = accountCaptor.getValue();
assertEquals(capturedAcct.getDataGroups(), makeSetOf(CRCController.AccountStates.TESTS_SCHEDULED, "group1"));
assertEquals(capturedAcct.getAttributes().get(TIMESTAMP_FIELD), TIMESTAMP.toString());
verify(mockHealthDataService).submitHealthData(eq(APP_ID), participantCaptor.capture(), dataCaptor.capture());
HealthDataSubmission healthData = dataCaptor.getValue();
assertEquals(healthData.getAppVersion(), "v1");
assertEquals(healthData.getCreatedOn(), TIMESTAMP);
assertEquals(healthData.getMetadata().toString(), "{\"type\":\"" + APPOINTMENT_REPORT + "\"}");
assertEquals(healthData.getData().toString(), APPOINTMENT_JSON_FULLY_RESOLVED);
}
Aggregations