Search in sources :

Example 1 with DateRangeResourceList

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();
    }
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 2 with DateRangeResourceList

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 3 with DateRangeResourceList

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()));
}
Also used : AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) Test(org.testng.annotations.Test)

Example 4 with DateRangeResourceList

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()));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ENTEREDINERROR(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.ENTEREDINERROR) CANCELLED(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.CANCELLED) SYN_USERNAME(org.sagebionetworks.bridge.spring.controllers.CRCController.SYN_USERNAME) Identifier(org.hl7.fhir.dstu3.model.Identifier) APPOINTMENT_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.APPOINTMENT_REPORT) Test(org.testng.annotations.Test) RequestContext(org.sagebionetworks.bridge.RequestContext) AfterMethod(org.testng.annotations.AfterMethod) StatusLine(org.apache.http.StatusLine) EMAIL(org.sagebionetworks.bridge.TestConstants.EMAIL) MockitoAnnotations(org.mockito.MockitoAnnotations) CUIMC_USERNAME(org.sagebionetworks.bridge.spring.controllers.CRCController.CUIMC_USERNAME) NotAuthenticatedException(org.sagebionetworks.bridge.exceptions.NotAuthenticatedException) JsonNode(com.fasterxml.jackson.databind.JsonNode) RESEARCHER(org.sagebionetworks.bridge.Roles.RESEARCHER) Assert.assertFalse(org.testng.Assert.assertFalse) BOOKED(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED) TIMESTAMP_FIELD(org.sagebionetworks.bridge.spring.controllers.CRCController.TIMESTAMP_FIELD) Reference(org.hl7.fhir.dstu3.model.Reference) OBSERVATION_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.OBSERVATION_REPORT) TestUtils.createJson(org.sagebionetworks.bridge.TestUtils.createJson) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Set(java.util.Set) Account(org.sagebionetworks.bridge.models.accounts.Account) IOUtils(org.apache.commons.io.IOUtils) Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) Stream(java.util.stream.Stream) Logger(ch.qos.logback.classic.Logger) USER_STUDY_IDS(org.sagebionetworks.bridge.TestConstants.USER_STUDY_IDS) TestUtils.mockRequestBody(org.sagebionetworks.bridge.TestUtils.mockRequestBody) TEST_ORG_ID(org.sagebionetworks.bridge.TestConstants.TEST_ORG_ID) ContactPointSystem(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) SHIP_TESTS_REQUESTED(org.sagebionetworks.bridge.spring.controllers.CRCController.AccountStates.SHIP_TESTS_REQUESTED) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) IP_ADDRESS(org.sagebionetworks.bridge.TestConstants.IP_ADDRESS) Mock(org.mockito.Mock) PHONE(org.sagebionetworks.bridge.TestConstants.PHONE) GBFOrderService(org.sagebionetworks.bridge.services.GBFOrderService) AppointmentStatus(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus) Roles(org.sagebionetworks.bridge.Roles) BridgeObjectMapper(org.sagebionetworks.bridge.json.BridgeObjectMapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) GBF_TEST_KIT_SHIP_METHOD(org.sagebionetworks.bridge.spring.controllers.CRCController.GBF_TEST_KIT_SHIP_METHOD) App(org.sagebionetworks.bridge.models.apps.App) PROCEDURE_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.PROCEDURE_REPORT) LimitExceededException(org.sagebionetworks.bridge.exceptions.LimitExceededException) InjectMocks(org.mockito.InjectMocks) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) SHIPMENT_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.SHIPMENT_REPORT) SHIPMENT_REPORT_KEY_ORDER_ID(org.sagebionetworks.bridge.spring.controllers.CRCController.SHIPMENT_REPORT_KEY_ORDER_ID) Patient(org.hl7.fhir.dstu3.model.Patient) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) HttpResponse(org.apache.http.HttpResponse) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) AUTHORIZATION(com.google.common.net.HttpHeaders.AUTHORIZATION) LoggerFactory(org.slf4j.LoggerFactory) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) Spy(org.mockito.Spy) USER_AGENT(com.google.common.net.HttpHeaders.USER_AGENT) TestUtils(org.sagebionetworks.bridge.TestUtils) APP_ID(org.sagebionetworks.bridge.spring.controllers.CRCController.APP_ID) ImmutableSet(com.google.common.collect.ImmutableSet) Address(org.hl7.fhir.dstu3.model.Address) ImmutableMap(com.google.common.collect.ImmutableMap) TEST_USER_ID(org.sagebionetworks.bridge.TestConstants.TEST_USER_ID) HttpEntity(org.apache.http.HttpEntity) BeforeMethod(org.testng.annotations.BeforeMethod) USER_ID_VALUE_NS(org.sagebionetworks.bridge.spring.controllers.CRCController.USER_ID_VALUE_NS) Appointment(org.hl7.fhir.dstu3.model.Appointment) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AppService(org.sagebionetworks.bridge.services.AppService) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) AccountService(org.sagebionetworks.bridge.services.AccountService) Base64(java.util.Base64) ParticipantService(org.sagebionetworks.bridge.services.ParticipantService) Optional(java.util.Optional) BridgeUtils(org.sagebionetworks.bridge.BridgeUtils) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) TestConstants(org.sagebionetworks.bridge.TestConstants) UTF_8(com.google.common.base.Charsets.UTF_8) Captor(org.mockito.Captor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ReportService(org.sagebionetworks.bridge.services.ReportService) Appender(ch.qos.logback.core.Appender) BridgeConfig(org.sagebionetworks.bridge.config.BridgeConfig) IParser(ca.uhn.fhir.parser.IParser) InOrder(org.mockito.InOrder) Assert.fail(org.testng.Assert.fail) HttpServletResponse(javax.servlet.http.HttpServletResponse) ShippingConfirmations(org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmations) LocalDate(org.joda.time.LocalDate) Mockito(org.mockito.Mockito) HealthDataService(org.sagebionetworks.bridge.services.HealthDataService) Level(ch.qos.logback.classic.Level) TEST_USER_GROUP(org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP) TIMESTAMP(org.sagebionetworks.bridge.TestConstants.TIMESTAMP) FHIR_CONTEXT(org.sagebionetworks.bridge.spring.controllers.CRCController.FHIR_CONTEXT) Assert.assertTrue(org.testng.Assert.assertTrue) ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) Test(org.testng.annotations.Test)

Example 5 with DateRangeResourceList

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);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) Account(org.sagebionetworks.bridge.models.accounts.Account) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Aggregations

DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)16 Test (org.testng.annotations.Test)15 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)11 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)10 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)8 Appointment (org.hl7.fhir.dstu3.model.Appointment)6 Account (org.sagebionetworks.bridge.models.accounts.Account)6 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)6 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)2 HttpEntity (org.apache.http.HttpEntity)2 HttpResponse (org.apache.http.HttpResponse)2 StatusLine (org.apache.http.StatusLine)2 LocalDate (org.joda.time.LocalDate)2 InOrder (org.mockito.InOrder)2 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)2 IParser (ca.uhn.fhir.parser.IParser)1 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 Appender (ch.qos.logback.core.Appender)1