use of org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContextTests method testValidateCodableConceptWithValueSetChecker.
@Test
public void testValidateCodableConceptWithValueSetChecker() throws IOException {
Mockito.doReturn(valueSetCheckerSimple).when(context).constructValueSetCheckerSimple(any(), any());
Mockito.doReturn(expectedValidationResult).when(valueSetCheckerSimple).validateCode(any(CodeableConcept.class));
CodeableConcept codeableConcept = new CodeableConcept();
ValueSet valueSet = new ValueSet();
Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(CacheTestUtils.validationOptions, codeableConcept, valueSet);
IWorkerContext.ValidationResult validationResultB = context.validateCode(CacheTestUtils.validationOptions, codeableConcept, valueSet);
assertEquals(expectedValidationResult, validationResultB);
Mockito.verify(valueSetCheckerSimple).validateCode(codeableConcept);
Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, false);
Mockito.verify(context, times(0)).validateOnServer(any(), any(), any());
}
use of org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method validateCode.
@Override
public ValidationResult validateCode(ValidationOptions options, CodeableConcept code, ValueSet vs) {
CacheToken cacheToken = txCache.generateValidationToken(options, code, vs);
ValidationResult res = txCache.getValidation(cacheToken);
if (res != null)
return res;
// ok, first we try to validate locally
try {
ValueSetCheckerSimple vsc = new ValueSetCheckerSimple(options, vs, this);
res = vsc.validateCode(code);
txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
return res;
} catch (Exception e) {
}
// if that failed, we try to validate on the server
if (noTerminologyServer)
return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
tlog("$validate " + txCache.summary(code) + " for " + txCache.summary(vs));
try {
Parameters pIn = new Parameters();
pIn.addParameter().setName("codeableConcept").setValue(code);
if (options != null)
setTerminologyOptions(options, pIn);
res = validateOnServer(vs, pIn);
} catch (Exception e) {
res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog.getLastId());
}
txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
return res;
}
use of org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContextTests method testValidateCodingWithValueSetChecker.
@Test
public void testValidateCodingWithValueSetChecker() throws IOException {
ValidationOptions validationOptions = new ValidationOptions().guessSystem().setVersionFlexible(false);
ValueSet valueSet = new ValueSet();
Coding coding = new Coding();
Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, coding, valueSet);
Mockito.doReturn(valueSetCheckerSimple).when(context).constructValueSetCheckerSimple(any(), any(), any());
Mockito.doReturn(expectedValidationResult).when(valueSetCheckerSimple).validateCode(any(Coding.class));
ValidationContextCarrier ctxt = mock(ValidationContextCarrier.class);
IWorkerContext.ValidationResult actualValidationResult = context.validateCode(validationOptions, coding, valueSet, ctxt);
assertEquals(expectedValidationResult, actualValidationResult);
Mockito.verify(valueSetCheckerSimple).validateCode(coding);
Mockito.verify(terminologyCache).getValidation(cacheToken);
Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, false);
}
use of org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContextTests method testValidateCodableConceptWithCache.
@Test
public void testValidateCodableConceptWithCache() throws IOException {
CodeableConcept codeableConcept = new CodeableConcept();
ValueSet valueSet = new ValueSet();
Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(CacheTestUtils.validationOptions, codeableConcept, valueSet);
Mockito.doReturn(expectedValidationResult).when(terminologyCache).getValidation(cacheToken);
IWorkerContext.ValidationResult actualValidationResult = context.validateCode(CacheTestUtils.validationOptions, codeableConcept, valueSet);
assertEquals(expectedValidationResult, actualValidationResult);
Mockito.verify(valueSetCheckerSimple, times(0)).validateCode(codeableConcept);
Mockito.verify(terminologyCache).getValidation(cacheToken);
Mockito.verify(terminologyCache, times(0)).cacheValidation(any(), any(), anyBoolean());
}
use of org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method validateCode.
@Override
public ValidationResult validateCode(ValidationOptions options, Coding code, ValueSet vs, ValidationContextCarrier ctxt) {
if (options == null) {
options = ValidationOptions.defaults();
}
if (code.hasSystem()) {
codeSystemsUsed.add(code.getSystem());
}
CacheToken cacheToken = txCache != null ? txCache.generateValidationToken(options, code, vs) : null;
ValidationResult res = null;
if (txCache != null) {
res = txCache.getValidation(cacheToken);
}
if (res != null) {
return res;
}
if (options.isUseClient()) {
// ok, first we try to validate locally
try {
ValueSetCheckerSimple vsc = new ValueSetCheckerSimple(options, vs, this, ctxt);
if (!vsc.isServerSide(code.getSystem())) {
res = vsc.validateCode(code);
if (txCache != null) {
txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
}
return res;
}
} catch (Exception e) {
}
}
String codeKey = code.hasVersion() ? code.getSystem() + "|" + code.getVersion() : code.getSystem();
if (!options.isUseServer()) {
return new ValidationResult(IssueSeverity.WARNING, formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS);
}
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) {
tlog("$validate " + csumm + " for " + txCache.summary(vs));
} else {
tlog("$validate " + csumm + " before cache exists");
}
try {
Parameters pIn = new Parameters();
pIn.addParameter().setName("coding").setValue(code);
if (options.isGuessSystem()) {
pIn.addParameter().setName("implySystem").setValue(new BooleanType(true));
}
setTerminologyOptions(options, pIn);
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);
}
if (res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED && !code.hasVersion()) {
unsupportedCodeSystems.add(codeKey);
} else if (txCache != null) {
// we never cache unsuppoted code systems - we always keep trying (but only once per run)
txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
}
return res;
}
Aggregations