diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
index 4dde180e6c75..46187593e635 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
@@ -93,10 +93,17 @@ public boolean matchesInclude(Include theInclude) {
int colonIndex = theInclude.getValue().indexOf(':');
if (colonIndex != -1) {
// DSTU2+ style
- String resourceName = theInclude.getValue().substring(0, colonIndex);
- String paramName = theInclude.getValue().substring(colonIndex + 1);
+ String targetResourceName = theInclude.getParamTargetType();
+ if (targetResourceName != null
+ && !targetResourceName.equals(
+ myResource.getReferenceElement().getResourceType())) {
+ return false;
+ }
+
+ String resourceName = theInclude.getParamType();
RuntimeResourceDefinition resourceDef = myContext.getResourceDefinition(resourceName);
if (resourceDef != null) {
+ String paramName = theInclude.getParamName();
RuntimeSearchParam searchParamDef = resourceDef.getSearchParam(paramName);
if (searchParamDef != null) {
final String completeName = myOwningResource + "." + myName;
diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ResourceReferenceInfoTest.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ResourceReferenceInfoTest.java
new file mode 100644
index 000000000000..e85b5abf93fd
--- /dev/null
+++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ResourceReferenceInfoTest.java
@@ -0,0 +1,48 @@
+package ca.uhn.fhir.util;
+
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.model.api.Include;
+import org.hl7.fhir.dstu3.model.Patient;
+import org.hl7.fhir.dstu3.model.Reference;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ResourceReferenceInfoTest {
+
+ private ResourceReferenceInfo resourceReferenceInfo;
+
+ private final FhirContext fhirContext = FhirContext.forDstu3();
+
+ @BeforeEach
+ public void setUp() {
+ Reference theElement = new Reference()
+ .setReference("Practitioner/123")
+ .setDisplay("Test Practitioner");
+
+ Patient theOwningResource = new Patient()
+ .addGeneralPractitioner(theElement);
+
+ resourceReferenceInfo =
+ new ResourceReferenceInfo(fhirContext, theOwningResource, List.of("generalPractitioner"), theElement);
+ }
+
+ @Test
+ public void matchesInclude_hasTargetResourceType_matched() {
+ assertTrue(resourceReferenceInfo.matchesInclude(new Include("Patient:general-practitioner:Practitioner")));
+ }
+
+ @Test
+ public void matchesInclude_hasNotTargetResourceType_matched() {
+ assertTrue(resourceReferenceInfo.matchesInclude(new Include("Patient:general-practitioner")));
+ }
+
+ @Test
+ public void matchesInclude_hasDifferentTargetResourceType_notMatched() {
+ assertFalse(resourceReferenceInfo.matchesInclude(new Include("Patient:general-practitioner:Organization")));
+ }
+}
diff --git a/pom.xml b/pom.xml
index 08b3a1c9d6a6..9d3f374e3d58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1113,7 +1113,7 @@
com.jayway.jsonpath
json-path
- 2.8.0
+ 2.9.0
com.jayway.jsonpath