Skip to content

Commit

Permalink
Issue #2187 - Support compartment search via POST
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Apr 1, 2021
1 parent 98391fe commit e9f6948
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;

import org.testng.annotations.Test;
Expand Down Expand Up @@ -835,6 +836,27 @@ public void testSearchObservationWithPatientCompartment() {
assertFalse(bundle.getLink().get(0).getUrl().getValue().contains("&&"));
}

@Test(groups = { "server-search" }, dependsOnMethods = {
"testCreateObservation", "retrieveConfig" })
public void testSearchObservationWithPatientCompartmentViaPost() {
assertNotNull(compartmentSearchSupported);
if (!compartmentSearchSupported.booleanValue()) {
return;
}

WebTarget target = getWebTarget();
String targetUri = "Patient/" + patientId + "/Observation/_search";
Response response =
target.path(targetUri).request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", tenantName)
.header("X-FHIR-DSID", dataStoreId)
.post(Entity.form(new Form()));
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
assertTrue(bundle.getEntry().size() >= 1);
}

@Test(groups = { "server-search" }, dependsOnMethods = {"testCreateObservation" })
public void test_SearchObservationWithSubject() throws Exception {
FHIRParameters parameters = new FHIRParameters();
Expand Down
67 changes: 27 additions & 40 deletions fhir-server/src/main/java/com/ibm/fhir/server/resources/Search.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016, 2020
* (C) Copyright IBM Corp. 2016, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -56,8 +56,19 @@ public Search() throws Exception {

@GET
@Path("{type}")
public Response search(@PathParam("type") String type) {
log.entering(this.getClass().getName(), "search(String)");
public Response searchGet(@PathParam("type") String type) {
return doSearch(type);
}

@POST
@Consumes("application/x-www-form-urlencoded")
@Path("{type}/_search")
public Response searchPost(@PathParam("type") String type) {
return doSearch(type);
}

private Response doSearch(String type) {
log.entering(this.getClass().getName(), "doSearch");
Date startTime = new Date();
Response.Status status = null;
MultivaluedMap<String, String> queryParameters = null;
Expand Down Expand Up @@ -85,51 +96,27 @@ public Response search(@PathParam("type") String type) {
log.log(Level.SEVERE, AUDIT_LOGGING_ERR_MSG, e);
}

log.exiting(this.getClass().getName(), "search(String)");
log.exiting(this.getClass().getName(), "doSearch");
}
}

@GET
@Path("{compartment}/{compartmentId}/{type}")
public Response searchCompartment(@PathParam("compartment") String compartment,
public Response searchCompartmentGet(@PathParam("compartment") String compartment,
@PathParam("compartmentId") String compartmentId, @PathParam("type") String type) {
log.entering(this.getClass().getName(), "search(String,String,String)");
Date startTime = new Date();
Response.Status status = null;
MultivaluedMap<String, String> queryParameters = null;
Bundle bundle = null;

try {
checkInitComplete();

queryParameters = uriInfo.getQueryParameters();
FHIRRestHelper helper = new FHIRRestHelper(getPersistenceImpl());
bundle = helper.doSearch(type, compartment, compartmentId, queryParameters, getRequestUri(), null, null);
status = Status.OK;
return Response.status(status).entity(bundle).build();
} catch (FHIROperationException e) {
status = issueListToStatus(e.getIssues());
return exceptionResponse(e, status);
} catch (Exception e) {
status = Status.INTERNAL_SERVER_ERROR;
return exceptionResponse(e, status);
} finally {
try {
RestAuditLogger.logSearch(httpServletRequest, queryParameters, bundle,
startTime, new Date(), status);
} catch (Exception e) {
log.log(Level.SEVERE, AUDIT_LOGGING_ERR_MSG, e);
}

log.exiting(this.getClass().getName(), "search(String,String,String)");
}
return doSearchCompartment(compartment, compartmentId, type);
}

@POST
@Consumes("application/x-www-form-urlencoded")
@Path("{type}/_search")
public Response _search(@PathParam("type") String type) {
log.entering(this.getClass().getName(), "_search(String)");
@Path("{compartment}/{compartmentId}/{type}/_search")
public Response searchCompartmentPost(@PathParam("compartment") String compartment,
@PathParam("compartmentId") String compartmentId, @PathParam("type") String type) {
return doSearchCompartment(compartment, compartmentId, type);
}

private Response doSearchCompartment(String compartment, String compartmentId, String type) {
log.entering(this.getClass().getName(), "doSearchCompartment");
Date startTime = new Date();
Response.Status status = null;
MultivaluedMap<String, String> queryParameters = null;
Expand All @@ -140,7 +127,7 @@ public Response _search(@PathParam("type") String type) {

queryParameters = uriInfo.getQueryParameters();
FHIRRestHelper helper = new FHIRRestHelper(getPersistenceImpl());
bundle = helper.doSearch(type, null, null, queryParameters, getRequestUri(), null, null);
bundle = helper.doSearch(type, compartment, compartmentId, queryParameters, getRequestUri(), null, null);
status = Status.OK;
return Response.status(status).entity(bundle).build();
} catch (FHIROperationException e) {
Expand All @@ -157,7 +144,7 @@ public Response _search(@PathParam("type") String type) {
log.log(Level.SEVERE, AUDIT_LOGGING_ERR_MSG, e);
}

log.exiting(this.getClass().getName(), "_search(String)");
log.exiting(this.getClass().getName(), "doSearchCompartment");
}
}

Expand Down

0 comments on commit e9f6948

Please sign in to comment.