use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, ExpansionProfile profile) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
List<ValueSet> imports = new ArrayList<ValueSet>();
for (UriType imp : inc.getValueSet()) imports.add(importValueSet(imp.getValue(), params, profile));
if (!inc.hasSystem()) {
if (// though this is not supposed to be the case
imports.isEmpty())
return;
ValueSet base = imports.get(0);
imports.remove(0);
copyImportContains(base.getExpansion().getContains(), null, profile, imports);
} else {
CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(inc.getSystem())) {
addCodes(context.expandVS(inc, canBeHeirarchy), params, profile, imports);
return;
}
if (cs == null) {
if (context.isNoTerminologyServer())
throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString());
else
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
}
if (cs.getContent() != CodeSystemContentMode.COMPLETE)
throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete");
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + cs.getVersion())));
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
// special case - add all the code system
for (ConceptDefinitionComponent def : cs.getConcept()) {
addCodeAndDescendents(cs, inc.getSystem(), def, null, profile, imports);
}
}
if (!inc.getConcept().isEmpty()) {
canBeHeirarchy = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay(), null, convertDesignations(c.getDesignation()), profile, false, CodeSystemUtilities.isInactive(cs, c.getCode()), imports);
}
}
if (inc.getFilter().size() > 1) {
// which will bt the case if we get around to supporting this
canBeHeirarchy = false;
// need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
throw new TerminologyServiceException("Multiple filters not handled yet");
}
if (inc.getFilter().size() == 1) {
ConceptSetFilterComponent fc = inc.getFilter().get(0);
if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
// special: all codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
addCodeAndDescendents(cs, inc.getSystem(), def, null, profile, imports);
} else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
// special: all codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, profile, imports);
} else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
// gg; note: wtf is this: if the filter is display=v, look up the code 'v', and see if it's diplsay is 'v'?
canBeHeirarchy = false;
ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
if (def != null) {
if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
if (def.getDisplay().contains(fc.getValue())) {
addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), profile, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def), imports);
}
}
}
} else
throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
}
}
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class TerminologyRenderer method addCsRef.
protected <T extends Resource> void addCsRef(ConceptSetComponent inc, XhtmlNode li, T cs) {
String ref = null;
boolean addHtml = true;
if (cs != null) {
ref = (String) cs.getUserData("external.url");
if (Utilities.noString(ref))
ref = (String) cs.getUserData("filename");
else
addHtml = false;
if (Utilities.noString(ref)) {
ref = (String) cs.getUserData("path");
if (ref != null) {
addHtml = false;
}
}
}
String spec = getSpecialReference(inc.getSystem());
if (spec != null) {
XhtmlNode a = li.ah(spec);
a.code(inc.getSystem());
} else if (cs != null && ref != null) {
if (addHtml && !ref.contains(".html"))
ref = ref + ".html";
ref = context.fixReference(ref);
XhtmlNode a = li.ah(ref.replace("\\", "/"));
a.code(inc.getSystem());
} else {
li.code(inc.getSystem());
}
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method addComposeRow.
private void addComposeRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t, String name) {
Row r = gen.new Row();
rows.add(r);
r.getCells().add(gen.new Cell(null, null, name, null, null));
if (t.hasLeft() && t.hasRight()) {
ConceptSetComponent csL = (ConceptSetComponent) t.getLeft();
ConceptSetComponent csR = (ConceptSetComponent) t.getRight();
if (csL.hasSystem() && csL.getSystem().equals(csR.getSystem())) {
r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).span(2).center());
} else {
r.getCells().add(gen.new Cell(null, null, csL.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
r.getCells().add(gen.new Cell(null, null, csR.getSystem(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
}
if (csL.hasVersion() && csR.hasVersion()) {
if (csL.getVersion().equals(csR.getVersion())) {
r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).span(2).center());
} else {
r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null).setStyle("background-color: " + COLOR_DIFFERENT));
}
} else if (csL.hasVersion()) {
r.getCells().add(gen.new Cell(null, null, csL.getVersion(), null, null));
r.getCells().add(missingCell(gen, COLOR_NO_CELL_RIGHT));
} else if (csR.hasVersion()) {
r.getCells().add(missingCell(gen, COLOR_NO_CELL_LEFT));
r.getCells().add(gen.new Cell(null, null, csR.getVersion(), null, null));
} else {
r.getCells().add(missingCell(gen).span(2).center());
}
} else if (t.hasLeft()) {
r.setColor(COLOR_NO_ROW_RIGHT);
ConceptSetComponent cs = (ConceptSetComponent) t.getLeft();
r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
r.getCells().add(missingCell(gen));
r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
r.getCells().add(missingCell(gen));
} else {
r.setColor(COLOR_NO_ROW_LEFT);
ConceptSetComponent cs = (ConceptSetComponent) t.getRight();
r.getCells().add(missingCell(gen));
r.getCells().add(gen.new Cell(null, null, cs.getSystem(), null, null));
r.getCells().add(missingCell(gen));
r.getCells().add(gen.new Cell(null, null, cs.hasVersion() ? "Version: " + cs.getVersion() : "", null, null));
}
r.getCells().add(cellForMessages(gen, t.getMessages()));
for (StructuralMatch<Element> c : t.getChildren()) {
if (c.either() instanceof ConceptReferenceComponent) {
addSetConceptRow(gen, r.getSubRows(), c);
} else {
addSetFilterRow(gen, r.getSubRows(), c);
}
}
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method compareDefinitions.
private void compareDefinitions(ConceptSetComponent left, ConceptSetComponent right, StructuralMatch<Element> combined, ConceptSetComponent union, ConceptSetComponent intersection) {
// system must match, but the rest might not. we're going to do the full comparison whatever, so the outcome looks consistent to the user
List<CanonicalType> matchVSR = new ArrayList<>();
for (CanonicalType l : left.getValueSet()) {
CanonicalType r = findInList(right.getValueSet(), l, left.getValueSet());
if (r == null) {
union.getValueSet().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed ValueSet", "ValueSet.compose.include.valueSet")));
} else {
matchVSR.add(r);
if (l.getValue().equals(r.getValue())) {
union.getValueSet().add(l);
intersection.getValueSet().add(l);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, null);
combined.getChildren().add(sm);
} else {
union.getValueSet().add(l);
union.getValueSet().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Values are different", "ValueSet.compose.include.valueSet"));
combined.getChildren().add(sm);
}
}
}
for (CanonicalType r : right.getValueSet()) {
if (!matchVSR.contains(r)) {
union.getValueSet().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Add ValueSet", "ValueSet.compose.include.valueSet"), r));
}
}
List<ConceptReferenceComponent> matchCR = new ArrayList<>();
for (ConceptReferenceComponent l : left.getConcept()) {
ConceptReferenceComponent r = findInList(right.getConcept(), l, left.getConcept());
if (r == null) {
union.getConcept().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this Concept", "ValueSet.compose.include.concept")));
} else {
matchCR.add(r);
if (l.getCode().equals(r.getCode())) {
ConceptReferenceComponent cu = new ConceptReferenceComponent();
ConceptReferenceComponent ci = new ConceptReferenceComponent();
union.getConcept().add(cu);
intersection.getConcept().add(ci);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
combined.getChildren().add(sm);
compareConcepts(l, r, sm, cu, ci);
} else {
union.getConcept().add(l);
union.getConcept().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Concepts are different", "ValueSet.compose.include.concept"));
combined.getChildren().add(sm);
compareConcepts(l, r, sm, null, null);
}
}
}
for (ConceptReferenceComponent r : right.getConcept()) {
if (!matchCR.contains(r)) {
union.getConcept().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this Concept", "ValueSet.compose.include.concept"), r));
}
}
List<ConceptSetFilterComponent> matchFR = new ArrayList<>();
for (ConceptSetFilterComponent l : left.getFilter()) {
ConceptSetFilterComponent r = findInList(right.getFilter(), l, left.getFilter());
if (r == null) {
union.getFilter().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this item", "ValueSet.compose.include.filter")));
} else {
matchFR.add(r);
if (l.getProperty().equals(r.getProperty()) && l.getOp().equals(r.getOp())) {
ConceptSetFilterComponent cu = new ConceptSetFilterComponent();
ConceptSetFilterComponent ci = new ConceptSetFilterComponent();
union.getFilter().add(cu);
intersection.getFilter().add(ci);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
combined.getChildren().add(sm);
compareFilters(l, r, sm, cu, ci);
} else {
union.getFilter().add(l);
union.getFilter().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Codes are different", "ValueSet.compose.include.filter"));
combined.getChildren().add(sm);
compareFilters(l, r, sm, null, null);
}
}
}
for (ConceptSetFilterComponent r : right.getFilter()) {
if (!matchFR.contains(r)) {
union.getFilter().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this item", "ValueSet.compose.include.filter"), r));
}
}
}
Aggregations