use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent in project kindling by HL7.
the class PageProcessor method getSnomedCTConceptList.
private String getSnomedCTConceptList() throws Exception {
Map<String, SnomedConceptUsage> concepts = new HashMap<String, SnomedConceptUsage>();
for (ValueSet vs : definitions.getValuesets().getList()) {
if (!vs.hasUrl() || !vs.getUrl().startsWith("http://terminology.hl7.org")) {
for (ConceptSetComponent cc : vs.getCompose().getInclude()) if (cc.hasSystem() && cc.getSystem().equals("http://snomed.info/sct")) {
for (ConceptReferenceComponent c : cc.getConcept()) {
String d = c.hasDisplay() ? c.getDisplay() : workerContext.getCodeDefinition("http://snomed.info/sct", c.getCode()).getDisplay();
if (concepts.containsKey(c.getCode()))
concepts.get(c.getCode()).update(d, vs);
else
concepts.put(c.getCode(), new SnomedConceptUsage(c.getCode(), d, vs));
}
for (ConceptSetFilterComponent c : cc.getFilter()) {
if ("concept".equals(c.getProperty())) {
getSnomedCTConcept(concepts, vs, c);
}
}
}
}
}
List<String> sorts = new ArrayList<String>();
for (String s : concepts.keySet()) sorts.add(s);
Collections.sort(sorts);
StringBuilder b = new StringBuilder();
b.append("<table class=\"codes\">\r\n");
b.append(" <tr><td><b>Code</b></td><td><b>Display</b></td><td>ValueSets</td></tr>\r\n");
for (String s : sorts) {
SnomedConceptUsage usage = concepts.get(s);
b.append(" <tr>\r\n <td>" + s + "</td>\r\n <td>" + Utilities.escapeXml(usage.getDisplay()) + "</td>\r\n <td>");
boolean first = true;
for (ValueSet vs : usage.getValueSets()) {
if (first)
first = false;
else
b.append("<br/>");
String path = (String) vs.getUserData("path");
b.append(" <a href=\"" + pathTail(Utilities.changeFileExt(path, ".html")) + "\">" + Utilities.escapeXml(vs.present()) + "</a>");
}
b.append("</td>\r\n </tr>\r\n");
}
b.append("</table>\r\n");
return b.toString();
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent in project kindling by HL7.
the class PageProcessor method getSnomedCTConcept.
public void getSnomedCTConcept(Map<String, SnomedConceptUsage> concepts, ValueSet vs, ConceptSetFilterComponent c) throws Exception {
ConceptDefinitionComponent def = workerContext.getCodeDefinition("http://snomed.info/sct", c.getValue());
if (def == null) {
throw new Exception("Unable to retrieve definition for SNOMED code: " + c.getValue());
}
String d = def.getDisplay();
if (concepts.containsKey(c.getValue()))
concepts.get(c.getValue()).update(d, vs);
else
concepts.put(c.getValue(), new SnomedConceptUsage(c.getValue(), d, vs));
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
if (context.supportsSystem(inc.getSystem())) {
addCodes(context.expandVS(inc), params);
return;
}
ValueSet cs = context.fetchCodeSystem(inc.getSystem());
if (cs == null)
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
// special case - add all the code system
for (ConceptDefinitionComponent def : cs.getCodeSystem().getConcept()) {
addCodeAndDescendents(inc.getSystem(), def);
}
}
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
}
if (inc.getFilter().size() > 1)
// 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 non-abstract codes in the target code system under the value
ConceptDefinitionComponent def = getConceptForCode(cs.getCodeSystem().getConcept(), fc.getValue());
if (def == null)
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
addCodeAndDescendents(inc.getSystem(), def);
} else
throw new NotImplementedException("not done yet");
}
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method includeCodes.
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
if (context.supportsSystem(inc.getSystem())) {
try {
int i = codes.size();
addCodes(context.expandVS(inc), params);
if (codes.size() > i)
return;
} catch (Exception e) {
// ok, we'll try locally
}
}
CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
if (cs == null)
throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
if (cs.hasVersion())
if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + 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);
}
}
for (ConceptReferenceComponent c : inc.getConcept()) {
addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
}
if (inc.getFilter().size() > 1)
// 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 non-abstract 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);
} else
throw new NotImplementedException("not done yet");
}
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptSetFilterComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method genInclude.
private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type) {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.addTag("li");
CodeSystem e = context.fetchCodeSystem(inc.getSystem());
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);
XhtmlNode t = li.addTag("table");
boolean hasComments = false;
boolean hasDefinition = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_COMMENT);
hasDefinition = hasDefinition || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION);
}
if (hasComments || hasDefinition)
hasExtensions = true;
addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false);
for (ConceptReferenceComponent c : inc.getConcept()) {
XhtmlNode tr = t.addTag("tr");
tr.addTag("td").addText(c.getCode());
ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc.getSystem());
XhtmlNode td = tr.addTag("td");
if (!Utilities.noString(c.getDisplay()))
td.addText(c.getDisplay());
else if (cc != null && !Utilities.noString(cc.getDisplay()))
td.addText(cc.getDisplay());
td = tr.addTag("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 (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_COMMENT)) {
smartAddText(tr.addTag("td"), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_COMMENT));
}
}
}
boolean first = true;
for (ConceptSetFilterComponent f : inc.getFilter()) {
if (first) {
li.addText(type + " codes from ");
first = false;
} else
li.addText(" and ");
addCsRef(inc, li, e);
li.addText(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
if (e != null && codeExistsInValueSet(e, f.getValue())) {
XhtmlNode a = li.addTag("a");
a.addText(f.getValue());
a.setAttribute("href", prefix + getCsRef(e) + "#" + Utilities.nmtokenize(f.getValue()));
} else
li.addText(f.getValue());
String disp = ToolingExtensions.getDisplayHint(f);
if (disp != null)
li.addText(" (" + disp + ")");
}
}
return hasExtensions;
}
Aggregations