introduced _list fix (#5664)

* introduced fix

* Add value

* Added backing tests

* Ignore _list as _has is done
This commit is contained in:
Jens Kristian Villadsen 2024-02-06 02:26:20 +01:00 committed by GitHub
parent cbd733c340
commit bc955b8539
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 2 deletions

View File

@ -151,6 +151,7 @@ import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -1985,8 +1986,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
private void translateListSearchParams(SearchParameterMap theParams) { private void translateListSearchParams(SearchParameterMap theParams) {
Set<Map.Entry<String, List<List<IQueryParameterType>>>> entryHashSet = new HashSet<>(theParams.entrySet());
// Translate _list=42 to _has=List:item:_id=42 // Translate _list=42 to _has=List:item:_id=42
for (String key : theParams.keySet()) { for (Map.Entry<String, List<List<IQueryParameterType>>> stringListEntry : entryHashSet) {
String key = stringListEntry.getKey();
if (Constants.PARAM_LIST.equals((key))) { if (Constants.PARAM_LIST.equals((key))) {
List<List<IQueryParameterType>> andOrValues = theParams.get(key); List<List<IQueryParameterType>> andOrValues = theParams.get(key);
theParams.remove(key); theParams.remove(key);

View File

@ -0,0 +1,74 @@
package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.ListResource;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.Reference;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ListR4Test extends BaseResourceProviderR4Test {
private IIdType orgInList;
private IIdType practitionerInList;
private IIdType list;
private String identifierSystem = "http://example123.com/identifier";
@BeforeEach
@Override
public void before() throws Exception {
super.before();
orgInList = createOrganization(withActiveTrue(), withIdentifier(identifierSystem, "B"));
practitionerInList = createPractitioner(withActiveTrue());
ListResource testList = new ListResource()
.addEntry(new ListResource.ListEntryComponent().setItem(new Reference(orgInList.toUnqualifiedVersionless().getValue())))
.addEntry(new ListResource.ListEntryComponent().setItem(new Reference(practitionerInList.toUnqualifiedVersionless().getValue())));
list = doCreateResource(testList);
}
@Test
public void organizationSearchUsingListReturnsOnlyOrgInList() {
Bundle results = (Bundle) myClient.search()
.forResource(Organization.class)
.whereMap(Collections.singletonMap("_list", Collections.singletonList(list.getIdPart())))
.execute();
assertEquals(1, results.getEntry().size());
assertEquals(orgInList.toUnqualifiedVersionless().getValue(), results.getEntryFirstRep().getResource().getIdElement().toUnqualifiedVersionless().getValue());
}
@Test
public void organizationSearchUsingListWorksWithAnotherParameter() {
Bundle results = (Bundle) myClient.search()
.forResource(Organization.class)
.whereMap(Collections.singletonMap("_list", Collections.singletonList(list.getIdPart())))
.and(Organization.IDENTIFIER.hasSystemWithAnyCode(identifierSystem))
.execute();
assertEquals(1, results.getEntry().size());
assertEquals(orgInList.toUnqualifiedVersionless().getValue(), results.getEntryFirstRep().getResource().getIdElement().toUnqualifiedVersionless().getValue());
}
@Test
public void practitionerSearchUsingListReturnsOnlyPractitionerInList() {
Bundle results = (Bundle) myClient.search()
.forResource(Practitioner.class)
.whereMap(Collections.singletonMap("_list", Collections.singletonList(list.getIdPart())))
.execute();
assertEquals(1, results.getEntry().size());
assertEquals(practitionerInList.toUnqualifiedVersionless().getValue(), results.getEntryFirstRep().getResource().getIdElement().toUnqualifiedVersionless().getValue());
}
}

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")) { if (nextSp.getName().equals("_has") || nextSp.getName().equals("_list")) {
if (nextSp.getDefinition() == null) { if (nextSp.getDefinition() == null) {
continue; continue;
} }

View File

@ -69,6 +69,10 @@ public class ${className}ResourceProvider extends
@OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE) @OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_PROFILE)
UriAndListParam theSearchForProfile, UriAndListParam theSearchForProfile,
@Description(shortDefinition="Search the contents of the resource's data using a list")
@OptionalParam(name=ca.uhn.fhir.rest.api.Constants.PARAM_LIST)
StringAndListParam theList,
@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)
UriAndListParam theSearchForSource, UriAndListParam theSearchForSource,
@ -149,6 +153,7 @@ public class ${className}ResourceProvider extends
paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SECURITY, theSearchForSecurity); paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_SECURITY, theSearchForSecurity);
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("_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});