diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java index 3a4b1835d8b..ec02e9ed523 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.util; * 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. @@ -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 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 parameterReps = parameterChild.getAccessor().getValues(theParameters); - addClientParameter(theContext, theValue, theParameters, paramChild, paramChildElem, theName); + List retVal = new ArrayList<>(); + + for (IBase nextParameter : parameterReps) { + BaseRuntimeElementCompositeDefinition nextParameterDef = (BaseRuntimeElementCompositeDefinition) theCtx.getElementDefinition(nextParameter.getClass()); + BaseRuntimeChildDefinition nameChild = nextParameterDef.getChildByName("name"); + List nameValues = nameChild.getAccessor().getValues(nextParameter); + Optional> 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 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(); } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index f654eb07eab..df7bf8e40c7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -293,7 +293,7 @@ public abstract class BaseHapiFhirDao 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() { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaProvider.java index 1aef3d0b66d..dba40dbea0d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaProvider.java @@ -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; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java index 72d733e283d..35b76ab3a6c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java @@ -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 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); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java index 00d528d0adc..922bd083691 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaSystemProviderDstu2.java @@ -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 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 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 { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java index 1c7862b73fe..3d63b14ac4a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/JpaSystemProviderDstu3.java @@ -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 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 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); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaSystemProviderR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaSystemProviderR4.java index 7604ff47e3f..ed82b607e92 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaSystemProviderR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaSystemProviderR4.java @@ -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 */ 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"; } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java index a0832639879..61c96221a96 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java @@ -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)); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ParametersUtilDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ParametersUtilDstu3Test.java new file mode 100644 index 00000000000..da97d6828cb --- /dev/null +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/ParametersUtilDstu3Test.java @@ -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 values = ParametersUtil.getNamedParameterValuesAsString(FhirContext.forDstu3(), p, "foo"); + MatcherAssert.assertThat(values, Matchers.contains("VALUE1", "VALUE2")); + } + +} diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java new file mode 100644 index 00000000000..1a17e64005c --- /dev/null +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java @@ -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 values = ParametersUtil.getNamedParameterValuesAsString(FhirContext.forR4(), p, "foo"); + MatcherAssert.assertThat(values, Matchers.contains("VALUE1", "VALUE2")); + } + +}