use of org.hl7.fhir.r5.utils.validation.ValidationContextCarrier in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method validateCode.
@Override
public ValidationResult validateCode(final ValidationOptions optionsArg, final Coding code, final ValueSet vs, final ValidationContextCarrier ctxt) {
ValidationOptions options = optionsArg != null ? optionsArg : ValidationOptions.defaults();
if (code.hasSystem()) {
codeSystemsUsed.add(code.getSystem());
}
final CacheToken cacheToken = txCache != null ? txCache.generateValidationToken(options, code, vs) : null;
ValidationResult res = null;
if (txCache != null) {
res = txCache.getValidation(cacheToken);
}
if (res != null) {
updateUnsupportedCodeSystems(res, code, getCodeKey(code));
return res;
}
if (options.isUseClient()) {
// ok, first we try to validate locally
try {
ValueSetCheckerSimple vsc = constructValueSetCheckerSimple(options, vs, ctxt);
if (!vsc.isServerSide(code.getSystem())) {
res = vsc.validateCode(code);
if (txCache != null) {
txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
}
return res;
}
} catch (Exception e) {
}
}
if (!options.isUseServer()) {
return new ValidationResult(IssueSeverity.WARNING, formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS);
}
String codeKey = getCodeKey(code);
if (unsupportedCodeSystems.contains(codeKey)) {
return new ValidationResult(IssueSeverity.ERROR, formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, code.getSystem()), TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED);
}
// if that failed, we try to validate on the server
if (noTerminologyServer) {
return new ValidationResult(IssueSeverity.ERROR, formatMessage(I18nConstants.ERROR_VALIDATING_CODE_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
}
String csumm = txCache != null ? txCache.summary(code) : null;
if (txCache != null) {
txLog("$validate " + csumm + " for " + txCache.summary(vs));
} else {
txLog("$validate " + csumm + " before cache exists");
}
try {
Parameters pIn = constructParameters(options, code);
res = validateOnServer(vs, pIn, options);
} catch (Exception e) {
res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog == null ? null : txLog.getLastId()).setErrorClass(TerminologyServiceErrorClass.SERVER_ERROR);
}
updateUnsupportedCodeSystems(res, code, codeKey);
if (txCache != null) {
// we never cache unsupported code systems - we always keep trying (but only once per run)
txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
}
return res;
}
Aggregations