use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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;
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method determineCacheId.
private String determineCacheId(ValueSet vs, boolean heirarchical) throws Exception {
// just the content logical definition is hashed
ValueSet vsid = new ValueSet();
vsid.setCompose(vs.getCompose());
JsonParser parser = new JsonParser();
parser.setOutputStyle(OutputStyle.NORMAL);
ByteArrayOutputStream b = new ByteArrayOutputStream();
parser.compose(b, vsid);
b.close();
String s = new String(b.toByteArray(), Constants.CHARSET_UTF8);
// any code systems we can find, we add these too.
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
CodeSystem cs = fetchCodeSystem(inc.getSystem());
if (cs != null) {
String css = cacheValue(cs);
s = s + css;
}
}
s = s + "-" + Boolean.toString(heirarchical);
String r = Integer.toString(s.hashCode());
// TextFile.stringToFile(s, Utilities.path(cache, r+".id.json"));
return r;
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method expandVS.
@Override
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heirachical) throws TerminologyServiceException {
ValueSet vs = new ValueSet();
vs.setCompose(new ValueSetComposeComponent());
vs.getCompose().getInclude().add(inc);
ValueSetExpansionOutcome vse = expandVS(vs, true, heirachical);
ValueSet valueset = vse.getValueset();
if (valueset == null) {
throw new TerminologyServiceException("Error Expanding ValueSet: " + vse.getError());
}
return valueset.getExpansion();
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method intersectByExpansion.
private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
// this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
ValueSet vs = new ValueSet();
vs.setStatus(PublicationStatus.DRAFT);
Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
scan(lvs.getExpansion().getContains(), left);
Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
scan(rvs.getExpansion().getContains(), right);
Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
for (String s : left.keySet()) {
if (right.containsKey(s)) {
ValueSetExpansionContainsComponent cc = left.get(s);
ConceptSetComponent c = inc.get(cc.getSystem());
if (c == null) {
c = vs.getCompose().addInclude().setSystem(cc.getSystem());
inc.put(cc.getSystem(), c);
}
c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
}
}
return vs;
}
use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileComparer method unite.
private ValueSet unite(ElementDefinition ed, ProfileComparison outcome, String path, ValueSet lvs, ValueSet rvs) {
ValueSet vs = new ValueSet();
if (lvs.hasCompose()) {
for (ConceptSetComponent inc : lvs.getCompose().getInclude()) vs.getCompose().getInclude().add(inc);
if (lvs.getCompose().hasExclude()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "The value sets " + lvs.getUrl() + " has exclude statements, and no union involving it can be correctly determined", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
}
}
if (rvs.hasCompose()) {
for (ConceptSetComponent inc : rvs.getCompose().getInclude()) if (!mergeIntoExisting(vs.getCompose().getInclude(), inc))
vs.getCompose().getInclude().add(inc);
if (rvs.getCompose().hasExclude()) {
outcome.messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "The value sets " + lvs.getUrl() + " has exclude statements, and no union involving it can be correctly determined", ValidationMessage.IssueSeverity.ERROR));
status(ed, ProfileUtilities.STATUS_ERROR);
}
}
return vs;
}
Aggregations