3986: Remove validation of max parameter lastn and add tests (#5737)

* 3986: Remove validation of max parameter lastn and add tests

* 3986: Add bug fix to changelog

* 3986: Re-add removed import

* Prepare for merge

* Spotless

---------

Co-authored-by: James Agnew <jamesagnew@gmail.com>
This commit is contained in:
Gijs 2024-05-02 20:42:27 +02:00 committed by GitHub
parent a91490f1ef
commit 22d7731d41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 3986
title: "Removed the validation error of the `max` query parameter on the $lastn operation. Now, the $lastn operation can be invoked with the `max` query parameter. Contribution by Gijs Groenewegen (@thetrueoneshots)."

View File

@ -84,6 +84,13 @@ public abstract class BaseJpaResourceProviderObservation<T extends IBaseResource
} }
if (theMax != null) { if (theMax != null) {
paramMap.setLastNMax(theMax.getValue()); paramMap.setLastNMax(theMax.getValue());
/**
* The removal of the original raw parameter is required as every implementing class
* has the "Observation" resource class defined. For this resource, the max parameter
* is not supported and thus has to be removed before the use of "translateRawParameters".
*/
theAdditionalRawParams.remove("max");
} }
if (theCount != null) { if (theCount != null) {
paramMap.setCount(theCount.getValue()); paramMap.setCount(theCount.getValue());

View File

@ -0,0 +1,37 @@
package ca.uhn.fhir.jpa.provider.dstu3;
import com.google.common.base.Charsets;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
public class ObservationLastnDstu3Test extends BaseResourceProviderDstu3Test {
/**
* See #3986. Verifies that supplying the max parameter in the $lastn does not cause a validation error.
*/
@Test
public void testSupplyingMaxToTheLastNOPerationDoesNotCauseAValidationError() throws Exception {
String outcome = executeApiCall(myServerBase + "/Observation/$lastn?max=1");
assertThat(outcome, not(containsString("HAPI-524")));
}
private String executeApiCall(String theUrl) throws IOException {
String outcome;
HttpGet get = new HttpGet(theUrl);
CloseableHttpResponse resp = ourHttpClient.execute(get);
try {
outcome = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
} finally {
IOUtils.closeQuietly(resp);
}
return outcome;
}
}

View File

@ -909,6 +909,10 @@
<id>jbonzohln</id> <id>jbonzohln</id>
<name>Jesse Bonzo</name> <name>Jesse Bonzo</name>
</developer> </developer>
<developer>
<id>thetrueoneshots</id>
<name>Gijs Groenewegen</name>
</developer>
</developers> </developers>
<licenses> <licenses>