Cleanup $everything for Patient and Encounter in JPA

This commit is contained in:
James Agnew 2015-07-09 09:47:28 -04:00
parent d5b99c2c10
commit 75e9b711a5
4 changed files with 57 additions and 45 deletions

View File

@ -24,6 +24,8 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import net.sourceforge.cobertura.CoverageIgnore;
import org.springframework.beans.factory.annotation.Required; import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
@ -48,6 +50,7 @@ public abstract class BaseJpaResourceProvider<T extends IResource> extends BaseJ
// nothing // nothing
} }
@CoverageIgnore
public BaseJpaResourceProvider(IFhirResourceDao<T> theDao) { public BaseJpaResourceProvider(IFhirResourceDao<T> theDao) {
myDao = theDao; myDao = theDao;
} }

View File

@ -22,18 +22,43 @@ package ca.uhn.fhir.jpa.provider;
import java.util.Collections; import java.util.Collections;
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu2.resource.Encounter; import ca.uhn.fhir.model.dstu2.resource.Encounter;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class BaseJpaResourceProviderEncounterDstu2 extends JpaResourceProviderDstu2<Encounter> { public class BaseJpaResourceProviderEncounterDstu2 extends JpaResourceProviderDstu2<Encounter> {
@Operation(name="everything", idempotent=true)
public ca.uhn.fhir.rest.server.IBundleProvider everything(
javax.servlet.http.HttpServletRequest theServletRequest,
@IdParam ca.uhn.fhir.model.primitive.IdDt theId,
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name="_count") ca.uhn.fhir.model.primitive.UnsignedIntDt theCount
){
startRequest(theServletRequest);
try {
SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) {
paramMap.setCount(theCount.getValue());
}
paramMap.setRevIncludes(Collections.singleton(new Include("*")));
paramMap.setIncludes(Collections.singleton(new Include("*")));
paramMap.add("_id", new StringParam(theId.getIdPart()));
ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap);
return retVal;
} finally {
endRequest(theServletRequest);
}
}
} }

View File

@ -22,24 +22,32 @@ package ca.uhn.fhir.jpa.provider;
import java.util.Collections; import java.util.Collections;
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu2<Patient> { public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu2<Patient> {
@Operation(name="$everything", idempotent=true) @Operation(name = "everything", idempotent = true)
public IBundleProvider everything(HttpServletRequest theServletRequest, @IdParam IdDt theId) { public ca.uhn.fhir.rest.server.IBundleProvider everything(
javax.servlet.http.HttpServletRequest theServletRequest,
@IdParam ca.uhn.fhir.model.primitive.IdDt theId,
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name = "_count")
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount) {
startRequest(theServletRequest); startRequest(theServletRequest);
try { try {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) {
paramMap.setCount(theCount.getValue());
}
paramMap.setRevIncludes(Collections.singleton(new Include("*"))); paramMap.setRevIncludes(Collections.singleton(new Include("*")));
paramMap.setIncludes(Collections.singleton(new Include("*"))); paramMap.setIncludes(Collections.singleton(new Include("*")));
paramMap.add("_id", new StringParam(theId.getIdPart())); paramMap.add("_id", new StringParam(theId.getIdPart()));
@ -48,6 +56,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
} finally { } finally {
endRequest(theServletRequest); endRequest(theServletRequest);
} }
} }
} }

View File

@ -19,7 +19,13 @@ import ca.uhn.fhir.model.dstu.resource.Binary;
// import ca.uhn.fhir.model.dstu2.resource.Bundle; // import ca.uhn.fhir.model.dstu2.resource.Bundle;
// import ca.uhn.fhir.model.api.Bundle; // import ca.uhn.fhir.model.api.Bundle;
public class ${className}ResourceProvider extends JpaResourceProvider${versionCapitalized}<${className}> { public class ${className}ResourceProvider extends
#if ( $version != 'dstu' && (${className} == 'Patient' || ${className} == 'Encounter') )
BaseJpaResourceProvider${className}${versionCapitalized}<${className}>
#else
JpaResourceProvider${versionCapitalized}<${className}>
#end
{
@Override @Override
public Class<? extends IResource> getResourceType() { public Class<? extends IResource> getResourceType() {
@ -121,35 +127,4 @@ public class ${className}ResourceProvider extends JpaResourceProvider${versionCa
} }
} }
#if ( $version != 'dstu' && (${className} == 'Patient' || ${className} == 'Encounter') )
@Operation(name="everything", idempotent=true)
public ca.uhn.fhir.rest.server.IBundleProvider everything(
javax.servlet.http.HttpServletRequest theServletRequest,
@IdParam ca.uhn.fhir.model.primitive.IdDt theId,
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
@OperationParam(name="_count") ca.uhn.fhir.model.primitive.UnsignedIntDt theCount
){
startRequest(theServletRequest);
try {
SearchParameterMap paramMap = new SearchParameterMap();
if (theCount != null) {
paramMap.setCount(theCount.getValue());
}
paramMap.setRevIncludes(Collections.singleton(new Include("*")));
paramMap.setIncludes(Collections.singleton(new Include("*")));
paramMap.add("_id", new StringParam(theId.getIdPart()));
ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap);
return retVal;
} finally {
endRequest(theServletRequest);
}
}
#end
} }