4671 Searching with _source parameter will return matches for all resource types (#4673)

* adding solution with new test.

* adding changelog

---------

Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
Etienne Poirier 2023-03-23 14:04:01 -04:00 committed by GitHub
parent b33b789880
commit fb057d4fb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 4671
jira: SMILE-6213
title: "Previously, searching with the '_source' parameter would return matching source for all resource types. This has been corrected."

View File

@ -1311,6 +1311,8 @@ public class QueryStack {
}
private Condition createPredicateSourceForAndList(@Nullable DbColumn theSourceJoinColumn, List<List<IQueryParameterType>> theAndOrParams) {
mySqlBuilder.getOrCreateFirstPredicateBuilder();
List<Condition> andPredicates = new ArrayList<>(theAndOrParams.size());
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
andPredicates.add(createPredicateSource(theSourceJoinColumn, nextAnd));

View File

@ -15,6 +15,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import org.apache.commons.text.RandomStringGenerator;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -80,6 +81,30 @@ public class FhirResourceDaoR4SourceTest extends BaseJpaR4Test {
}
@Test
public void testSearchSource_whenSameSourceForMultipleResourceTypes_willMatchSearchResourceTypeOnly(){
String sourceUrn = "urn:source:0";
String requestId = "a_request_id";
when(mySrd.getRequestId()).thenReturn(requestId);
Patient patient = new Patient();
patient.getMeta().setSource(sourceUrn);
patient.setActive(true);
IIdType ptId = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
Observation observation = new Observation();
observation.setStatus(Observation.ObservationStatus.FINAL);
observation.getMeta().setSource(sourceUrn);
myObservationDao.create(observation, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap params = new SearchParameterMap();
params.setLoadSynchronous(true);
params.add(Constants.PARAM_SOURCE, new TokenParam("urn:source:0"));
IBundleProvider result = myPatientDao.search(params);
assertThat(toUnqualifiedVersionlessIdValues(result), containsInAnyOrder(ptId.getValue()));
}
@Test
public void testSearchWithOr() {