IndexedSearchParamExtractor regression returned wrong number of links pre-persistence (#4341)

* fixed the issue

* change log

* fix regression

Co-authored-by: Ken Stevens <ken@smilecdr.com>
This commit is contained in:
Ken Stevens 2022-12-08 00:22:51 -05:00 committed by GitHub
parent 0e59665711
commit f4ce765122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 4341
title: "Fixes a regression where IndexedSearchParamExtractor returns too few links when extracting search parameters from
a resource that hasn't persisted yet. E.g. when a create interceptor needs to extract search parameters from the resource
before it is persisted."

View File

@ -143,7 +143,13 @@ public class ResourceLink extends BaseResourceIndex {
b.append(myTargetResourceUrl, obj.myTargetResourceUrl);
b.append(myTargetResourceType, obj.myTargetResourceType);
b.append(myTargetResourceVersion, obj.myTargetResourceVersion);
b.append(getTargetResourcePid(), obj.getTargetResourcePid());
// In cases where we are extracting links from a resource that has not yet been persisted, the target resource pid
// will be null so we use the target resource id to differentiate instead
if (getTargetResourcePid() == null) {
b.append(getTargetResourceId(), obj.getTargetResourceId());
} else {
b.append(getTargetResourcePid(), obj.getTargetResourcePid());
}
return b.isEquals();
}
@ -256,7 +262,14 @@ public class ResourceLink extends BaseResourceIndex {
b.append(mySourceResource);
b.append(myTargetResourceUrl);
b.append(myTargetResourceVersion);
b.append(getTargetResourcePid());
// In cases where we are extracting links from a resource that has not yet been persisted, the target resource pid
// will be null so we use the target resource id to differentiate instead
if (getTargetResourcePid() == null) {
b.append(getTargetResourceId());
} else {
b.append(getTargetResourcePid());
}
return b.toHashCode();
}

View File

@ -0,0 +1,41 @@
package ca.uhn.fhir.jpa.searchparam.matcher;
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
import org.hl7.fhir.r4.model.Appointment;
import org.hl7.fhir.r4.model.Encounter;
import org.hl7.fhir.r4.model.Reference;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class IndexedSearchParamExtractorTest extends BaseJpaR4Test {
@Autowired
PlatformTransactionManager myPlatformTransactionManager;
// SUT: System Under Test
@Autowired
IndexedSearchParamExtractor mySrv;
@Override
protected PlatformTransactionManager getTxManager() {
return myPlatformTransactionManager;
}
@Test
public void extractIndexedSearchParams_twoReferences_twoLinks() {
Encounter encounter = new Encounter();
Appointment appt1 = new Appointment();
appt1.setId("Appointment/appt1");
encounter.addAppointment(new Reference(appt1));
Appointment appt2 = new Appointment();
appt2.setId("Appointment/appt2");
encounter.addAppointment(new Reference(appt2));
ResourceIndexedSearchParams result = mySrv.extractIndexedSearchParams(encounter, mySrd);
// red-green before the fix, the size was 1
assertEquals(2, result.myLinks.size());
}
}