001package ca.uhn.fhir.jpa.dao.dstu3;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoComposition;
024import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
025import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
026import ca.uhn.fhir.model.api.IResource;
027import ca.uhn.fhir.rest.api.SortSpec;
028import ca.uhn.fhir.rest.api.server.IBundleProvider;
029import ca.uhn.fhir.rest.api.server.RequestDetails;
030import ca.uhn.fhir.rest.param.DateRangeParam;
031import ca.uhn.fhir.rest.param.StringParam;
032import org.hl7.fhir.dstu3.model.Composition;
033import org.hl7.fhir.instance.model.api.IIdType;
034import org.hl7.fhir.instance.model.api.IPrimitiveType;
035
036import javax.servlet.http.HttpServletRequest;
037import java.util.Collections;
038
039public class FhirResourceDaoCompositionDstu3 extends BaseHapiFhirResourceDao<Composition> implements IFhirResourceDaoComposition<Composition> {
040
041        @Override
042        public IBundleProvider getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType<Integer> theCount, IPrimitiveType<Integer> theOffset, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) {
043                SearchParameterMap paramMap = new SearchParameterMap();
044                if (theCount != null) {
045                        paramMap.setCount(theCount.getValue());
046                }
047                if (theOffset != null) {
048                        paramMap.setOffset(theOffset.getValue());
049                }
050                paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive()));
051                paramMap.setSort(theSort);
052                paramMap.setLastUpdated(theLastUpdate);
053                if (theId != null) {
054                        paramMap.add("_id", new StringParam(theId.getIdPart()));
055                }
056                return search(paramMap, theRequestDetails);
057        }
058}
059