Skip to content

Commit 7513b2e

Browse files
updated screener evaluation
1 parent 0b0369f commit 7513b2e

File tree

11 files changed

+251
-180
lines changed

11 files changed

+251
-180
lines changed

builder-api/src/main/java/org/acme/controller/DecisionResource.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.acme.enums.OptionalBoolean;
1313
import org.acme.model.domain.Benefit;
1414
import org.acme.model.domain.CheckConfig;
15-
import org.acme.model.domain.EligibilityCheck;
1615
import org.acme.model.domain.Screener;
1716
import org.acme.persistence.EligibilityCheckRepository;
1817
import org.acme.persistence.PublishedScreenerRepository;
@@ -103,6 +102,7 @@ public Response evaluateScreener(
103102

104103
try {
105104
Map<String, Object> screenerResults = new HashMap<String, Object>();
105+
//TODO: consider ways of processing benefits in parallel
106106
for (Benefit benefit : benefits) {
107107
// Evaluate benefit
108108
Map<String, Object> benefitResults = evaluateBenefit(benefit, inputData);
@@ -116,7 +116,6 @@ public Response evaluateScreener(
116116
}
117117

118118
private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object> inputData) throws Exception {
119-
List<EligibilityCheck> checks = eligibilityCheckRepository.getChecksInBenefit(benefit);
120119

121120
if (benefit.getPublic()){
122121
// Public benefit, call the Library API to evaluate
@@ -127,25 +126,13 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
127126
List<OptionalBoolean> checkResultsList = new ArrayList<>();
128127
Map<String, Object> checkResults = new HashMap<>();
129128

130-
// TODO: update implementation here
131-
for (EligibilityCheck check : checks) {
132-
Optional<CheckConfig> matchingCheckConfig = benefit.getChecks().stream().filter(
133-
checkConfig -> checkConfig.getCheckId().equals(check.getId())
134-
).findFirst();
135-
if (matchingCheckConfig.isEmpty()) {
136-
throw new Exception("Could not find CheckConfig for check " + check.getId());
137-
}
138-
139-
String dmnFilepath = storageService.getCheckDmnModelPath(
140-
check.getOwnerId(), check.getId()
141-
);
142-
String dmnModelName = check.getId();
143-
129+
for (CheckConfig checkConfig : benefit.getChecks()) {
130+
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
144131
OptionalBoolean result = dmnService.evaluateSimpleDmn(
145-
dmnFilepath, dmnModelName, inputData, matchingCheckConfig.get().getParameters()
132+
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
146133
);
147134
checkResultsList.add(result);
148-
checkResults.put(check.getId(), Map.of("name", check.getName(), "result", result));
135+
checkResults.put(checkConfig.getCheckId(), Map.of("name", checkConfig.getCheckName(), "result", result));
149136
}
150137

151138
// Determine overall Benefit result

builder-api/src/main/java/org/acme/controller/EligibilityCheckResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Response updateCheckDmn(@Context SecurityIdentity identity, SaveDmnReques
133133
.build();
134134
}
135135
try {
136-
String filePath = storageService.getCheckDmnModelPath(userId, checkId);
136+
String filePath = storageService.getCheckDmnModelPath(checkId);
137137
storageService.writeStringToStorage(filePath, dmnModel, "application/xml");
138138
Log.info("Saved DMN model of check " + checkId + " to storage");
139139

@@ -278,10 +278,10 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
278278
String publishedCheckId = eligibilityCheckRepository.saveNewPublishedCustomCheck(check);
279279

280280
// save published check DMN to storage
281-
Optional<String> workingDmnOpt = storageService.getStringFromStorage(storageService.getCheckDmnModelPath(userId, check.getId()));
281+
Optional<String> workingDmnOpt = storageService.getStringFromStorage(storageService.getCheckDmnModelPath(check.getId()));
282282
if (workingDmnOpt.isPresent()){
283283
String workingDmn = workingDmnOpt.get();
284-
storageService.writeStringToStorage(storageService.getCheckDmnModelPath(userId, publishedCheckId), workingDmn, "application/xml");
284+
storageService.writeStringToStorage(storageService.getCheckDmnModelPath(publishedCheckId), workingDmn, "application/xml");
285285
}
286286
} catch (Exception e){
287287
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)

builder-api/src/main/java/org/acme/model/domain/CheckConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@JsonIgnoreProperties(ignoreUnknown = true)
88
public class CheckConfig {
99
private String checkId;
10+
private String checkName;
1011
private Map<String, Object> parameters;
1112

1213
public String getCheckId() {
@@ -24,4 +25,12 @@ public Map<String, Object> getParameters() {
2425
public void setParameters(Map<String, Object> parameters) {
2526
this.parameters = parameters;
2627
}
28+
29+
public String getCheckName() {
30+
return checkName;
31+
}
32+
33+
public void setCheckName(String checkName) {
34+
this.checkName = checkName;
35+
}
2736
}

builder-api/src/main/java/org/acme/persistence/GoogleStorageService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public String getScreenerPublishedFormSchemaPath(String screenerId){
141141
}
142142

143143
@Override
144-
public String getCheckDmnModelPath(String userId, String checkId){
145-
return "check/" + userId + "/" + checkId + ".dmn";
144+
public String getCheckDmnModelPath(String checkId){
145+
return "check/" + checkId + ".dmn";
146146
}
147147

148148
@Override

builder-api/src/main/java/org/acme/persistence/StorageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface StorageService {
2323

2424
String getScreenerPublishedFormSchemaPath(String screenerId);
2525

26-
String getCheckDmnModelPath(String userId, String checkId);
26+
String getCheckDmnModelPath(String checkId);
2727

2828
Map<String, Object> getFormSchemaFromStorage(String filePath);
2929

builder-api/src/main/java/org/acme/persistence/impl/EligibilityCheckRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private Optional<EligibilityCheck> getCustomCheck(String userId, String checkId,
101101
ObjectMapper mapper = new ObjectMapper();
102102
EligibilityCheck check = mapper.convertValue(data, EligibilityCheck.class);
103103

104-
String dmnPath = storageService.getCheckDmnModelPath(userId, checkId);
104+
String dmnPath = storageService.getCheckDmnModelPath(checkId);
105105
Optional<String> dmnModel = storageService.getStringFromStorage(dmnPath);
106106
dmnModel.ifPresent(check::setDmnModel);
107107

builder-api/src/main/java/org/acme/service/KieDmnService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public OptionalBoolean evaluateSimpleDmn(
118118
DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context);
119119

120120
// Collect and interpret results
121-
List<DMNDecisionResult> decisionResults = dmnResult.getDecisionResults();
121+
List<DMNDecisionResult> decisionResults = dmnResult.getDecisionResults().stream()
122+
.filter(result -> result.getDecisionName().equals(dmnModelName)).toList();
123+
122124
if (decisionResults.isEmpty()) {
123125
throw new RuntimeException("No decision results from DMN evaluation");
124126
}

builder-frontend/src/components/project/manageBenefits/configureBenefit/EligibilityCheckListView.tsx

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Accessor, For, Resource, Setter } from "solid-js";
22

33
import type { Benefit, CheckConfig, EligibilityCheck } from "@/types";
44

5-
65
export type EligibilityCheckListMode = "user-defined" | "public";
76
interface CheckModeConfig {
87
mode: EligibilityCheckListMode;
@@ -19,7 +18,8 @@ const PublicCheckConfig: CheckModeConfig = {
1918
const UserDefinedCheckConfig: CheckModeConfig = {
2019
mode: "user-defined",
2120
title: "User defined eligibility checks",
22-
description: "Browse and select your own custom checks to add to your benefit.",
21+
description:
22+
"Browse and select your own custom checks to add to your benefit.",
2323
buttonTitle: "Your checks",
2424
};
2525

@@ -32,31 +32,42 @@ const UserDefinedCheckConfig: CheckModeConfig = {
3232
- publicChecks: resource containing the list of public eligibility checks
3333
- userDefinedChecks: resource containing the list of user-defined eligibility checks
3434
*/
35-
const EligibilityCheckListView = (
36-
{ benefit, addCheck, removeCheck, mode, setMode, publicChecks, userDefinedChecks }:
37-
{
38-
benefit: Accessor<Benefit>;
39-
addCheck: (newCheck: CheckConfig) => void;
40-
removeCheck: (indexToRemove: number) => void;
41-
mode: Accessor<EligibilityCheckListMode>,
42-
setMode: Setter<EligibilityCheckListMode>,
43-
publicChecks: Resource<EligibilityCheck[]>,
44-
userDefinedChecks: Resource<EligibilityCheck[]>,
45-
}
46-
) => {
47-
const activeCheckConfig: Accessor<CheckModeConfig> = (
48-
() => mode() === "public" ? PublicCheckConfig : UserDefinedCheckConfig
49-
);
50-
const activeChecks: Accessor<Resource<EligibilityCheck[]>> = (
51-
() => mode() === "public" ? publicChecks : userDefinedChecks
52-
);
35+
const EligibilityCheckListView = ({
36+
benefit,
37+
addCheck,
38+
removeCheck,
39+
mode,
40+
setMode,
41+
publicChecks,
42+
userDefinedChecks,
43+
}: {
44+
benefit: Accessor<Benefit>;
45+
addCheck: (newCheck: CheckConfig) => void;
46+
removeCheck: (indexToRemove: number) => void;
47+
mode: Accessor<EligibilityCheckListMode>;
48+
setMode: Setter<EligibilityCheckListMode>;
49+
publicChecks: Resource<EligibilityCheck[]>;
50+
userDefinedChecks: Resource<EligibilityCheck[]>;
51+
}) => {
52+
const activeCheckConfig: Accessor<CheckModeConfig> = () =>
53+
mode() === "public" ? PublicCheckConfig : UserDefinedCheckConfig;
54+
const activeChecks: Accessor<Resource<EligibilityCheck[]>> = () =>
55+
mode() === "public" ? publicChecks : userDefinedChecks;
5356
const onEligibilityCheckToggle = (check: EligibilityCheck) => {
54-
const isCheckSelected = benefit().checks.some((selected) => selected.checkId === check.id);
57+
const isCheckSelected = benefit().checks.some(
58+
(selected) => selected.checkId === check.id
59+
);
5560
if (isCheckSelected) {
56-
const checkIndexToRemove = benefit().checks.findIndex((selected) => selected.checkId === check.id);
61+
const checkIndexToRemove = benefit().checks.findIndex(
62+
(selected) => selected.checkId === check.id
63+
);
5764
removeCheck(checkIndexToRemove);
5865
} else {
59-
const checkConfig: CheckConfig = { checkId: check.id, parameters: {} };
66+
const checkConfig: CheckConfig = {
67+
checkId: check.id,
68+
checkName: check.name,
69+
parameters: {},
70+
};
6071
addCheck(checkConfig);
6172
}
6273
};
@@ -65,14 +76,18 @@ const EligibilityCheckListView = (
6576
<>
6677
<div class="p-4">
6778
<div class="flex items-center mb-2">
68-
<div class="text-2xl font-bold">
69-
{activeCheckConfig().title}
70-
</div>
79+
<div class="text-2xl font-bold">{activeCheckConfig().title}</div>
7180
<div class="ml-auto flex gap-2">
72-
<For each={[PublicCheckConfig, UserDefinedCheckConfig] as CheckModeConfig[]}>
81+
<For
82+
each={
83+
[PublicCheckConfig, UserDefinedCheckConfig] as CheckModeConfig[]
84+
}
85+
>
7386
{(modeOption) => (
7487
<div
75-
class={`btn-default ${mode() === modeOption.mode ? "btn-blue" : "btn-gray"}`}
88+
class={`btn-default ${
89+
mode() === modeOption.mode ? "btn-blue" : "btn-gray"
90+
}`}
7691
onClick={() => setMode(modeOption.mode)}
7792
title={modeOption.buttonTitle}
7893
>
@@ -82,9 +97,7 @@ const EligibilityCheckListView = (
8297
</For>
8398
</div>
8499
</div>
85-
<div>
86-
{ activeCheckConfig().description }
87-
</div>
100+
<div>{activeCheckConfig().description}</div>
88101
</div>
89102
<table class="table-auto w-full mt-4 border-collapse">
90103
<thead>
@@ -102,7 +115,7 @@ const EligibilityCheckListView = (
102115
</td>
103116
</tr>
104117
)}
105-
{(activeChecks()() && activeChecks()().length === 0) && (
118+
{activeChecks()() && activeChecks()().length === 0 && (
106119
<tr>
107120
<td colSpan={3} class="p-4 font-bold text-center text-gray-600">
108121
No checks available.
@@ -124,15 +137,17 @@ const EligibilityCheckListView = (
124137
);
125138
};
126139

127-
const EligibilityCheckRow = (
128-
{ check, selectedCheckConfigs, onToggle }:
129-
{
130-
check: EligibilityCheck;
131-
selectedCheckConfigs: CheckConfig[];
132-
onToggle: (check: EligibilityCheck) => void;
133-
}
134-
) => {
135-
const isCheckSelected = () => selectedCheckConfigs.some((selected) => selected.checkId === check.id);
140+
const EligibilityCheckRow = ({
141+
check,
142+
selectedCheckConfigs,
143+
onToggle,
144+
}: {
145+
check: EligibilityCheck;
146+
selectedCheckConfigs: CheckConfig[];
147+
onToggle: (check: EligibilityCheck) => void;
148+
}) => {
149+
const isCheckSelected = () =>
150+
selectedCheckConfigs.some((selected) => selected.checkId === check.id);
136151

137152
return (
138153
<tr>
@@ -144,11 +159,9 @@ const EligibilityCheckRow = (
144159
onChange={() => onToggle(check)}
145160
/>
146161
</td>
162+
<td class="eligibility-check-table-cell border-top">{check.name}</td>
147163
<td class="eligibility-check-table-cell border-top">
148-
{ check.name }
149-
</td>
150-
<td class="eligibility-check-table-cell border-top">
151-
{ check.description }
164+
{check.description}
152165
</td>
153166
</tr>
154167
);

0 commit comments

Comments
 (0)