Skip to content

Commit

Permalink
#149 Experimental changes for alternative filter names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Oct 10, 2024
1 parent 38259db commit ebbfb42
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ public class AgeFilterTest extends AbstractFilterTest {

private final AlertService alertService = Mockito.mock(AlertService.class);

@Test
public void filterWithAlternateName() throws Exception {

final FilterConfiguration filterConfiguration = new FilterConfiguration.FilterConfigurationBuilder()
.withStrategies(List.of(new AgeFilterStrategy()))
.withAlertService(alertService)
.withAnonymizationService(new AgeAnonymizationService(new LocalAnonymizationCacheService()))
.withWindowSize(windowSize)
.build();

final AgeFilter filter = new AgeFilter(filterConfiguration);

final FilterResult filterResult = filter.filter(getPolicy(), "context", "documentid", PIECE, "patient is 4161 y/o and", attributes);

showSpans(filterResult.getSpans());

Assertions.assertEquals(0, filterResult.getSpans().size());

}

@Test
public void filterIgnoredPattern1() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public abstract class Filter {
*/
protected final FilterType filterType;

/**
* When given, an alternative name to use instead of the {@link FilterType}.
*/
protected String alternativeName;

/**
* The alert service.
*/
Expand Down Expand Up @@ -130,6 +135,7 @@ public Filter(final FilterType filterType, final FilterConfiguration filterConfi
this.crypto = filterConfiguration.getCrypto();
this.fpe = filterConfiguration.getFPE();
this.windowSize = filterConfiguration.getWindowSize();
this.alternativeName = filterConfiguration.getAlternativeName();

if(this.ignored == null) {
this.ignored = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class FilterConfiguration {
private final Crypto crypto;
private final FPE fpe;
private int windowSize = 5;
private String alternativeName;

private FilterConfiguration(
final List<? extends AbstractFilterStrategy> strategies,
Expand All @@ -50,7 +51,8 @@ private FilterConfiguration(
final List<IgnoredPattern> ignoredPatterns,
final Crypto crypto,
final FPE fpe,
final int windowSize
final int windowSize,
final String alternativeName
) {

this.strategies = strategies;
Expand All @@ -62,6 +64,7 @@ private FilterConfiguration(
this.crypto = crypto;
this.fpe = fpe;
this.windowSize = windowSize;
this.alternativeName = alternativeName;

}

Expand All @@ -76,6 +79,7 @@ public static class FilterConfigurationBuilder {
private Crypto crypto;
private FPE fpe;
private int windowSize;
private String alternativeName;

public FilterConfiguration build() {

Expand All @@ -91,7 +95,8 @@ public FilterConfiguration build() {
ignoredPatterns,
crypto,
fpe,
windowSize
windowSize,
alternativeName
);

}
Expand Down Expand Up @@ -229,4 +234,8 @@ public int getWindowSize() {
return windowSize;
}

public String getAlternativeName() {
return alternativeName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public abstract class AbstractFilter {
@Expose
protected List<IgnoredPattern> ignoredPatterns = Collections.emptyList();

@SerializedName("alternativeName")
@Expose
protected String alternativeName;

public String getAlternativeName() {
return alternativeName;
}

public void setAlternativeName(String alternativeName) {
this.alternativeName = alternativeName;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
Expand Down

0 comments on commit ebbfb42

Please sign in to comment.