
ca.uhn.fhir.rest.param.ParamPrefixEnum Maven / Gradle / Ivy
package ca.uhn.fhir.rest.param;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
/**
* Comparator/qualifier for values used in REST params, such as {@link DateParam}, {@link NumberParam}, and
* {@link QuantityParam}
*
* @since 1.5
*/
public enum ParamPrefixEnum {
/**
* Code Value: eq
*
* The actual value is equal to the given value
*/
APPROXIMATE("~", "ap"),
/**
* Code Value: eb
*
* The range of the search value does overlap not with the range of the target value, and the range above the search value contains the range of the target value
*/
ENDS_BEFORE("", "eb"),
/**
* Code Value: eq
*
* The actual value is equal to the given value
*/
EQUAL("", "eq"),
/**
* Code Value: gt
*
* The actual value is greater than the given value.
*/
GREATERTHAN(">", "gt"),
/**
* Code Value: ge
*
* The actual value is greater than or equal to the given value.
*/
GREATERTHAN_OR_EQUALS(">=", "ge"),
/**
* Code Value: lt
*
* The actual value is less than the given value.
*/
LESSTHAN("<", "lt"),
/**
* Code Value: le
*
* The actual value is less than or equal to the given value.
*/
LESSTHAN_OR_EQUALS("<=", "le"),
/**
* Code Value: ne
*
* The actual value is not equal to the given value
*/
NOT_EQUAL("", "ne"),
/**
* Code Value: sa
*
* The range of the search value does not overlap with the range of the target value, and the range below the search value contains the range of the target value
*/
STARTS_AFTER("", "sa");
private static final Map DSTU1_TO_PREFIX;
private static final Map VALUE_TO_PREFIX;
static {
HashMap valueToPrefix = new HashMap();
HashMap dstu1ToPrefix = new HashMap();
for (ParamPrefixEnum next : values()) {
valueToPrefix.put(next.getValue(), next);
if (isNotBlank(next.getDstu1Value())) {
dstu1ToPrefix.put(next.getDstu1Value(), next);
}
}
VALUE_TO_PREFIX = Collections.unmodifiableMap(valueToPrefix);
DSTU1_TO_PREFIX = Collections.unmodifiableMap(dstu1ToPrefix);
}
private final String myDstu1Value;
private final String myValue;
private ParamPrefixEnum(String theDstu1Value, String theValue) {
myDstu1Value = theDstu1Value;
myValue = theValue;
}
/**
* Returns the DSTU1 value, e.g. <
or ~
*/
public String getDstu1Value() {
return myDstu1Value;
}
/**
* Returns the DSTU2+ value, e.g. lt
or eq
*/
public String getValue() {
return myValue;
}
/**
* Returns the appropriate value for the given context, based on the
* FHIR version supported by the context
*/
public String getValueForContext(FhirContext theContext) {
if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
return getDstu1Value();
} else {
return getValue();
}
}
/**
* Returns the prefix associated with a given DSTU1 value (e.g. <
or ~
)
*
* @param theValue
* e.g. <
or ~
* @return The prefix, or null
if no prefix matches the value
*/
public static ParamPrefixEnum forDstu1Value(String theValue) {
return DSTU1_TO_PREFIX.get(theValue);
}
/**
* Returns the prefix associated with a given DSTU2+ value (e.g. lt
or eq
)
*
* @param theValue
* e.g. <
or ~
* @return The prefix, or null
if no prefix matches the value
*/
public static ParamPrefixEnum forValue(String theValue) {
return VALUE_TO_PREFIX.get(theValue);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy