Search in sources :

Example 11 with ValueSetComposeComponent

use of org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method compareCompose.

private void compareCompose(ValueSetComposeComponent left, ValueSetComposeComponent right, ValueSetComparison res, ValueSetComposeComponent union, ValueSetComposeComponent intersection) {
    // first, the includes
    List<ConceptSetComponent> matchR = new ArrayList<>();
    for (ConceptSetComponent l : left.getInclude()) {
        ConceptSetComponent r = findInList(right.getInclude(), l, left.getInclude());
        if (r == null) {
            union.getInclude().add(l);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Include", "ValueSet.compose.include")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getInclude().add(csM);
            intersection.getInclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getIncludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getInclude()) {
        if (!matchR.contains(r)) {
            union.getInclude().add(r);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Include", "ValueSet.compose.include"), r));
        }
    }
    // now. the excludes
    matchR.clear();
    for (ConceptSetComponent l : left.getExclude()) {
        ConceptSetComponent r = findInList(right.getExclude(), l, left.getExclude());
        if (r == null) {
            union.getExclude().add(l);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Exclude", "ValueSet.compose.exclude")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getExclude().add(csM);
            intersection.getExclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getExcludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getExclude()) {
        if (!matchR.contains(r)) {
            union.getExclude().add(r);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Exclude", "ValueSet.compose.exclude"), r));
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r4b.model.Element) ArrayList(java.util.ArrayList)

Example 12 with ValueSetComposeComponent

use of org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetComparer method compareCompose.

private void compareCompose(ValueSetComposeComponent left, ValueSetComposeComponent right, ValueSetComparison res, ValueSetComposeComponent union, ValueSetComposeComponent intersection) {
    // first, the includes
    List<ConceptSetComponent> matchR = new ArrayList<>();
    for (ConceptSetComponent l : left.getInclude()) {
        ConceptSetComponent r = findInList(right.getInclude(), l, left.getInclude());
        if (r == null) {
            union.getInclude().add(l);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Include", "ValueSet.compose.include")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getInclude().add(csM);
            intersection.getInclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getIncludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getInclude()) {
        if (!matchR.contains(r)) {
            union.getInclude().add(r);
            res.getIncludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Include", "ValueSet.compose.include"), r));
        }
    }
    // now. the excludes
    matchR.clear();
    for (ConceptSetComponent l : left.getExclude()) {
        ConceptSetComponent r = findInList(right.getExclude(), l, left.getExclude());
        if (r == null) {
            union.getExclude().add(l);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed Exclude", "ValueSet.compose.exclude")));
        } else {
            matchR.add(r);
            ConceptSetComponent csM = new ConceptSetComponent();
            ConceptSetComponent csI = new ConceptSetComponent();
            union.getExclude().add(csM);
            intersection.getExclude().add(csI);
            StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
            res.getExcludes().getChildren().add(sm);
            compareDefinitions(l, r, sm, csM, csI);
        }
    }
    for (ConceptSetComponent r : right.getExclude()) {
        if (!matchR.contains(r)) {
            union.getExclude().add(r);
            res.getExcludes().getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added Exclude", "ValueSet.compose.exclude"), r));
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) Element(org.hl7.fhir.r5.model.Element) ArrayList(java.util.ArrayList)

Example 13 with ValueSetComposeComponent

use of org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method expandVS.

@Override
public ValueSetExpansionOutcome expandVS(ConceptSetComponent inc, boolean heirachical) throws TerminologyServiceException {
    ValueSet vs = new ValueSet();
    vs.setCompose(new ValueSetComposeComponent());
    vs.getCompose().getInclude().add(inc);
    CacheToken cacheToken = txCache.generateExpandToken(vs, heirachical);
    ValueSetExpansionOutcome res;
    res = txCache.getExpansion(cacheToken);
    if (res != null)
        return res;
    Parameters p = expParameters.copy();
    p.setParameter("includeDefinition", false);
    p.setParameter("excludeNested", !heirachical);
    if (noTerminologyServer)
        return new ValueSetExpansionOutcome("Error expanding ValueSet: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
    Map<String, String> params = new HashMap<String, String>();
    params.put("_limit", Integer.toString(expandCodesLimit));
    params.put("_incomplete", "true");
    tlog("$expand on " + txCache.summary(vs));
    try {
        ValueSet result = txClient.expandValueset(vs, p, params);
        res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
    } catch (Exception e) {
        res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
        if (txLog != null)
            res.setTxLink(txLog.getLastId());
    }
    txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
    return res;
}
Also used : HashMap(java.util.HashMap) CacheToken(org.hl7.fhir.r4.context.TerminologyCache.CacheToken) ValueSetExpansionOutcome(org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 14 with ValueSetComposeComponent

use of org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent in project pathling by aehrc.

the class ValueSetMapping method toIntersection.

/**
 * Constructs a {@link ValueSet} representing the intersection of a set of codings and a server
 *
 * @param valueSetUri the server defined value set.
 * @param codings the set of codings to intersect.
 * @return the intersection value set.
 */
@Nonnull
public static ValueSet toIntersection(@Nonnull final String valueSetUri, @Nonnull final Collection<SimpleCoding> codings) {
    final Set<CodeSystemReference> validCodeSystems = codings.stream().filter(SimpleCoding::isDefined).map(coding -> new CodeSystemReference(Optional.ofNullable(coding.getSystem()), Optional.ofNullable(coding.getVersion()))).collect(Collectors.toUnmodifiableSet());
    // Create a ValueSet to represent the intersection of the input codings and the ValueSet
    // described by the URI in the argument.
    final ValueSet intersection = new ValueSet();
    final ValueSetComposeComponent compose = new ValueSetComposeComponent();
    final List<ConceptSetComponent> includes = new ArrayList<>();
    // Create an include section for each unique code system present within the input codings.
    for (final CodeSystemReference codeSystem : validCodeSystems) {
        final ConceptSetComponent include = new ConceptSetComponent();
        include.setValueSet(Collections.singletonList(new CanonicalType(valueSetUri)));
        // noinspection OptionalGetWithoutIsPresent
        include.setSystem(codeSystem.getSystem().get());
        codeSystem.getVersion().ifPresent(include::setVersion);
        // Add the codings that match the current code system.
        final List<ConceptReferenceComponent> concepts = codings.stream().filter(codeSystem::matchesCoding).map(SimpleCoding::getCode).filter(Objects::nonNull).distinct().map(code -> {
            final ConceptReferenceComponent concept = new ConceptReferenceComponent();
            concept.setCode(code);
            return concept;
        }).collect(Collectors.toList());
        if (!concepts.isEmpty()) {
            include.setConcept(concepts);
            includes.add(include);
        }
    }
    compose.setInclude(includes);
    intersection.setCompose(compose);
    return intersection;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) java.util(java.util) Slf4j(lombok.extern.slf4j.Slf4j) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ValueSet(org.hl7.fhir.r4.model.ValueSet) Collectors(java.util.stream.Collectors) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Value(lombok.Value) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) ValueSet(org.hl7.fhir.r4.model.ValueSet) Nonnull(javax.annotation.Nonnull)

Example 15 with ValueSetComposeComponent

use of org.hl7.fhir.r4b.model.ValueSet.ValueSetComposeComponent in project eCRNow by drajer-health.

the class ValueSetServiceImpl method createValueSetGrouper.

@Override
public void createValueSetGrouper(ValueSet valueSet) {
    List<CanonicalType> valuesetList = null;
    ValueSetGrouperModel valueSetGrouperModel = null;
    ValueSetComposeComponent valueSetComposeComponent = valueSet.getCompose();
    List<ConceptSetComponent> conceptSetComponentList = valueSetComposeComponent.getInclude();
    for (ConceptSetComponent conceptSetComponent : conceptSetComponentList) {
        valuesetList = conceptSetComponent.getValueSet();
        for (CanonicalType canonicalType : valuesetList) {
            valueSetGrouperModel = new ValueSetGrouperModel();
            valueSetGrouperModel.setValueSetGrouper(valueSet.getUrl());
            valueSetGrouperModel.setValueSetId(canonicalType.getValueAsString());
            valueSetDao.createValuesetGrouper(valueSetGrouperModel);
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) ValueSetGrouperModel(com.drajer.ersd.model.ValueSetGrouperModel) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ValueSetComposeComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent)

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