Search in sources :

Example 1 with Value

use of com.cerner.bunsen.spark.codes.Value in project bunsen by cerner.

the class ValueSetsTest method testCreateSimpleValueSets.

@Test
public void testCreateSimpleValueSets() {
    ValueSets valueSets = ValueSets.getEmpty(spark).withValueSets(valueSet("urn:cerner:valueset:valueset1", "1"), valueSet("urn:cerner:valueset:valueset2", "1"));
    Dataset<Value> values = valueSets.getValues();
    Assert.assertEquals(2, values.count());
    ValueSet firstValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset1", "1");
    checkValueSet(firstValueSet, "urn:cerner:valueset:valueset1", "1");
    ValueSet secondValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset2", "1");
    checkValueSet(secondValueSet, "urn:cerner:valueset:valueset2", "1");
}
Also used : Value(com.cerner.bunsen.spark.codes.Value) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Test(org.junit.Test)

Example 2 with Value

use of com.cerner.bunsen.spark.codes.Value in project bunsen by cerner.

the class MockValueSets method createWithTestValue.

/**
 * Convenience method to create a MockValueSets instance with some test data.
 */
public static MockValueSets createWithTestValue(SparkSession spark, SparkRowConverter valueSetRowConverter) {
    Dataset<UrlAndVersion> urlAndVersion = spark.createDataset(ImmutableList.of(new UrlAndVersion("http://hl7.org/fhir/us/core/ValueSet/us-core-encounter-type", "1.1.0"), new UrlAndVersion("http://hl7.org/fhir/ValueSet/v3-ActPriority", "2017-04-19")), AbstractValueSets.getUrlAndVersionEncoder());
    Dataset<Row> valueSet = valueSetRowConverter.toDataFrame(spark, ImmutableList.of(new ValueSet().setUrl("http://hl7.org/fhir/us/core/ValueSet/us-core-encounter-type").setVersion("1.1.0"), new ValueSet().setUrl("http://hl7.org/fhir/ValueSet/v3-ActPriority").setVersion("2017-04-19"))).withColumn("timestamp", lit("20180101120000").cast("timestamp"));
    Dataset<Value> values = spark.createDataset(ImmutableList.of(new Value("http://hl7.org/fhir/us/core/ValueSet/us-core-encounter-type", "1.1.0", "http://www.ama-assn.org/go/cpt", "0.0.1", "99200"), new Value("http://hl7.org/fhir/ValueSet/v3-ActPriority", "2017-04-19", "http://hl7.org/fhir/v3/ActPriority", "2017-04-19", "EM")), AbstractValueSets.getValueEncoder());
    return new MockValueSets(spark, urlAndVersion, valueSet, values, valueSetRowConverter);
}
Also used : UrlAndVersion(com.cerner.bunsen.spark.codes.UrlAndVersion) Value(com.cerner.bunsen.spark.codes.Value) Row(org.apache.spark.sql.Row) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 3 with Value

use of com.cerner.bunsen.spark.codes.Value in project bunsen by cerner.

the class ValueSetsTest method testExpandValues.

@Test
public void testExpandValues() {
    ValueSet valueSet = ValueSets.getEmpty(spark).withValueSets(valueSet("urn:cerner:valueset:valueset", "1")).getValueSet("urn:cerner:valueset:valueset", "1");
    List<Value> values = ValueSets.expandValues(valueSet);
    Value expectedValue = new Value("urn:cerner:valueset:valueset", "1", "urn:cerner:system", "1", "a");
    Assert.assertEquals(1, values.size());
    Assert.assertEquals(expectedValue, values.get(0));
}
Also used : Value(com.cerner.bunsen.spark.codes.Value) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Test(org.junit.Test)

Example 4 with Value

use of com.cerner.bunsen.spark.codes.Value in project bunsen by cerner.

the class ValueSets method addToValueSet.

@Override
protected void addToValueSet(ValueSet valueSet, Dataset<Value> values) {
    ValueSetComposeComponent composeComponent = valueSet.getCompose();
    ConceptSetComponent currentInclusion = null;
    ConceptReferenceComponent concept = null;
    List<Value> sortedValues = values.sort("system", "version", "value").collectAsList();
    // Workaround for the decoder producing an immutable array by replacing it with a mutable one
    composeComponent.setInclude(new ArrayList<>(composeComponent.getInclude()));
    for (Value value : sortedValues) {
        if (currentInclusion == null || !value.getSystem().equals(currentInclusion.getSystem()) || !value.getVersion().equals(currentInclusion.getVersion())) {
            // Find a matching inclusion
            for (ConceptSetComponent candidate : composeComponent.getInclude()) {
                if (value.getSystem().equals(candidate.getSystem()) && value.getVersion().equals(candidate.getVersion())) {
                    currentInclusion = candidate;
                    // Workaround for the decoder producing an immutable array by replacing it with a
                    // mutable one
                    currentInclusion.setConcept(new ArrayList<>(currentInclusion.getConcept()));
                }
            }
            // No matching inclusion found, so add one
            if (currentInclusion == null) {
                currentInclusion = composeComponent.addInclude();
                currentInclusion.setSystem(value.getSystem());
                currentInclusion.setVersion(value.getVersion());
                concept = null;
            }
        }
        // Create concept if not exists
        if (concept == null || !value.getValue().equals(concept.getCode())) {
            concept = currentInclusion.addConcept();
            concept.setCode(value.getValue());
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) Value(com.cerner.bunsen.spark.codes.Value) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 5 with Value

use of com.cerner.bunsen.spark.codes.Value in project bunsen by cerner.

the class ValueSets method expandValuesIterator.

private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {
    List<Value> values = new ArrayList<>();
    ValueSetComposeComponent compose = valueSet.getCompose();
    for (ConceptSetComponent inclusion : compose.getInclude()) {
        for (ConceptReferenceComponent concept : inclusion.getConcept()) {
            Value value = new Value();
            value.setValueSetUri(valueSet.getUrl());
            value.setValueSetVersion(valueSet.getVersion());
            value.setSystem(inclusion.getSystem());
            value.setVersion(inclusion.getVersion());
            value.setValue(concept.getCode());
            values.add(value);
        }
    }
    return values.iterator();
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) Value(com.cerner.bunsen.spark.codes.Value) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Aggregations

Value (com.cerner.bunsen.spark.codes.Value)6 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)3 UrlAndVersion (com.cerner.bunsen.spark.codes.UrlAndVersion)2 Row (org.apache.spark.sql.Row)2 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)2 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)2 ValueSetComposeComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)2 Test (org.junit.Test)2 FhirVersionEnum (ca.uhn.fhir.context.FhirVersionEnum)1 IParser (ca.uhn.fhir.parser.IParser)1 FhirContexts (com.cerner.bunsen.FhirContexts)1 SparkRowConverter (com.cerner.bunsen.spark.SparkRowConverter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1