Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2427 - Add missing modifiers to FHIRParameters in FHIR Client #2437

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 58 additions & 32 deletions fhir-client/src/main/java/com/ibm/fhir/client/FHIRParameters.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,6 +12,8 @@
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;

import com.ibm.fhir.model.type.code.ResourceType;

/**
* This class is used as a container for request parameters associated with a FHIR Client API request.
*/
Expand All @@ -27,18 +29,22 @@ public class FHIRParameters {

/**
* The valid set of modifiers that can be used when constructing the parameters for a search operation.
* @implNote please keep in sync with @see SearchConstants.Modifier
*/
public enum Modifier {
tbieste marked this conversation as resolved.
Show resolved Hide resolved
MISSING("missing"),
EXACT("exact"),
CONTAINS("contains"),
TEXT("text"),
IN("in"),
BELOW("below"),
ABOVE("above"),
NOT("not"),
NOT_IN("not-in"),
TYPE("[type]");
MISSING("missing"),
EXACT("exact"),
CONTAINS("contains"),
TEXT("text"),
IN("in"),
BELOW("below"),
ABOVE("above"),
NOT("not"),
NOT_IN("not-in"),
// For TYPE, the ResourceType class is used instead
IDENTIFIER("identifier"),
OF_TYPE("of-type"),
ITERATE("iterate");

private String text;

Expand All @@ -53,16 +59,17 @@ public String text() {

/**
* The valid set of value prefixes that can be used when constructing the parameters for a search operation.
* @implNote please keep in sync with @see SearchConstants.Prefix
tbieste marked this conversation as resolved.
Show resolved Hide resolved
*/
public static enum ValuePrefix {
EQ("eq"),
NE("ne"),
GT("gt"),
LT("lt"),
GE("ge"),
LE("le"),
SA("sa"),
EB("eb"),
EQ("eq"),
NE("ne"),
GT("gt"),
LT("lt"),
GE("ge"),
LE("le"),
SA("sa"),
EB("eb"),
AP("ap");

private String text;
Expand All @@ -83,7 +90,7 @@ public FHIRParameters() {

/**
* Convenience method which sets the "_format" query parameter.
*
*
* @param mimeType
* the mimeType to use for the request
* @return a handle to the FHIRParameters object
Expand All @@ -94,7 +101,7 @@ public FHIRParameters format(String mimeType) {

/**
* Convenience method which sets the "_count" query parameter.
*
*
* @param count
* the count value to use for the request
* @return a handle to the FHIRParameters object
Expand All @@ -105,7 +112,7 @@ public FHIRParameters count(int count) {

/**
* Convenience method which sets the "_page" query parameter.
*
*
* @param page
* the page number to use for the request
* @return a handle to the FHIRParameters object
Expand All @@ -116,7 +123,7 @@ public FHIRParameters page(int page) {

/**
* Convenience method which sets the "_since" query parameter.
*
*
* @param since
* a string representing the "since" date value to use for the request
* @return a handle to the FHIRParameters object
Expand All @@ -127,7 +134,7 @@ public FHIRParameters since(String since) {

/**
* Clears the set of parameters currently contained in the FHIRParameters object.
*
*
* @return a handle to the FHIRParameters object
*/
public FHIRParameters clear() {
Expand All @@ -137,7 +144,7 @@ public FHIRParameters clear() {

/**
* Adds the specified query parameter name and value to 'this'.
*
*
* @param name
* the parameter name
* @param value
Expand All @@ -151,7 +158,7 @@ public FHIRParameters queryParam(String name, String value) {

/**
* Adds the specified search parameter (name, modifier, values) to 'this'.
*
*
* @param name
* the parameter name
* @param modifier
Expand All @@ -167,9 +174,27 @@ public FHIRParameters searchParam(String name, Modifier modifier, String... valu
return this;
}

/**
* Adds the specified search parameter (name, resourceType, values) to 'this'.
*
* @param name
* the parameter name
* @param resourceType
* a resource type (e.g. Patient) as a modifier
* @param values
* one or more values associated with the search parameter
* @return a handle to the FHIRParameters object
*/
public FHIRParameters searchParam(String name, ResourceType resourceType, String... values) {
String parameterName = name + ":" + resourceType.getValue();
String value = getValueString(values);
addMultivaluedParameter(parameterName, value);
return this;
}

/**
* Adds the specified search parameter (name, value-prefix, values) to 'this'.
*
*
* @param name
* the parameter name
* @param prefix
Expand All @@ -186,7 +211,7 @@ public FHIRParameters searchParam(String name, ValuePrefix prefix, String... val

/**
* Returns a comma-separated string containing the elements of the 'values' array.
*
*
* @param values
* an array of strings containing parameter values
*/
Expand All @@ -205,7 +230,7 @@ private String getValueString(String[] values) {

/**
* Adds the specified search parameter name and values to 'this'.
*
*
* @param name
* the name of the search parameter
* @param values
Expand All @@ -222,7 +247,7 @@ public FHIRParameters searchParam(String name, String... values) {

/**
* Returns the collection of parameters that have been added to 'this'.
*
*
* @return a MultivalueMap where the key (query parameter name) maps to a list of string values
*/
public final MultivaluedMap<String, String> getParameterMap() {
Expand All @@ -248,7 +273,7 @@ public void addMultivaluedParameter(String name, String value) {

/**
* Adds a single-valued parameter to 'this'.
*
*
* @param name
* @param value
*/
Expand Down Expand Up @@ -277,14 +302,15 @@ public String queryString(boolean includeSeparator) {
}
return sb.toString();
}

public String queryString() {
return queryString(true);
}

/**
* This method returns a string representation of the FHIRParameters object.
*/
@Override
public String toString() {
return "FHIRParameters[parameters=" + (getParameters() != null ? getParameters().toString() : "<null>" + "]");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -14,12 +14,13 @@
import com.ibm.fhir.client.FHIRParameters;
import com.ibm.fhir.client.FHIRParameters.Modifier;
import com.ibm.fhir.client.FHIRParameters.ValuePrefix;
import com.ibm.fhir.model.type.code.ResourceType;

/**
* Tests related to the FHIRParameters class.
*/
public class FHIRParametersTest {

@Test
public void testParameter1() {
FHIRParameters p = new FHIRParameters();
Expand All @@ -31,7 +32,7 @@ public void testParameter1() {
assertTrue(queryString.contains("_page=3"));
assertTrue(queryString.contains("_since=2016-01-01"));
}

@Test
public void testParameter2() {
FHIRParameters p = new FHIRParameters();
Expand All @@ -42,7 +43,7 @@ public void testParameter2() {
assertTrue(queryString.contains("name:contains=Ortiz"));
assertTrue(queryString.contains("favorite-color:in=red,green,blue"));
}

@Test
public void testParameter3() {
FHIRParameters p = new FHIRParameters();
Expand All @@ -53,4 +54,17 @@ public void testParameter3() {
assertTrue(queryString.contains("name=eqOrtiz"));
assertTrue(queryString.contains("favorite-color=nered"));
}

@Test
public void testParameter4() {
FHIRParameters p = new FHIRParameters();
p.searchParam("patient", Modifier.IDENTIFIER, "http://acme.org/fhir/identifier/mrn|123456")
.searchParam("identifier", Modifier.OF_TYPE, "http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053")
.searchParam("subject", ResourceType.PATIENT, "Patient/23");
String queryString = p.queryString();
assertNotNull(queryString);
assertTrue(queryString.contains("patient:identifier=http://acme.org/fhir/identifier/mrn|123456"));
assertTrue(queryString.contains("identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053"));
assertTrue(queryString.contains("subject:Patient=Patient/23"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private SearchConstants() {

/**
* Prefixes for Search parameters
* @implNote please keep in sync with @see FHIRParameters.ValuePrefix
tbieste marked this conversation as resolved.
Show resolved Hide resolved
*/
public enum Prefix {
EQ("eq"),
Expand Down Expand Up @@ -252,6 +253,7 @@ public static Type fromValue(String value) {

/**
* Search Modifiers
* @implNote please keep in sync with @see FHIRParameters.Modifier
tbieste marked this conversation as resolved.
Show resolved Hide resolved
*/
public enum Modifier {
MISSING("missing"),
Expand Down