diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index f827a395a3e..e5a2bbfdf1f 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -34,7 +34,6 @@ import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.test.util.LogbackTestExtension; import ca.uhn.test.util.LogbackTestExtensionAssert; -import ch.qos.logback.classic.Level; import org.apache.commons.io.IOUtils; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.UnknownCodeSystemWarningValidationSupport; @@ -53,6 +52,7 @@ import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.Composition; import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.DateTimeType; import org.hl7.fhir.r4.model.ElementDefinition; @@ -95,6 +95,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -2439,4 +2440,161 @@ public void testValidateObservationWithVitalSignsLoincCode() { assertHasNoErrors(oo); } + @Test + public void testValidate_CompositionStructureDefinitionWithProfileTypeResolveDiscriminator_WithTargetProfileSlice_NoDuplicateIssue() { + String compositionSdStr = + """ + { + "resourceType": "StructureDefinition", + "url": "http://compositionprofile", + "status": "active", + "abstract": false, + "type": "Composition", + "derivation": "constraint", + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/Composition", + "differential": { + "element": [ + { + "id": "Composition.section.entry", + "path": "Composition.section.entry", + "slicing": { + "discriminator": [ { + "type": "profile", + "path": "resolve()" + } ], + "ordered": false, + "rules": "open" + } + }, + { + "id": "Composition.section.entry:allergyOrIntolerance", + "path": "Composition.section.entry", + "sliceName": "allergyOrIntolerance", + "min": 1, + "max": "*", + "type": [ + { + "code": "Reference", + "targetProfile": "http://allergyintoleranceprofile" + } + ] + } + ] + } + } + """; + + + String allergyIntoleranceSdStr = """ + { + "resourceType": "StructureDefinition", + "url": "http://allergyintoleranceprofile", + "status": "active", + "abstract": false, + "type": "AllergyIntolerance", + "baseDefinition": "http://hl7.org/fhir/StructureDefinition/AllergyIntolerance", + "derivation": "constraint", + "differential": { + "element": [ { + "id": "AllergyIntolerance.verificationStatus", + "path": "AllergyIntolerance.verificationStatus", + "min": 1, + "max": "1", + "binding": { + "strength": "required", + "valueSet": "http://vs" + } + } ] + } + } + """; + + StructureDefinition sdComposition = (StructureDefinition) myFhirContext.newJsonParser().parseResource(compositionSdStr); + StructureDefinition sdAllergyIntolerance = (StructureDefinition) myFhirContext.newJsonParser().parseResource(allergyIntoleranceSdStr); + + + myStructureDefinitionDao.create(sdAllergyIntolerance, new SystemRequestDetails()); + + myStructureDefinitionDao.create(sdComposition, new SystemRequestDetails()); + + CodeSystem cs = new CodeSystem(); + cs.setUrl("http://cs"); + cs.setStatus(Enumerations.PublicationStatus.ACTIVE); + cs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE); + cs.addConcept() + .setCode("xxxx") + .setDisplay("XXXX"); + + myCodeSystemDao.create(cs, new SystemRequestDetails()); + + ValueSet vs = new ValueSet(); + vs.setUrl("http://vs"); + vs.setStatus(Enumerations.PublicationStatus.ACTIVE); + vs.getCompose().addInclude().setSystem("http://cs"); + + myValueSetDao.create(vs, new SystemRequestDetails()); + + + String resourceToValidateStr = """ + { + "resourceType": "Bundle", + "entry": [ { + "resource": { + "resourceType": "Composition", + "meta": { + "profile": [ "http://compositionprofile" ] + }, + "section": [ { + "code": { + "coding": [ { + "system": "http://loinc.org", + "code": "48765-2" + } ] + }, + "entry": [ { + "reference": "AllergyIntolerance/123" + } ] + } ] + } + }, { + "resource": { + "resourceType": "AllergyIntolerance", + "id": "123", + "meta": { + "profile": [ "http://allergyintoleranceprofile" ] + }, + "text": { + "status": "generated", + "div": "