-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
70843cd
commit e39ee7f
Showing
8 changed files
with
359 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_2_0/5801-add-_language-param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |
67 changes: 67 additions & 0 deletions
67
...-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderLanguageParamDstu2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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))); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
.../src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderLanguageParamDstu3Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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))); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...est-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderLanguageParamR4Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...-r4b/src/test/java/ca/uhn/fhir/jpa/provider/r4b/ResourceProviderLanguageParamR4BTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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))); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...est-r5/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderLanguageParamR5Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters