diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java index 1ab5eca2e12..e6301929bfa 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java @@ -199,7 +199,7 @@ public class Constants { public static final String PARAM_PRETTY_VALUE_FALSE = "false"; public static final String PARAM_PRETTY_VALUE_TRUE = "true"; public static final String PARAM_PROFILE = "_profile"; - public static final String PARAM__PID = "__pid"; + public static final String PARAM_PID = "_pid"; public static final String PARAM_QUERY = "_query"; public static final String PARAM_RESPONSE_URL = "response-url"; // Used in messaging diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_10_0/5428-pid-sp.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_10_0/5428-pid-sp.yaml index 2b698f9ecd9..2c91eef4d4e 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_10_0/5428-pid-sp.yaml +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_10_0/5428-pid-sp.yaml @@ -1,5 +1,5 @@ --- type: add issue: 5428 -title: "Add support for non-standard __pid SearchParameter to the the JPA engine. +title: "Add support for non-standard _pid SearchParameter to the the JPA engine. This new SP provides an efficient tie-breaking sort key." diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md index 32e7fd1b9bb..e760b4a3dab 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md @@ -22,11 +22,13 @@ Searching on Location.Position using `near` currently uses a box search, not a r The special `_filter` is only partially implemented. -### __pid +### _pid -The JPA server implements a non-standard special `__pid` which matches/sorts on the raw internal database id. +The JPA server implements a non-standard special `_pid` which matches/sorts on the raw internal database id. This sort is useful for imposing tie-breaking sort order in an efficient way. +Note that this is an internal feature that may change or be removed in the future. Use with caution. + # Uplifted Refchains and Chaining Performance diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java index 9191e023087..1075761f352 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java @@ -2293,7 +2293,7 @@ public class QueryStack { null, theSearchForIdsParams.myRequestPartitionId); - case Constants.PARAM__PID: + case Constants.PARAM_PID: return createPredicateResourcePID( theSearchForIdsParams.mySourceJoinColumn, theSearchForIdsParams.myAndOrParams); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index 39d6747507b..a268f5f0d84 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -838,7 +838,7 @@ public class SearchBuilder implements ISearchBuilder { theQueryStack.addSortOnResourceId(ascending); - } else if (Constants.PARAM__PID.equals(theSort.getParamName())) { + } else if (Constants.PARAM_PID.equals(theSort.getParamName())) { theQueryStack.addSortOnResourcePID(ascending); diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/ResourceMetaParams.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/ResourceMetaParams.java index 59c0f5a827d..0114fba0b7a 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/ResourceMetaParams.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/ResourceMetaParams.java @@ -51,8 +51,8 @@ public class ResourceMetaParams { Map>> resourceMetaAndParams = new HashMap<>(); resourceMetaParams.put(IAnyResource.SP_RES_ID, StringParam.class); resourceMetaAndParams.put(IAnyResource.SP_RES_ID, StringAndListParam.class); - resourceMetaParams.put(Constants.PARAM__PID, TokenParam.class); - resourceMetaAndParams.put(Constants.PARAM__PID, TokenAndListParam.class); + resourceMetaParams.put(Constants.PARAM_PID, TokenParam.class); + resourceMetaAndParams.put(Constants.PARAM_PID, TokenAndListParam.class); resourceMetaParams.put(Constants.PARAM_TAG, TokenParam.class); resourceMetaAndParams.put(Constants.PARAM_TAG, TokenAndListParam.class); resourceMetaParams.put(Constants.PARAM_PROFILE, UriParam.class); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QuerySandbox.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QuerySandbox.java index 06208dc101f..7efc920ccaf 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QuerySandbox.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QuerySandbox.java @@ -110,7 +110,7 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest { myDataBuilder.withActiveTrue(), myDataBuilder.withFamily("Smith")).getIdPart(); - myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?__pid=" + id, id); + myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?_pid=" + id, id); } @Test @@ -123,7 +123,7 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest { myDataBuilder.withActiveTrue(), myDataBuilder.withFamily("Smith")).getIdPart(); - myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?name=smith&__pid=" + id, id); + myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?name=smith&_pid=" + id, id); } @Test @@ -133,8 +133,8 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest { String id2 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithwick")).getIdPart(); String id3 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smith")).getIdPart(); - myTestDaoSearch.assertSearchFindsInOrder("sort by server assigned id", "Patient?family=smith&_sort=__pid", id1,id2,id3); - myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-__pid", id3,id2,id1); + myTestDaoSearch.assertSearchFindsInOrder("sort by server assigned id", "Patient?family=smith&_sort=_pid", id1,id2,id3); + myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-_pid", id3,id2,id1); } public static final class TestDirtiesContextTestExecutionListener extends DirtiesContextTestExecutionListener { diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StandardQueriesNoFTTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StandardQueriesNoFTTest.java index 0e4e498aacb..3d23277dc19 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StandardQueriesNoFTTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StandardQueriesNoFTTest.java @@ -515,8 +515,8 @@ public class FhirResourceDaoR4StandardQueriesNoFTTest extends BaseJpaTest { myDataBuilder.withActiveTrue(), myDataBuilder.withFamily("Smith")).getIdPart(); - myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?__pid=" + id, id); - myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?family=smith&__pid=" + id, id); + myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?_pid=" + id, id); + myTestDaoSearch.assertSearchFindsOnly("search by server assigned id", "Patient?family=smith&_pid=" + id, id); } @Test @@ -526,8 +526,8 @@ public class FhirResourceDaoR4StandardQueriesNoFTTest extends BaseJpaTest { String id2 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithwick")).getIdPart(); String id3 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smith")).getIdPart(); - myTestDaoSearch.assertSearchFindsInOrder("sort by server assigned id", "Patient?family=smith&_sort=__pid", id1,id2,id3); - myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-__pid", id3,id2,id1); + myTestDaoSearch.assertSearchFindsInOrder("sort by server assigned id", "Patient?family=smith&_sort=_pid", id1,id2,id3); + myTestDaoSearch.assertSearchFindsInOrder("reverse sort by server assigned id", "Patient?family=smith&_sort=-_pid", id3,id2,id1); } @Nested