diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/Operation.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/Operation.java index 11cada28f96..0dd2d9775dc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/Operation.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/Operation.java @@ -27,6 +27,8 @@ import java.lang.annotation.Target; import org.hl7.fhir.instance.model.api.IBaseResource; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; + /** * RESTful method annotation used for a method which provides FHIR "operations". */ @@ -71,4 +73,11 @@ public @interface Operation { * response to this operation. */ OperationParam[] returnParameters() default {}; + + /** + * If this operation returns a bundle, this parameter can be used to specify the + * bundle type to set in the bundle. + */ + BundleTypeEnum bundleType() default BundleTypeEnum.COLLECTION; + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java index 4ca0f1df3cc..b7e16a497bf 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java @@ -73,11 +73,13 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { private final RestOperationTypeEnum myOtherOperatiopnType; private List myReturnParams; private final ReturnTypeEnum myReturnType; + private BundleTypeEnum myBundleType; protected OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, boolean theIdempotent, String theOperationName, Class theOperationType, - OperationParam[] theReturnParams) { + OperationParam[] theReturnParams, BundleTypeEnum theBundleType) { super(theReturnResourceType, theMethod, theContext, theProvider); + myBundleType = theBundleType; myIdempotent = theIdempotent; myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { @@ -168,7 +170,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } public OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Operation theAnnotation) { - this(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, theAnnotation.idempotent(), theAnnotation.name(), theAnnotation.type(), theAnnotation.returnParameters()); + this(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, theAnnotation.idempotent(), theAnnotation.name(), theAnnotation.type(), theAnnotation.returnParameters(), theAnnotation.bundleType()); } public String getDescription() { @@ -184,7 +186,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { @Override protected BundleTypeEnum getResponseBundleType() { - return BundleTypeEnum.COLLECTION; + return myBundleType; } @Override diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java index 8d09e42f4b3..ae74a088d6f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/ValidateMethodBindingDstu2.java @@ -28,21 +28,20 @@ import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; import ca.uhn.fhir.rest.param.ResourceParameter; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; -import ca.uhn.fhir.rest.server.IRestfulServer; -import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.util.ParametersUtil; public class ValidateMethodBindingDstu2 extends OperationMethodBinding { public ValidateMethodBindingDstu2(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Validate theAnnotation) { - super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0]); + super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); List newParams = new ArrayList(); int idx = 0; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderEncounterDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderEncounterDstu2.java index 9459ee46bc5..c92d4ada157 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderEncounterDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderEncounterDstu2.java @@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoEncounter; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.dstu2.resource.Encounter; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; @@ -37,7 +38,7 @@ public class BaseJpaResourceProviderEncounterDstu2 extends JpaResourceProviderDs * Encounter/123/$everything */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider EncounterInstanceEverything( javax.servlet.http.HttpServletRequest theServletRequest, @@ -69,7 +70,7 @@ public class BaseJpaResourceProviderEncounterDstu2 extends JpaResourceProviderDs * /Encounter/$everything */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider EncounterTypeEverything( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java index b53db1a44dc..1305ff74b5c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java @@ -28,6 +28,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; @@ -47,7 +48,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu * @param theRequestDetails */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider patientInstanceEverything( javax.servlet.http.HttpServletRequest theServletRequest, @@ -91,7 +92,7 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu * @param theRequestDetails */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider patientTypeEverything( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderEncounterDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderEncounterDstu3.java index 54d69185b34..c25af941e64 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderEncounterDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderEncounterDstu3.java @@ -26,6 +26,7 @@ import org.hl7.fhir.dstu3.model.UnsignedIntType; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoEncounter; import ca.uhn.fhir.model.api.annotation.Description; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; @@ -40,7 +41,7 @@ public class BaseJpaResourceProviderEncounterDstu3 extends JpaResourceProviderDs * Encounter/123/$everything */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider EncounterInstanceEverything( javax.servlet.http.HttpServletRequest theServletRequest, @@ -72,7 +73,7 @@ public class BaseJpaResourceProviderEncounterDstu3 extends JpaResourceProviderDs * /Encounter/$everything */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider EncounterTypeEverything( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderPatientDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderPatientDstu3.java index b7847e79866..37f9795922d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderPatientDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderPatientDstu3.java @@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.model.UnsignedIntType; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.model.api.annotation.Description; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; @@ -50,7 +51,7 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu * @param theRequestDetails */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider patientInstanceEverything( javax.servlet.http.HttpServletRequest theServletRequest, @@ -94,7 +95,7 @@ public class BaseJpaResourceProviderPatientDstu3 extends JpaResourceProviderDstu * @param theRequestDetails */ //@formatter:off - @Operation(name = "everything", idempotent = true) + @Operation(name = "everything", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) public ca.uhn.fhir.rest.server.IBundleProvider patientTypeEverything( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java index 9b18330883e..8887cc1a1bf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java @@ -165,7 +165,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { assertEquals(200, http.getStatusLine().getStatusCode()); Bundle responseBundle = ourCtx.newXmlParser().parseResource(Bundle.class, response); - assertEquals(BundleTypeEnum.COLLECTION, responseBundle.getTypeElement().getValueAsEnum()); + assertEquals(BundleTypeEnum.SEARCH_RESULTS, responseBundle.getTypeElement().getValueAsEnum()); } finally { http.close(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 9722e72f087..c4f138bb54e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -1121,6 +1121,8 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); + + assertEquals(BundleType.SEARCHSET, b.getType()); List ids = toUnqualifiedVersionlessIds(b); assertThat(ids, containsInAnyOrder(o1Id, o2Id, p1Id, p2Id, c1Id, c2Id)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java index 1f780b40435..2fe9daacdbd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java @@ -233,7 +233,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { assertEquals(200, http.getStatusLine().getStatusCode()); Bundle responseBundle = ourCtx.newXmlParser().parseResource(Bundle.class, response); - assertEquals(BundleType.COLLECTION, responseBundle.getTypeElement().getValue()); + assertEquals(BundleType.SEARCHSET, responseBundle.getTypeElement().getValue()); } finally { http.close(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 12d88795ea5..0babe4f8b21 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -202,6 +202,10 @@ page the most recent 20000 entries. Now it has no limit. + + JPA server returned the wrong Bundle.type value (COLLECTION, should be SEARCHSET) + for $everything operation responses. Thanks to Sonali Somase for reporting! +