Search in sources :

Example 16 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project snowstorm by IHTSDO.

the class HapiValueSetMapper method addExpansion.

private void addExpansion(ValueSet vs, List<ConceptMini> concepts, Map<String, Concept> conceptDetails, List<LanguageDialect> designations, Boolean includeDesignations) {
    // Will autocreate
    ValueSetExpansionComponent expansion = vs.getExpansion();
    for (ConceptMini concept : concepts) {
        ValueSetExpansionContainsComponent component = expansion.addContains().setCode(concept.getConceptId()).setSystem(SNOMED_URI);
        if (conceptDetails != null && conceptDetails.containsKey(concept.getConceptId())) {
            Concept c = conceptDetails.get(concept.getConceptId());
            for (Description d : c.getActiveDescriptions()) {
                if (includeDesignations && d.hasAcceptability(designations)) {
                    component.addDesignation(asDesignation(d));
                }
                // Use the preferred term in the specified display language.
                if (!designations.isEmpty() && d.hasAcceptability(Concepts.PREFERRED, designations.get(0)) && d.getTypeId().equals(Concepts.SYNONYM)) {
                    component.setDisplay(d.getTerm());
                    boolean inactive = !c.isActive();
                    if (inactive) {
                        component.setInactive(inactive);
                    }
                }
            }
        }
    }
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) Concept(org.snomed.snowstorm.core.data.domain.Concept) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) Description(org.snomed.snowstorm.core.data.domain.Description) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini)

Example 17 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project eCRNow by drajer-health.

the class ApplicationUtils method convertValueSetsToString.

public static Set<String> convertValueSetsToString(Set<ValueSet> valuesets) {
    Set<String> retVal = new HashSet<>();
    ValueSetExpansionComponent valueSetExpansionComponent;
    List<ValueSetExpansionContainsComponent> valueSetExpansionContainsComponentList;
    if (valuesets != null && !valuesets.isEmpty()) {
        for (ValueSet vs : valuesets) {
            logger.debug("Value Set Id = {}", vs.getId());
            valueSetExpansionComponent = vs.getExpansion();
            valueSetExpansionContainsComponentList = valueSetExpansionComponent.getContains();
            for (ValueSetExpansionContainsComponent vscomp : valueSetExpansionContainsComponentList) {
                if (vscomp.getSystem() != null && vscomp.getCode() != null) {
                    retVal.add(vscomp.getSystem() + "|" + vscomp.getCode());
                }
            }
        }
    }
    return retVal;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r4.model.ValueSet) HashSet(java.util.HashSet)

Example 18 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent 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 19 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method importValueSet.

private ValueSet importValueSet(String value, ValueSetExpansionComponent exp, Parameters expParams, boolean noInactive, ValueSet valueSet) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException, FHIRFormatError {
    if (value == null)
        throw fail("unable to find value set with no identity");
    ValueSet vs = context.fetchResource(ValueSet.class, value);
    if (vs == null) {
        if (context.fetchResource(CodeSystem.class, value) != null) {
            throw fail("Cannot include value set " + value + " because it's actually a code system");
        } else {
            throw fail("Unable to find imported value set " + value);
        }
    }
    if (noInactive) {
        expParams = expParams.copy();
        expParams.addParameter("activeOnly", true);
    }
    ValueSetExpansionOutcome vso = new ValueSetExpanderSimple(context, allErrors).expand(vs, expParams);
    if (vso.getError() != null) {
        addErrors(vso.getAllErrors());
        throw fail("Unable to expand imported value set " + vs.getUrl() + ": " + vso.getError());
    }
    if (vs.hasVersion())
        if (!existsInParams(exp.getParameter(), "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
            exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
    for (Extension ex : vso.getValueset().getExpansion().getExtension()) {
        if (ex.getUrl().equals(ToolingExtensions.EXT_EXP_TOOCOSTLY)) {
            if (ex.getValue() instanceof BooleanType) {
                exp.getExtension().add(new Extension(ToolingExtensions.EXT_EXP_TOOCOSTLY).setValue(new UriType(value)));
            } else {
                exp.getExtension().add(ex);
            }
        }
    }
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(exp.getParameter(), p.getName(), p.getValue()))
            exp.getParameter().add(p);
    }
    if (isValueSetUnionImports(valueSet)) {
        copyExpansion(vso.getValueset().getExpansion().getContains());
    }
    // if we're importing a value set, we have to be combining, so we won't try for a heirarchy
    canBeHeirarchy = false;
    return vso.getValueset();
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) BooleanType(org.hl7.fhir.r5.model.BooleanType) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) UriType(org.hl7.fhir.r5.model.UriType)

Example 20 with ValueSetExpansionComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method doServerIncludeCodes.

private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, ValueSetExpansionComponent exp, List<ValueSet> imports, Parameters expParams, List<Extension> extensions, boolean noInactive) throws FHIRException {
    ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical, noInactive);
    if (vso.getError() != null) {
        throw failTSE("Unable to expand imported value set: " + vso.getError());
    }
    ValueSet vs = vso.getValueset();
    if (vs.hasVersion()) {
        if (!existsInParams(exp.getParameter(), "version", new UriType(vs.getUrl() + "|" + vs.getVersion()))) {
            exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
        }
    }
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(exp.getParameter(), p.getName(), p.getValue())) {
            exp.getParameter().add(p);
        }
    }
    for (Extension ex : vs.getExpansion().getExtension()) {
        if (Utilities.existsInList(ex.getUrl(), ToolingExtensions.EXT_EXP_TOOCOSTLY, "http://hl7.org/fhir/StructureDefinition/valueset-unclosed")) {
            if (!hasExtension(extensions, ex.getUrl())) {
                extensions.add(ex);
            }
        }
    }
    for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
        addCodeAndDescendents(cc, null, expParams, imports, noInactive);
    }
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) UriType(org.hl7.fhir.r5.model.UriType)

Aggregations

UriType (org.hl7.fhir.r4b.model.UriType)7 ValueSetExpansionParameterComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionParameterComponent)7 UriType (org.hl7.fhir.r5.model.UriType)7 ValueSetExpansionParameterComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent)7 ArrayList (java.util.ArrayList)6 ValueSet (org.hl7.fhir.r4.model.ValueSet)5 ValueSetExpansionComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent)5 ValueSetExpansionContainsComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)5 ValueSet (org.hl7.fhir.r4b.model.ValueSet)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 HashMap (java.util.HashMap)3 List (java.util.List)2 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)2 ValueSet (org.hl7.fhir.dstu2016may.model.ValueSet)2 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)2 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)2 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)2 Extension (org.hl7.fhir.r4b.model.Extension)2