Search in sources :

Example 1 with Condition

use of org.hl7.fhir.r4.model.Condition in project openhab1-addons by openhab.

the class DynamoDBPersistenceService method constructTimeCondition.

private Condition constructTimeCondition(FilterCriteria filter) {
    boolean hasBegin = filter.getBeginDate() != null;
    boolean hasEnd = filter.getEndDate() != null;
    final Condition timeCondition;
    if (!hasBegin && !hasEnd) {
        timeCondition = null;
    } else if (!hasBegin && hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.LE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    } else if (hasBegin && !hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.GE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())));
    } else {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())), new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    }
    return timeCondition;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue)

Example 2 with Condition

use of org.hl7.fhir.r4.model.Condition in project openhab1-addons by openhab.

the class DynamoDBPersistenceService method createQueryExpression.

/**
     * Construct dynamodb query from filter
     *
     * @param filter
     * @return DynamoDBQueryExpression corresponding to the given FilterCriteria
     */
private DynamoDBQueryExpression<DynamoDBItem<?>> createQueryExpression(Class<? extends DynamoDBItem<?>> dtoClass, FilterCriteria filter) {
    DynamoDBItem<?> item = getDynamoDBHashKey(dtoClass, filter.getItemName());
    final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = new DynamoDBQueryExpression<DynamoDBItem<?>>().withHashKeyValues(item).withScanIndexForward(filter.getOrdering() == Ordering.ASCENDING).withLimit(filter.getPageSize());
    Condition timeFilter = maybeAddTimeFilter(queryExpression, filter);
    maybeAddStateFilter(filter, queryExpression);
    logger.debug("Querying: {} with {}", filter.getItemName(), timeFilter);
    return queryExpression;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition)

Example 3 with Condition

use of org.hl7.fhir.r4.model.Condition in project aws-doc-sdk-examples by awsdocs.

the class LowLevelGlobalSecondaryIndexExample method queryIndex.

public static void queryIndex(String indexName) {
    System.out.println("\n***********************************************************\n");
    System.out.print("Querying index " + indexName + "...");
    QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withIndexName(indexName).withScanIndexForward(true);
    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
    if (indexName == "CreateDateIndex") {
        System.out.println("Issues filed on 2013-11-01");
        keyConditions.put("CreateDate", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS("2013-11-01")));
        keyConditions.put("IssueId", new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH).withAttributeValueList(new AttributeValue().withS("A-")));
    } else if (indexName == "TitleIndex") {
        System.out.println("Compilation errors");
        keyConditions.put("Title", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS("Compilation error")));
        keyConditions.put("IssueId", new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH).withAttributeValueList(new AttributeValue().withS("A-")));
        // Select
        queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
    } else if (indexName == "DueDateIndex") {
        System.out.println("Items that are due on 2013-11-30");
        keyConditions.put("DueDate", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS("2013-11-30")));
        // Select
        queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
    } else {
        System.out.println("\nNo valid index name provided");
        return;
    }
    queryRequest.setKeyConditions(keyConditions);
    QueryResult result = client.query(queryRequest);
    List<Map<String, AttributeValue>> items = result.getItems();
    Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
    System.out.println();
    while (itemsIter.hasNext()) {
        Map<String, AttributeValue> currentItem = itemsIter.next();
        Iterator<String> currentItemIter = currentItem.keySet().iterator();
        while (currentItemIter.hasNext()) {
            String attr = (String) currentItemIter.next();
            if (attr == "Priority") {
                System.out.println(attr + "---> " + currentItem.get(attr).getN());
            } else {
                System.out.println(attr + "---> " + currentItem.get(attr).getS());
            }
        }
        System.out.println();
    }
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) QueryResult(com.amazonaws.services.dynamodbv2.model.QueryResult) QueryRequest(com.amazonaws.services.dynamodbv2.model.QueryRequest) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Condition

use of org.hl7.fhir.r4.model.Condition in project aws-doc-sdk-examples by awsdocs.

the class LowLevelLocalSecondaryIndexExample method query.

public static void query(String indexName) {
    System.out.println("\n***********************************************************\n");
    System.out.println("Querying table " + tableName + "...");
    QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withConsistentRead(true).withScanIndexForward(true).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("CustomerId", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS("bob@example.com")));
    if (indexName == "IsOpenIndex") {
        System.out.println("\nUsing index: '" + indexName + "': Bob's orders that are open.");
        System.out.println("Only a user-specified list of attributes are returned\n");
        queryRequest.setIndexName(indexName);
        keyConditions.put("IsOpen", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withN("1")));
        // ProjectionExpression
        queryRequest.setProjectionExpression("OrderCreationDate, ProductCategory, ProductName, OrderStatus");
    } else if (indexName == "OrderCreationDateIndex") {
        System.out.println("\nUsing index: '" + indexName + "': Bob's orders that were placed after 01/31/2013.");
        System.out.println("Only the projected attributes are returned\n");
        queryRequest.setIndexName(indexName);
        keyConditions.put("OrderCreationDate", new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(new AttributeValue().withN("20130131")));
        // Select
        queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
    } else {
        System.out.println("\nNo index: All of Bob's orders, by OrderId:\n");
    }
    queryRequest.setKeyConditions(keyConditions);
    QueryResult result = client.query(queryRequest);
    List<Map<String, AttributeValue>> items = result.getItems();
    Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
    while (itemsIter.hasNext()) {
        Map<String, AttributeValue> currentItem = itemsIter.next();
        Iterator<String> currentItemIter = currentItem.keySet().iterator();
        while (currentItemIter.hasNext()) {
            String attr = (String) currentItemIter.next();
            if (attr == "OrderId" || attr == "IsOpen" || attr == "OrderCreationDate") {
                System.out.println(attr + "---> " + currentItem.get(attr).getN());
            } else {
                System.out.println(attr + "---> " + currentItem.get(attr).getS());
            }
        }
        System.out.println();
    }
    System.out.println("\nConsumed capacity: " + result.getConsumedCapacity() + "\n");
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) QueryResult(com.amazonaws.services.dynamodbv2.model.QueryResult) QueryRequest(com.amazonaws.services.dynamodbv2.model.QueryRequest) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Condition

use of org.hl7.fhir.r4.model.Condition in project aws-doc-sdk-examples by awsdocs.

the class LowLevelQuery method findRepliesInLast15DaysWithConfig.

private static void findRepliesInLast15DaysWithConfig(String forumName, String threadSubject) {
    long twoWeeksAgoMilli = (new Date()).getTime() - (15L * 24L * 60L * 60L * 1000L);
    Date twoWeeksAgo = new Date();
    twoWeeksAgo.setTime(twoWeeksAgoMilli);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    String twoWeeksAgoStr = df.format(twoWeeksAgo);
    Condition sortKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr));
    Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
    keyConditions.put("ReplyDateTime", sortKeyCondition);
    QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withKeyConditions(keyConditions).withProjectionExpression("Message, ReplyDateTime, PostedBy");
    QueryResult result = client.query(queryRequest);
    for (Map<String, AttributeValue> item : result.getItems()) {
        printItem(item);
    }
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) QueryResult(com.amazonaws.services.dynamodbv2.model.QueryResult) QueryRequest(com.amazonaws.services.dynamodbv2.model.QueryRequest) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Test (org.junit.Test)178 Condition (org.hl7.fhir.r4.model.Condition)139 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)88 Condition (com.amazonaws.services.dynamodbv2.model.Condition)77 Condition (org.hl7.fhir.dstu3.model.Condition)57 Bundle (org.hl7.fhir.r4.model.Bundle)50 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)46 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)44 Test (org.junit.jupiter.api.Test)41 Coding (org.hl7.fhir.r4.model.Coding)39 Date (java.util.Date)35 HashMap (java.util.HashMap)34 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)34 Reference (org.hl7.fhir.r4.model.Reference)32 Resource (org.hl7.fhir.r4.model.Resource)26 Test (org.testng.annotations.Test)25 Patient (org.hl7.fhir.r4.model.Patient)23 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)19