Skip to content

Commit 69ee95f

Browse files
committed
Adding class shadowing for issue reported on hapifhir/hapi-fhir#7242
1 parent feadd7f commit 69ee95f

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* #%L
3+
* HAPI FHIR JPA Server
4+
* %%
5+
* Copyright (C) 2014 - 2025 Smile CDR, Inc.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package ca.uhn.fhir.jpa.provider;
21+
22+
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoObservation;
23+
import ca.uhn.fhir.jpa.model.util.JpaConstants;
24+
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
25+
import ca.uhn.fhir.model.api.annotation.Description;
26+
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
27+
import ca.uhn.fhir.rest.annotation.Operation;
28+
import ca.uhn.fhir.rest.annotation.OperationParam;
29+
import ca.uhn.fhir.rest.annotation.RawParam;
30+
import ca.uhn.fhir.rest.api.Constants;
31+
import ca.uhn.fhir.rest.api.server.IBundleProvider;
32+
import ca.uhn.fhir.rest.param.DateAndListParam;
33+
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
34+
import ca.uhn.fhir.rest.param.TokenAndListParam;
35+
import org.hl7.fhir.instance.model.api.IBaseResource;
36+
import org.hl7.fhir.instance.model.api.IPrimitiveType;
37+
38+
import java.util.List;
39+
import java.util.Map;
40+
41+
public abstract class BaseJpaResourceProviderObservation<T extends IBaseResource> extends BaseJpaResourceProvider<T> {
42+
43+
/**
44+
* Observation/$lastn
45+
*/
46+
@Operation(name = JpaConstants.OPERATION_LASTN, idempotent = true, bundleType = BundleTypeEnum.SEARCHSET)
47+
public IBundleProvider observationLastN(
48+
jakarta.servlet.http.HttpServletRequest theServletRequest,
49+
jakarta.servlet.http.HttpServletResponse theServletResponse,
50+
ca.uhn.fhir.rest.api.server.RequestDetails theRequestDetails,
51+
@Description(
52+
formalDefinition =
53+
"Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
54+
@OperationParam(name = Constants.PARAM_COUNT, typeName = "unsignedInt")
55+
IPrimitiveType<Integer> theCount,
56+
@Description(shortDefinition = "The classification of the type of observation")
57+
@OperationParam(name = "category")
58+
TokenAndListParam theCategory,
59+
@Description(shortDefinition = "The code of the observation type") @OperationParam(name = "code")
60+
TokenAndListParam theCode,
61+
@Description(shortDefinition = "The effective date of the observation") @OperationParam(name = "date")
62+
DateAndListParam theDate,
63+
@Description(shortDefinition = "The subject that the observation is about (if patient)")
64+
@OperationParam(name = "patient")
65+
ReferenceAndListParam thePatient,
66+
@Description(shortDefinition = "The subject that the observation is about")
67+
@OperationParam(name = "subject")
68+
ReferenceAndListParam theSubject,
69+
@Description(shortDefinition = "The maximum number of observations to return for each observation code")
70+
@OperationParam(name = "max", typeName = "integer", min = 0, max = 1)
71+
IPrimitiveType<Integer> theMax,
72+
@RawParam Map<String, List<String>> theAdditionalRawParams) {
73+
startRequest(theServletRequest);
74+
try {
75+
SearchParameterMap paramMap = new SearchParameterMap();
76+
paramMap.add(org.hl7.fhir.r4.model.Observation.SP_CATEGORY, theCategory);
77+
paramMap.add(org.hl7.fhir.r4.model.Observation.SP_CODE, theCode);
78+
paramMap.add(org.hl7.fhir.r4.model.Observation.SP_DATE, theDate);
79+
if (thePatient != null) {
80+
paramMap.add(org.hl7.fhir.r4.model.Observation.SP_PATIENT, thePatient);
81+
}
82+
if (theSubject != null) {
83+
paramMap.add(org.hl7.fhir.r4.model.Observation.SP_SUBJECT, theSubject);
84+
}
85+
if (theMax != null) {
86+
paramMap.setLastNMax(theMax.getValue());
87+
88+
/**
89+
* The removal of the original raw parameter is required as every implementing class
90+
* has the "Observation" resource class defined. For this resource, the max parameter
91+
* is not supported and thus has to be removed before the use of "translateRawParameters".
92+
*/
93+
if (theAdditionalRawParams != null) theAdditionalRawParams.remove("max");
94+
}
95+
if (theCount != null) {
96+
paramMap.setCount(theCount.getValue());
97+
}
98+
99+
getDao().translateRawParameters(theAdditionalRawParams, paramMap);
100+
101+
return ((IFhirResourceDaoObservation<?>) getDao())
102+
.observationsLastN(paramMap, theRequestDetails, theServletResponse);
103+
} finally {
104+
endRequest(theServletRequest);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)