001package ca.uhn.fhir.jpa.provider.r4;
002
003import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoComposition;
004import ca.uhn.fhir.jpa.model.util.JpaConstants;
005import ca.uhn.fhir.model.api.annotation.Description;
006import ca.uhn.fhir.model.valueset.BundleTypeEnum;
007import ca.uhn.fhir.rest.annotation.IdParam;
008import ca.uhn.fhir.rest.annotation.Operation;
009import ca.uhn.fhir.rest.annotation.OperationParam;
010import ca.uhn.fhir.rest.annotation.Sort;
011import ca.uhn.fhir.rest.api.Constants;
012import ca.uhn.fhir.rest.api.SortSpec;
013import ca.uhn.fhir.rest.api.server.IBundleProvider;
014import ca.uhn.fhir.rest.api.server.RequestDetails;
015import ca.uhn.fhir.rest.param.DateRangeParam;
016import org.hl7.fhir.instance.model.api.IBaseBundle;
017import org.hl7.fhir.instance.model.api.IBaseResource;
018import org.hl7.fhir.r4.model.Bundle;
019import org.hl7.fhir.r4.model.Composition;
020import org.hl7.fhir.r4.model.IdType;
021import org.hl7.fhir.r4.model.Resource;
022import org.hl7.fhir.r4.model.UnsignedIntType;
023
024import java.util.List;
025
026
027/*
028 * #%L
029 * HAPI FHIR JPA Server
030 * %%
031 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
032 * %%
033 * Licensed under the Apache License, Version 2.0 (the "License");
034 * you may not use this file except in compliance with the License.
035 * You may obtain a copy of the License at
036 *
037 *      http://www.apache.org/licenses/LICENSE-2.0
038 *
039 * Unless required by applicable law or agreed to in writing, software
040 * distributed under the License is distributed on an "AS IS" BASIS,
041 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
042 * See the License for the specific language governing permissions and
043 * limitations under the License.
044 * #L%
045 */
046
047public class BaseJpaResourceProviderCompositionR4 extends JpaResourceProviderR4<Composition> {
048
049        /**
050         * Composition/123/$document
051         */
052        @Operation(name = JpaConstants.OPERATION_DOCUMENT, idempotent = true, bundleType=BundleTypeEnum.DOCUMENT)
053        public IBaseBundle getDocumentForComposition(
054
055                        javax.servlet.http.HttpServletRequest theServletRequest,
056
057                        @IdParam
058                        IdType theId,
059
060                        @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
061                        @OperationParam(name = Constants.PARAM_COUNT)
062                        UnsignedIntType theCount,
063
064                        @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the offset when fetching a page.")
065                        @OperationParam(name = Constants.PARAM_OFFSET)
066                        UnsignedIntType theOffset,
067
068                        @Description(shortDefinition="Only return resources which were last updated as specified by the given range")
069                        @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1)
070                        DateRangeParam theLastUpdated,
071
072                        @Sort
073                        SortSpec theSortSpec,
074
075                        RequestDetails theRequestDetails
076                        ) {
077
078                startRequest(theServletRequest);
079                try {
080                        IBundleProvider bundleProvider = ((IFhirResourceDaoComposition<Composition>) getDao()).getDocumentForComposition(theServletRequest, theId, theCount, theOffset, theLastUpdated, theSortSpec, theRequestDetails);
081                        List<IBaseResource> resourceList = bundleProvider.getAllResources();
082
083                        boolean foundCompositionResource = false;
084                        Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT);
085                        for (IBaseResource resource : resourceList) {
086                                bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource));
087                        }
088                        return bundle;
089                } finally {
090                        endRequest(theServletRequest);
091                }
092        }
093}