Search in sources :

Example 1 with ReportData

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

the class ParticipantReportControllerTest method saveParticipantReportData.

@Test
public void saveParticipantReportData() throws Exception {
    String json = TestUtils.createJson("{'date':'2015-02-12','data':{'field1':'Last','field2':'Name'}}");
    mockRequestBody(mockRequest, json);
    when(mockAccountService.getAccount(any())).thenReturn(Optional.of(mockOtherAccount));
    StatusMessage result = controller.saveParticipantReport(OTHER_PARTICIPANT_ID, REPORT_ID);
    assertEquals(result.getMessage(), "Report data saved.");
    verify(mockReportService).saveParticipantReport(eq(TEST_APP_ID), eq(TEST_USER_ID), eq(REPORT_ID), eq(OTHER_PARTICIPANT_HEALTH_CODE), reportDataCaptor.capture());
    ReportData reportData = reportDataCaptor.getValue();
    assertEquals(reportData.getDate().toString(), LocalDate.parse("2015-02-12").toString());
    assertNull(reportData.getKey());
    assertEquals(reportData.getData().get("field1").asText(), "Last");
    assertEquals(reportData.getData().get("field2").asText(), "Name");
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 2 with ReportData

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

the class ParticipantReportControllerTest method createReport.

private ReportData createReport(DateTime date, String fieldValue1, String fieldValue2) {
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    node.put("field1", fieldValue1);
    node.put("field2", fieldValue2);
    ReportData report = ReportData.create();
    report.setKey("foo:" + TEST_APP_ID);
    report.setDateTime(date);
    report.setData(node);
    return report;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ReportData(org.sagebionetworks.bridge.models.reports.ReportData)

Example 3 with ReportData

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

the class ParticipantReportController method saveParticipantReportForSelf.

@PostMapping({ "/v4/users/self/reports/{identifier}", "/v3/users/self/reports/{identifier}" })
@ResponseStatus(HttpStatus.CREATED)
public StatusMessage saveParticipantReportForSelf(@PathVariable String identifier) {
    UserSession session = getAuthenticatedSession();
    ReportData reportData = parseJson(ReportData.class);
    // set in service, but just so no future use depends on it
    reportData.setKey(null);
    reportService.saveParticipantReport(session.getAppId(), session.getId(), identifier, session.getHealthCode(), reportData);
    return new StatusMessage("Report data saved.");
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 4 with ReportData

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

the class ReportServiceTest method saveStudyReport.

@Test
public void saveStudyReport() {
    ReportData someData = createReport(LocalDate.parse("2015-02-10"), "First", "Name");
    service.saveStudyReport(TEST_APP_ID, IDENTIFIER, someData);
    verify(mockReportDataDao).saveReportData(reportDataCaptor.capture());
    ReportData retrieved = reportDataCaptor.getValue();
    assertEquals(retrieved, someData);
    assertEquals(retrieved.getKey(), STUDY_REPORT_DATA_KEY.getKeyString());
    assertEquals(retrieved.getDate(), "2015-02-10");
    assertEquals(retrieved.getData().get("field1").asText(), "First");
    assertEquals(retrieved.getData().get("field2").asText(), "Name");
    verify(mockReportIndexDao).addIndex(new ReportDataKey.Builder().withAppId(TEST_APP_ID).withReportType(ReportType.STUDY).withIdentifier(IDENTIFIER).build(), null);
}
Also used : ReportDataKey(org.sagebionetworks.bridge.models.reports.ReportDataKey) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) Test(org.testng.annotations.Test)

Example 5 with ReportData

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

the class ReportServiceTest method saveParticipantReportAuthorizes.

@Test(expectedExceptions = EntityNotFoundException.class)
public void saveParticipantReportAuthorizes() {
    setupMismatchedStudies(PARTICIPANT_REPORT_DATA_KEY);
    ReportData data = createReport(START_DATE, "value", "value2");
    service.saveParticipantReport(TEST_APP_ID, "some-other-user", IDENTIFIER, HEALTH_CODE, data);
}
Also used : ReportData(org.sagebionetworks.bridge.models.reports.ReportData) Test(org.testng.annotations.Test)

Aggregations

ReportData (org.sagebionetworks.bridge.models.reports.ReportData)53 Test (org.testng.annotations.Test)36 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)14 ReportDataKey (org.sagebionetworks.bridge.models.reports.ReportDataKey)13 Account (org.sagebionetworks.bridge.models.accounts.Account)11 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)8 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)7 ReportIndex (org.sagebionetworks.bridge.models.reports.ReportIndex)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)7 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)7 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)6 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Condition (com.amazonaws.services.dynamodbv2.model.Condition)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LocalDate (org.joda.time.LocalDate)3 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3