Skip to content

Commit

Permalink
[DUOS-2605]add approve rationale cases (#877)
Browse files Browse the repository at this point in the history
* add approve rationale cases

* fixing coverage failure
  • Loading branch information
Kaitlyn O'Flaherty committed Jul 19, 2023
1 parent 82fb6db commit 4569054
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@

public class DataUseMatchCasesV3 {

// rationale for failures
private static final String HMB_F1 = "The GRU Research Purpose does not match the HMB data use limitations.";
private static final String HMB_F2 = "The HMB Research Purpose does not match the Disease-Specific data use limitations.";
private static final String HMB_F3 = "The HMB Research Purpose does not match the POA data use limitations.";
private static final String DS_F2 = "The Disease-Specific: %s Research Purpose is not a valid subclass of the Disease-Specific data use limitations.";
private static final String MDS_F1 = "The Methods development Research Purpose does not match the Disease-Specific data use limitations.";
private static final String POA_F1 = "The Populations, Origins, Ancestry Research Purpose does not match the HMB or Disease-Specific data use limitation.";
private static final String NCU_F1 = "The Commercial Use Research Purpose does not match the No Commercial Use data use limitation.";

// rationale for approvals - based on dataset terms
private static final String DS_APPROVE_GRU = "The proposed disease-specific research is within the bounds of the general research use permissions of the dataset(s)";
private static final String DS_APPROVE_HMB = "The proposed disease-specific research is within the bounds of the health, medical, biomedical use permissions of the dataset(s)";
private static final String HMB_APPROVE_HMB = "The proposed health, medical, biomedical research is within the bounds of the health, medical, biomedical use permissions of the dataset(s)";
private static final String HMB_APPROVE_GRU = "The proposed health, medical, biomedical research is within the bounds of the general research use permissions of the dataset(s)";
private static final String POA_APPROVE_GRU = "The proposed population, origins, and/or ancestry research is within the bounds of the general research use permissions of the dataset(s)";
private static final String POA_APPROVE_POA = "The proposed population, origins, and/or ancestry research is within the bounds of the population, origins, and/or ancestry use permissions of the dataset(s)";
private static final String MDS_APPROVE = "Methods research is permitted on controlled-access data so long as it is not expressly prohibited";

// rationale for abstain cases
private static final String ABSTAIN = "The Research Purpose does not result in DUOS Decision.";

/**
Expand Down Expand Up @@ -44,11 +56,11 @@ static MatchResult matchDiseases(
}
// Approve dataset GRU condition
if (purposeDSX && datasetGRU) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(DS_APPROVE_GRU));
}
// Approve dataset HMB condition
if (purposeDSX && datasetHMB) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(DS_APPROVE_HMB));
}

// We want all-purpose disease IDs to be a subclass of any dataset disease ID
Expand Down Expand Up @@ -104,12 +116,12 @@ static MatchResult matchHMB(DataUseV3 purpose, DataUseV3 dataset) {

// Approve dataset GRU condition
if (datasetGRU) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(HMB_APPROVE_GRU));
}

// Approve dataset HMB condition
if (purposeHMB && datasetHMB) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(HMB_APPROVE_HMB));
} else {

return MatchResult.from(failures.isEmpty() ? MatchResultType.APPROVE : MatchResultType.DENY,
Expand All @@ -134,12 +146,12 @@ static MatchResult matchPOA(DataUseV3 purpose, DataUseV3 dataset) {

// Approve dataset GRU condition
if (datasetGRU) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(POA_APPROVE_GRU));
}

// Approve dataset POA condition
if (purposePOA && datasetPOA) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(POA_APPROVE_POA));
}

List<String> failures = new ArrayList<>();
Expand Down Expand Up @@ -175,22 +187,22 @@ static MatchResult matchMDS(DataUseV3 purpose, DataUseV3 dataset, MatchResultTyp

// Approve dataset GRU condition
if (datasetGRU) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(MDS_APPROVE));
}

// Approve dataset HMB condition
if (purposeMDS && datasetHMB) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(MDS_APPROVE));
}

// Approve dataset POA condition
if (purposeMDS && datasetPOA) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(MDS_APPROVE));
}

// short-circuit if there is a disease match
if (diseaseMatch == MatchResultType.APPROVE) {
return MatchResult.from(MatchResultType.APPROVE, Collections.emptyList());
return MatchResult.from(MatchResultType.APPROVE, Collections.singletonList(MDS_APPROVE));
} else {
return MatchResult.from(MatchResultType.DENY, Collections.singletonList(MDS_F1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public class MatchV3ResponseEntity {

private final MatchResultType result;
private final DataUseMatchPairV3 matchPair;
private final List<String> failureReasons;
private final List<String> rationale;

public MatchV3ResponseEntity(MatchResultType result, DataUseMatchPairV3 matchPair,
List<String> failureReasons) {
List<String> rationale) {
this.result = result;
this.matchPair = matchPair;
this.failureReasons = failureReasons;
this.rationale = rationale;
}

public ImmutableMap<String, Object> get() {
return ImmutableMap.of(
"result", this.result,
"matchPair", this.matchPair,
"failureReasons", this.failureReasons);
"rationale", this.rationale);
}

public MatchResultType getResult() {
Expand All @@ -31,8 +31,7 @@ public MatchResultType getResult() {
public DataUseMatchPairV3 getMatchPair() {
return this.matchPair;
}

public List<String> getFailureReasons() {
return this.failureReasons;
public List<String> getRationale() {
return this.rationale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public Response matchDataUse(final DataUseMatchPair matchPair) {
ImmutablePair<Boolean, List<String>> matchResult = dataUseMatcher.matchPurposeAndDatasetV2(
purpose, dataset);
boolean match = matchResult.getLeft();
List<String> failures = matchResult.getRight();
List<String> rationale = matchResult.getRight();
return Response
.ok()
.entity(ImmutableMap.of(
"result", match,
"matchPair", matchPair,
"failureReasons", failures))
"rationale", rationale))
.type(MediaType.APPLICATION_JSON)
.build();
}
Expand Down Expand Up @@ -97,11 +97,11 @@ public Response matchDataUseV3(final DataUseMatchPairV3 matchPair) {
if (purpose != null && dataset != null) {
MatchResult matchResult = dataUseMatcherV3.matchPurposeAndDatasetV3(purpose, dataset);
MatchResultType match = matchResult.getMatchResultType();
List<String> failures = matchResult.getMessage();
List<String> rationale = matchResult.getMessage();
// nosemgrep
return Response
.ok()
.entity(new MatchV3ResponseEntity(match, matchPair, failures).get())
.entity(new MatchV3ResponseEntity(match, matchPair, rationale).get())
.type(MediaType.APPLICATION_JSON)
.build();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ definitions:
matchPair:
$ref: '#/definitions/DataUseMatchPair'
description: The provided purpose and consent
failureReasons:
rationale:
type: array
items:
type: string
Expand All @@ -387,12 +387,12 @@ definitions:
matchPair:
$ref: '#/definitions/DataUseMatchPairV3'
description: The provided purpose and consent
failureReasons:
rationale:
type: array
items:
type: string
description: |
Optional list of reasons why a match result may have failed. Only supported in
List of reasons why a match result occurred. Only supported in
in versions 2 and higher
TranslateParagraph:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ public void testAbstainDecision_ethicsApprovalRequired() {
private void assertApprove(DataUseV3 purpose, DataUseV3 dataset) {
MatchResult match = matchPurposeAndDataset(purpose, dataset);
assertTrue(Approve(match.getMatchResultType()));
assertTrue(match.getMessage().isEmpty());
}

private void assertDeny(DataUseV3 purpose, DataUseV3 dataset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void testOKV3ResponseApprove() {
MatchV3ResponseEntity entity = new Gson().fromJson(stringEntity, MatchV3ResponseEntity.class);
assertEquals(MatchResultType.APPROVE, entity.getResult());
assertEquals(pair, entity.getMatchPair());
assertEquals(Collections.emptyList(), entity.getFailureReasons());
assertEquals(Collections.emptyList(), entity.getRationale());
}
}

Expand All @@ -152,7 +152,7 @@ public void testOKV3ResponseDeny() {
MatchV3ResponseEntity entity = new Gson().fromJson(stringEntity, MatchV3ResponseEntity.class);
assertEquals(deny, entity.getResult());
assertEquals(pair, entity.getMatchPair());
assertEquals(Collections.emptyList(), entity.getFailureReasons());
assertEquals(Collections.emptyList(), entity.getRationale());
}
}

Expand All @@ -173,7 +173,7 @@ public void testOKV3ResponseAbstain() {
MatchV3ResponseEntity entity = new Gson().fromJson(stringEntity, MatchV3ResponseEntity.class);
assertEquals(abstain, entity.getResult());
assertEquals(pair, entity.getMatchPair());
assertEquals(Collections.emptyList(), entity.getFailureReasons());
assertEquals(Collections.emptyList(), entity.getRationale());
}
}

Expand Down

0 comments on commit 4569054

Please sign in to comment.