Fix a bug validating ValueSets (#1981)

* Fix a buig validating ValueSets

* Test fix
This commit is contained in:
James Agnew 2020-07-15 09:25:34 -04:00 committed by GitHub
parent addcdc9269
commit 29bf6b8171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 9 deletions

View File

@ -175,7 +175,7 @@ public class FhirResourceDaoR4ConcurrentWriteTest extends BaseJpaR4Test {
@Test
public void testDelete() {
myInterceptorRegistry.registerInterceptor(myRetryInterceptor);
String value = UserRequestRetryVersionConflictsInterceptor.RETRY + "; " + UserRequestRetryVersionConflictsInterceptor.MAX_RETRIES + "=10";
String value = UserRequestRetryVersionConflictsInterceptor.RETRY + "; " + UserRequestRetryVersionConflictsInterceptor.MAX_RETRIES + "=100";
when(mySrd.getHeaders(eq(UserRequestRetryVersionConflictsInterceptor.HEADER_NAME))).thenReturn(Collections.singletonList(value));
IIdType patientId = runInTransaction(() -> {

View File

@ -505,6 +505,64 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
}
@Test
public void testValidateValueSet() {
String input = "{\n" +
" \"resourceType\": \"ValueSet\",\n" +
" \"meta\": {\n" +
" \"profile\": [\n" +
" \"https://foo\"\n" +
" ]\n" +
" },\n" +
" \"text\": {\n" +
" \"status\": \"generated\",\n" +
" \"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\"></div>\"\n" +
" },\n" +
" \"url\": \"https://foo/bb\",\n" +
" \"name\": \"BBBehaviourType\",\n" +
" \"title\": \"BBBehaviour\",\n" +
" \"status\": \"draft\",\n" +
" \"version\": \"20190731\",\n" +
" \"experimental\": false,\n" +
" \"description\": \"alcohol habits.\",\n" +
" \"publisher\": \"BB\",\n" +
" \"immutable\": false,\n" +
" \"compose\": {\n" +
" \"include\": [\n" +
" {\n" +
" \"system\": \"https://bb\",\n" +
" \"concept\": [\n" +
" {\n" +
" \"code\": \"123\",\n" +
" \"display\": \"Current drinker\"\n" +
" },\n" +
" {\n" +
" \"code\": \"456\",\n" +
" \"display\": \"Ex-drinker\"\n" +
" },\n" +
" {\n" +
" \"code\": \"789\",\n" +
" \"display\": \"Lifetime non-drinker (finding)\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
ValueSet vs = myFhirCtx.newJsonParser().parseResource(ValueSet.class, input);
OperationOutcome oo = validateAndReturnOutcome(vs);
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo));
assertEquals("The code 123 is not valid in the system https://bb", oo.getIssue().get(0).getDiagnostics());
}
/**
* Per: https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Handling.20incomplete.20CodeSystems
* <p>

View File

@ -471,8 +471,9 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo
@Override
public ValidationResult validateCode(ValidationOptions theOptions, String system, String code, String display) {
IValidationSupport.CodeValidationResult result = myValidationSupportContext.getRootValidationSupport().validateCode(myValidationSupportContext, convertConceptValidationOptions(theOptions), system, code, display, null);
return convertValidationResult(result);
ConceptValidationOptions validationOptions = convertConceptValidationOptions(theOptions);
return doValidation(null, validationOptions, system, code, display);
}
@Override
@ -487,8 +488,9 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo
throw new InternalErrorException(e);
}
IValidationSupport.CodeValidationResult result = myValidationSupportContext.getRootValidationSupport().validateCodeInValueSet(myValidationSupportContext, convertConceptValidationOptions(theOptions), theSystem, theCode, display, convertedVs);
return convertValidationResult(result);
ConceptValidationOptions validationOptions = convertConceptValidationOptions(theOptions);
return doValidation(convertedVs, validationOptions, theSystem, theCode, display);
}
@Override
@ -502,12 +504,13 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo
throw new InternalErrorException(e);
}
IValidationSupport.CodeValidationResult result = myValidationSupportContext.getRootValidationSupport().validateCodeInValueSet(myValidationSupportContext, convertConceptValidationOptions(theOptions).setInferSystem(true), null, code, null, convertedVs);
return convertValidationResult(result);
ConceptValidationOptions validationOptions = convertConceptValidationOptions(theOptions).setInferSystem(true);
return doValidation(convertedVs, validationOptions, null, code, null);
}
@Override
public ValidationResult validateCode(ValidationOptions theOptions, org.hl7.fhir.r5.model.Coding code, org.hl7.fhir.r5.model.ValueSet theValueSet) {
public ValidationResult validateCode(ValidationOptions theOptions, org.hl7.fhir.r5.model.Coding theCoding, org.hl7.fhir.r5.model.ValueSet theValueSet) {
IBaseResource convertedVs = null;
try {
@ -518,7 +521,22 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo
throw new InternalErrorException(e);
}
IValidationSupport.CodeValidationResult result = myValidationSupportContext.getRootValidationSupport().validateCodeInValueSet(myValidationSupportContext, convertConceptValidationOptions(theOptions), code.getSystem(), code.getCode(), code.getDisplay(), convertedVs);
ConceptValidationOptions validationOptions = convertConceptValidationOptions(theOptions);
String system = theCoding.getSystem();
String code = theCoding.getCode();
String display = theCoding.getDisplay();
return doValidation(convertedVs, validationOptions, system, code, display);
}
@Nonnull
private ValidationResult doValidation(IBaseResource theValueSet, ConceptValidationOptions theValidationOptions, String theSystem, String theCode, String theDisplay) {
IValidationSupport.CodeValidationResult result;
if (theValueSet != null) {
result = myValidationSupportContext.getRootValidationSupport().validateCodeInValueSet(myValidationSupportContext, theValidationOptions, theSystem, theCode, theDisplay, theValueSet);
} else {
result = myValidationSupportContext.getRootValidationSupport().validateCode(myValidationSupportContext, theValidationOptions, theSystem, theCode, theDisplay, null);
}
return convertValidationResult(result);
}