use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postObservationCreated.
@Test
public void postObservationCreated() 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(VALID_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, "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 postAppointmentSkipsLocationIfNotPresent.
@Test
public void postAppointmentSkipsLocationIfNotPresent() 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));
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);
addAppointmentSageId(appointment, TEST_USER_ID);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
mockRequestBody(mockRequest, json);
controller.postAppointment();
verify(controller, never()).post(any(), any(), any());
verify(mockHealthDataService).submitHealthData(any(), any(), any());
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class DynamoReportDataDao method getReportData.
@Override
public DateRangeResourceList<? extends ReportData> getReportData(ReportDataKey key, LocalDate startDate, LocalDate endDate) {
checkNotNull(key);
checkNotNull(startDate);
checkNotNull(endDate);
DynamoReportData hashKey = new DynamoReportData();
hashKey.setKey(key.getKeyString());
// range key is between start date and end date
Condition dateCondition = new Condition().withComparisonOperator(BETWEEN).withAttributeValueList(new AttributeValue().withS(startDate.toString()), new AttributeValue().withS(endDate.toString()));
DynamoDBQueryExpression<DynamoReportData> query = new DynamoDBQueryExpression<DynamoReportData>().withHashKeyValues(hashKey).withRangeKeyCondition("date", dateCondition);
List<DynamoReportData> results = mapper.query(DynamoReportData.class, query);
return new DateRangeResourceList<DynamoReportData>(results).withRequestParam(START_DATE, startDate).withRequestParam(END_DATE, endDate);
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentFailsWhenLocationCallFails.
@Test
public void postAppointmentFailsWhenLocationCallFails() 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));
// 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);
HttpResponse mockResponse = mock(HttpResponse.class);
doReturn(mockResponse).when(controller).post(any(), any(), any());
StatusLine mockStatusLine = mock(StatusLine.class);
when(mockResponse.getStatusLine()).thenReturn(mockStatusLine);
when(mockStatusLine.getStatusCode()).thenReturn(400);
HttpEntity mockEntity = mock(HttpEntity.class);
when(mockResponse.getEntity()).thenReturn(mockEntity);
when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("This was an error.", UTF_8));
ResponseEntity<StatusMessage> retValue = controller.postAppointment();
assertEquals(retValue.getBody().getMessage(), "Appointment created (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAppender).doAppend(loggingEventCaptor.capture());
final LoggingEvent loggingEvent = loggingEventCaptor.getValue();
assertEquals(loggingEvent.getLevel(), Level.WARN);
assertEquals(loggingEvent.getFormattedMessage(), "Error retrieving location, id = foo, status = 400, response body = This was an error.");
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postProcedureUpdated.
@Test
public void postProcedureUpdated() 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 = makeProcedureRequest();
mockRequestBody(mockRequest, json);
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of(ReportData.create()));
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, PROCEDURE_REPORT, HEALTH_CODE, JAN1, JAN2);
ResponseEntity<StatusMessage> retValue = controller.postProcedureRequest();
assertEquals(retValue.getBody().getMessage(), "ProcedureRequest updated.");
assertEquals(retValue.getStatusCodeValue(), 200);
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\":\"" + PROCEDURE_REPORT + "\"}");
assertEquals(healthData.getData().toString(), json);
}
Aggregations