use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method handleByCache.
private ValidationResult handleByCache(ValueSet vs, CodeableConcept concept, boolean tryCache) {
String cacheId = cacheId(concept);
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
if (cache == null) {
cache = new HashMap<String, IWorkerContext.ValidationResult>();
validationCache.put(vs.getUrl(), cache);
}
if (cache.containsKey(cacheId))
return cache.get(cacheId);
if (validationCache.containsKey(vs.getUrl()) && validationCache.get(vs.getUrl()).containsKey(cacheId))
return validationCache.get(vs.getUrl()).get(cacheId);
if (!tryCache)
return null;
if (!cacheValidation)
return null;
if (failed.contains(vs.getUrl()))
return null;
ValueSetExpansionOutcome vse = expandVS(vs, true);
if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
failed.add(vs.getUrl());
return null;
}
ValidationResult res = validateCode(concept, vse.getValueset());
cache.put(cacheId, res);
return res;
}
use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method handleByCache.
private ValidationResult handleByCache(ValueSet vs, Coding coding, boolean tryCache) {
String cacheId = cacheId(coding);
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
if (cache == null) {
cache = new HashMap<String, IWorkerContext.ValidationResult>();
validationCache.put(vs.getUrl(), cache);
}
if (cache.containsKey(cacheId))
return cache.get(cacheId);
if (!tryCache)
return null;
if (!cacheValidation)
return null;
if (failed.contains(vs.getUrl()))
return null;
ValueSetExpansionOutcome vse = expandVS(vs, true);
if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
failed.add(vs.getUrl());
return null;
}
ValidationResult res = validateCode(coding, vse.getValueset());
cache.put(cacheId, res);
return res;
}
use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method expand.
@Override
public ValueSetExpansionOutcome expand(ValueSet source) {
try {
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter());
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c))) {
focus.getExpansion().getContains().add(c);
}
}
return new ValueSetExpansionOutcome(focus, null);
} catch (RuntimeException e) {
// it swallows bugs.. what would be expected to be caught there?
throw e;
} catch (Exception e) {
// that might fail too, but it might not, later.
return new ValueSetExpansionOutcome(new ValueSetCheckerSimple(source, factory, context), e.getMessage());
}
}
use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method handleByCache.
private ValidationResult handleByCache(ValueSet vs, CodeableConcept concept, boolean tryCache) {
String cacheId = cacheId(concept);
Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
if (cache == null) {
cache = new HashMap<String, IWorkerContext.ValidationResult>();
validationCache.put(vs.getUrl(), cache);
}
if (cache.containsKey(cacheId)) {
return cache.get(cacheId);
}
if (validationCache.containsKey(vs.getUrl()) && validationCache.get(vs.getUrl()).containsKey(cacheId)) {
return validationCache.get(vs.getUrl()).get(cacheId);
}
if (!tryCache) {
return null;
}
if (!cacheValidation) {
return null;
}
if (failed.contains(vs.getUrl())) {
return null;
}
ValueSetExpansionOutcome vse = expandVS(vs, true, false);
if (vse.getValueset() == null || notcomplete(vse.getValueset())) {
failed.add(vs.getUrl());
return null;
}
ValidationResult res = validateCode(concept, vse.getValueset());
cache.put(cacheId, res);
return res;
}
use of org.hl7.fhir.r4b.terminologies.ValueSetExpander.ValueSetExpansionOutcome in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method expandVS.
@Override
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical) {
try {
if (vs.hasExpansion()) {
return new ValueSetExpansionOutcome(vs.copy());
}
String cacheFn = null;
if (cache != null) {
cacheFn = Utilities.path(cache, determineCacheId(vs, heirarchical) + ".json");
if (new File(cacheFn).exists()) {
return loadFromCache(vs.copy(), cacheFn);
}
}
if (cacheOk && vs.hasUrl()) {
if (expProfile == null) {
throw new Exception("No ExpansionProfile provided");
}
ValueSetExpansionOutcome vse = expansionCache.getExpander().expand(vs, expProfile.setExcludeNested(!heirarchical));
if (vse.getValueset() != null) {
if (cache != null) {
FileOutputStream s = new FileOutputStream(cacheFn);
newJsonParser().compose(new FileOutputStream(cacheFn), vse.getValueset());
s.close();
}
}
return vse;
} else {
ValueSetExpansionOutcome res = expandOnServer(vs, cacheFn);
if (cacheFn != null) {
if (res.getValueset() != null) {
saveToCache(res.getValueset(), cacheFn);
} else {
OperationOutcome oo = new OperationOutcome();
oo.addIssue().getDetails().setText(res.getError());
saveToCache(oo, cacheFn);
}
}
return res;
}
} catch (NoTerminologyServiceException e) {
return new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.NOSERVICE);
} catch (Exception e) {
return new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN);
}
}
Aggregations