From e39ee7f47d2d729e1d83fc3e0b2104306f689516 Mon Sep 17 00:00:00 2001 From: Lila Mikalson <100242827+lilamikalson-smilecdr@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:26:33 -0700 Subject: [PATCH] Add _language param to providers (#5801) * Add _language param to providers and tests * add pr number to docs * fix test * remove unnecessary code --------- Co-authored-by: Lila Mikalson --- .../7_2_0/5801-add-_language-param.yaml | 7 ++ ...esourceProviderLanguageParamDstu2Test.java | 67 +++++++++++++++ ...esourceProviderLanguageParamDstu3Test.java | 84 +++++++++++++++++++ .../ResourceProviderLanguageParamR4Test.java | 67 +++++++++++++++ ...rCapabilityStatementProviderJpaR4Test.java | 2 +- .../ResourceProviderLanguageParamR4BTest.java | 66 +++++++++++++++ .../ResourceProviderLanguageParamR5Test.java | 66 +++++++++++++++ .../resources/vm/jpa_resource_provider.vm | 5 +- 8 files changed, 359 insertions(+), 5 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5801-add-_language-param.yaml create mode 100644 hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderLanguageParamDstu2Test.java create mode 100644 hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderLanguageParamDstu3Test.java create mode 100644 hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderLanguageParamR4Test.java create mode 100644 hapi-fhir-jpaserver-test-r4b/src/test/java/ca/uhn/fhir/jpa/provider/r4b/ResourceProviderLanguageParamR4BTest.java create mode 100644 hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderLanguageParamR5Test.java diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5801-add-_language-param.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5801-add-_language-param.yaml new file mode 100644 index 00000000000..b8ed8d41f51 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5801-add-_language-param.yaml @@ -0,0 +1,7 @@ +--- +type: fix +issue: 5801 +title: "Support for the _language parameter was added but it was not able to be used by clients of a JPA server +because the _language parameter was not added to the resource providers. Additionally, no error message +was returned when language support was disabled and a search with _language was performed. This has +been fixed." diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderLanguageParamDstu2Test.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderLanguageParamDstu2Test.java new file mode 100644 index 00000000000..a69593a0490 --- /dev/null +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderLanguageParamDstu2Test.java @@ -0,0 +1,67 @@ +package ca.uhn.fhir.jpa.provider; + +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ResourceProviderLanguageParamDstu2Test extends BaseResourceProviderDstu2Test { + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamEnabled() { + myStorageSettings.setLanguageSearchParameterEnabled(true); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage(new CodeDt("en")); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage(new CodeDt("fr")); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + List foundResources; + Bundle result; + + result = myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + + foundResources = toUnqualifiedVersionlessIdValues(result); + assertThat(foundResources, contains(patId.getValue())); + } + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamDisabled() { + myStorageSettings.setLanguageSearchParameterEnabled(new JpaStorageSettings().isLanguageSearchParameterEnabled()); + mySearchParamRegistry.forceRefresh(); + + InvalidRequestException exception = assertThrows(InvalidRequestException.class, () -> { + myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + }); + assertThat(exception.getMessage(), containsString(Msg.code(1223))); + } +} diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderLanguageParamDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderLanguageParamDstu3Test.java new file mode 100644 index 00000000000..523467c83d4 --- /dev/null +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderLanguageParamDstu3Test.java @@ -0,0 +1,84 @@ +package ca.uhn.fhir.jpa.provider.dstu3; + +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Patient; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ResourceProviderLanguageParamDstu3Test extends BaseResourceProviderDstu3Test { + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamEnabled() { + myStorageSettings.setLanguageSearchParameterEnabled(true); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage("en"); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage("fr"); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + SearchParameterMap map; + IBundleProvider results; + List foundResources; + Bundle result; + + result = myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + + foundResources = toUnqualifiedVersionlessIdValues(result); + assertThat(foundResources, contains(patId.getValue())); + } + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamDisabled() { + myStorageSettings.setLanguageSearchParameterEnabled(new JpaStorageSettings().isLanguageSearchParameterEnabled()); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage("en"); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage("fr"); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + SearchParameterMap map; + IBundleProvider results; + List foundResources; + Bundle result; + + + InvalidRequestException exception = assertThrows(InvalidRequestException.class, () -> { + myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + }); + assertThat(exception.getMessage(), containsString(Msg.code(1223))); + } +} diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderLanguageParamR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderLanguageParamR4Test.java new file mode 100644 index 00000000000..6d89e6b7564 --- /dev/null +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderLanguageParamR4Test.java @@ -0,0 +1,67 @@ +package ca.uhn.fhir.jpa.provider.r4; + +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; +import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ResourceProviderLanguageParamR4Test extends BaseResourceProviderR4Test { + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamEnabled() { + myStorageSettings.setLanguageSearchParameterEnabled(true); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage("en"); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage("fr"); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + List foundResources; + Bundle result; + + result = myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + + foundResources = toUnqualifiedVersionlessIdValues(result); + assertThat(foundResources, contains(patId.getValue())); + } + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamDisabled() { + myStorageSettings.setLanguageSearchParameterEnabled(new JpaStorageSettings().isLanguageSearchParameterEnabled()); + mySearchParamRegistry.forceRefresh(); + + InvalidRequestException exception = assertThrows(InvalidRequestException.class, () -> { + myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + }); + assertThat(exception.getMessage(), containsString(Msg.code(1223))); + } +} diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java index 51632c5c249..5cabad60eb3 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerCapabilityStatementProviderJpaR4Test.java @@ -346,7 +346,7 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute(); for (CapabilityStatement.CapabilityStatementRestResourceComponent nextResource : cs.getRestFirstRep().getResource()) { for (CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent nextSp : nextResource.getSearchParam()) { - if (nextSp.getName().equals("_has") || nextSp.getName().equals("_list")) { + if (nextSp.getName().equals("_has") || nextSp.getName().equals("_list") || nextSp.getName().equals("_language")) { if (nextSp.getDefinition() == null) { continue; } diff --git a/hapi-fhir-jpaserver-test-r4b/src/test/java/ca/uhn/fhir/jpa/provider/r4b/ResourceProviderLanguageParamR4BTest.java b/hapi-fhir-jpaserver-test-r4b/src/test/java/ca/uhn/fhir/jpa/provider/r4b/ResourceProviderLanguageParamR4BTest.java new file mode 100644 index 00000000000..1d18ea0ce3b --- /dev/null +++ b/hapi-fhir-jpaserver-test-r4b/src/test/java/ca/uhn/fhir/jpa/provider/r4b/ResourceProviderLanguageParamR4BTest.java @@ -0,0 +1,66 @@ +package ca.uhn.fhir.jpa.provider.r4b; + +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4b.model.Bundle; +import org.hl7.fhir.r4b.model.Patient; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ResourceProviderLanguageParamR4BTest extends BaseResourceProviderR4BTest { + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamEnabled() { + myStorageSettings.setLanguageSearchParameterEnabled(true); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage("en"); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage("fr"); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + List foundResources; + Bundle result; + + result = myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + + foundResources = toUnqualifiedVersionlessIdValues(result); + assertThat(foundResources, contains(patId.getValue())); + } + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamDisabled() { + myStorageSettings.setLanguageSearchParameterEnabled(new JpaStorageSettings().isLanguageSearchParameterEnabled()); + mySearchParamRegistry.forceRefresh(); + + InvalidRequestException exception = assertThrows(InvalidRequestException.class, () -> { + myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + }); + assertThat(exception.getMessage(), containsString(Msg.code(1223))); + } +} diff --git a/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderLanguageParamR5Test.java b/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderLanguageParamR5Test.java new file mode 100644 index 00000000000..4f0ceb0fc92 --- /dev/null +++ b/hapi-fhir-jpaserver-test-r5/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderLanguageParamR5Test.java @@ -0,0 +1,66 @@ +package ca.uhn.fhir.jpa.provider.r5; + +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.config.JpaStorageSettings; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r5.model.Bundle; +import org.hl7.fhir.r5.model.Patient; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ResourceProviderLanguageParamR5Test extends BaseResourceProviderR5Test { + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamEnabled() { + myStorageSettings.setLanguageSearchParameterEnabled(true); + mySearchParamRegistry.forceRefresh(); + + Patient pat = new Patient(); + pat.setLanguage("en"); + IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); + + Patient pat2 = new Patient(); + pat.setLanguage("fr"); + IIdType patId2 = myPatientDao.create(pat2, mySrd).getId().toUnqualifiedVersionless(); + + List foundResources; + Bundle result; + + result = myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + + foundResources = toUnqualifiedVersionlessIdValues(result); + assertThat(foundResources, contains(patId.getValue())); + } + + @SuppressWarnings("unused") + @Test + public void testSearchWithLanguageParamDisabled() { + myStorageSettings.setLanguageSearchParameterEnabled(new JpaStorageSettings().isLanguageSearchParameterEnabled()); + mySearchParamRegistry.forceRefresh(); + + InvalidRequestException exception = assertThrows(InvalidRequestException.class, () -> { + myClient + .search() + .forResource(Patient.class) + .where(new TokenClientParam(Constants.PARAM_LANGUAGE).exactly().code("en")) + .returnBundle(Bundle.class) + .execute(); + }); + assertThat(exception.getMessage(), containsString(Msg.code(1223))); + } +} diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm index 807fe45c5b0..421c2a663d9 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm @@ -73,11 +73,9 @@ public class ${className}ResourceProvider extends @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LIST) StringAndListParam theList, -#if ( $version == 'R5' ) @Description(shortDefinition="The language of the resource") @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE) TokenAndListParam theResourceLanguage, -#end @Description(shortDefinition="Search for resources which have the given source value (Resource.meta.source)") @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE) @@ -160,9 +158,8 @@ public class ${className}ResourceProvider extends paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE, theSearchForProfile); paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE, theSearchForSource); paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LIST, theList); -#if ( $version == 'R5' ) paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE, theResourceLanguage); -#end + paramMap.add("_has", theHas); #foreach ( $param in $searchParams ) paramMap.add("${param.name}", the${param.nameCapitalized});