Search in sources :

Example 16 with DateRangeResourceList

use of org.sagebionetworks.bridge.models.DateRangeResourceList in project BridgeServer2 by Sage-Bionetworks.

the class CRCControllerTest method postAppointmentUpdated.

@Test
public void postAppointmentUpdated() 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(BOOKED);
    // add a wrong participant to verify we go through them all and look for ours
    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 = booked).");
    assertEquals(retValue.getStatusCodeValue(), 200);
    assertTrue(account.getDataGroups().contains("tests_scheduled"));
    verify(controller).addLocation(any(), eq(account), eq("foo"));
    verify(controller).post("http://testServer/location/_search", account, "id=\"foo\"");
    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) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) 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