use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method doExpand.
public ValueSetExpansionOutcome doExpand(ValueSet source, Parameters expParams) throws FHIRException, ETooCostly, FileNotFoundException, IOException {
if (expParams == null)
expParams = makeDefaultExpansion();
source.checkNoModifiers("ValueSet", "expanding");
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
for (ParametersParameterComponent p : expParams.getParameter()) {
if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested"))
focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
}
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion(), expParams, source.getUrl(), focus.getExpansion().getExtension());
if (canBeHeirarchy) {
for (ValueSetExpansionContainsComponent c : roots) {
focus.getExpansion().getContains().add(c);
}
} else {
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c)) && (includeAbstract || !c.getAbstract())) {
// we may have added abstract codes earlier while we still thought it might be heirarchical, but later we gave up, so now ignore them
focus.getExpansion().getContains().add(c);
// make sure any heirarchy is wiped
c.getContains().clear();
}
}
}
if (total > 0) {
focus.getExpansion().setTotal(total);
}
return new ValueSetExpansionOutcome(focus);
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method addCodeAndDescendents.
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters) throws FHIRException {
focus.checkNoModifiers("Expansion.contains", "expanding");
ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), parent, convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), filters);
for (ValueSetExpansionContainsComponent c : focus.getContains()) addCodeAndDescendents(focus, np, expParams, filters);
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method excludeCode.
private void excludeCode(String theSystem, String theCode) {
ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
n.setSystem(theSystem);
n.setCode(theCode);
String s = key(n);
excludeKeys.add(s);
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method addCode.
private ValueSetExpansionContainsComponent addCode(String system, String code, String display, ValueSetExpansionContainsComponent parent, List<ConceptDefinitionDesignationComponent> designations, Parameters expParams, boolean isAbstract, boolean inactive, List<ValueSet> filters) {
if (filters != null && !filters.isEmpty() && !filterContainsCode(filters, system, code))
return null;
ValueSetExpansionContainsComponent n = new ValueSet.ValueSetExpansionContainsComponent();
n.setSystem(system);
n.setCode(code);
if (isAbstract)
n.setAbstract(true);
if (inactive)
n.setInactive(true);
if (expParams.getParameterBool("includeDesignations") && designations != null) {
for (ConceptDefinitionDesignationComponent t : designations) {
ToolingExtensions.addLanguageTranslation(n, t.getLanguage(), t.getValue());
}
}
ConceptDefinitionDesignationComponent t = expParams.hasLanguage() ? getMatchingLang(designations, expParams.getLanguage()) : null;
if (t == null)
n.setDisplay(display);
else
n.setDisplay(t.getValue());
String s = key(n);
if (map.containsKey(s) || excludeKeys.contains(s)) {
canBeHeirarchy = false;
} else {
codes.add(n);
map.put(s, n);
total++;
}
if (canBeHeirarchy && parent != null) {
parent.getContains().add(n);
} else {
roots.add(n);
}
return n;
}
use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetCheckerSimple method findValueSetRef.
private ConceptReferenceComponent findValueSetRef(String system, String code) {
if (valueset == null)
return null;
// if it has an expansion
for (ValueSetExpansionContainsComponent exp : valueset.getExpansion().getContains()) {
if (system.equals(exp.getSystem()) && code.equals(exp.getCode())) {
ConceptReferenceComponent cc = new ConceptReferenceComponent();
cc.setDisplay(exp.getDisplay());
cc.setDesignation(exp.getDesignation());
return cc;
}
}
for (ConceptSetComponent inc : valueset.getCompose().getInclude()) {
if (system.equals(inc.getSystem())) {
for (ConceptReferenceComponent cc : inc.getConcept()) {
if (cc.getCode().equals(code)) {
return cc;
}
}
}
for (CanonicalType url : inc.getValueSet()) {
ConceptReferenceComponent cc = getVs(url.asStringValue()).findValueSetRef(system, code);
if (cc != null) {
return cc;
}
}
}
return null;
}
Aggregations