001package ca.uhn.fhir.jpa.provider.r4;
002
003import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoObservation;
004import ca.uhn.fhir.jpa.model.util.JpaConstants;
005import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
006import ca.uhn.fhir.model.api.annotation.Description;
007import ca.uhn.fhir.model.valueset.BundleTypeEnum;
008import ca.uhn.fhir.rest.annotation.Operation;
009import ca.uhn.fhir.rest.annotation.OperationParam;
010import ca.uhn.fhir.rest.api.Constants;
011import ca.uhn.fhir.rest.api.server.IBundleProvider;
012import ca.uhn.fhir.rest.param.DateAndListParam;
013import ca.uhn.fhir.rest.param.ReferenceAndListParam;
014import ca.uhn.fhir.rest.param.TokenAndListParam;
015import org.hl7.fhir.instance.model.api.IPrimitiveType;
016import org.hl7.fhir.r4.model.Observation;
017import org.hl7.fhir.r4.model.UnsignedIntType;
018
019/*
020 * #%L
021 * HAPI FHIR JPA Server
022 * %%
023 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
024 * %%
025 * Licensed under the Apache License, Version 2.0 (the "License");
026 * you may not use this file except in compliance with the License.
027 * You may obtain a copy of the License at
028 *
029 *      http://www.apache.org/licenses/LICENSE-2.0
030 *
031 * Unless required by applicable law or agreed to in writing, software
032 * distributed under the License is distributed on an "AS IS" BASIS,
033 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
034 * See the License for the specific language governing permissions and
035 * limitations under the License.
036 * #L%
037 */
038
039public class BaseJpaResourceProviderObservationR4 extends JpaResourceProviderR4<Observation> {
040
041        /**
042         * Observation/$lastn
043         */
044        @Operation(name = JpaConstants.OPERATION_LASTN, idempotent = true, bundleType = BundleTypeEnum.SEARCHSET)
045        public IBundleProvider observationLastN(
046
047                javax.servlet.http.HttpServletRequest theServletRequest,
048                javax.servlet.http.HttpServletResponse theServletResponse,
049
050                ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails,
051
052                @Description(formalDefinition = "Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
053                @OperationParam(name = Constants.PARAM_COUNT)
054                        UnsignedIntType theCount,
055
056                @Description(shortDefinition="The classification of the type of observation")
057                @OperationParam(name="category")
058                        TokenAndListParam theCategory,
059
060                @Description(shortDefinition="The code of the observation type")
061                @OperationParam(name="code")
062                        TokenAndListParam theCode,
063
064                @Description(shortDefinition="The effective date of the observation")
065                @OperationParam(name="date")
066                        DateAndListParam theDate,
067
068                @Description(shortDefinition="The subject that the observation is about (if patient)")
069                @OperationParam(name="patient")
070                        ReferenceAndListParam thePatient,
071
072                @Description(shortDefinition="The subject that the observation is about")
073                @OperationParam(name="subject" )
074                        ReferenceAndListParam theSubject,
075
076                @Description(shortDefinition="The maximum number of observations to return for each observation code")
077                @OperationParam(name = "max", typeName = "integer", min = 0, max = 1)
078                        IPrimitiveType<Integer> theMax
079
080                ) {
081                startRequest(theServletRequest);
082                try {
083                        SearchParameterMap paramMap = new SearchParameterMap();
084                        paramMap.add(Observation.SP_CATEGORY, theCategory);
085                        paramMap.add(Observation.SP_CODE, theCode);
086                        paramMap.add(Observation.SP_DATE, theDate);
087                        if (thePatient != null) {
088                                paramMap.add(Observation.SP_PATIENT, thePatient);
089                        }
090                        if (theSubject != null) {
091                                paramMap.add(Observation.SP_SUBJECT, theSubject);
092                        }
093                        if(theMax != null) {
094                                paramMap.setLastNMax(theMax.getValue());
095                        }
096                        if (theCount != null) {
097                                paramMap.setCount(theCount.getValue());
098                        }
099
100                        return ((IFhirResourceDaoObservation<Observation>) getDao()).observationsLastN(paramMap, theRequestDetails, theServletResponse);
101                } finally {
102                        endRequest(theServletRequest);
103                }
104        }
105
106
107}