use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent 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.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class Element method getAsICoding.
public ICoding getAsICoding() throws FHIRException {
if ("code".equals(fhirType())) {
if (property.getDefinition().getBinding().getStrength() != BindingStrength.REQUIRED)
return null;
ICodingImpl c = new ICodingImpl(true, true, false, false);
c.code = primitiveValue();
ValueSetExpansionOutcome vse = property.getContext().expandVS(property.getDefinition().getBinding(), true, false);
if (vse.getValueset() == null)
return null;
for (ValueSetExpansionContainsComponent cc : vse.getValueset().getExpansion().getContains()) {
if (cc.getCode().equals(c.code)) {
c.system = cc.getSystem();
if (cc.hasVersion()) {
c.doesVersion = true;
c.version = cc.getVersion();
}
if (cc.hasDisplay()) {
c.doesDisplay = true;
c.display = cc.getDisplay();
}
}
}
if (c.system == null)
return null;
return c;
} else if ("Coding".equals(fhirType())) {
ICodingImpl c = new ICodingImpl(true, true, true, true);
c.system = getNamedChildValue("system");
c.code = getNamedChildValue("code");
c.display = getNamedChildValue("display");
c.version = getNamedChildValue("version");
return c;
} else if ("Quantity".equals(fhirType())) {
ICodingImpl c = new ICodingImpl(true, true, false, false);
c.system = getNamedChildValue("system");
c.code = getNamedChildValue("code");
return c;
} else
return null;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method generateExpandToken.
public CacheToken generateExpandToken(ValueSet vs, boolean heirarchical) {
CacheToken ct = new CacheToken();
ValueSet vsc = getVSEssense(vs);
for (ConceptSetComponent inc : vs.getCompose().getInclude()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
for (ConceptSetComponent inc : vs.getCompose().getExclude()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains()) if (inc.hasSystem())
ct.setName(getNameForSystem(inc.getSystem()));
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
try {
ct.request = "{\"hierarchical\" : " + (heirarchical ? "true" : "false") + ", \"valueSet\" :" + json.composeString(vsc) + "}\r\n";
} catch (IOException e) {
throw new Error(e);
}
ct.key = String.valueOf(hashNWS(ct.request));
return ct;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateExpansion.
private boolean generateExpansion(XhtmlNode x, ValueSet vs, ValueSet src, boolean header) {
boolean hasExtensions = false;
Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
for (ConceptMap a : context.findMapsForSource(vs.getUrl())) {
String url = "";
ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
if (vsr != null)
url = (String) vsr.getUserData("filename");
mymaps.put(a, url);
}
if (header) {
XhtmlNode h = x.addTag("h3");
h.addText("Value Set Contents");
if (IsNotFixedExpansion(vs))
x.addTag("p").addText(vs.getDescription());
if (vs.hasCopyright())
generateCopyright(x, vs);
}
if (ToolingExtensions.hasExtension(vs.getExpansion(), "http://hl7.org/fhir/StructureDefinition/valueset-toocostly"))
x.addTag("p").setAttribute("style", "border: maroon 1px solid; background-color: #FFCCCC; font-weight: bold; padding: 8px").addText(tooCostlyNote);
else {
Integer count = countMembership(vs);
if (count == null)
x.addTag("p").addText("This value set does not contain a fixed number of concepts");
else
x.addTag("p").addText("This value set contains " + count.toString() + " concepts");
}
boolean doSystem = checkDoSystem(vs, src);
if (doSystem && allFromOneSystem(vs)) {
doSystem = false;
XhtmlNode p = x.addTag("p");
p.addText("All codes from system ");
p.addTag("code").addText(vs.getExpansion().getContains().get(0).getSystem());
}
XhtmlNode t = x.addTag("table").setAttribute("class", "codes");
XhtmlNode tr = t.addTag("tr");
tr.addTag("td").addTag("b").addText("Code");
if (doSystem)
tr.addTag("td").addTag("b").addText("System");
tr.addTag("td").addTag("b").addText("Display");
addMapHeaders(tr, mymaps);
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
addExpansionRowToTable(t, c, 0, doSystem, mymaps);
}
return hasExtensions;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method addCode.
private void addCode(String system, String code, String display) {
ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
n.setSystem(system);
n.setCode(code);
n.setDisplay(display);
String s = key(n);
if (!map.containsKey(s)) {
codes.add(n);
map.put(s, n);
}
}
Aggregations