Start include params
This commit is contained in:
parent
55524e4e8a
commit
6b60703a74
|
@ -9,7 +9,7 @@ public interface IQueryParameterOr {
|
|||
* format is used in HTTP queries as a parameter format.
|
||||
*
|
||||
* @see See FHIR specification
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search Parameter Types</a>
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
|
||||
* for information on the <b>token</b> format
|
||||
*/
|
||||
public void setValuesAsQueryTokens(List<String> theParameters);
|
||||
|
@ -19,7 +19,7 @@ public interface IQueryParameterOr {
|
|||
* format is used in HTTP queries as a parameter format.
|
||||
*
|
||||
* @see See FHIR specification
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search Parameter Types</a>
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
|
||||
* for information on the <b>token</b> format
|
||||
*/
|
||||
public List<String> getValuesAsQueryTokens();
|
||||
|
|
|
@ -7,7 +7,7 @@ public interface IQueryParameterType {
|
|||
* format is used in HTTP queries as a parameter format.
|
||||
*
|
||||
* @see See FHIR specification
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search Parameter Types</a>
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
|
||||
* for information on the <b>token</b> format
|
||||
*/
|
||||
public void setValueAsQueryToken(String theParameter);
|
||||
|
@ -17,7 +17,7 @@ public interface IQueryParameterType {
|
|||
* format is used in HTTP queries as a parameter format.
|
||||
*
|
||||
* @see See FHIR specification
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search Parameter Types</a>
|
||||
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
|
||||
* for information on the <b>token</b> format
|
||||
*/
|
||||
public String getValueAsQueryToken();
|
||||
|
|
|
@ -3350,7 +3350,7 @@ public class Conformance extends BaseResource implements IResource {
|
|||
|
||||
@Child(name="parameter", type=RestResourceSearchParam.class, order=3, min=0, max=Child.MAX_UNLIMITED)
|
||||
@Description(
|
||||
shortDefinition="Parameter for the named query",
|
||||
shortDefinition="SearchParameter for the named query",
|
||||
formalDefinition="Identifies which of the parameters for the named query are supported"
|
||||
)
|
||||
private java.util.List<RestResourceSearchParam> myParameter;
|
||||
|
@ -3501,7 +3501,7 @@ public class Conformance extends BaseResource implements IResource {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the value(s) for <b>parameter</b> (Parameter for the named query).
|
||||
* Gets the value(s) for <b>parameter</b> (SearchParameter for the named query).
|
||||
* creating it if it does
|
||||
* not exist. Will not return <code>null</code>.
|
||||
*
|
||||
|
@ -3518,7 +3518,7 @@ public class Conformance extends BaseResource implements IResource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the value(s) for <b>parameter</b> (Parameter for the named query)
|
||||
* Sets the value(s) for <b>parameter</b> (SearchParameter for the named query)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
|
@ -3530,7 +3530,7 @@ public class Conformance extends BaseResource implements IResource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds and returns a new value for <b>parameter</b> (Parameter for the named query)
|
||||
* Adds and returns a new value for <b>parameter</b> (SearchParameter for the named query)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
|
|
|
@ -4508,7 +4508,7 @@ public class Profile extends BaseResource implements IResource {
|
|||
|
||||
@Child(name="parameter", type=StructureSearchParam.class, order=2, min=0, max=Child.MAX_UNLIMITED)
|
||||
@Description(
|
||||
shortDefinition="Parameter for the named query",
|
||||
shortDefinition="SearchParameter for the named query",
|
||||
formalDefinition="A parameter of a named query"
|
||||
)
|
||||
private java.util.List<StructureSearchParam> myParameter;
|
||||
|
@ -4616,7 +4616,7 @@ public class Profile extends BaseResource implements IResource {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the value(s) for <b>parameter</b> (Parameter for the named query).
|
||||
* Gets the value(s) for <b>parameter</b> (SearchParameter for the named query).
|
||||
* creating it if it does
|
||||
* not exist. Will not return <code>null</code>.
|
||||
*
|
||||
|
@ -4633,7 +4633,7 @@ public class Profile extends BaseResource implements IResource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the value(s) for <b>parameter</b> (Parameter for the named query)
|
||||
* Sets the value(s) for <b>parameter</b> (SearchParameter for the named query)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
|
@ -4645,7 +4645,7 @@ public class Profile extends BaseResource implements IResource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds and returns a new value for <b>parameter</b> (Parameter for the named query)
|
||||
* Adds and returns a new value for <b>parameter</b> (SearchParameter for the named query)
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package ca.uhn.fhir.rest.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Method parameter which is used to indicate a parameter that will
|
||||
* be populated with the "_include" values for a search param.
|
||||
* <p>
|
||||
* Only one parameter may be annotated with this annotation, and that
|
||||
* parameter should be of type Collection, List, or Set.
|
||||
* </p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value= {ElementType.PARAMETER})
|
||||
public @interface Include {
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package ca.uhn.fhir.rest.method;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -111,6 +112,8 @@ public abstract class BaseMethodBinding {
|
|||
// return sm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean verifyMethodHasZeroOrOneOperationAnnotation(Method theNextMethod, Object... theAnnotations) {
|
||||
Object obj1 = null;
|
||||
for (Object object : theAnnotations) {
|
||||
|
|
|
@ -13,7 +13,8 @@ import java.util.Set;
|
|||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.client.GetClientInvocation;
|
||||
import ca.uhn.fhir.rest.param.Parameter;
|
||||
import ca.uhn.fhir.rest.param.IParameter;
|
||||
import ca.uhn.fhir.rest.param.SearchParameter;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.Util;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
|
@ -29,7 +30,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
private Method method;
|
||||
|
||||
private Class<?> myDeclaredResourceType;
|
||||
private List<Parameter> myParameters;
|
||||
private List<SearchParameter> myParameters;
|
||||
|
||||
public SearchMethodBinding(MethodReturnTypeEnum theMethodReturnTypeEnum, Class<? extends IResource> theReturnResourceType, Method theMethod) {
|
||||
super(theMethodReturnTypeEnum, theReturnResourceType);
|
||||
|
@ -47,7 +48,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
return method;
|
||||
}
|
||||
|
||||
public List<Parameter> getParameters() {
|
||||
public List<SearchParameter> getParameters() {
|
||||
return myParameters;
|
||||
}
|
||||
|
||||
|
@ -64,11 +65,11 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
|
||||
for (int idx = 0; idx < theArgs.length; idx++) {
|
||||
Object object = theArgs[idx];
|
||||
Parameter nextParam = myParameters.get(idx);
|
||||
SearchParameter nextParam = myParameters.get(idx);
|
||||
|
||||
if (object == null) {
|
||||
if (nextParam.isRequired()) {
|
||||
throw new NullPointerException("Parameter '" + nextParam.getName() + "' is required and may not be null");
|
||||
throw new NullPointerException("SearchParameter '" + nextParam.getName() + "' is required and may not be null");
|
||||
}
|
||||
} else {
|
||||
List<List<String>> value = nextParam.encode(object);
|
||||
|
@ -100,7 +101,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
|
||||
Object[] params = new Object[myParameters.size()];
|
||||
for (int i = 0; i < myParameters.size(); i++) {
|
||||
Parameter param = myParameters.get(i);
|
||||
IParameter param = myParameters.get(i);
|
||||
String[] value = parameterValues.get(param.getName());
|
||||
if (value == null || value.length == 0) {
|
||||
continue;
|
||||
|
@ -155,7 +156,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
|
||||
Set<String> methodParamsTemp = new HashSet<String>();
|
||||
for (int i = 0; i < this.myParameters.size(); i++) {
|
||||
Parameter temp = this.myParameters.get(i);
|
||||
SearchParameter temp = this.myParameters.get(i);
|
||||
methodParamsTemp.add(temp.getName());
|
||||
if (temp.isRequired() && !theRequest.getParameterNames().contains(temp.getName())) {
|
||||
ourLog.trace("Method {} doesn't match param '{}' is not present", method.getName(), temp.getName());
|
||||
|
@ -173,7 +174,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
|||
this.method = method;
|
||||
}
|
||||
|
||||
public void setParameters(List<Parameter> parameters) {
|
||||
public void setParameters(List<SearchParameter> parameters) {
|
||||
this.myParameters = parameters;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
public interface IParameter {
|
||||
|
||||
public abstract List<List<String>> encode(Object theObject) throws InternalErrorException;
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract Object parse(List<List<String>> theString) throws InternalErrorException, InvalidRequestException;
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
public class IncludeParameter implements IParameter {
|
||||
|
||||
@Override
|
||||
public List<List<String>> encode(Object theObject) throws InternalErrorException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object parse(List<List<String>> theString) throws InternalErrorException, InvalidRequestException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,25 +12,33 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public class Parameter {
|
||||
public class SearchParameter implements IParameter {
|
||||
|
||||
private String name;
|
||||
private IParamBinder parser;
|
||||
private boolean required;
|
||||
private Class<?> type;
|
||||
|
||||
public Parameter() {
|
||||
public SearchParameter() {
|
||||
}
|
||||
|
||||
public Parameter(String name, boolean required) {
|
||||
public SearchParameter(String name, boolean required) {
|
||||
this.name = name;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ca.uhn.fhir.rest.param.IParameter#encode(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public List<List<String>> encode(Object theObject) throws InternalErrorException {
|
||||
return parser.encode(theObject);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ca.uhn.fhir.rest.param.IParameter#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -43,6 +51,10 @@ public class Parameter {
|
|||
return required;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ca.uhn.fhir.rest.param.IParameter#parse(java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public Object parse(List<List<String>> theString) throws InternalErrorException, InvalidRequestException {
|
||||
return parser.parse(theString);
|
||||
}
|
|
@ -10,10 +10,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.rest.annotation.Include;
|
||||
import ca.uhn.fhir.rest.annotation.Optional;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.Required;
|
||||
import ca.uhn.fhir.rest.param.Parameter;
|
||||
import ca.uhn.fhir.rest.param.IParameter;
|
||||
import ca.uhn.fhir.rest.param.SearchParameter;
|
||||
import ca.uhn.fhir.util.ReflectionUtil;
|
||||
|
||||
/**
|
||||
|
@ -38,16 +40,17 @@ public class Util {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Parameter> getResourceParameters(Method method) {
|
||||
List<Parameter> parameters = new ArrayList<Parameter>();
|
||||
public static List<IParameter> getResourceParameters(Method method) {
|
||||
List<IParameter> parameters = new ArrayList<IParameter>();
|
||||
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
for (Annotation[] annotations : method.getParameterAnnotations()) {
|
||||
for (int i = 0; i < annotations.length; i++) {
|
||||
Annotation nextAnnotation = annotations[i];
|
||||
Parameter parameter = new Parameter();
|
||||
Class<?> parameterType = parameterTypes[i];
|
||||
|
||||
|
||||
|
||||
Class<? extends java.util.Collection<?>> outerCollectionType = null;
|
||||
Class<? extends java.util.Collection<?>> innerCollectionType = null;
|
||||
|
||||
|
@ -62,17 +65,22 @@ public class Util {
|
|||
parameterType = ReflectionUtil.getGenericCollectionTypeOfMethodParameter(method, i);
|
||||
}
|
||||
|
||||
IParameter param;
|
||||
if (nextAnnotation instanceof Required) {
|
||||
SearchParameter parameter = new SearchParameter();
|
||||
parameter.setName(((Required) nextAnnotation).name());
|
||||
parameter.setRequired(true);
|
||||
parameter.setType(parameterType, innerCollectionType, outerCollectionType);
|
||||
|
||||
} else if (nextAnnotation instanceof Optional) {
|
||||
SearchParameter parameter = new SearchParameter();
|
||||
parameter.setName(((Optional) nextAnnotation).name());
|
||||
parameter.setRequired(false);
|
||||
parameter.setType(parameterType, innerCollectionType, innerCollectionType);
|
||||
} else if (nextAnnotation instanceof Include) {
|
||||
|
||||
}
|
||||
parameters.add(parameter);
|
||||
|
||||
parameters.add(param);
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
|
|
|
@ -14,6 +14,7 @@ import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
|
|||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.annotation.Include;
|
||||
import ca.uhn.fhir.rest.annotation.Optional;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.Required;
|
||||
|
@ -92,6 +93,18 @@ public class DummyPatientResourceProvider implements IResourceProvider {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
@Search()
|
||||
public Patient getPatientWithIncludes(@Required(name = "withIncludes") StringDt theString, @Include List<String> theIncludes) {
|
||||
Patient next = getIdToPatient().get("1");
|
||||
|
||||
for (String line : theIncludes) {
|
||||
next.addAddress().addLine(line);
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
@Search()
|
||||
public List<Patient> getPatientMultipleIdentifiers(@Required(name = "ids") CodingListParam theIdentifiers) {
|
||||
List<Patient> retVal = new ArrayList<Patient>();
|
||||
|
|
|
@ -15,7 +15,7 @@ import ca.uhn.fhir.rest.method.BaseMethodBinding.MethodReturnTypeEnum;
|
|||
import ca.uhn.fhir.rest.method.Request;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
|
||||
import ca.uhn.fhir.rest.param.Parameter;
|
||||
import ca.uhn.fhir.rest.param.SearchParameter;
|
||||
|
||||
public class ResourceMethodTest {
|
||||
|
||||
|
@ -28,11 +28,11 @@ public class ResourceMethodTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredParamsMissing() {
|
||||
List<Parameter> methodParams = new ArrayList<Parameter>();
|
||||
List<SearchParameter> methodParams = new ArrayList<SearchParameter>();
|
||||
|
||||
methodParams.add(new Parameter("firstName", false));
|
||||
methodParams.add(new Parameter("lastName", false));
|
||||
methodParams.add(new Parameter("mrn", true));
|
||||
methodParams.add(new SearchParameter("firstName", false));
|
||||
methodParams.add(new SearchParameter("lastName", false));
|
||||
methodParams.add(new SearchParameter("mrn", true));
|
||||
|
||||
rm.setParameters(methodParams);
|
||||
|
||||
|
@ -45,11 +45,11 @@ public class ResourceMethodTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredParamsOnly() {
|
||||
List<Parameter> methodParams = new ArrayList<Parameter>();
|
||||
List<SearchParameter> methodParams = new ArrayList<SearchParameter>();
|
||||
|
||||
methodParams.add(new Parameter("firstName", false));
|
||||
methodParams.add(new Parameter("lastName", false));
|
||||
methodParams.add(new Parameter("mrn", true));
|
||||
methodParams.add(new SearchParameter("firstName", false));
|
||||
methodParams.add(new SearchParameter("lastName", false));
|
||||
methodParams.add(new SearchParameter("mrn", true));
|
||||
|
||||
rm.setParameters(methodParams);
|
||||
|
||||
|
@ -60,11 +60,11 @@ public class ResourceMethodTest {
|
|||
|
||||
@Test
|
||||
public void testMixedParams() {
|
||||
List<Parameter> methodParams = new ArrayList<Parameter>();
|
||||
List<SearchParameter> methodParams = new ArrayList<SearchParameter>();
|
||||
|
||||
methodParams.add(new Parameter("firstName", false));
|
||||
methodParams.add(new Parameter("lastName", false));
|
||||
methodParams.add(new Parameter("mrn", true));
|
||||
methodParams.add(new SearchParameter("firstName", false));
|
||||
methodParams.add(new SearchParameter("lastName", false));
|
||||
methodParams.add(new SearchParameter("mrn", true));
|
||||
|
||||
rm.setParameters(methodParams);
|
||||
|
||||
|
@ -77,11 +77,11 @@ public class ResourceMethodTest {
|
|||
|
||||
@Test
|
||||
public void testAllParams() {
|
||||
List<Parameter> methodParams = new ArrayList<Parameter>();
|
||||
List<SearchParameter> methodParams = new ArrayList<SearchParameter>();
|
||||
|
||||
methodParams.add(new Parameter("firstName", false));
|
||||
methodParams.add(new Parameter("lastName", false));
|
||||
methodParams.add(new Parameter("mrn", true));
|
||||
methodParams.add(new SearchParameter("firstName", false));
|
||||
methodParams.add(new SearchParameter("lastName", false));
|
||||
methodParams.add(new SearchParameter("mrn", true));
|
||||
|
||||
rm.setParameters(methodParams);
|
||||
|
||||
|
@ -95,11 +95,11 @@ public class ResourceMethodTest {
|
|||
|
||||
@Test
|
||||
public void testAllParamsWithExtra() {
|
||||
List<Parameter> methodParams = new ArrayList<Parameter>();
|
||||
List<SearchParameter> methodParams = new ArrayList<SearchParameter>();
|
||||
|
||||
methodParams.add(new Parameter("firstName", false));
|
||||
methodParams.add(new Parameter("lastName", false));
|
||||
methodParams.add(new Parameter("mrn", true));
|
||||
methodParams.add(new SearchParameter("firstName", false));
|
||||
methodParams.add(new SearchParameter("lastName", false));
|
||||
methodParams.add(new SearchParameter("mrn", true));
|
||||
|
||||
rm.setParameters(methodParams);
|
||||
|
||||
|
|
Loading…
Reference in New Issue