diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/sql/SearchQueryBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/sql/SearchQueryBuilder.java index f9544347593..3f254e6cfd8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/sql/SearchQueryBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/sql/SearchQueryBuilder.java @@ -361,6 +361,12 @@ public class SearchQueryBuilder { public ComboCondition createOnCondition(DbColumn theSourceColumn, DbColumn theTargetColumn) { ComboCondition onCondition = ComboCondition.and(); onCondition.addCondition(BinaryCondition.equalTo(theSourceColumn, theTargetColumn)); + // fixme cosmos hack + if (true) { + DbColumn sourcePartId = theSourceColumn.getTable().findColumn("PARTITION_ID"); + DbColumn targetPartId = theTargetColumn.getTable().findColumn("PARTITION_ID"); + onCondition.addCondition(BinaryCondition.equalTo(sourcePartId, targetPartId)); + } return onCondition; } @@ -459,18 +465,18 @@ public class SearchQueryBuilder { DbColumn theToColumn, SelectQuery.JoinType theJoinType) { DbColumn[] fromColumns; - DbColumn[] toColumns; + DbColumn[] toColumns; if (true) { // fixme cosmos hack - fromColumns = new DbColumn[]{theFromColumn, theFromTable.findColumn("PARTITION_ID")}; - toColumns = new DbColumn[]{theToColumn, theToTable.findColumn("PARTITION_ID")}; + fromColumns = new DbColumn[] {theFromColumn, theFromTable.findColumn("PARTITION_ID")}; + toColumns = new DbColumn[] {theToColumn, theToTable.findColumn("PARTITION_ID")}; } else { - fromColumns = new DbColumn[]{theFromColumn}; - toColumns = new DbColumn[]{theToColumn}; + fromColumns = new DbColumn[] {theFromColumn}; + toColumns = new DbColumn[] {theToColumn}; } - Join join = new DbJoin(mySpec, theFromTable, theToTable, fromColumns, toColumns); + Join join = new DbJoin(mySpec, theFromTable, theToTable, fromColumns, toColumns); mySelect.addJoins(theJoinType, join); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/cosmos/CosmosDbTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/cosmos/CosmosDbTest.java index 4dd4f09f871..5f4cffe4f29 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/cosmos/CosmosDbTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/cosmos/CosmosDbTest.java @@ -7,6 +7,7 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.api.svc.ISearchCoordinatorSvc; import ca.uhn.fhir.jpa.bulk.export.api.IBulkDataExportJobSchedulingHelper; +import ca.uhn.fhir.jpa.dao.TestDaoSearch; import ca.uhn.fhir.jpa.entity.PartitionEntity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc; @@ -18,9 +19,7 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; import ca.uhn.fhir.util.BundleBuilder; -import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IAnyResource; -import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.IdType; @@ -32,6 +31,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -72,6 +73,8 @@ public class CosmosDbTest extends BaseJpaTest { private ISearchParamRegistry mySearchParamRegistry; @Autowired private IBulkDataExportJobSchedulingHelper myBulkDataScheduleHelper; + @Autowired + private TestDaoSearch myDaoSearch; @Override protected FhirContext getFhirContext() { @@ -142,6 +145,26 @@ public class CosmosDbTest extends BaseJpaTest { assertThat(toUnqualifiedVersionlessIdValues(outcome), contains(OBSERVATION_O0)); } + @ParameterizedTest + @CsvSource(textBlock = """ + string, Patient?_sort=name + date, Observation?_sort=date + _id, Patient?_sort=_id + _lastUpdated, Patient?_sort=_lastUpdated + _pid, Patient?_sort=_pid + """) + void testSort(String theComment, String theQuery) { + // Create resource + createPatientAndObservation(); + + // when + addReadPartition(1); + List ids = myDaoSearch.searchForIds(theQuery); + + assertEquals(1, ids.size(), theComment); + } + + @Test public void testIncludes() { // Setup @@ -222,6 +245,7 @@ public class CosmosDbTest extends BaseJpaTest { patient.setId(PATIENT_P0); patient.addIdentifier().setSystem("http://foo").setValue("123"); patient.setGender(Enumerations.AdministrativeGender.MALE); + patient.addName().setFamily("Smith"); myPatientDao.update(patient, mySrd).getId().toUnqualifiedVersionless(); addCreatePartition1();