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