Search in sources :

Example 16 with Condition

use of org.hl7.fhir.dstu3.model.Condition in project bunsen by cerner.

the class BroadcastableMappings method broadcast.

/**
 * Broadcast mappings stored in the given conceptMaps instance that match the given
 * conceptMapUris.
 *
 * @param conceptMaps the {@link ConceptMaps} instance with the content to broadcast
 * @param conceptMapUriToVersion map of the concept map URIs to broadcast to their versions.
 * @return a broadcast variable containing a mappings object usable in UDFs.
 */
public static Broadcast<BroadcastableMappings> broadcast(ConceptMaps conceptMaps, Map<String, String> conceptMapUriToVersion) {
    Map<String, ConceptMap> mapsToLoad = conceptMaps.getMaps().collectAsList().stream().filter(conceptMap -> conceptMap.getVersion().equals(conceptMapUriToVersion.get(conceptMap.getUrl()))).collect(Collectors.toMap(ConceptMap::getUrl, Function.identity()));
    // Expand the concept maps to load and sort them so dependencies are before
    // their dependents in the list.
    List<String> sortedMapsToLoad = sortMapsToLoad(conceptMapUriToVersion.keySet(), mapsToLoad);
    // Since this is used to map from one system to another, we use only targets
    // that don't introduce inaccurate meanings. (For instance, we can't map
    // general condition code to a more specific type, since that is not
    // representative of the source data.)
    Dataset<Mapping> mappings = conceptMaps.getMappings(conceptMapUriToVersion).filter("equivalence in ('equivalent', 'equals', 'wider', 'subsumes')");
    // Group mappings by their concept map URI
    Map<String, List<Mapping>> groupedMappings = mappings.collectAsList().stream().collect(Collectors.groupingBy(Mapping::getConceptMapUri));
    Map<String, BroadcastableConceptMap> broadcastableMaps = new HashMap<>();
    for (String conceptMapUri : sortedMapsToLoad) {
        ConceptMap map = mapsToLoad.get(conceptMapUri);
        Set<String> children = getMapChildren(map);
        List<BroadcastableConceptMap> childMaps = children.stream().map(child -> broadcastableMaps.get(child)).collect(Collectors.toList());
        BroadcastableConceptMap broadcastableConceptMap = new BroadcastableConceptMap(conceptMapUri, groupedMappings.getOrDefault(conceptMapUri, Collections.emptyList()), childMaps);
        broadcastableMaps.put(conceptMapUri, broadcastableConceptMap);
    }
    JavaSparkContext ctx = new JavaSparkContext(conceptMaps.getMaps().sparkSession().sparkContext());
    return ctx.broadcast(new BroadcastableMappings(broadcastableMaps));
}
Also used : Broadcast(org.apache.spark.broadcast.Broadcast) Dataset(org.apache.spark.sql.Dataset) ConceptMaps(com.cerner.bunsen.codes.ConceptMaps) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Set(java.util.Set) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) ConceptMapGroupUnmappedMode(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupUnmappedMode) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Mapping(com.cerner.bunsen.codes.Mapping) SparkSession(org.apache.spark.sql.SparkSession) HashMap(java.util.HashMap) Mapping(com.cerner.bunsen.codes.Mapping) ArrayList(java.util.ArrayList) List(java.util.List) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap)

Example 17 with Condition

use of org.hl7.fhir.dstu3.model.Condition in project jcabi-dynamo by jcabi.

the class ConditionsTest method workAsMapOfConditions.

/**
 * Conditions can work as a map of conditions.
 * @throws Exception If some problem inside
 */
@Test
public void workAsMapOfConditions() throws Exception {
    final String name = "id";
    final Condition condition = new Condition();
    final Map<String, Condition> conds = new Conditions().with(name, condition);
    MatcherAssert.assertThat(conds.keySet(), Matchers.hasSize(1));
    MatcherAssert.assertThat(conds, Matchers.hasEntry(name, condition));
    MatcherAssert.assertThat(new Conditions(conds), Matchers.hasEntry(name, condition));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) Test(org.junit.Test)

Example 18 with Condition

use of org.hl7.fhir.dstu3.model.Condition in project jcabi-dynamo by jcabi.

the class H2Data method iterate.

@Override
public Iterable<Attributes> iterate(final String table, final Conditions conds) throws IOException {
    try {
        final StringBuilder sql = new StringBuilder("SELECT * FROM ").append(H2Data.encodeTableName(table));
        if (!conds.isEmpty()) {
            sql.append(" WHERE ");
            Joiner.on(H2Data.AND).appendTo(sql, Iterables.transform(conds.keySet(), H2Data.WHERE));
        }
        JdbcSession session = new JdbcSession(this.connection()).sql(sql.toString());
        for (final Condition cond : conds.values()) {
            if (cond.getAttributeValueList().size() != 1) {
                throw new UnsupportedOperationException("at the moment only one value of condition is supported");
            }
            if (!cond.getComparisonOperator().equals(ComparisonOperator.EQ.toString())) {
                throw new UnsupportedOperationException(String.format("at the moment only EQ operator is supported: %s", cond.getComparisonOperator()));
            }
            final AttributeValue val = cond.getAttributeValueList().get(0);
            session = session.set(H2Data.value(val));
        }
        return session.select(H2Data.OUTCOME);
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
Also used : JdbcSession(com.jcabi.jdbc.JdbcSession) Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 19 with Condition

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

the class DynamoDBDynamicFaultInjection method main.

public static void main(String[] args) throws Exception {
    init();
    try {
        // Create a table with a primary key named 'name', which holds a
        // string
        createTable();
        // Describe our new table
        describeTable();
        // Add some items
        putItem(newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"));
        putItem(newItem("Airplane", 1980, "*****", "James", "Billy Bob"));
        // Get some items
        getItem("Airplane");
        getItem("Bill & Ted's Excellent Adventure");
        // Scan items for movies with a year attribute greater than 1985
        Map<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
        scanFilter.put("year", condition);
        ScanRequest scanRequest = new ScanRequest(TABLENAME).withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDBClient.scan(scanRequest);
        logger.info("Result: " + scanResult);
    } catch (AmazonServiceException ase) {
        logger.error("Service Exception: " + ase);
    } catch (AmazonClientException ace) {
        logger.error("Client Exception: " + ace);
    }
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) HashMap(java.util.HashMap) AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 20 with Condition

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

the class LowLevelQuery method makeReplyKeyConditions.

/**
 * A simple helper function that returns a KeyCondition map filled in with
 * the partition key equality condition for a the Reply example table, given
 * a forumName and threadSubject.
 */
private static Map<String, Condition> makeReplyKeyConditions(String forumName, String threadSubject) {
    String replyId = forumName + "#" + threadSubject;
    Condition partitionKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(replyId));
    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    keyConditions.put("Id", partitionKeyCondition);
    return keyConditions;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap)

Aggregations

Condition (com.amazonaws.services.dynamodbv2.model.Condition)16 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)14 HashMap (java.util.HashMap)9 Condition (org.hl7.fhir.dstu3.model.Condition)7 Test (org.junit.Test)7 QueryRequest (com.amazonaws.services.dynamodbv2.model.QueryRequest)6 QueryResult (com.amazonaws.services.dynamodbv2.model.QueryResult)6 Map (java.util.Map)5 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)2 IdDt (ca.uhn.fhir.model.primitive.IdDt)1 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)1 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1