Search in sources :

Example 26 with Condition

use of org.hl7.fhir.r4.model.Condition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForApp.

@Test
public void getRecordsForApp() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    ForwardCursorPagedResourceList<HealthDataRecordEx3> resultList = dao.getRecordsForApp(TestConstants.TEST_APP_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, null);
    assertEquals(resultList.getItems().size(), 1);
    assertSame(resultList.getItems().get(0), record);
    assertNull(resultList.getNextPageOffsetKey());
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    assertFalse(query.isConsistentRead());
    assertEquals(query.getIndexName(), DynamoHealthDataRecordEx3.APPID_CREATEDON_INDEX);
    assertEquals(query.getHashKeyValues().getAppId(), TestConstants.TEST_APP_ID);
    assertEquals(query.getLimit().intValue(), BridgeConstants.API_DEFAULT_PAGE_SIZE + 1);
    assertEquals(query.getRangeKeyConditions().size(), 1);
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
    assertEquals(rangeKeyCondition.getAttributeValueList().size(), 2);
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
    assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(CREATED_ON_END));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 27 with Condition

use of org.hl7.fhir.r4.model.Condition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode.

@Test
public void getRecordsForHealthCode() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    ForwardCursorPagedResourceList<HealthDataRecordEx3> resultList = dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, null);
    assertEquals(resultList.getItems().size(), 1);
    assertSame(resultList.getItems().get(0), record);
    assertNull(resultList.getNextPageOffsetKey());
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    assertFalse(query.isConsistentRead());
    assertEquals(query.getIndexName(), DynamoHealthDataRecordEx3.HEALTHCODE_CREATEDON_INDEX);
    assertEquals(query.getHashKeyValues().getHealthCode(), TestConstants.HEALTH_CODE);
    assertEquals(query.getLimit().intValue(), BridgeConstants.API_DEFAULT_PAGE_SIZE + 1);
    assertEquals(query.getRangeKeyConditions().size(), 1);
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
    assertEquals(rangeKeyCondition.getAttributeValueList().size(), 2);
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
    assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(CREATED_ON_END));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 28 with Condition

use of org.hl7.fhir.r4.model.Condition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode_offsetKeyAfterCreatedOnStart.

@Test
public void getRecordsForHealthCode_offsetKeyAfterCreatedOnStart() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, String.valueOf(CREATED_ON_START + 10000));
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START + 10000));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) Test(org.testng.annotations.Test)

Example 29 with Condition

use of org.hl7.fhir.r4.model.Condition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode_offsetKeyBeforeCreatedOnStart.

@Test
public void getRecordsForHealthCode_offsetKeyBeforeCreatedOnStart() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, String.valueOf(CREATED_ON_START - 10000));
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) Test(org.testng.annotations.Test)

Example 30 with Condition

use of org.hl7.fhir.r4.model.Condition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoNotificationTopicDao method listTopics.

@Override
public List<NotificationTopic> listTopics(String appId, boolean includeDeleted) {
    checkNotNull(appId);
    // Consistent reads is set to true, because this is the table's primary key, and having reliable tests is more
    // important than saving a small amount of DDB capacity.
    DynamoNotificationTopic hashKey = new DynamoNotificationTopic();
    hashKey.setAppId(appId);
    DynamoDBQueryExpression<DynamoNotificationTopic> query = new DynamoDBQueryExpression<DynamoNotificationTopic>();
    query.withConsistentRead(true);
    query.withHashKeyValues(hashKey);
    if (!includeDeleted) {
        query.withQueryFilterEntry("deleted", new Condition().withComparisonOperator(ComparisonOperator.NE).withAttributeValueList(new AttributeValue().withN("1")));
    }
    QueryResultPage<DynamoNotificationTopic> resultPage = mapper.queryPage(DynamoNotificationTopic.class, query);
    List<DynamoNotificationTopic> topicList = resultPage.getResults();
    // Load criteria.
    topicList.forEach(this::loadCriteria);
    return ImmutableList.copyOf(topicList);
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)

Aggregations

Test (org.junit.Test)178 Condition (org.hl7.fhir.r4.model.Condition)145 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)88 Condition (com.amazonaws.services.dynamodbv2.model.Condition)77 Condition (org.hl7.fhir.dstu3.model.Condition)64 Test (org.junit.jupiter.api.Test)60 Bundle (org.hl7.fhir.r4.model.Bundle)52 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)50 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)44 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)39 Coding (org.hl7.fhir.r4.model.Coding)39 Date (java.util.Date)37 HashMap (java.util.HashMap)35 Reference (org.hl7.fhir.r4.model.Reference)32 Resource (org.hl7.fhir.r4.model.Resource)26 Test (org.testng.annotations.Test)26 ArrayList (java.util.ArrayList)25 Patient (org.hl7.fhir.r4.model.Patient)25 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20