Search in sources :

Example 1 with BloodPressureConstraints

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

the class DynamoSurveyDaoTest method getSurveyExcludeElements.

@Test
public void getSurveyExcludeElements() {
    DynamoSurvey survey = new DynamoSurvey();
    mockSurveyMapper(survey);
    // There is a question that should be retrieved.
    DynamoSurveyQuestion element = new DynamoSurveyQuestion();
    element.setType(SurveyElementConstants.SURVEY_QUESTION_TYPE);
    element.setUiHint(UIHint.BLOODPRESSURE);
    element.setConstraints(new BloodPressureConstraints());
    when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
    when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of(element));
    Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, false);
    assertSame(result, survey);
    assertEquals(result.getElements().size(), 0);
    verify(mockSurveyElementMapper, never()).queryPage(eq(DynamoSurveyElement.class), any());
}
Also used : Survey(org.sagebionetworks.bridge.models.surveys.Survey) BloodPressureConstraints(org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints) Test(org.testng.annotations.Test)

Example 2 with BloodPressureConstraints

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

the class DynamoSurveyDaoTest method constraintRulesShiftedToQuestionAfterRules.

@Test
public void constraintRulesShiftedToQuestionAfterRules() {
    DynamoSurvey survey = new DynamoSurvey();
    mockSurveyMapper(survey);
    // This needs to be shifted to the after rules of the question itself
    BloodPressureConstraints constraints = new BloodPressureConstraints();
    constraints.getRules().add(new SurveyRule.Builder().withEndSurvey(true).build());
    SurveyQuestion question = new DynamoSurveyQuestion();
    question.setUiHint(UIHint.BLOODPRESSURE);
    question.setType(SURVEY_QUESTION_TYPE);
    question.setConstraints(constraints);
    when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
    when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of((DynamoSurveyElement) question));
    Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, true);
    SurveyQuestion resultQuestion = result.getUnmodifiableQuestionList().get(0);
    SurveyRule rule = resultQuestion.getAfterRules().get(0);
    assertTrue(rule.getEndSurvey());
}
Also used : Survey(org.sagebionetworks.bridge.models.surveys.Survey) SurveyRule(org.sagebionetworks.bridge.models.surveys.SurveyRule) BloodPressureConstraints(org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints) SurveyQuestion(org.sagebionetworks.bridge.models.surveys.SurveyQuestion) Test(org.testng.annotations.Test)

Example 3 with BloodPressureConstraints

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

the class SurveyServiceTest method updateSurveyValidatesDataGroups.

@Test
public void updateSurveyValidatesDataGroups() {
    app.setDataGroups(ImmutableSet.of("groupA", "groupB", "groupC"));
    Survey existing = Survey.create();
    existing.setAppId(TEST_APP_ID);
    when(mockSurveyDao.getSurvey(any(), any(), eq(false))).thenReturn(existing);
    when(mockSurveyDao.getSurvey(any(), any(), eq(true))).thenReturn(existing);
    Survey update = Survey.create();
    update.setIdentifier("surveyIdentifier");
    update.setName("This is a survey name");
    update.setGuid(BridgeUtils.generateGuid());
    update.setAppId(TEST_APP_ID);
    // Create a data group rule that includes invalid data groups
    SurveyRule rule = new SurveyRule.Builder().withDataGroups(ImmutableSet.of("groupB", "groupdD")).withOperator(Operator.ALL).withEndSurvey(true).build();
    SurveyQuestion element = new DynamoSurveyQuestion();
    element.setIdentifier("anIdentifier");
    element.setPrompt("This is a prompt.");
    element.setConstraints(new BloodPressureConstraints());
    element.setUiHint(UIHint.BLOODPRESSURE);
    element.setAfterRules(ImmutableList.of(rule));
    update.setElements(ImmutableList.of(element));
    try {
        service.updateSurvey(TEST_APP_ID, update);
        fail("Should have thrown an exception");
    } catch (InvalidEntityException e) {
        assertEquals(e.getErrors().get("elements[0].afterRules[0].dataGroups").get(0), "elements[0].afterRules[0].dataGroups contains data groups 'groupB, groupdD' " + "that are not valid data groups: groupA, groupB, groupC");
    }
}
Also used : TestSurvey(org.sagebionetworks.bridge.models.surveys.TestSurvey) Survey(org.sagebionetworks.bridge.models.surveys.Survey) DynamoSurvey(org.sagebionetworks.bridge.dynamodb.DynamoSurvey) SurveyRule(org.sagebionetworks.bridge.models.surveys.SurveyRule) DynamoSurveyQuestion(org.sagebionetworks.bridge.dynamodb.DynamoSurveyQuestion) BloodPressureConstraints(org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) DynamoSurveyQuestion(org.sagebionetworks.bridge.dynamodb.DynamoSurveyQuestion) SurveyQuestion(org.sagebionetworks.bridge.models.surveys.SurveyQuestion) Test(org.testng.annotations.Test)

Example 4 with BloodPressureConstraints

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

the class DynamoSurveyDaoTest method constraintRulesOnQuestionOverwriteConstraintRules.

@Test
public void constraintRulesOnQuestionOverwriteConstraintRules() {
    DynamoSurvey survey = new DynamoSurvey();
    mockSurveyMapper(survey);
    // This needs to be shifted to the after rules of the question itself
    BloodPressureConstraints constraints = new BloodPressureConstraints();
    // This does not have endSurvey as a rule, but it will be replaced
    constraints.getRules().add(new SurveyRule.Builder().build());
    SurveyQuestion question = new DynamoSurveyQuestion();
    question.setAfterRules(ImmutableList.of(new SurveyRule.Builder().withEndSurvey(true).build()));
    question.setUiHint(UIHint.BLOODPRESSURE);
    question.setType(SURVEY_QUESTION_TYPE);
    question.setConstraints(constraints);
    when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
    when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of((DynamoSurveyElement) question));
    Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, true);
    SurveyQuestion resultQuestion = result.getUnmodifiableQuestionList().get(0);
    SurveyRule rule = resultQuestion.getConstraints().getRules().get(0);
    assertTrue(rule.getEndSurvey());
}
Also used : Survey(org.sagebionetworks.bridge.models.surveys.Survey) SurveyRule(org.sagebionetworks.bridge.models.surveys.SurveyRule) BloodPressureConstraints(org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints) SurveyQuestion(org.sagebionetworks.bridge.models.surveys.SurveyQuestion) Test(org.testng.annotations.Test)

Example 5 with BloodPressureConstraints

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

the class DynamoSurveyDaoTest method getSurveyIncludeElementsByIdentifer.

@Test
public void getSurveyIncludeElementsByIdentifer() {
    DynamoSurvey survey = new DynamoSurvey();
    survey.setAppId(TEST_APP_ID);
    survey.setGuid(GUID);
    survey.setIdentifier(SURVEY_ID);
    survey.setCreatedOn(CREATED_ON);
    mockSurveyMapper(survey);
    // There is a question that should be retrieved.
    DynamoSurveyQuestion element = new DynamoSurveyQuestion();
    element.setType(SurveyElementConstants.SURVEY_QUESTION_TYPE);
    element.setUiHint(UIHint.BLOODPRESSURE);
    element.setConstraints(new BloodPressureConstraints());
    when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
    when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of(element));
    Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_IDENTIFIER_KEYS, true);
    assertSame(result, survey);
    assertEquals(result.getElements().size(), 1);
    verify(mockSurveyMapper).queryPage(eq(DynamoSurvey.class), queryCaptor.capture());
    DynamoDBQueryExpression<DynamoSurvey> query = queryCaptor.getValue();
    assertEquals(query.getHashKeyValues().getAppId(), TEST_APP_ID);
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
    assertEquals(rangeKeyCondition.getComparisonOperator(), EQ.name());
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), SURVEY_ID);
    assertEquals(query.getQueryFilter().size(), 1);
    verifyCreatedOnQueryCondition(query);
    verify(mockSurveyElementMapper).queryPage(eq(DynamoSurveyElement.class), elementQueryCaptor.capture());
    DynamoDBQueryExpression<DynamoSurveyElement> elementQuery = elementQueryCaptor.getValue();
    assertEquals(elementQuery.getHashKeyValues().getSurveyCompoundKey(), GUID + ":" + CREATED_ON);
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) Survey(org.sagebionetworks.bridge.models.surveys.Survey) BloodPressureConstraints(org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints) Test(org.testng.annotations.Test)

Aggregations

BloodPressureConstraints (org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints)6 Survey (org.sagebionetworks.bridge.models.surveys.Survey)6 Test (org.testng.annotations.Test)6 SurveyQuestion (org.sagebionetworks.bridge.models.surveys.SurveyQuestion)3 SurveyRule (org.sagebionetworks.bridge.models.surveys.SurveyRule)3 Condition (com.amazonaws.services.dynamodbv2.model.Condition)1 DynamoSurvey (org.sagebionetworks.bridge.dynamodb.DynamoSurvey)1 DynamoSurveyQuestion (org.sagebionetworks.bridge.dynamodb.DynamoSurveyQuestion)1 InvalidEntityException (org.sagebionetworks.bridge.exceptions.InvalidEntityException)1 TestSurvey (org.sagebionetworks.bridge.models.surveys.TestSurvey)1