Support modifiers on token parameters
This commit is contained in:
parent
98dfceb90a
commit
1bc35f1ba3
|
@ -30,12 +30,11 @@ import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
||||||
import ca.uhn.fhir.model.primitive.UriDt;
|
import ca.uhn.fhir.model.primitive.UriDt;
|
||||||
import ca.uhn.fhir.rest.server.Constants;
|
|
||||||
|
|
||||||
public class TokenParam extends BaseParam implements IQueryParameterType {
|
public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
|
private TokenParamModifier myModifier;
|
||||||
private String mySystem;
|
private String mySystem;
|
||||||
private boolean myText;
|
|
||||||
private String myValue;
|
private String myValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,8 +45,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor which copies the {@link InternalCodingDt#getSystemElement() system} and {@link InternalCodingDt#getCodeElement() code} from a {@link InternalCodingDt} instance and adds it as a
|
* Constructor which copies the {@link InternalCodingDt#getSystemElement() system} and
|
||||||
* parameter
|
* {@link InternalCodingDt#getCodeElement() code} from a {@link InternalCodingDt} instance and adds it as a parameter
|
||||||
*
|
*
|
||||||
* @param theCodingDt
|
* @param theCodingDt
|
||||||
* The coding
|
* The coding
|
||||||
|
@ -57,7 +56,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor which copies the {@link BaseIdentifierDt#getSystemElement() system} and {@link BaseIdentifierDt#getValueElement() value} from a {@link BaseIdentifierDt} instance and adds it as a
|
* Constructor which copies the {@link BaseIdentifierDt#getSystemElement() system} and
|
||||||
|
* {@link BaseIdentifierDt#getValueElement() value} from a {@link BaseIdentifierDt} instance and adds it as a
|
||||||
* parameter
|
* parameter
|
||||||
*
|
*
|
||||||
* @param theIdentifierDt
|
* @param theIdentifierDt
|
||||||
|
@ -74,8 +74,7 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
public TokenParam(String theSystem, String theValue, boolean theText) {
|
public TokenParam(String theSystem, String theValue, boolean theText) {
|
||||||
if (theText && isNotBlank(theSystem)) {
|
if (theText && isNotBlank(theSystem)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
||||||
"theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
|
||||||
}
|
}
|
||||||
setSystem(theSystem);
|
setSystem(theSystem);
|
||||||
setValue(theValue);
|
setValue(theValue);
|
||||||
|
@ -84,8 +83,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String doGetQueryParameterQualifier() {
|
String doGetQueryParameterQualifier() {
|
||||||
if (isText()) {
|
if (getModifier() != null) {
|
||||||
return Constants.PARAMQUALIFIER_TOKEN_TEXT;
|
return getModifier().getValue();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -108,25 +107,46 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void doSetValueAsQueryToken(String theQualifier, String theParameter) {
|
void doSetValueAsQueryToken(String theQualifier, String theParameter) {
|
||||||
setText(Constants.PARAMQUALIFIER_TOKEN_TEXT.equals(theQualifier));
|
setModifier(null);
|
||||||
setSystem(null);
|
if (theQualifier != null) {
|
||||||
if (theParameter == null) {
|
TokenParamModifier modifier = TokenParamModifier.forValue(theQualifier);
|
||||||
setValue(null);
|
setModifier(modifier);
|
||||||
|
setSystem(null);
|
||||||
|
setValue(ParameterUtil.unescape(theParameter));
|
||||||
} else {
|
} else {
|
||||||
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
|
setSystem(null);
|
||||||
if (barIndex != -1) {
|
if (theParameter == null) {
|
||||||
setSystem(theParameter.substring(0, barIndex));
|
setValue(null);
|
||||||
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
|
||||||
} else {
|
} else {
|
||||||
setValue(ParameterUtil.unescape(theParameter));
|
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
|
||||||
|
if (barIndex != -1) {
|
||||||
|
setSystem(theParameter.substring(0, barIndex));
|
||||||
|
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
||||||
|
} else {
|
||||||
|
setValue(ParameterUtil.unescape(theParameter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the modifier for this token
|
||||||
|
*/
|
||||||
|
public TokenParamModifier getModifier() {
|
||||||
|
return myModifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the system for this token. Note that if a {@link #getModifier()} is being used, the entire value of the
|
||||||
|
* parameter will be placed in {@link #getValue() value} and this method will return <code>null</code>.
|
||||||
|
*/
|
||||||
public String getSystem() {
|
public String getSystem() {
|
||||||
return mySystem;
|
return mySystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value for the token
|
||||||
|
*/
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return myValue;
|
return myValue;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +164,12 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isText() {
|
public boolean isText() {
|
||||||
return myText;
|
return myModifier == TokenParamModifier.TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TokenParam setModifier(TokenParamModifier theModifier) {
|
||||||
|
myModifier = theModifier;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenParam setSystem(String theSystem) {
|
public TokenParam setSystem(String theSystem) {
|
||||||
|
@ -152,8 +177,15 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use
|
||||||
|
*/
|
||||||
public TokenParam setText(boolean theText) {
|
public TokenParam setText(boolean theText) {
|
||||||
myText = theText;
|
if (theText) {
|
||||||
|
myModifier = TokenParamModifier.TEXT;
|
||||||
|
} else {
|
||||||
|
myModifier = null;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,10 +198,10 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||||
builder.append("system", defaultString(getSystem()));
|
builder.append("system", defaultString(getSystem()));
|
||||||
builder.append("value", getValue());
|
if (myModifier != null) {
|
||||||
if (myText) {
|
builder.append(":" + myModifier.getValue());
|
||||||
builder.append(":text", myText);
|
|
||||||
}
|
}
|
||||||
|
builder.append("value", getValue());
|
||||||
if (getMissing() != null) {
|
if (getMissing() != null) {
|
||||||
builder.append(":missing", getMissing());
|
builder.append(":missing", getMissing());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package ca.uhn.fhir.rest.param;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifiers for {@link TokenParam}
|
||||||
|
*/
|
||||||
|
public enum TokenParamModifier {
|
||||||
|
/**
|
||||||
|
* :above
|
||||||
|
*/
|
||||||
|
ABOVE(":above"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :above
|
||||||
|
*/
|
||||||
|
BELOW(":below"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :in
|
||||||
|
*/
|
||||||
|
IN(":in"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :not
|
||||||
|
*/
|
||||||
|
NOT(":not"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :not-in
|
||||||
|
*/
|
||||||
|
NOT_IN(":not-in"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* :text
|
||||||
|
*/
|
||||||
|
TEXT(":text");
|
||||||
|
|
||||||
|
private static final Map<String, TokenParamModifier> VALUE_TO_ENUM;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Map<String, TokenParamModifier> valueToEnum = new HashMap<String, TokenParamModifier>();
|
||||||
|
for (TokenParamModifier next : values()) {
|
||||||
|
valueToEnum.put(next.getValue(), next);
|
||||||
|
}
|
||||||
|
VALUE_TO_ENUM = valueToEnum;
|
||||||
|
}
|
||||||
|
private final String myValue;
|
||||||
|
|
||||||
|
private TokenParamModifier(String theValue) {
|
||||||
|
myValue = theValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return myValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TokenParamModifier forValue(String theValue) {
|
||||||
|
return VALUE_TO_ENUM.get(theValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
import ca.uhn.fhir.rest.annotation.Search;
|
||||||
import ca.uhn.fhir.rest.param.StringParam;
|
import ca.uhn.fhir.rest.param.StringParam;
|
||||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||||
|
import ca.uhn.fhir.rest.param.TokenParamModifier;
|
||||||
import ca.uhn.fhir.util.PortUtil;
|
import ca.uhn.fhir.util.PortUtil;
|
||||||
import ca.uhn.fhir.util.UrlUtil;
|
import ca.uhn.fhir.util.UrlUtil;
|
||||||
|
|
||||||
|
@ -218,4 +219,35 @@ public class TokenParameterTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetModifiersNone() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=a%7Cb");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertEquals(1, ourLastOrList.getListAsCodings().size());
|
||||||
|
assertEquals(null, ourLastOrList.getValuesAsQueryTokens().get(0).getModifier());
|
||||||
|
assertEquals("a", ourLastOrList.getListAsCodings().get(0).getSystemElement().getValue());
|
||||||
|
assertEquals("b", ourLastOrList.getListAsCodings().get(0).getCodeElement().getValue());
|
||||||
|
assertEquals("a", ourLastOrList.getValuesAsQueryTokens().get(0).getSystem());
|
||||||
|
assertEquals("b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetModifiersText() throws Exception {
|
||||||
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier:text=a%7Cb");
|
||||||
|
HttpResponse status = ourClient.execute(httpGet);
|
||||||
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||||
|
|
||||||
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
|
assertEquals(1, ourLastOrList.getListAsCodings().size());
|
||||||
|
assertEquals(TokenParamModifier.TEXT, ourLastOrList.getValuesAsQueryTokens().get(0).getModifier());
|
||||||
|
assertEquals(null, ourLastOrList.getValuesAsQueryTokens().get(0).getSystem());
|
||||||
|
assertEquals("a|b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,10 @@
|
||||||
client pool used by Apache HttpClient. Thanks to Matt Blanchette for the pull
|
client pool used by Apache HttpClient. Thanks to Matt Blanchette for the pull
|
||||||
request!
|
request!
|
||||||
</action>
|
</action>
|
||||||
|
<action type="add">
|
||||||
|
Add support for new modifier types on Token search params in Server and
|
||||||
|
annotation client.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="1.3" date="2015-11-14">
|
<release version="1.3" date="2015-11-14">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
|
Loading…
Reference in New Issue