use of org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method expandVS.
@Override
public ValueSetExpansionOutcome expandVS(ConceptSetComponent inc, boolean hierarchical) throws TerminologyServiceException {
ValueSet vs = new ValueSet();
vs.setStatus(PublicationStatus.ACTIVE);
vs.setCompose(new ValueSetComposeComponent());
vs.getCompose().getInclude().add(inc);
CacheToken cacheToken = txCache.generateExpandToken(vs, hierarchical);
ValueSetExpansionOutcome res;
res = txCache.getExpansion(cacheToken);
if (res != null) {
return res;
}
Parameters p = expParameters.copy();
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !hierarchical);
boolean cached = addDependentResources(p, vs);
if (cached) {
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
for (ConceptSetComponent incl : vs.getCompose().getInclude()) {
codeSystemsUsed.add(incl.getSystem());
}
for (ConceptSetComponent incl : vs.getCompose().getExclude()) {
codeSystemsUsed.add(incl.getSystem());
}
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
}
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit));
params.put("_incomplete", "true");
tlog("$expand on " + txCache.summary(vs));
try {
ValueSet result = txClient.expandValueset(vs, p, params);
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
} catch (Exception e) {
res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
if (txLog != null) {
res.setTxLink(txLog.getLastId());
}
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
return res;
}
use of org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method expandVS.
@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
ValueSet vs = null;
vs = fetchResource(ValueSet.class, binding.getValueSet());
if (vs == null) {
throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
}
return expandVS(vs, cacheOk, heirarchical);
}
use of org.hl7.fhir.dstu3.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.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method expandVS.
@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
ValueSet vs = null;
vs = fetchResource(ValueSet.class, binding.getValueSet());
if (vs == null) {
throw new FHIRException(formatMessage(I18nConstants.UNABLE_TO_RESOLVE_VALUE_SET_, binding.getValueSet()));
}
return expandVS(vs, cacheOk, heirarchical);
}
use of org.hl7.fhir.dstu3.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class TerminologyCache method getCacheEntry.
private CacheEntry getCacheEntry(String request, String resultString) throws IOException {
CacheEntry ce = new CacheEntry();
ce.persistent = true;
ce.request = request;
boolean e = resultString.charAt(0) == 'e';
resultString = resultString.substring(3);
JsonObject o = (JsonObject) new com.google.gson.JsonParser().parse(resultString);
String error = loadJS(o.get("error"));
if (e) {
if (o.has("valueSet"))
ce.e = new ValueSetExpansionOutcome((ValueSet) new JsonParser().parse(o.getAsJsonObject("valueSet")), error, TerminologyServiceErrorClass.UNKNOWN);
else
ce.e = new ValueSetExpansionOutcome(error, TerminologyServiceErrorClass.UNKNOWN);
} else {
String t = loadJS(o.get("severity"));
IssueSeverity severity = t == null ? null : IssueSeverity.fromCode(t);
String display = loadJS(o.get("display"));
String code = loadJS(o.get("code"));
String system = loadJS(o.get("system"));
String definition = loadJS(o.get("definition"));
t = loadJS(o.get("class"));
TerminologyServiceErrorClass errorClass = t == null ? null : TerminologyServiceErrorClass.valueOf(t);
ce.v = new ValidationResult(severity, error, system, new ConceptDefinitionComponent().setDisplay(display).setDefinition(definition).setCode(code)).setErrorClass(errorClass);
}
return ce;
}
Aggregations