diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/validation/ResourceValidationR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/validation/ResourceValidationR4Test.java index c58313ac199..ebfd48ae4a1 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/validation/ResourceValidationR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/validation/ResourceValidationR4Test.java @@ -19,6 +19,8 @@ import org.hl7.fhir.r4.model.StructureDefinition; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Iterator; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -89,6 +91,27 @@ public class ResourceValidationR4Test extends BaseJpaR4Test { assertTrue(message.getMessage().contains(PATIENT_STRUCTURE_DEFINITION_URL + "|2")); } + @Test + public void testValidatePatient_withMultipleProfilesDifferentUrls_validatesAgainstAllProfiles() { + final String sdIdentifier = PATIENT_STRUCTURE_DEFINITION_URL + "-identifier"; + final String sdName = PATIENT_STRUCTURE_DEFINITION_URL + "-name"; + createPatientStructureDefinitionWithMandatoryField(sdIdentifier, "1", "Patient.identifier"); + createPatientStructureDefinitionWithMandatoryField(sdName, "1", "Patient.name"); + + Patient patient = new Patient(); + patient.getMeta().addProfile(sdIdentifier).addProfile(sdName); + myPatientDao.create(patient, mySrd); + + ValidationResult validationResult = myFhirValidator.validateWithResult(patient); + assertFalse(validationResult.isSuccessful()); + assertEquals(2, validationResult.getMessages().size()); + + Iterator messageIterator = validationResult.getMessages().iterator(); + assertTrue(messageIterator.next().getMessage().contains(sdIdentifier)); + assertTrue(messageIterator.next().getMessage().contains(sdName)); + } + + @Test public void testStructureDefinition_createResourceWithMultipleProfilesSameStructureDefinition_usesFirstVersion() { createPatientStructureDefinitionWithMandatoryField(PATIENT_STRUCTURE_DEFINITION_URL, "1", "Patient.identifier");