use of org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method doServerIncludeCodes.
private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, ValueSetExpansionComponent exp, List<ValueSet> imports, Parameters expParams, List<Extension> extensions) throws FHIRException {
ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
if (vso.getError() != null) {
throw failTSE("Unable to expand imported value set: " + vso.getError());
}
ValueSet vs = vso.getValueset();
if (vs.hasVersion()) {
if (!existsInParams(exp.getParameter(), "version", new UriType(vs.getUrl() + "|" + vs.getVersion()))) {
exp.getParameter().add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
}
}
for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
if (!existsInParams(exp.getParameter(), p.getName(), p.getValue())) {
exp.getParameter().add(p);
}
}
for (Extension ex : vs.getExpansion().getExtension()) {
if (Utilities.existsInList(ex.getUrl(), ToolingExtensions.EXT_EXP_TOOCOSTLY, "http://hl7.org/fhir/StructureDefinition/valueset-unclosed")) {
if (!hasExtension(extensions, ex.getUrl())) {
extensions.add(ex);
}
}
}
for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
addCodeAndDescendents(cc, null, expParams, imports);
}
}
use of org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method excludeCodes.
private void excludeCodes(ConceptSetComponent exc, List<ValueSetExpansionParameterComponent> params, String ctxt) throws FHIRException {
exc.checkNoModifiers("Compose.exclude", "expanding");
if (exc.hasSystem() && exc.getConcept().size() == 0 && exc.getFilter().size() == 0) {
excludeSystems.add(exc.getSystem());
}
if (exc.hasValueSet())
throw fail("Processing Value set references in exclude is not yet done in " + ctxt);
// importValueSet(imp.getValue(), params, expParams);
CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
ValueSetExpansionOutcome vse = context.expandVS(exc, false);
ValueSet valueset = vse.getValueset();
if (valueset == null)
throw failTSE("Error Expanding ValueSet: " + vse.getError());
excludeCodes(valueset.getExpansion(), params);
return;
}
for (ConceptReferenceComponent c : exc.getConcept()) {
excludeCode(exc.getSystem(), c.getCode());
}
if (exc.getFilter().size() > 0)
throw fail("not done yet - multiple filters");
}
use of org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method countMembership.
private Integer countMembership(ValueSet vs) {
int count = 0;
if (vs.hasExpansion())
count = count + conceptCount(vs.getExpansion().getContains());
else {
if (vs.hasCompose()) {
if (vs.getCompose().hasExclude()) {
try {
ValueSetExpansionOutcome vse = getContext().getWorker().expandVS(vs, true, false);
count = 0;
count += conceptCount(vse.getValueset().getExpansion().getContains());
return count;
} catch (Exception e) {
return null;
}
}
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
if (inc.hasFilter())
return null;
if (!inc.hasConcept())
return null;
count = count + inc.getConcept().size();
}
}
}
return count;
}
use of org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method buildCoding.
private Coding buildCoding(String uri, String code) throws FHIRException {
// if we can get this as a valueSet, we will
String system = null;
String display = null;
String version = null;
ValueSet vs = Utilities.noString(uri) ? null : worker.fetchResourceWithException(ValueSet.class, uri);
if (vs != null) {
ValueSetExpansionOutcome vse = worker.expandVS(vs, true, false);
if (vse.getError() != null)
throw new FHIRException(vse.getError());
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (ValueSetExpansionContainsComponent t : vse.getValueset().getExpansion().getContains()) {
if (t.hasCode())
b.append(t.getCode());
if (code.equals(t.getCode()) && t.hasSystem()) {
system = t.getSystem();
version = t.getVersion();
display = t.getDisplay();
break;
}
if (code.equalsIgnoreCase(t.getDisplay()) && t.hasSystem()) {
system = t.getSystem();
version = t.getVersion();
display = t.getDisplay();
break;
}
}
if (system == null)
throw new FHIRException("The code '" + code + "' is not in the value set '" + uri + "' (valid codes: " + b.toString() + "; also checked displays)");
} else {
system = uri;
}
ValidationResult vr = worker.validateCode(terminologyServiceOptions.setVersionFlexible(true), system, version, code, null);
if (vr != null && vr.getDisplay() != null)
display = vr.getDisplay();
return new Coding().setSystem(system).setCode(code).setDisplay(display);
}
use of org.hl7.fhir.r4.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project kindling by HL7.
the class MarkDownPreProcessor method process.
public static String process(Definitions definitions, BuildWorkerContext workerContext, List<ValidationMessage> validationErrors, String text, String location, String prefix) throws Exception {
if (Utilities.noString(text))
return "";
text = text.replace("||", "\r\n\r\n");
while (text.contains("[[[")) {
String left = text.substring(0, text.indexOf("[[["));
if (text.indexOf("]]]") < 0)
throw new Error(location + ": Missing closing ]]] in markdown text: " + text);
String linkText = text.substring(text.indexOf("[[[") + 3, text.indexOf("]]]"));
String right = text.substring(text.indexOf("]]]") + 3);
if (linkText.startsWith("valueset:")) {
String vsid = linkText.substring(9);
ValueSet vs = workerContext.fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/" + vsid);
ValueSetExpansionOutcome exp = workerContext.expandVS(vs, true, false);
if (exp.getValueset() != null)
text = left + presentExpansion(exp.getValueset().getExpansion().getContains(), workerContext) + right;
else
text = left + "[" + vs.getName() + "](" + vs.getUserData("path") + ")" + right;
} else {
String url = "";
String[] parts = linkText.split("\\#");
if (parts[0].contains("/StructureDefinition/")) {
StructureDefinition ed = workerContext.getExtensionStructure(null, parts[0]);
if (ed == null)
throw new Error(location + ": Unable to find extension " + parts[0]);
url = ed.getUserString("path");
if (url == null && ed.hasUserData("filename")) {
url = ed.getUserData("filename") + ".html";
}
if (url == null) {
System.out.println("Broken link for " + ed.getUrl());
}
}
if (Utilities.noString(url)) {
String[] paths = parts[0].split("\\.");
StructureDefinition p = new ProfileUtilities(workerContext, null, null).getProfile(null, paths[0]);
if (p != null) {
String suffix = (paths.length > 1) ? "-definitions.html#" + parts[0] : ".html";
if (p.getUserData("filename") == null)
url = paths[0].toLowerCase() + suffix;
else
url = p.getUserData("filename") + suffix;
} else if (definitions.hasResource(linkText)) {
url = linkText.toLowerCase() + ".html#";
} else if (definitions.hasResource(paths[0])) {
url = paths[0].toLowerCase() + "-definitions.html#" + linkText;
} else if (definitions.hasElementDefn(linkText)) {
url = definitions.getSrcFile(linkText) + ".html#" + linkText;
} else if (definitions.hasPrimitiveType(linkText)) {
url = "datatypes.html#" + linkText;
} else if (definitions.getPageTitles().containsKey(linkText)) {
url = definitions.getPageTitles().get(linkText);
} else if (definitions.getLogicalModel(linkText.toLowerCase()) != null) {
url = definitions.getLogicalModel(linkText.toLowerCase()).getId() + ".html";
} else if (validationErrors != null) {
validationErrors.add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, location, "Unresolved logical URL '" + linkText + "'", IssueSeverity.WARNING));
// throw new Exception("Unresolved logical URL "+url);
} else
url = "??";
}
text = left + "[" + linkText + "](" + url + ")" + right;
}
}
// 1. if prefix <> "", then check whether we need to insert the prefix
if (!Utilities.noString(prefix)) {
int i = text.length() - 3;
while (i > 0) {
if (text.substring(i, i + 2).equals("](")) {
if (!text.substring(i, i + 7).equals("](http:")) {
// && !text.substring(i, i+8).equals("](https:"));
text = text.substring(0, i) + "](" + prefix + text.substring(i + 2);
}
}
i--;
}
}
return text;
}
Aggregations