Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple isReportable call #7

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ builder.add("other keyword", Group.OTHER);
ReportabilityScreener screener = builder.build();
```

To screen text:
To screen text and get information about reportability and the keywords used:

```java
ScreeningResult result = screener.screen("full path report text goes here");
```

The `ScreeningResult` contains the `ReportabilityResult` as well as the postitive, negative and other keywords that were found and contributed to the reportability.
The `ScreeningResult` contains the `ReportabilityResult` as well as the positive, negative and other keywords that were found and contributed to the reportability.

To just check reportability
To just check reportability:

```java
if (result.getResult().equals(ReportabilityResult.REPORTABLE)) {
if (screener.isReportable("full path text report goes here")) {
// process reportable report
}
```
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/imsweb/ReportabilityScreener.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public ReportabilityScreener(Trie positiveTrie, Trie negativeTrie, Trie otherTri
_otherTrie = otherTrie;
}

/**
* Screen text and return information about reportability and keywords found
* @param text text to screen
* @return a {@link ScreeningResult} which includes reportability as well as the keywords used to determine it
*/
public ScreeningResult screen(String text) {
ScreeningResult result = new ScreeningResult();

Expand All @@ -40,6 +45,15 @@ public ScreeningResult screen(String text) {
return result;
}

/**
* Returns true if the text screens as reportable
* @param text text to screen
* @return true if reportable
*/
public boolean isReportable(String text) {
return screen(text).getResult().equals(REPORTABLE);
}

/**
* If the start/end indexes of a positive keyword are withing the start/end indexes of a negative keyword,
* set ignored=true on the positive keyword.
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/imsweb/ReportabilityScreenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void testReportabilityScreener() throws URISyntaxException, IOException {
assertThat(result.getOtherKeywords()).hasSize(20).extracting("keyword").contains("blood");
verifyKeywords(result.getOtherKeywords(), content);

// check the simple reportable call
assertThat(screener.isReportable(content)).isTrue();

assertThat(screener.screen("cancer").getResult()).isEqualTo(REPORTABLE);
assertThat(screener.screen("not cancer").getResult()).isEqualTo(NON_REPORTABLE);
assertThat(screener.screen("not cancer cancer").getResult()).isEqualTo(REPORTABLE);
Expand All @@ -76,6 +79,7 @@ void testReportabilityScreener() throws URISyntaxException, IOException {
.build();
assertThat(screener.screen("cancer").getResult()).isEqualTo(REPORTABLE);
assertThat(screener.screen("not cancer").getResult()).isEqualTo(NON_REPORTABLE);
assertThat(screener.isReportable("not cancer")).isFalse();

// test case with no negative/other keywords defined
screener = new ReportabilityScreenerBuilder()
Expand Down