Search in sources :

Example 21 with ValueSetComposeComponent

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

Example 22 with ValueSetComposeComponent

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

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

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

the class FHIRValueSetProvider method obtainConsistentCodeSystemVersionFromCompose.

private BranchPath obtainConsistentCodeSystemVersionFromCompose(ValueSetComposeComponent compose, BranchPath branchPath) throws FHIROperationException {
    String system = null;
    String version = null;
    // Check all include and exclude elements to ensure they have a consistent snomed URI
    List<ConceptSetComponent> allIncludeExcludes = new ArrayList<>(compose.getInclude());
    allIncludeExcludes.addAll(compose.getExclude());
    for (ConceptSetComponent thisIncludeExclude : allIncludeExcludes) {
        if (thisIncludeExclude.getSystem() != null && !thisIncludeExclude.getSystem().contains(SNOMED_URI)) {
            throw new FHIROperationException(IssueType.NOTSUPPORTED, "Server currently limited to compose elements using SNOMED CT code system");
        }
        if (thisIncludeExclude.getSystem() != null && system == null) {
            system = thisIncludeExclude.getSystem();
        }
        if (thisIncludeExclude.getVersion() != null && version == null) {
            version = thisIncludeExclude.getVersion();
        }
        if (system != null && thisIncludeExclude.getSystem() != null && !system.equals(thisIncludeExclude.getSystem())) {
            String msg = "Server currently requires consistency in ValueSet compose element code systems.";
            msg += " Encoundered both '" + system + "' and '" + thisIncludeExclude.getSystem() + "'.";
            throw new FHIROperationException(IssueType.NOTSUPPORTED, msg);
        }
        if (version != null && thisIncludeExclude.getVersion() != null && !version.equals(thisIncludeExclude.getVersion())) {
            throw new FHIROperationException(IssueType.NOTSUPPORTED, "Server currently requires consistency in ValueSet compose element code system versions");
        }
    }
    StringType codeSystemVersionUri;
    if (version == null) {
        if (system == null) {
            return branchPath;
        } else {
            codeSystemVersionUri = new StringType(system);
        }
    } else {
        codeSystemVersionUri = new StringType(version);
    }
    return fhirHelper.getBranchPathFromURI(codeSystemVersionUri);
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)

Example 25 with ValueSetComposeComponent

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

the class FHIRValueSetProvider method covertComposeToEcl.

public String covertComposeToEcl(ValueSetComposeComponent compose) throws FHIROperationException {
    // Successive include elements will be added using 'OR'
    // While the excludes will be added using 'MINUS'
    String ecl = "";
    boolean isFirstInclude = true;
    for (ConceptSetComponent include : compose.getInclude()) {
        if (isFirstInclude) {
            isFirstInclude = false;
        } else {
            ecl += " OR ";
        }
        ecl += "( " + fhirHelper.convertToECL(include) + " )";
    }
    // We need something to minus!
    if (isFirstInclude) {
        throw new FHIROperationException(IssueType.VALUE, "Invalid use of exclude without include in ValueSet compose element.");
    }
    for (ConceptSetComponent exclude : compose.getExclude()) {
        ecl += " MINUS ( " + fhirHelper.convertToECL(exclude) + " )";
    }
    return ecl;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)

Aggregations

ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)9 ArrayList (java.util.ArrayList)8 ValueSetComposeComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent)8 ValueSetComposeComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent)7 ValueSetComposeComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)6 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)6 CodeType (org.hl7.fhir.r5.model.CodeType)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)5 HashMap (java.util.HashMap)4 ConceptReferenceComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)4 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)4 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 ConceptReferenceComponent (org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent)4 ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)3 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)3