diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java
index 2a7e5214327..d9e5f62f148 100644
--- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java
+++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java
@@ -20,29 +20,115 @@
package org.hl7.fhir.instance.model.api;
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
+import ca.uhn.fhir.rest.gclient.DateClientParam;
import ca.uhn.fhir.rest.gclient.TokenClientParam;
+import ca.uhn.fhir.rest.gclient.UriClientParam;
/**
* An IBaseResource that has a FHIR version of DSTU3 or higher
*/
public interface IAnyResource extends IBaseResource {
+ String SP_RES_ID = "_id";
/**
* Search parameter constant for _id
*/
- @SearchParamDefinition(name = "_id", path = "", description = "The ID of the resource", type = "token")
- String SP_RES_ID = "_id";
+ @SearchParamDefinition(
+ name = SP_RES_ID,
+ path = "Resource.id",
+ description = "The ID of the resource",
+ type = "token")
/**
* Fluent Client search parameter constant for _id
*
* Description: the _id of a resource
* Type: string
- * Path: Resource._id
+ * Path: Resource.id
*
*/
TokenClientParam RES_ID = new TokenClientParam(IAnyResource.SP_RES_ID);
+ String SP_RES_LAST_UPDATED = "_lastUpdated";
+ /**
+ * Search parameter constant for _lastUpdated
+ */
+ @SearchParamDefinition(
+ name = SP_RES_LAST_UPDATED,
+ path = "Resource.meta.lastUpdated",
+ description = "The last updated date of the resource",
+ type = "date")
+
+ /**
+ * Fluent Client search parameter constant for _lastUpdated
+ *
+ * Description: The last updated date of a resource
+ * Type: date
+ * Path: Resource.meta.lastUpdated
+ *
+ */
+ DateClientParam RES_LAST_UPDATED = new DateClientParam(IAnyResource.SP_RES_LAST_UPDATED);
+
+ String SP_RES_TAG = "_tag";
+ /**
+ * Search parameter constant for _tag
+ */
+ @SearchParamDefinition(
+ name = SP_RES_TAG,
+ path = "Resource.meta.tag",
+ description = "The tag of the resource",
+ type = "token")
+
+ /**
+ * Fluent Client search parameter constant for _tag
+ *
+ * Description: The tag of a resource
+ * Type: token
+ * Path: Resource.meta.tag
+ *
+ */
+ TokenClientParam RES_TAG = new TokenClientParam(IAnyResource.SP_RES_TAG);
+
+ String SP_RES_PROFILE = "_profile";
+ /**
+ * Search parameter constant for _profile
+ */
+ @SearchParamDefinition(
+ name = SP_RES_PROFILE,
+ path = "Resource.meta.profile",
+ description = "The profile of the resource",
+ type = "uri")
+
+ /**
+ * Fluent Client search parameter constant for _profile
+ *
+ * Description: The profile of a resource
+ * Type: uri
+ * Path: Resource.meta.profile
+ *
+ */
+ UriClientParam RES_PROFILE = new UriClientParam(IAnyResource.SP_RES_PROFILE);
+
+ String SP_RES_SECURITY = "_security";
+ /**
+ * Search parameter constant for _security
+ */
+ @SearchParamDefinition(
+ name = SP_RES_SECURITY,
+ path = "Resource.meta.security",
+ description = "The security of the resource",
+ type = "token")
+
+ /**
+ * Fluent Client search parameter constant for _security
+ *
+ * Description: The security of a resource
+ * Type: token
+ * Path: Resource.meta.security
+ *
+ */
+ TokenClientParam RES_SECURITY = new TokenClientParam(IAnyResource.SP_RES_SECURITY);
+
String getId();
IIdType getIdElement();
diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/6123-search-parameters-missing-in-ianyresource.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/6123-search-parameters-missing-in-ianyresource.yaml
new file mode 100644
index 00000000000..158a1aee33c
--- /dev/null
+++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_4_0/6123-search-parameters-missing-in-ianyresource.yaml
@@ -0,0 +1,6 @@
+---
+type: fix
+issue: 6123
+title: "`IAnyResource` `_id` search parameter was missing `path` property value, which resulted in extractor not
+ working when standard search parameters were instantiated from defined context. This has been fixed, and also
+ `_LastUpdated`, `_tag`, `_profile`, and `_security` parameter definitions were added to the class."
diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/FhirContextSearchParamRegistryTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/FhirContextSearchParamRegistryTest.java
new file mode 100644
index 00000000000..d51b344ccd0
--- /dev/null
+++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/FhirContextSearchParamRegistryTest.java
@@ -0,0 +1,38 @@
+package ca.uhn.fhir.jpa.searchparam.registry;
+
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.context.RuntimeSearchParam;
+import ca.uhn.fhir.rest.server.util.FhirContextSearchParamRegistry;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_ID;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_LAST_UPDATED;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_PROFILE;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_SECURITY;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_TAG;
+
+class FhirContextSearchParamRegistryTest {
+
+ private static final FhirContext ourFhirContext = FhirContext.forR4();
+
+ FhirContextSearchParamRegistry mySearchParamRegistry = new FhirContextSearchParamRegistry(ourFhirContext);
+
+ @ParameterizedTest
+ @CsvSource({
+ SP_RES_ID + ", Resource.id",
+ SP_RES_LAST_UPDATED + ", Resource.meta.lastUpdated",
+ SP_RES_TAG + ", Resource.meta.tag",
+ SP_RES_PROFILE + ", Resource.meta.profile",
+ SP_RES_SECURITY + ", Resource.meta.security"
+ })
+ void testResourceLevelSearchParamsAreRegistered(String theSearchParamName, String theSearchParamPath) {
+ RuntimeSearchParam sp = mySearchParamRegistry.getActiveSearchParam("Patient", theSearchParamName);
+
+ assertThat(sp)
+ .as("path is null for search parameter: '%s'", theSearchParamName)
+ .isNotNull().extracting("path").isEqualTo(theSearchParamPath);
+ }
+
+}
diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java
index b5a4e35f883..a94fe869672 100644
--- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java
+++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java
@@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.dao.dstu3;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
@@ -9,6 +10,7 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.test.BaseJpaDstu3Test;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
+import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.NumberParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
@@ -17,6 +19,7 @@ import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
+import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.ClasspathUtil;
import org.hl7.fhir.dstu3.model.Appointment;
import org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus;
@@ -192,7 +195,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
}
@Test
- public void testCustomReferenceParameter() throws Exception {
+ public void testCustomReferenceParameter() {
SearchParameter sp = new SearchParameter();
sp.addBase("Patient");
sp.setCode("myDoctor");
@@ -238,7 +241,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Patient p1 = new Patient();
p1.setActive(true);
p1.addExtension().setUrl("http://acme.org/eyecolour").addExtension().setUrl("http://foo").setValue(new StringType("VAL"));
- IIdType p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless();
+ myPatientDao.create(p1).getId().toUnqualifiedVersionless();
}
@@ -253,7 +256,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
attendingSp.setXpathUsage(org.hl7.fhir.dstu3.model.SearchParameter.XPathUsageType.NORMAL);
attendingSp.setStatus(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.ACTIVE);
attendingSp.getTarget().add(new CodeType("Practitioner"));
- IIdType spId = mySearchParameterDao.create(attendingSp, mySrd).getId().toUnqualifiedVersionless();
+ mySearchParameterDao.create(attendingSp, mySrd).getId().toUnqualifiedVersionless();
mySearchParamRegistry.forceRefresh();
@@ -417,7 +420,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Patient p2 = new Patient();
p2.addName().setFamily("P2");
p2.addExtension().setUrl("http://acme.org/sibling").setValue(new Reference(p1id));
- IIdType p2id = myPatientDao.create(p2).getId().toUnqualifiedVersionless();
+ myPatientDao.create(p2).getId().toUnqualifiedVersionless();
SearchParameterMap map;
IBundleProvider results;
@@ -571,7 +574,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Patient p2 = new Patient();
p2.setActive(true);
p2.addExtension().setUrl("http://acme.org/eyecolour").setValue(new CodeType("green"));
- IIdType p2id = myPatientDao.create(p2).getId().toUnqualifiedVersionless();
+ myPatientDao.create(p2).getId().toUnqualifiedVersionless();
// Try with custom gender SP
SearchParameterMap map = new SearchParameterMap();
@@ -889,7 +892,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
.setUrl("http://acme.org/bar")
.setValue(new Reference(aptId.getValue()));
- IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
+ myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map;
IBundleProvider results;
@@ -1035,7 +1038,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Patient pat2 = new Patient();
pat.setGender(AdministrativeGender.FEMALE);
- IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless();
+ myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap map;
IBundleProvider results;
@@ -1069,7 +1072,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
myPatientDao.search(map).size();
fail("");
} catch (InvalidRequestException e) {
- assertEquals(Msg.code(1223) + "Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
}
}
@@ -1094,7 +1097,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
Patient pat2 = new Patient();
pat.setGender(AdministrativeGender.FEMALE);
- IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless();
+ myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap map;
IBundleProvider results;
@@ -1107,7 +1110,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
myPatientDao.search(map).size();
fail("");
} catch (InvalidRequestException e) {
- assertEquals(Msg.code(1223) + "Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
}
// Try with normal gender SP
@@ -1148,10 +1151,10 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu
.findAll()
.stream()
.filter(t -> t.getParamName().equals("medicationadministration-ingredient-medication"))
- .collect(Collectors.toList());
- ourLog.info("Tokens:\n * {}", tokens.stream().map(t -> t.toString()).collect(Collectors.joining("\n * ")));
+ .toList();
+ ourLog.info("Tokens:\n * {}", tokens.stream().map(ResourceIndexedSearchParamToken::toString).collect(Collectors.joining("\n * ")));
assertEquals(1, tokens.size(), tokens.toString());
- assertEquals(false, tokens.get(0).isMissing());
+ assertFalse(tokens.get(0).isMissing());
});
diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java
index f1a4171d565..c0e299559ce 100644
--- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java
+++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java
@@ -1,5 +1,8 @@
package ca.uhn.fhir.jpa.dao.dstu3;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_PROFILE;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_SECURITY;
+import static org.hl7.fhir.instance.model.api.IAnyResource.SP_RES_TAG;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -33,6 +36,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
+import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
@@ -42,6 +46,7 @@ import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
+import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
@@ -2082,7 +2087,102 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE + "AAAA", new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
assertThat(found).isEmpty();
} catch (InvalidRequestException e) {
- assertEquals(Msg.code(1223) + "Unknown search parameter \"birthdateAAAA\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"birthdateAAAA\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPersistSearchParamTag() {
+ Coding TEST_PARAM_VALUE_CODING_1 = new Coding("test-system", "test-code-1", null);
+ Coding TEST_PARAM_VALUE_CODING_2 = new Coding("test-system", "test-code-2", null);
+
+ List found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_TAG, new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeCoding1 = found.size();
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_TAG, new TokenParam(TEST_PARAM_VALUE_CODING_2)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeCoding2 = found.size();
+
+ Patient patient = new Patient();
+ patient.addIdentifier().setSystem("urn:system").setValue("001");
+ patient.getMeta().addTag(TEST_PARAM_VALUE_CODING_1);
+
+ myPatientDao.create(patient, mySrd);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_TAG, new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(1 + initialSizeCoding1);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_TAG, new TokenParam(TEST_PARAM_VALUE_CODING_2)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(initialSizeCoding2);
+
+ // If this throws an exception, that would be an acceptable outcome as well..
+ try {
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_TAG + "AAAA", new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).isEmpty();
+ } catch (InvalidRequestException e) {
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"" + SP_RES_TAG+"AAAA" + "\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPersistSearchParamProfile() {
+ String profileA = "profile-AAA";
+ String profileB = "profile-BBB";
+ List found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_PROFILE, new UriParam(profileA)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeProfileA = found.size();
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_PROFILE, new UriParam(profileB)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeProfileB = found.size();
+
+ Patient patient = new Patient();
+ patient.addIdentifier().setSystem("urn:system").setValue("001");
+ patient.getMeta().addProfile(profileA);
+
+ myPatientDao.create(patient, mySrd);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_PROFILE, new UriParam(profileA)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(1 + initialSizeProfileA);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_PROFILE, new UriParam(profileB)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(initialSizeProfileB);
+
+ // If this throws an exception, that would be an acceptable outcome as well..
+ try {
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_PROFILE + "AAAA", new UriParam(profileA)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).isEmpty();
+ } catch (InvalidRequestException e) {
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"" + SP_RES_PROFILE+"AAAA" + "\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPersistSearchParamSecurity() {
+ Coding TEST_PARAM_VALUE_CODING_1 = new Coding("test-system", "test-code-1", null);
+ Coding TEST_PARAM_VALUE_CODING_2 = new Coding("test-system", "test-code-2", null);
+
+ List found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_SECURITY, new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeSecurityA = found.size();
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_SECURITY, new TokenParam(TEST_PARAM_VALUE_CODING_2)).setLoadSynchronous(true), new SystemRequestDetails()));
+ int initialSizeSecurityB = found.size();
+
+ Patient patient = new Patient();
+ patient.addIdentifier().setSystem("urn:system").setValue("001");
+ patient.getMeta().addSecurity(TEST_PARAM_VALUE_CODING_1);
+
+ myPatientDao.create(patient, mySrd);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_SECURITY, new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(1 + initialSizeSecurityA);
+
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_SECURITY, new TokenParam(TEST_PARAM_VALUE_CODING_2)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).hasSize(initialSizeSecurityB);
+
+ // If this throws an exception, that would be an acceptable outcome as well..
+ try {
+ found = toList(myPatientDao.search(new SearchParameterMap(SP_RES_SECURITY + "AAAA", new TokenParam(TEST_PARAM_VALUE_CODING_1)).setLoadSynchronous(true), new SystemRequestDetails()));
+ assertThat(found).isEmpty();
+ } catch (InvalidRequestException e) {
+ assertEquals(Msg.code(1223) + "Unknown search parameter \"" + SP_RES_SECURITY+"AAAA" + "\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, active, address, address-city, address-country, address-postalcode, address-state, address-use, animal-breed, animal-species, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]", e.getMessage());
}
}
diff --git a/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/search/reindex/InstanceReindexServiceImplR5Test.java b/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/search/reindex/InstanceReindexServiceImplR5Test.java
index 40e68b557ca..de2be916e6a 100644
--- a/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/search/reindex/InstanceReindexServiceImplR5Test.java
+++ b/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/search/reindex/InstanceReindexServiceImplR5Test.java
@@ -71,7 +71,7 @@ public class InstanceReindexServiceImplR5Test extends BaseJpaR5Test {
.map(t -> t.getName() + " " + getPartValue("Action", t) + " " + getPartValue("Type", t) + " " + getPartValue("Missing", t))
.sorted()
.toList();
- assertThat(indexInstances).as(indexInstances.toString()).containsExactly("_id NO_CHANGE Token true", "active NO_CHANGE Token true", "address NO_CHANGE String true", "address-city NO_CHANGE String true", "address-country NO_CHANGE String true", "address-postalcode NO_CHANGE String true", "address-state NO_CHANGE String true", "address-use NO_CHANGE Token true", "birthdate NO_CHANGE Date true", "death-date NO_CHANGE Date true", "email NO_CHANGE Token true", "gender NO_CHANGE Token true", "general-practitioner NO_CHANGE Reference true", "identifier NO_CHANGE Token true", "language NO_CHANGE Token true", "link NO_CHANGE Reference true", "organization NO_CHANGE Reference true", "part-agree NO_CHANGE Reference true", "phone NO_CHANGE Token true", "telecom NO_CHANGE Token true");
+ assertThat(indexInstances).as(indexInstances.toString()).containsExactly("active NO_CHANGE Token true", "address NO_CHANGE String true", "address-city NO_CHANGE String true", "address-country NO_CHANGE String true", "address-postalcode NO_CHANGE String true", "address-state NO_CHANGE String true", "address-use NO_CHANGE Token true", "birthdate NO_CHANGE Date true", "death-date NO_CHANGE Date true", "email NO_CHANGE Token true", "gender NO_CHANGE Token true", "general-practitioner NO_CHANGE Reference true", "identifier NO_CHANGE Token true", "language NO_CHANGE Token true", "link NO_CHANGE Reference true", "organization NO_CHANGE Reference true", "part-agree NO_CHANGE Reference true", "phone NO_CHANGE Token true", "telecom NO_CHANGE Token true");
}