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));
}
}
}
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));
}
}
}
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;
}
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;
}
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);
}
}
}
Aggregations