use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method countMembership.
private Integer countMembership(ValueSet vs) {
int count = 0;
if (vs.hasExpansion())
count = count + conceptCount(vs.getExpansion().getContains());
else {
if (vs.hasCompose()) {
if (vs.getCompose().hasExclude()) {
try {
ValueSetExpansionOutcome vse = getContext().getWorker().expandVS(vs, true, false);
count = 0;
count += conceptCount(vse.getValueset().getExpansion().getContains());
return count;
} catch (Exception e) {
return null;
}
}
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
if (inc.hasFilter())
return null;
if (!inc.hasConcept())
return null;
count = count + inc.getConcept().size();
}
}
}
return count;
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method renderExpandGroup.
private void renderExpandGroup(HierarchicalTableGenerator gen, TableModel model, Extension ext, ConceptSetComponent inc, Map<String, ConceptDefinitionComponent> definitions) {
Row row = gen.new Row();
model.getRows().add(row);
row.setIcon("icon_entry_blue.png", "entry");
String code = ext.getExtensionString("code");
if (code != null) {
row.getCells().add(gen.new Cell(null, null, code, null, null));
row.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, code, definitions), null, null));
} else if (ext.hasId()) {
row.getCells().add(gen.new Cell(null, null, "(#" + ext.getId() + ")", null, null));
row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
} else {
row.getCells().add(gen.new Cell(null, null, null, null, null));
row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
}
for (Extension member : ext.getExtensionsByUrl("member")) {
Row subRow = gen.new Row();
row.getSubRows().add(subRow);
subRow.setIcon("icon_entry_blue.png", "entry");
String mc = member.getValue().primitiveValue();
// mc might be a reference to another expansion group - we check that first, or to a code in the compose
if (mc.startsWith("#")) {
// it's a reference by id
subRow.getCells().add(gen.new Cell(null, null, "(" + mc + ")", null, null));
subRow.getCells().add(gen.new Cell(null, null, "group reference by id", null, null));
} else {
Extension tgt = findTargetByCode(inc, mc);
if (tgt != null) {
subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
subRow.getCells().add(gen.new Cell(null, null, "group reference by code", null, null));
} else {
subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
subRow.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, mc, definitions), null, null));
}
}
}
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method genInclude.
private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index) throws FHIRException, IOException {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.li();
CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
if (inc.hasSystem()) {
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
li.addText(type + " all codes defined in ");
addCsRef(inc, li, e);
} else {
if (inc.getConcept().size() > 0) {
li.addText(type + " these codes as defined in ");
addCsRef(inc, li, e);
if (inc.hasVersion()) {
li.addText(" version ");
li.code(inc.getVersion());
}
// for performance reasons, we do all the fetching in one batch
definitions = getConceptsForCodes(e, inc);
XhtmlNode t = li.table("none");
boolean hasComments = false;
boolean hasDefinition = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
ConceptDefinitionComponent cc = definitions.get(c.getCode());
hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
}
if (hasComments || hasDefinition)
hasExtensions = true;
addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, designations, doDesignations), maps);
for (ConceptReferenceComponent c : inc.getConcept()) {
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
ConceptDefinitionComponent cc = definitions.get(c.getCode());
addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
td = tr.td();
if (!Utilities.noString(c.getDisplay()))
td.addText(c.getDisplay());
else if (cc != null && !Utilities.noString(cc.getDisplay()))
td.addText(cc.getDisplay());
if (hasDefinition) {
td = tr.td();
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION)) {
smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
} else if (cc != null && !Utilities.noString(cc.getDefinition())) {
smartAddText(td, cc.getDefinition());
}
}
if (hasComments) {
td = tr.td();
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
}
}
if (doDesignations) {
addDesignationsToRow(c, designations, tr);
addLangaugesToRow(c, langs, tr);
}
}
}
if (inc.getFilter().size() > 0) {
li.addText(type + " codes from ");
addCsRef(inc, li, e);
li.tx(" where ");
for (int i = 0; i < inc.getFilter().size(); i++) {
ConceptSetFilterComponent f = inc.getFilter().get(i);
if (i > 0) {
if (i == inc.getFilter().size() - 1) {
li.tx(" and ");
} else {
li.tx(", ");
}
}
if (f.getOp() == FilterOperator.EXISTS) {
if (f.getValue().equals("true")) {
li.tx(f.getProperty() + " exists");
} else {
li.tx(f.getProperty() + " doesn't exist");
}
} else {
li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
if (e != null && codeExistsInValueSet(e, f.getValue())) {
String href = getContext().fixReference(getCsRef(e));
if (href.contains("#"))
href = href + "-" + Utilities.nmtokenize(f.getValue());
else
href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
li.ah(href).addText(f.getValue());
} else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
li.addText(f.getValue());
ValidationResult vr = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), f.getValue(), null);
if (vr.isOk()) {
li.tx(" (" + vr.getDisplay() + ")");
}
} else
li.addText(f.getValue());
String disp = ToolingExtensions.getDisplayHint(f);
if (disp != null)
li.tx(" (" + disp + ")");
}
}
}
}
if (inc.hasValueSet()) {
li.tx(", where the codes are contained in ");
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(vs.asStringValue(), li);
}
}
if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
hasExtensions = true;
renderExpansionRules(li, inc, index, definitions);
}
} else {
li.tx("Import all the codes that are contained in ");
if (inc.getValueSet().size() < 4) {
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(vs.asStringValue(), li);
}
} else {
XhtmlNode xul = li.ul();
for (UriType vs : inc.getValueSet()) {
AddVsRef(vs.asStringValue(), xul.li());
}
}
}
return hasExtensions;
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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.r4.model.ValueSet.ConceptSetComponent in project pathling by aehrc.
the class DefaultTerminologyServiceTest method testIntersectFiltersIllegalAndUnknownCodings.
@SuppressWarnings("ConstantConditions")
@Test
void testIntersectFiltersIllegalAndUnknownCodings() {
final ValueSet responseExpansion = new ValueSet();
responseExpansion.getExpansion().getContains().addAll(Arrays.asList(fromSimpleCoding(CODING1_VERSION1), fromSimpleCoding(CODING2_VERSION1)));
when(terminologyClient.expand(any(), any())).thenReturn(responseExpansion);
// setup SYSTEM1 as known system
when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
final Set<SimpleCoding> actualExpansion = terminologyService.intersect("uuid:value-set", Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
final Set<SimpleCoding> expectedExpansion = ImmutableSet.of(CODING1_VERSION1, CODING2_VERSION1);
assertEquals(expectedExpansion, actualExpansion);
// verify behaviour
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
final ValueSet requestValueSet = new ValueSet();
final List<ConceptSetComponent> includes = requestValueSet.getCompose().getInclude();
includes.add(new ConceptSetComponent().addValueSet("uuid:value-set").setSystem(SYSTEM1).setVersion("version1").addConcept(new ConceptReferenceComponent().setCode("code1")).addConcept(new ConceptReferenceComponent().setCode("code2")));
verify(terminologyClient).expand(deepEq(requestValueSet), deepEq(new IntegerType(2)));
verifyNoMoreInteractions(terminologyClient);
}
Aggregations