Skip to content

Commit cc6e172

Browse files
authored
Adding support for pheye medical conditions filter. (#287)
1 parent d9a905c commit cc6e172

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

src/main/java/ai/philterd/phileas/model/filtering/FilterType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ public enum FilterType {
5252
URL("url", true),
5353
VIN("vin", true),
5454
ZIP_CODE("zip-code", true),
55-
CUSTOM_DICTIONARY("custom-dictionary", false);
55+
CUSTOM_DICTIONARY("custom-dictionary", false),
56+
57+
// These are not natively identified by Phileas.
58+
MEDICAL_CONDITION("medical-condition", false),
59+
OTHER("other", false);
5660

5761
private final String type;
5862
private final boolean deterministic;

src/main/java/ai/philterd/phileas/policy/Identifiers.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import ai.philterd.phileas.policy.filters.Identifier;
3535
import ai.philterd.phileas.policy.filters.IpAddress;
3636
import ai.philterd.phileas.policy.filters.MacAddress;
37+
import ai.philterd.phileas.policy.filters.MedicalCondition;
3738
import ai.philterd.phileas.policy.filters.PassportNumber;
3839
import ai.philterd.phileas.policy.filters.PhEye;
3940
import ai.philterd.phileas.policy.filters.PhoneNumber;
@@ -161,6 +162,10 @@ public class Identifiers {
161162
@Expose
162163
private ZipCode zipCode;
163164

165+
@SerializedName("medicalCondition")
166+
@Expose
167+
private MedicalCondition medicalCondition;
168+
164169
@SerializedName("city")
165170
@Expose
166171
private City city;
@@ -239,6 +244,8 @@ public boolean hasFilter(FilterType filterType) {
239244
if(this.getIpAddress() != null) { return true; } break;
240245
case MAC_ADDRESS:
241246
if(this.getMacAddress() != null) { return true; } break;
247+
case MEDICAL_CONDITION:
248+
if(this.getMedicalCondition() != null) {return true; } break;
242249
case PERSON:
243250
if(this.getPhEye() != null) { return true; } break;
244251
case PASSPORT_NUMBER:
@@ -725,5 +732,13 @@ public Currency getCurrency() {
725732
public void setCurrency(Currency currency) {
726733
this.currency = currency;
727734
}
728-
735+
736+
public MedicalCondition getMedicalCondition() {
737+
return medicalCondition;
738+
}
739+
740+
public void setMedicalCondition(MedicalCondition medicalCondition) {
741+
this.medicalCondition = medicalCondition;
742+
}
743+
729744
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 Philterd, LLC @ https://www.philterd.ai
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ai.philterd.phileas.policy.filters;
17+
18+
import ai.philterd.phileas.services.strategies.rules.VinFilterStrategy;
19+
import com.google.gson.annotations.Expose;
20+
import com.google.gson.annotations.SerializedName;
21+
22+
import java.util.List;
23+
24+
public class MedicalCondition extends AbstractFilter {
25+
26+
@SerializedName("medicalConditionFilterStrategies")
27+
@Expose
28+
private List<VinFilterStrategy> medicalConditionFilterStrategies;
29+
30+
public List<VinFilterStrategy> getMedicalConditionFilterStrategies() {
31+
return medicalConditionFilterStrategies;
32+
}
33+
34+
public void setMedicalConditionFilterStrategies(List<VinFilterStrategy> medicalConditionFilterStrategies) {
35+
this.medicalConditionFilterStrategies = medicalConditionFilterStrategies;
36+
}
37+
38+
}

src/main/java/ai/philterd/phileas/services/FilterPolicyLoader.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,46 @@ public List<Filter> getFiltersForPolicy(final Policy policy, final Map<String, M
12351235

12361236
}
12371237

1238+
if(policy.getIdentifiers().hasFilter(FilterType.MEDICAL_CONDITION) && policy.getIdentifiers().getPhEye().isEnabled()) {
1239+
1240+
if(cache.containsKey(FilterType.MEDICAL_CONDITION)) {
1241+
enabledFilters.add(cache.get(FilterType.MEDICAL_CONDITION));
1242+
} else {
1243+
1244+
final int windowSize = policy.getIdentifiers().getPhEye().getWindowSizeOrDefault(phileasConfiguration.spanWindowSize());
1245+
1246+
final FilterConfiguration filterConfiguration = new FilterConfiguration.FilterConfigurationBuilder()
1247+
.withStrategies(policy.getIdentifiers().getPhEye().getPhEyeFilterStrategies())
1248+
.withAnonymizationService(new AlphanumericAnonymizationService(contextService, random))
1249+
.withIgnored(policy.getIdentifiers().getPhEye().getIgnored())
1250+
.withIgnoredFiles(policy.getIdentifiers().getPhEye().getIgnoredFiles())
1251+
.withIgnoredPatterns(policy.getIdentifiers().getPhEye().getIgnoredPatterns())
1252+
.withCrypto(policy.getCrypto())
1253+
.withFPE(policy.getFpe())
1254+
.withWindowSize(windowSize)
1255+
.withPriority(policy.getIdentifiers().getPhEye().getPriority())
1256+
.build();
1257+
1258+
final PhEyeConfiguration phEyeConfiguration = new PhEyeConfiguration(policy.getIdentifiers().getPhEye().getPhEyeConfiguration().getEndpoint());
1259+
phEyeConfiguration.setTimeout(policy.getIdentifiers().getPhEye().getPhEyeConfiguration().getTimeout());
1260+
phEyeConfiguration.setMaxIdleConnections(policy.getIdentifiers().getPhEye().getPhEyeConfiguration().getMaxIdleConnections());
1261+
phEyeConfiguration.setBearerToken(policy.getIdentifiers().getPhEye().getPhEyeConfiguration().getBearerToken());
1262+
1263+
final Filter filter = new PhEyeFilter(
1264+
filterConfiguration,
1265+
phEyeConfiguration,
1266+
policy.getIdentifiers().getPhEye().isRemovePunctuation(),
1267+
policy.getIdentifiers().getPhEye().getThresholds(),
1268+
httpClient
1269+
);
1270+
1271+
enabledFilters.add(filter);
1272+
filterCache.get(policy.getName()).put(FilterType.MEDICAL_CONDITION, filter);
1273+
1274+
}
1275+
1276+
}
1277+
12381278
return enabledFilters;
12391279

12401280
}

src/main/java/ai/philterd/phileas/services/filters/ai/pheye/PhEyeFilter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,15 @@ public Filtered filter(final Policy policy, final String context, final int piec
157157
// Get the window of text surrounding the token.
158158
final String[] window = getWindow(formattedInput, phEyeSpan.getStart(), phEyeSpan.getEnd());
159159

160-
// Currently only PERSON type is supported.
161-
final FilterType filterType = FilterType.PERSON;
160+
// Set the filter type based on the entity's type that's returned from pheye.
161+
final FilterType filterType;
162+
if(phEyeSpan.getLabel().equalsIgnoreCase("PERSON")) {
163+
filterType = FilterType.PERSON;
164+
} else if(phEyeSpan.getLabel().equalsIgnoreCase("DISEASE_DISORDER")) {
165+
filterType = FilterType.MEDICAL_CONDITION;
166+
} else {
167+
filterType = FilterType.OTHER;
168+
}
162169

163170
final Span span = createSpan(policy, context, filterType, phEyeSpan.getText(),
164171
window, phEyeSpan.getLabel(), phEyeSpan.getStart(), phEyeSpan.getEnd(),

0 commit comments

Comments
 (0)