001package ca.uhn.fhir.rest.server.provider;
002
003/*-
004 * #%L
005 * HAPI FHIR - Server Framework
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.rest.annotation.Operation;
024import ca.uhn.fhir.rest.annotation.OperationParam;
025import ca.uhn.fhir.rest.api.Constants;
026import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
027import org.hl7.fhir.instance.model.api.IBaseBundle;
028import org.hl7.fhir.instance.model.api.IBaseCoding;
029import org.hl7.fhir.instance.model.api.IBaseReference;
030import org.hl7.fhir.instance.model.api.IPrimitiveType;
031
032import java.util.List;
033
034/**
035 * This class implements the Observation
036 * <a href="http://hl7.org/fhir/observation-operation-lastn.html">$lastn</a> operation.
037 * <p>
038 * It is does not implement the actual storage logic for this operation, but can be
039 * subclassed to provide this functionality.
040 * </p>
041 *
042 * @since 4.1.0
043 */
044public abstract class BaseLastNProvider {
045
046        @Operation(name = Constants.OPERATION_LASTN, typeName = "Observation", idempotent = true)
047        public IBaseBundle lastN(
048                ServletRequestDetails theRequestDetails,
049                @OperationParam(name = "subject", typeName = "reference", min = 0, max = 1) IBaseReference theSubject,
050                @OperationParam(name = "category", typeName = "coding", min = 0, max = OperationParam.MAX_UNLIMITED) List<IBaseCoding> theCategories,
051                @OperationParam(name = "code", typeName = "coding", min = 0, max = OperationParam.MAX_UNLIMITED) List<IBaseCoding> theCodes,
052                @OperationParam(name = "max", typeName = "integer", min = 0, max = 1) IPrimitiveType<Integer> theMax
053        ) {
054                return processLastN(theSubject, theCategories, theCodes, theMax);
055        }
056
057        /**
058         * Subclasses should implement this method
059         */
060        protected abstract IBaseBundle processLastN(IBaseReference theSubject, List<IBaseCoding> theCategories, List<IBaseCoding> theCodes, IPrimitiveType<Integer> theMax);
061
062
063}