use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method internalLabShipmentRequestSetsShipMethod.
@Test
public void internalLabShipmentRequestSetsShipMethod() {
setupParticipantAuthentication();
setupShippingAddress();
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, SHIPMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
ArgumentCaptor<Order> orderCaptor = ArgumentCaptor.forClass(Order.class);
controller.internalLabShipmentRequest(mockApp, AccountId.forId(APP_ID, TEST_USER_ID));
verify(mockGBFOrderService).placeOrder(orderCaptor.capture(), anyBoolean());
Order requestedOrder = orderCaptor.getValue();
assertEquals(requestedOrder.ShippingInfo.ShipMethod, GBF_TEST_KIT_SHIP_METHOD);
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postObservationFailsOnUnknownTestCode.
@Test
public void postObservationFailsOnUnknownTestCode() 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_PCR_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 postObservationUpdated.
@Test
public void postObservationUpdated() 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(ReportData.create()));
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 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\":\"" + OBSERVATION_REPORT + "\"}");
assertEquals(healthData.getData().toString(), json);
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postProcedureCreated.
@Test
public void postProcedureCreated() 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);
InOrder inorder = inOrder(mockAccountService, mockHealthDataService, mockReportService);
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
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 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");
inorder.verify(mockAccountService).updateAccount(accountCaptor.capture());
Account capturedAcct = accountCaptor.getValue();
assertEquals(capturedAcct.getDataGroups(), makeSetOf(CRCController.AccountStates.TESTS_COLLECTED, "group1"));
assertEquals(capturedAcct.getAttributes().get(TIMESTAMP_FIELD), TIMESTAMP.toString());
inorder.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);
inorder.verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(PROCEDURE_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);
}
use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentCancelled.
@Test
public void postAppointmentCancelled() 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(ReportData.create()));
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
Appointment appointment = new Appointment();
appointment.setStatus(CANCELLED);
addAppointmentParticipantComponent(appointment, LOCATION_NS + "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 updated (status = cancelled).");
assertEquals(retValue.getStatusCodeValue(), 200);
assertTrue(account.getDataGroups().contains("tests_cancelled"));
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_CANCELLED);
}
Aggregations