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 <lila.mikalson@smilecdr.com>
This commit is contained in:
Lila Mikalson 2024-04-02 13:26:33 -07:00 committed by GitHub
parent 70843cdf45
commit e39ee7f47d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 359 additions and 5 deletions

View File

@ -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."

View File

@ -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)));
}
}

View File

@ -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)));
}
}

View File

@ -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)));
}
}

View File

@ -346,7 +346,7 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv
CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute(); CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute();
for (CapabilityStatement.CapabilityStatementRestResourceComponent nextResource : cs.getRestFirstRep().getResource()) { for (CapabilityStatement.CapabilityStatementRestResourceComponent nextResource : cs.getRestFirstRep().getResource()) {
for (CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent nextSp : nextResource.getSearchParam()) { 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) { if (nextSp.getDefinition() == null) {
continue; continue;
} }

View File

@ -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)));
}
}

View File

@ -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)));
}
}

View File

@ -73,11 +73,9 @@ public class ${className}ResourceProvider extends
@OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LIST) @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LIST)
StringAndListParam theList, StringAndListParam theList,
#if ( $version == 'R5' )
@Description(shortDefinition="The language of the resource") @Description(shortDefinition="The language of the resource")
@OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE) @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE)
TokenAndListParam theResourceLanguage, TokenAndListParam theResourceLanguage,
#end
@Description(shortDefinition="Search for resources which have the given source value (Resource.meta.source)") @Description(shortDefinition="Search for resources which have the given source value (Resource.meta.source)")
@OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_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_PROFILE, theSearchForProfile);
paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE, theSearchForSource); paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SOURCE, theSearchForSource);
paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LIST, theList); 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); paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE, theResourceLanguage);
#end
paramMap.add("_has", theHas); paramMap.add("_has", theHas);
#foreach ( $param in $searchParams ) #foreach ( $param in $searchParams )
paramMap.add("${param.name}", the${param.nameCapitalized}); paramMap.add("${param.name}", the${param.nameCapitalized});