Search in sources :

Example 71 with ConceptSetComponent

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

the class ValueSetsTest method checkValueSet.

private static void checkValueSet(ValueSet valueSet, String url, String version) {
    Assert.assertNotNull(MessageFormat.format("Could not find value set for url {0} and version {1}", url, version), valueSet);
    Assert.assertEquals(url, valueSet.getUrl());
    Assert.assertEquals(version, valueSet.getVersion());
    ConceptSetComponent inclusion = valueSet.getCompose().getIncludeFirstRep();
    Assert.assertEquals("urn:cerner:system", inclusion.getSystem());
    Assert.assertEquals("1", inclusion.getVersion());
    Assert.assertEquals("a", inclusion.getConceptFirstRep().getCode());
    Assert.assertEquals(1, valueSet.getCompose().getInclude().size());
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)

Example 72 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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)

Example 73 with ConceptSetComponent

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

the class ValueSetsTest method valueSet.

private static ValueSet valueSet(String valueSetUrl, String valueSetVersion, String... codes) {
    ValueSet valueSet = new ValueSet();
    valueSet.setUrl(valueSetUrl);
    valueSet.setVersion(valueSetVersion);
    valueSet.setExperimental(true);
    ConceptSetComponent inclusion = valueSet.getCompose().addInclude();
    inclusion.setSystem("urn:cerner:system").setVersion("1");
    for (String code : codes) {
        inclusion.addConcept().setCode(code);
    }
    return valueSet;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 74 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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.r4.model.ValueSet.ConceptSetComponent) Value(com.cerner.bunsen.codes.Value) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Example 75 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project snowstorm by IHTSDO.

the class FHIRHelper method convertFilterToECL.

public String convertFilterToECL(ConceptSetComponent setDefn, boolean firstItem) throws FHIROperationException {
    StringBuilder eclBuilder = new StringBuilder();
    for (ConceptSetFilterComponent filter : setDefn.getFilter()) {
        if (firstItem) {
            firstItem = false;
        } else {
            eclBuilder.append(" OR ");
        }
        if (filter.getProperty().equals("concept")) {
            eclBuilder.append(convertOperationToECL(filter.getOp()));
            eclBuilder.append(filter.getValue());
        } else if (filter.getProperty().equals("constraint")) {
            if (filter.getOp().toCode() != "=") {
                throw new FHIROperationException(IssueType.NOTSUPPORTED, "ValueSet compose filter 'constaint' operation - only '=' currently implemented");
            }
            eclBuilder.append(filter.getValue());
        } else {
            throw new FHIROperationException(IssueType.NOTSUPPORTED, "ValueSet compose filter property - only 'concept' and 'constraint' currently implemented");
        }
    }
    return eclBuilder.toString();
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetFilterComponent)

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)21 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 HashMap (java.util.HashMap)15 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)14 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)14 ValueSet (org.hl7.fhir.r4.model.ValueSet)13 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)12 FileNotFoundException (java.io.FileNotFoundException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)10 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)9