hapi-fhir/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm
2014-07-17 08:32:01 -04:00

88 lines
2.7 KiB
Plaintext

package ${packageBase};
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import ca.uhn.fhir.jpa.provider.JpaResourceProvider;
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.dstu.composite.*;
import ca.uhn.fhir.model.dstu.resource.*;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.param.*;
public class ${className}ResourceProvider extends JpaResourceProvider<${className}> {
@Override
public Class<? extends IResource> getResourceType() {
return ${className}.class;
}
@Search()
public ca.uhn.fhir.rest.server.IBundleProvider search(
javax.servlet.http.HttpServletRequest theServletRequest,
@Description(shortDefinition="The resource identity")
@OptionalParam(name="_id")
StringParam theId,
#foreach ( $param in $searchParamsWithoutComposite ) #{if}(true) #{end}
@Description(shortDefinition="${param.description}")
#if (${param.type} == 'string' )
@OptionalParam(name="${param.name}")
StringParam the${param.nameCapitalized},
#elseif (${param.type} == 'token' )
@OptionalParam(name="${param.name}")
IdentifierListParam the${param.nameCapitalized},
#elseif (${param.type} == 'date' )
@OptionalParam(name="${param.name}")
DateRangeParam the${param.nameCapitalized},
#elseif (${param.type} == 'quantity' )
@OptionalParam(name="${param.name}")
QuantityDt the${param.nameCapitalized},
#elseif (${param.type} == 'number' )
@OptionalParam(name="${param.name}")
QuantityDt the${param.nameCapitalized},
#elseif (${param.type} == 'reference' )
@OptionalParam(name="${param.name}", targetTypes={ #{foreach}($nextType in ${param.targetTypes}) ${nextType}.class #{if}($foreach.hasNext), #{end} #{end} } )
ReferenceParam the${param.nameCapitalized},
#elseif (${param.type} == 'composite' )
@OptionalParam(name="${param.name}")
ReferenceParam the${param.nameCapitalized},
#end
#end
@IncludeParam(allow= {
#foreach ( $param in $searchParamsReference )
#set ( $haveMore = $foreach.hasNext )
#foreach ( $include in $param.paths )
"${include.path}" #{if}($foreach.hasNext || $haveMore), #{end}
#end
#end
})
Set<Include> theIncludes
) {
startRequest(theServletRequest);
try {
SearchParameterMap paramMap = new SearchParameterMap();
paramMap.add("_id", theId);
#foreach ( $param in $searchParamsWithoutComposite )
paramMap.add("${param.name}", the${param.nameCapitalized});
#end
paramMap.setIncludes(theIncludes);
ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap);
return retVal;
} finally {
endRequest(theServletRequest);
}
}
}