Skip to content

Commit 8bb65a6

Browse files
TipzCMleif stawnyczy
andauthored
71180rel group list 2 (#7159)
* Revert "7082 add ability to filter everything (#7083)" This reverts commit f565711. * initial changes * omit list and group from patient compartment * spotless * fixing things that might have to be tossed * updating hapi to allow omitting some SP from security compartments * fixing tests * adding test for delete * spotless * git status * cleanup * fixing some tests * test fix * review fixes * more review fixes * review fixes * version bump * merging in master * spotless * fixing bug * review fixes 2 * fixing tests * spotless * filtering for patient export * spotless * fix * fixing the link * version change * adding version * release version change * review fix * spotless * remove the version * commit to force build --------- Co-authored-by: leif stawnyczy <[email protected]>
1 parent 85edf3c commit 8bb65a6

File tree

125 files changed

+926
-760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+926
-760
lines changed

hapi-deployable-pom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-fhir</artifactId>
8-
<version>8.3.16-SNAPSHOT</version>
8+
<version>8.3.17-SNAPSHOT</version>
99

1010
<relativePath>../pom.xml</relativePath>
1111
</parent>

hapi-fhir-android/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-deployable-pom</artifactId>
8-
<version>8.3.16-SNAPSHOT</version>
8+
<version>8.3.17-SNAPSHOT</version>
99

1010
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
1111
</parent>

hapi-fhir-base/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-deployable-pom</artifactId>
8-
<version>8.3.16-SNAPSHOT</version>
8+
<version>8.3.17-SNAPSHOT</version>
99

1010
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
1111
</parent>

hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import ca.uhn.fhir.model.api.IValueSetEnumBinder;
3131
import ca.uhn.fhir.model.api.annotation.Block;
3232
import ca.uhn.fhir.model.api.annotation.Child;
33-
import ca.uhn.fhir.model.api.annotation.Compartment;
3433
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
3534
import ca.uhn.fhir.model.api.annotation.ResourceDef;
3635
import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
@@ -39,6 +38,7 @@
3938
import ca.uhn.fhir.rest.api.Constants;
4039
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
4140
import ca.uhn.fhir.util.ReflectionUtil;
41+
import ca.uhn.fhir.util.SearchParameterUtil;
4242
import jakarta.annotation.Nonnull;
4343
import org.hl7.fhir.instance.model.api.IBase;
4444
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
@@ -63,7 +63,6 @@
6363
import java.util.Collections;
6464
import java.util.HashMap;
6565
import java.util.HashSet;
66-
import java.util.LinkedHashMap;
6766
import java.util.List;
6867
import java.util.Map;
6968
import java.util.Map.Entry;
@@ -393,7 +392,6 @@ private void scanResourceForSearchParams(
393392
Class<? extends IBaseResource> theClass, RuntimeResourceDefinition theResourceDef) {
394393

395394
Map<String, RuntimeSearchParam> nameToParam = new HashMap<>();
396-
Map<Field, SearchParamDefinition> compositeFields = new LinkedHashMap<>();
397395

398396
/*
399397
* Make sure we pick up fields in interfaces too.. This ensures that we
@@ -420,39 +418,8 @@ private void scanResourceForSearchParams(
420418
throw new ConfigurationException(Msg.code(1721) + "Search param " + searchParam.name()
421419
+ " has an invalid type: " + searchParam.type());
422420
}
423-
Set<String> providesMembershipInCompartments;
424-
providesMembershipInCompartments = new HashSet<>();
425-
for (Compartment next : searchParam.providesMembershipIn()) {
426-
if (paramType != RestSearchParameterTypeEnum.REFERENCE) {
427-
StringBuilder b = new StringBuilder();
428-
b.append("Search param ");
429-
b.append(searchParam.name());
430-
b.append(" on resource type ");
431-
b.append(theClass.getName());
432-
b.append(" provides compartment membership but is not of type 'reference'");
433-
ourLog.warn(b.toString());
434-
continue;
435-
}
436-
String name = next.name();
437-
438-
// As of 2021-12-28 the R5 structures incorrectly have this prefix
439-
if (name.startsWith("Base FHIR compartment definition for ")) {
440-
name = name.substring("Base FHIR compartment definition for ".length());
441-
}
442-
providesMembershipInCompartments.add(name);
443-
}
444-
445-
/**
446-
* In the base FHIR R4 specification, the Device resource is not a part of the Patient compartment.
447-
* However, it is a patient-specific resource that most users expect to be, and several derivative
448-
* specifications including g(10) testing expect it to be, and the fact that it is not has led to many
449-
* bug reports in HAPI FHIR. As of HAPI FHIR 8.0.0 it is being manually added in response to those
450-
* requests.
451-
* See https://github.com/hapifhir/hapi-fhir/issues/6536 for more information.
452-
*/
453-
if (searchParam.name().equals("patient") && searchParam.path().equals("Device.patient")) {
454-
providesMembershipInCompartments.add("Patient");
455-
}
421+
Set<String> providesMembershipInCompartments =
422+
SearchParameterUtil.getMembershipCompartmentsForSearchParameter(theClass, searchParam);
456423

457424
List<RuntimeSearchParam.Component> components = null;
458425
if (paramType == RestSearchParameterTypeEnum.COMPOSITE) {

hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,8 @@ public void sealAndInitialize(
200200

201201
myNameToSearchParam = Collections.unmodifiableMap(myNameToSearchParam);
202202

203-
ArrayList<RuntimeSearchParam> searchParams = new ArrayList<RuntimeSearchParam>(myNameToSearchParam.values());
204-
Collections.sort(searchParams, new Comparator<RuntimeSearchParam>() {
205-
@Override
206-
public int compare(RuntimeSearchParam theArg0, RuntimeSearchParam theArg1) {
207-
return theArg0.getName().compareTo(theArg1.getName());
208-
}
209-
});
203+
ArrayList<RuntimeSearchParam> searchParams = new ArrayList<>(myNameToSearchParam.values());
204+
Collections.sort(searchParams, Comparator.comparing(RuntimeSearchParam::getName));
210205
mySearchParams = Collections.unmodifiableList(searchParams);
211206

212207
Map<String, List<RuntimeSearchParam>> compartmentNameToSearchParams = new HashMap<>();
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*-
2+
* #%L
3+
* HAPI FHIR - Server Framework
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.interceptor.auth;
21+
22+
import jakarta.annotation.Nonnull;
23+
24+
import java.util.HashMap;
25+
import java.util.HashSet;
26+
import java.util.Map;
27+
import java.util.Set;
28+
29+
/**
30+
* This class is used in RuleBuilder, as a way to allow adding or removing certain Search Parameters
31+
* to the compartment.
32+
* For example, if you were to add as additional SPs
33+
* [device -> ["patient", "subject"]
34+
* and apply it to compartment Patient/123, then any device with Patient/123 as its patient would be considered "in"
35+
* the compartment, despite the fact that device is technically not part of the compartment definition for patient.
36+
*/
37+
public class CompartmentSearchParameterModifications {
38+
39+
/**
40+
* Construct compartment modifications from resource type and sets of SP names to add or omit respectively.
41+
* @param theResourceType the resource type the SPs are based on
42+
* @param theAdditionalSPs the additional SP names
43+
* @param theOmittedSps the omitted SP names
44+
* @return
45+
*/
46+
public static CompartmentSearchParameterModifications fromAdditionalAndOmittedSPNames(
47+
@Nonnull String theResourceType,
48+
@Nonnull Set<String> theAdditionalSPs,
49+
@Nonnull Set<String> theOmittedSps) {
50+
CompartmentSearchParameterModifications modifications = new CompartmentSearchParameterModifications();
51+
theAdditionalSPs.forEach(spName -> {
52+
modifications.addSPToIncludeInCompartment(theResourceType, spName);
53+
});
54+
theOmittedSps.forEach(spName -> {
55+
modifications.addSPToOmitFromCompartment(theResourceType, spName);
56+
});
57+
return modifications;
58+
}
59+
60+
public static CompartmentSearchParameterModifications fromAdditionalCompartmentParamNames(
61+
String theResourceType, @Nonnull Set<String> theAdditionalCompartmentParamNames) {
62+
return fromAdditionalAndOmittedSPNames(theResourceType, theAdditionalCompartmentParamNames, Set.of());
63+
}
64+
65+
private final Map<String, Set<String>> myAdditionalResourceTypeToParameterCodeMap;
66+
67+
private final Map<String, Set<String>> myOmittedResourceTypeToParameterCodeMap;
68+
69+
public CompartmentSearchParameterModifications() {
70+
myAdditionalResourceTypeToParameterCodeMap = new HashMap<>();
71+
myOmittedResourceTypeToParameterCodeMap = new HashMap<>();
72+
}
73+
74+
/**
75+
* Add an SP, normally included in the compartment, that will be omitted
76+
* hereafter.
77+
* @param theResourceType the resource type on which the SP exists
78+
* @param theSPName the name of the search parameter
79+
*/
80+
public void addSPToOmitFromCompartment(String theResourceType, String theSPName) {
81+
myOmittedResourceTypeToParameterCodeMap
82+
.computeIfAbsent(theResourceType.toLowerCase(), (key) -> new HashSet<>())
83+
.add(theSPName);
84+
}
85+
86+
/**
87+
* Add an SP, not in the compartment, that will now be included hereafter
88+
* @param theResourceType the resource type on which the SP exists
89+
* @param theSPName the name of the search parameter
90+
*/
91+
public void addSPToIncludeInCompartment(String theResourceType, String theSPName) {
92+
myAdditionalResourceTypeToParameterCodeMap
93+
.computeIfAbsent(theResourceType.toLowerCase(), (key) -> new HashSet<>())
94+
.add(theSPName);
95+
}
96+
97+
public Set<String> getAdditionalSearchParamNamesForResourceType(@Nonnull String theResourceType) {
98+
return myAdditionalResourceTypeToParameterCodeMap.computeIfAbsent(
99+
theResourceType.toLowerCase(), (key) -> new HashSet<>());
100+
}
101+
102+
public Set<String> getOmittedSPNamesForResourceType(String theResourceType) {
103+
return myOmittedResourceTypeToParameterCodeMap.computeIfAbsent(
104+
theResourceType.toLowerCase(), (key) -> new HashSet<>());
105+
}
106+
}
Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +0,0 @@
1-
/*-
2-
* #%L
3-
* HAPI FHIR - Core Library
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.svcs;
21-
22-
import jakarta.annotation.Nonnull;
23-
24-
import java.util.Collection;
25-
26-
public interface ISearchLimiterSvc {
27-
28-
/**
29-
* Add a resource type to omit from all search results for the named operation.
30-
* @param theOperationName operation name (eg: $everything, $export, etc)
31-
* @param theResourceType the resource name to omit (eg: Group, List, etc)
32-
*/
33-
void addOmittedResourceType(@Nonnull String theOperationName, @Nonnull String theResourceType);
34-
35-
/**
36-
* Get all omitted resources for the named operation.
37-
*/
38-
Collection<String> getResourcesToOmitForOperationSearches(@Nonnull String theOperationName);
39-
40-
/**
41-
* Remove the resource type from the omission criteria.
42-
* @param theOperationName the operation name
43-
* @param theResourceType the resource type to remove
44-
*/
45-
void removeOmittedResourceType(@Nonnull String theOperationName, @Nonnull String theResourceType);
46-
47-
/**
48-
* Remove all omitted resource types for the operation.
49-
* @param theOperationName the operation name
50-
*/
51-
void removeAllResourcesForOperation(String theOperationName);
52-
}

0 commit comments

Comments
 (0)