Search in sources :

Example 6 with ValueSet

use of org.hl7.fhir.r5.model.ValueSet in project bunsen by cerner.

the class ValueSets method getValueSet.

/**
 * Returns the value set with the given uri and version, or null if there is no such value set.
 *
 * @param uri the uri of the value set to return
 * @param version the version of the value set to return
 * @return the specified value set.
 */
public ValueSet getValueSet(String uri, String version) {
    // Load the value sets, which may contain zero items if the value set does not exist
    // Typecast necessary to placate the Java compiler calling this Scala function
    ValueSet[] valueSets = (ValueSet[]) this.valueSets.filter(col("url").equalTo(lit(uri)).and(col("version").equalTo(lit(version)))).head(1);
    if (valueSets.length == 0) {
        return null;
    } else {
        ValueSet valueSet = valueSets[0];
        Dataset<Value> filteredValues = getValues(uri, version);
        addToValueSet(valueSet, filteredValues);
        return valueSet;
    }
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 7 with ValueSet

use of org.hl7.fhir.r5.model.ValueSet in project bunsen by cerner.

the class ValueSets method addToValueSet.

/**
 * Adds the given values to the given value set instance.
 */
private 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) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 8 with ValueSet

use of org.hl7.fhir.r5.model.ValueSet 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 : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Test(org.junit.Test)

Example 9 with ValueSet

use of org.hl7.fhir.r5.model.ValueSet in project bunsen by cerner.

the class ValueSetsTest method testWithValueSetsFromDirectoryJson.

@Test
public void testWithValueSetsFromDirectoryJson() {
    ValueSets valueSets = ValueSets.getEmpty(spark).withValueSetsFromDirectory("src/test/resources/json/valuesets");
    ValueSet marriedValueSet = valueSets.getValueSet("urn:cerner:bunsen:valueset:married_maritalstatus", "0.0.1");
    Assert.assertNotNull(marriedValueSet);
    Assert.assertEquals("urn:cerner:bunsen:valueset:married_maritalstatus", marriedValueSet.getUrl());
    Assert.assertEquals("0.0.1", marriedValueSet.getVersion());
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Test(org.junit.Test)

Example 10 with ValueSet

use of org.hl7.fhir.r5.model.ValueSet in project bunsen by cerner.

the class ValueSetsTest method testAppendValueSets.

@Test
public void testAppendValueSets() {
    ValueSets original = ValueSets.getEmpty(spark).withValueSets(valueSet("urn:cerner:valueset:valueset1", "1"), valueSet("urn:cerner:valueset:valueset2", "1"));
    ValueSets valueSets = original.withValueSets(valueSet("urn:cerner:valueset:valueset3", "1"));
    Assert.assertEquals(2, original.getValues().count());
    Assert.assertEquals(3, valueSets.getValues().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");
    ValueSet newValueSet = valueSets.getValueSet("urn:cerner:valueset:valueset3", "1");
    checkValueSet(newValueSet, "urn:cerner:valueset:valueset3", "1");
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Test(org.junit.Test)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)115 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)95 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 File (java.io.File)35 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27