|
11 | 11 | import org.acme.auth.AuthUtils; |
12 | 12 | import org.acme.enums.OptionalBoolean; |
13 | 13 | import org.acme.model.domain.Benefit; |
| 14 | +import org.acme.model.domain.CheckConfig; |
14 | 15 | import org.acme.model.domain.EligibilityCheck; |
15 | 16 | import org.acme.model.domain.Screener; |
16 | 17 | import org.acme.persistence.EligibilityCheckRepository; |
@@ -126,50 +127,48 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object> |
126 | 127 | List<OptionalBoolean> checkResultsList = new ArrayList<>(); |
127 | 128 | Map<String, Object> checkResults = new HashMap<>(); |
128 | 129 |
|
129 | | - Map<String, Object> result = new HashMap<>(); |
130 | | - return result; |
131 | | - //TODO: update implementation here |
132 | | -// for (EligibilityCheck check : checks) { |
133 | | -// Optional<CheckConfig> matchingCheckConfig = benefit.getChecks().stream().filter( |
134 | | -// checkConfig -> checkConfig.getCheckId().equals(check.getId()) |
135 | | -// ).findFirst(); |
136 | | -// if (matchingCheckConfig.isEmpty()) { |
137 | | -// throw new Exception("Could not find CheckConfig for check " + check.getId()); |
138 | | -// } |
139 | | -// |
140 | | -// String dmnFilepath = storageService.getCheckDmnModelPath( |
141 | | -// check.getModule(), check.getId(), check.getVersion() |
142 | | -// ); |
143 | | -// String dmnModelName = check.getId(); |
144 | | -// |
145 | | -// OptionalBoolean result = dmnService.evaluateSimpleDmn( |
146 | | -// dmnFilepath, dmnModelName, inputData, matchingCheckConfig.get().getParameters() |
147 | | -// ); |
148 | | -// checkResultsList.add(result); |
149 | | -// checkResults.put(check.getId(), Map.of("name", check.getName(), "result", result)); |
150 | | -// } |
151 | | -// |
152 | | -// // Determine overall Benefit result |
153 | | -// Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == OptionalBoolean.TRUE); |
154 | | -// Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == OptionalBoolean.FALSE); |
155 | | -// Log.info("All True: " + allChecksTrue + " Any False: " + anyChecksFalse); |
156 | | -// |
157 | | -// OptionalBoolean benefitResult; |
158 | | -// if (allChecksTrue) { |
159 | | -// benefitResult = OptionalBoolean.TRUE; |
160 | | -// } else if (anyChecksFalse) { |
161 | | -// benefitResult = OptionalBoolean.FALSE; |
162 | | -// } else { |
163 | | -// benefitResult = OptionalBoolean.UNABLE_TO_DETERMINE; |
164 | | -// } |
165 | | -// |
166 | | -// return new HashMap<String, Object>( |
167 | | -// Map.of( |
168 | | -// "name", benefit.getName(), |
169 | | -// "result", benefitResult, |
170 | | -// "check_results", checkResults |
171 | | -// ) |
172 | | -// ); |
| 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 | + |
| 144 | + OptionalBoolean result = dmnService.evaluateSimpleDmn( |
| 145 | + dmnFilepath, dmnModelName, inputData, matchingCheckConfig.get().getParameters() |
| 146 | + ); |
| 147 | + checkResultsList.add(result); |
| 148 | + checkResults.put(check.getId(), Map.of("name", check.getName(), "result", result)); |
| 149 | + } |
| 150 | + |
| 151 | + // Determine overall Benefit result |
| 152 | + Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == OptionalBoolean.TRUE); |
| 153 | + Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == OptionalBoolean.FALSE); |
| 154 | + Log.info("All True: " + allChecksTrue + " Any False: " + anyChecksFalse); |
| 155 | + |
| 156 | + OptionalBoolean benefitResult; |
| 157 | + if (allChecksTrue) { |
| 158 | + benefitResult = OptionalBoolean.TRUE; |
| 159 | + } else if (anyChecksFalse) { |
| 160 | + benefitResult = OptionalBoolean.FALSE; |
| 161 | + } else { |
| 162 | + benefitResult = OptionalBoolean.UNABLE_TO_DETERMINE; |
| 163 | + } |
| 164 | + |
| 165 | + return new HashMap<String, Object>( |
| 166 | + Map.of( |
| 167 | + "name", benefit.getName(), |
| 168 | + "result", benefitResult, |
| 169 | + "check_results", checkResults |
| 170 | + ) |
| 171 | + ); |
173 | 172 | } |
174 | 173 | } |
175 | 174 |
|
|
0 commit comments