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 #1323 - Add support for ':of-type' modifier #2116

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ public void setHidden(boolean hidden) {
}

/**
* Sets whether the value of an :of-type modifier.
* Gets whether the value is of an :of-type modifier.
* @return true or false
*/
public boolean isOfTypeModifier() {
return ofTypeModifier;
}

/**
* Gets whether the value of an :of-type modifier.
* @param ofTypeModifier true if value of an :of-type modifier
* Sets whether the value is of an :of-type modifier.
* @param ofTypeModifier true if value is of an :of-type modifier, otherwise false
*/
public void setOfTypeModifier(boolean ofTypeModifier) {
this.ofTypeModifier = ofTypeModifier;
Expand Down Expand Up @@ -195,7 +195,7 @@ public String toString() {
delim = outputBuilder(returnString, delim, valueString);
delim = outputBuilder(returnString, delim, valueDate);

// token search with :of-type modifier is handled as a composite search
// token search with :of-type modifier is handled internally as a composite search
if (component != null && !component.isEmpty()) {
String componentDelim = "";
for (QueryParameter componentParam : component) {
Expand All @@ -208,6 +208,8 @@ public String toString() {
throw new IllegalStateException("Components of a composite search parameter may only have a single value");
}
returnString.append(componentDelim).append(componentValues.get(0));
// Since the self/next/previous links generated by UriBuilder for the search response Bundle use this output,
// this needs to use "|" instead of "$" as the component delimiter
lmsurpre marked this conversation as resolved.
Show resolved Hide resolved
componentDelim = ofTypeModifier ? SearchConstants.PARAMETER_DELIMITER : SearchConstants.COMPOSITE_DELIMITER;
tbieste marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.testng.annotations.Test;

import com.ibm.fhir.search.SearchConstants.Prefix;
import com.ibm.fhir.search.SearchConstants.Type;
import com.ibm.fhir.search.parameters.QueryParameter;
import com.ibm.fhir.search.parameters.QueryParameterValue;

/**
Expand Down Expand Up @@ -86,4 +88,28 @@ public void testValueDate() throws Exception {
assertEquals(testObj.toString(), "eq2019-12-11");
assertEquals(testObj.toString(), "eq2019-12-11");
}

@Test
public void testToStringOfComposite() throws Exception {
QueryParameterValue testObj = new QueryParameterValue();
QueryParameter qp1 = new QueryParameter(Type.TOKEN, "qp1", null, null);
QueryParameterValue qpv1 = new QueryParameterValue();
String valueSystem1 = "valueSystem1";
String valueCode1 = "valueCode1";
qpv1.setValueSystem(valueSystem1);
qpv1.setValueCode(valueCode1);
qp1.getValues().add(qpv1);
QueryParameter qp2 = new QueryParameter(Type.TOKEN, "qp2", null, null);
QueryParameterValue qpv2 = new QueryParameterValue();
String valueCode2 = "valueCode2";
qpv2.setValueCode(valueCode2);
qp2.getValues().add(qpv2);
testObj.addComponent(qp1, qp2);
// toString of an :of-type modifier uses '|' as component delimiter
testObj.setOfTypeModifier(true);
assertEquals(testObj.toString(), "valueSystem1|valueCode1|valueCode2");
// Otherwise toString uses '$' as component delimiter
testObj.setOfTypeModifier(false);
assertEquals(testObj.toString(), "valueSystem1|valueCode1$valueCode2");
}
}