Search in sources :

Example 31 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent 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) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 32 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent 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 33 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent 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 34 with ConceptReferenceComponent

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

Example 35 with ConceptReferenceComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent in project synthea by synthetichealth.

the class ValidationSupportR4 method validateCodeUsingValueSet.

private CodeValidationResult validateCodeUsingValueSet(String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
    CodeValidationResult result = null;
    if (theValueSetUrl == null || theValueSetUrl.isEmpty()) {
        result = new CodeValidationResult();
        result.setCode(theCode);
        result.setDisplay(theDisplay);
        result.setMessage("No ValueSet!");
        result.setSeverity(IssueSeverity.FATAL);
    } else {
        ValueSet vs = (ValueSet) this.fetchValueSet(theValueSetUrl);
        if (vs.hasCompose()) {
            ValueSetComposeComponent vscc = vs.getCompose();
            if (vscc.hasInclude()) {
                for (ConceptSetComponent csc : vscc.getInclude()) {
                    if ((theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(csc.getSystem())))) {
                        for (ConceptReferenceComponent crc : csc.getConcept()) {
                            if (crc.hasCode() && crc.getCode().equals(theCode)) {
                                result = new CodeValidationResult();
                                result.setCode(theCode);
                                result.setDisplay(theDisplay);
                                result.setMessage("Included");
                                result.setSeverity(IssueSeverity.INFORMATION);
                            }
                        }
                    }
                }
            }
            if (result == null && vscc.hasExclude()) {
                for (ConceptSetComponent csc : vscc.getExclude()) {
                    if ((theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(csc.getSystem())))) {
                        for (ConceptReferenceComponent crc : csc.getConcept()) {
                            if (crc.hasCode() && crc.getCode().equals(theCode)) {
                                result = new CodeValidationResult();
                                result.setCode(theCode);
                                result.setDisplay(theDisplay);
                                result.setMessage("Excluded");
                                result.setSeverity(IssueSeverity.ERROR);
                            }
                        }
                    }
                }
            }
        }
        if (result == null && vs.hasExpansion()) {
            ValueSetExpansionComponent vsec = vs.getExpansion();
            if (vsec.hasContains()) {
                for (ValueSetExpansionContainsComponent vsecc : vsec.getContains()) {
                    if (theCodeSystem == null || (theCodeSystem != null && theCodeSystem.equals(vsecc.getSystem()))) {
                        if (vsecc.getCode().equals(theCode)) {
                            result = new CodeValidationResult();
                            result.setCode(theCode);
                            result.setDisplay(theDisplay);
                            result.setMessage("Included");
                            result.setSeverity(IssueSeverity.INFORMATION);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)

Aggregations

ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)17 ArrayList (java.util.ArrayList)14 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)14 ConceptReferenceComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent)12 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)10 HashMap (java.util.HashMap)7 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)7 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)7 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)7 ValueSet (org.hl7.fhir.r4.model.ValueSet)6 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)5 ConceptReferenceDesignationComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent)5 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)4 ConceptReferenceDesignationComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4 ConceptSetFilterComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent)4