Work on expunge operation

This commit is contained in:
James Agnew 2018-04-22 22:03:23 -04:00
parent a21d0a7752
commit 07e7af746f
13 changed files with 241 additions and 115 deletions

View File

@ -20,39 +20,58 @@ package ca.uhn.fhir.util;
* #L%
*/
import java.util.Collection;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.primitive.StringDt;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
/**
* Utilities for dealing with parameters resources in a version indepenedent way
*/
public class ParametersUtil {
/**
* Add a paratemer value to a Parameters resource
* @param theContext The FhirContext
* @param theParameters The Parameters resource
* @param theName The parametr name
* @param theValue The parameter value (can be a {@link IBaseResource resource} or a {@link IBaseDatatype datatype})
*/
public static void addParameterToParameters(FhirContext theContext, IBaseParameters theParameters, String theName, Object theValue) {
RuntimeResourceDefinition def = theContext.getResourceDefinition(theParameters);
BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter");
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
public static List<String> getNamedParameterValuesAsString(FhirContext theCtx, IBaseParameters theParameters, String theParameterName) {
Validate.notNull(theParameters, "theParameters must not be null");
RuntimeResourceDefinition resDef = theCtx.getResourceDefinition(theParameters.getClass());
BaseRuntimeChildDefinition parameterChild = resDef.getChildByName("parameter");
List<IBase> parameterReps = parameterChild.getAccessor().getValues(theParameters);
addClientParameter(theContext, theValue, theParameters, paramChild, paramChildElem, theName);
List<String> retVal = new ArrayList<>();
for (IBase nextParameter : parameterReps) {
BaseRuntimeElementCompositeDefinition<?> nextParameterDef = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(nextParameter.getClass());
BaseRuntimeChildDefinition nameChild = nextParameterDef.getChildByName("name");
List<IBase> nameValues = nameChild.getAccessor().getValues(nextParameter);
Optional<? extends IPrimitiveType<?>> nameValue = nameValues
.stream()
.filter(t -> t instanceof IPrimitiveType<?>)
.map(t -> ((IPrimitiveType<?>) t))
.findFirst();
if (!nameValue.isPresent() || !theParameterName.equals(nameValue.get().getValueAsString())) {
continue;
}
BaseRuntimeChildDefinition valueChild = nextParameterDef.getChildByName("value[x]");
List<IBase> valueValues = valueChild.getAccessor().getValues(nextParameter);
valueValues
.stream()
.filter(t->t instanceof IPrimitiveType<?>)
.map(t->((IPrimitiveType<?>)t).getValueAsString())
.filter(StringUtils::isNotBlank)
.forEach(retVal::add);
}
return retVal;
}
private static void addClientParameter(FhirContext theContext, Object theValue, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) {
@ -72,6 +91,22 @@ public class ParametersUtil {
}
}
/**
* Add a paratemer value to a Parameters resource
*
* @param theContext The FhirContext
* @param theParameters The Parameters resource
* @param theName The parametr name
* @param theValue The parameter value (can be a {@link IBaseResource resource} or a {@link IBaseDatatype datatype})
*/
public static void addParameterToParameters(FhirContext theContext, IBaseParameters theParameters, String theName, Object theValue) {
RuntimeResourceDefinition def = theContext.getResourceDefinition(theParameters);
BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter");
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
addClientParameter(theContext, theValue, theParameters, paramChild, paramChildElem, theName);
}
private static IBase createParameterRepetition(FhirContext theContext, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) {
IBase parameter = paramChildElem.newInstance();
paramChild.getMutator().addValue(theTargetResource, parameter);
@ -95,4 +130,5 @@ public class ParametersUtil {
Validate.notNull(theContext, "theContext must not be null");
return (IBaseParameters) theContext.getResourceDefinition("Parameters").newInstance();
}
}

View File

@ -293,7 +293,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
private void doExpungeEverything() {
ourLog.info("** BEGINNING GLOBAL EXPUNGE **");
ourLog.info("** BEGINNING GLOBAL OPERATION_NAME_EXPUNGE **");
TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager);
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
txTemplate.execute(new TransactionCallback<Void>() {

View File

@ -1,9 +1,9 @@
package ca.uhn.fhir.jpa.provider;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.provider.r4.JpaResourceProviderR4;
import ca.uhn.fhir.jpa.util.ExpungeOptions;
import ca.uhn.fhir.jpa.util.ExpungeOutcome;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
@ -69,7 +69,7 @@ public class BaseJpaProvider {
Parameters retVal = new Parameters();
retVal
.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_COUNT)
.setName(JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT)
.setValue(new IntegerType(theOutcome.getDeletedCount()));
return retVal;
}

View File

@ -21,7 +21,7 @@ package ca.uhn.fhir.jpa.provider;
*/
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.provider.r4.JpaResourceProviderR4;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.model.dstu2.resource.Parameters;
@ -78,26 +78,26 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
}
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theIdParam, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
return JpaSystemProviderDstu2.toExpungeResponse(retVal);
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(null, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
return JpaSystemProviderDstu2.toExpungeResponse(retVal);

View File

@ -4,7 +4,7 @@ import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl.Suggestion;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
import ca.uhn.fhir.jpa.provider.r4.JpaResourceProviderR4;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
@ -59,28 +59,28 @@ public class JpaSystemProviderDstu2 extends BaseJpaSystemProviderDstu2Plus<Bundl
@Autowired(required = false)
private IFulltextSearchSvc mySearchDao;
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerDt.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerDt.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerDt theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanDt theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanDt theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanDt theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerDt theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanDt theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanDt theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanDt theExpungeEverything
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
return toExpungeResponse(retVal);
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerDt.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerDt.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerDt theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanDt theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanDt theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanDt theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerDt theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanDt theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanDt theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanDt theExpungeEverything
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
return toExpungeResponse(retVal);

View File

@ -22,7 +22,7 @@ package ca.uhn.fhir.jpa.provider.dstu3;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider;
import ca.uhn.fhir.jpa.provider.r4.JpaResourceProviderR4;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
@ -82,14 +82,14 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
}
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theIdParam, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
try {
@ -99,13 +99,13 @@ public class JpaResourceProviderDstu3<T extends IAnyResource> extends BaseJpaRes
}
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = org.hl7.fhir.r4.model.IntegerType.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) org.hl7.fhir.r4.model.IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) org.hl7.fhir.r4.model.BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) org.hl7.fhir.r4.model.BooleanType theExpungeOldVersions
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(null, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
try {

View File

@ -4,7 +4,7 @@ import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl.Suggestion;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
import ca.uhn.fhir.jpa.provider.BaseJpaSystemProviderDstu2Plus;
import ca.uhn.fhir.jpa.provider.r4.JpaResourceProviderR4;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.server.RequestDetails;
@ -55,15 +55,15 @@ public class JpaSystemProviderDstu3 extends BaseJpaSystemProviderDstu2Plus<Bundl
@Autowired(required = false)
private IFulltextSearchSvc mySearchDao;
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
try {
@ -73,14 +73,14 @@ public class JpaSystemProviderDstu3 extends BaseJpaSystemProviderDstu2Plus<Bundl
}
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
) {
org.hl7.fhir.r4.model.Parameters retVal = super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
try {

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
@ -39,12 +40,6 @@ public class JpaResourceProviderR4<T extends IAnyResource> extends BaseJpaResour
public static final String OPERATION_NAME_META = "$meta";
public static final String OPERATION_NAME_META_DELETE = "$meta-delete";
public static final String OPERATION_NAME_META_ADD = "$meta-add";
public static final String EXPUNGE = "$expunge";
public static final String EXPUNGE_LIMIT = "limit";
public static final String EXPUNGE_DELETED_RESOURCES = "expungeDeletedResources";
public static final String EXPUNGE_OLD_VERSIONS = "expungeOldVersions";
public static final String EXPUNGE_COUNT = "count";
public static final String EXPUNGE_EVERYTHING = "expungeEverything";
public JpaResourceProviderR4() {
// nothing
@ -82,25 +77,25 @@ public class JpaResourceProviderR4<T extends IAnyResource> extends BaseJpaResour
}
}
@Operation(name = EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions
) {
return super.doExpunge(theIdParam, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
}
@Operation(name = EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions
) {
return super.doExpunge(null, theLimit, theExpungeDeletedResources, theExpungeOldVersions, null);
}

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl.Suggestion;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
import ca.uhn.fhir.jpa.provider.BaseJpaSystemProviderDstu2Plus;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.server.RequestDetails;
@ -51,27 +52,27 @@ public class JpaSystemProviderR4 extends BaseJpaSystemProviderDstu2Plus<Bundle,
@Autowired(required = false)
private IFulltextSearchSvc mySearchDao;
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@IdParam IIdType theIdParam,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
) {
return super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
}
@Operation(name = JpaResourceProviderR4.EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_COUNT, type = IntegerType.class)
@Operation(name = JpaConstants.OPERATION_NAME_EXPUNGE, idempotent = false, returnParameters = {
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, type = IntegerType.class)
})
public Parameters expunge(
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaResourceProviderR4.EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT) IntegerType theLimit,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES) BooleanType theExpungeDeletedResources,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS) BooleanType theExpungeOldVersions,
@OperationParam(name = JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING) BooleanType theExpungeEverything
) {
return super.doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
}

View File

@ -68,5 +68,28 @@ public class JpaConstants {
* </p>
*/
public static final String EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION = "http://hapifhir.io/fhir/StructureDefinition/subscription-resthook-deliver-latest-version";
/**
* Operation name for the $expunge operation
*/
public static final String OPERATION_NAME_EXPUNGE = "$expunge";
/**
* Parameter name for the $expunge operation
*/
public static final String OPERATION_EXPUNGE_PARAM_LIMIT = "limit";
/**
* Parameter name for the $expunge operation
*/
public static final String OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES = "expungeDeletedResources";
/**
* Parameter name for the $expunge operation
*/
public static final String OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS = "expungeOldVersions";
/**
* Parameter name for the $expunge operation
*/
public static final String OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING = "expungeEverything";
/**
* Output parameter name for the $expunge operation
*/
public static final String OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT = "count";
}

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.util.JpaConstants;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.TestUtil;
@ -114,13 +115,13 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test {
public void testExpungeInstanceOldVersionsAndDeleted() {
Parameters input = new Parameters();
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_LIMIT)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT)
.setValue(new IntegerType(1000));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES)
.setValue(new BooleanType(true));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS)
.setValue(new BooleanType(true));
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input));
@ -153,7 +154,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test {
public void testExpungeSystemEverything() {
Parameters input = new Parameters();
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_EVERYTHING)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING)
.setValue(new BooleanType(true));
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input));
@ -186,13 +187,13 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test {
public void testExpungeTypeOldVersionsAndDeleted() {
Parameters input = new Parameters();
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_LIMIT)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT)
.setValue(new IntegerType(1000));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES)
.setValue(new BooleanType(true));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS)
.setValue(new BooleanType(true));
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input));
@ -232,13 +233,13 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test {
Parameters input = new Parameters();
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_LIMIT)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_LIMIT)
.setValue(new IntegerType(1000));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_DELETED_RESOURCES)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES)
.setValue(new BooleanType(true));
input.addParameter()
.setName(JpaResourceProviderR4.EXPUNGE_OLD_VERSIONS)
.setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_OLD_VERSIONS)
.setValue(new BooleanType(true));
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input));

View File

@ -0,0 +1,35 @@
package ca.uhn.fhir.util;
import ca.uhn.fhir.context.FhirContext;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.StringType;
import org.junit.Test;
import java.util.List;
public class ParametersUtilDstu3Test {
@Test
public void testGetValues(){
Parameters p = new Parameters();
p.addParameter()
.setName("foo")
.setValue(new StringType("VALUE1"));
p.addParameter()
.setName("foo")
.setValue(new StringType("VALUE2"));
p.addParameter()
.setName("foo");
p.addParameter()
.setName("bar")
.setValue(new StringType("VALUE3"));
p.addParameter()
.setValue(new StringType("VALUE4"));
List<String> values = ParametersUtil.getNamedParameterValuesAsString(FhirContext.forDstu3(), p, "foo");
MatcherAssert.assertThat(values, Matchers.contains("VALUE1", "VALUE2"));
}
}

View File

@ -0,0 +1,35 @@
package ca.uhn.fhir.util;
import ca.uhn.fhir.context.FhirContext;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.StringType;
import org.junit.Test;
import java.util.List;
public class ParametersUtilR4Test {
@Test
public void testGetValues(){
Parameters p = new Parameters();
p.addParameter()
.setName("foo")
.setValue(new StringType("VALUE1"));
p.addParameter()
.setName("foo")
.setValue(new StringType("VALUE2"));
p.addParameter()
.setName("foo");
p.addParameter()
.setName("bar")
.setValue(new StringType("VALUE3"));
p.addParameter()
.setValue(new StringType("VALUE4"));
List<String> values = ParametersUtil.getNamedParameterValuesAsString(FhirContext.forR4(), p, "foo");
MatcherAssert.assertThat(values, Matchers.contains("VALUE1", "VALUE2"));
}
}