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");
}
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);
}
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));
}
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());
}
}
}
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();
}
Aggregations