diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConcurrentWriteTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConcurrentWriteTest.java index 3b1fab83c08..30bc79b07e2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConcurrentWriteTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConcurrentWriteTest.java @@ -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(() -> { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index baa846ac3f9..e29e814178e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -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\": \"
\"\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 *diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java index 0ef8b423be7..848ab9e1d5c 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java @@ -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); }