Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8c1f685
Add plain-language explanations to configured checks
prestoncabe Oct 29, 2026
5b80826
Keep preview explanations beside their check labels
prestoncabe Oct 29, 2026
6bcc535
Build check explanations on the shared tooltip
prestoncabe Nov 1, 2026
156410e
Keep tooltips from being clipped by scrolling sections
prestoncabe Nov 1, 2026
210d568
Let tooltips be dismissed however they were opened
prestoncabe Nov 1, 2026
18d344c
Keep long tooltips readable within the viewport
prestoncabe Nov 1, 2026
b618589
Save explanations without reloading the benefit
prestoncabe Nov 1, 2026
27c731a
Return focus to Edit explanation when its modal closes
prestoncabe Nov 1, 2026
fcd9408
Keep line breaks in explanations outside the tooltip
prestoncabe Nov 1, 2026
b43f33b
Require JSON on the explanation endpoint
prestoncabe Nov 1, 2026
dc2ee0e
Document explanations in the CRM contract
prestoncabe Nov 1, 2026
5b794d5
Share the check display name across results
prestoncabe Nov 1, 2026
62c1738
Save an explanation to every config sharing a check ID
prestoncabe Nov 2, 2026
454bfe8
Update a benefit's checks in a transaction
prestoncabe Nov 2, 2026
4c9a91a
Keep saved explanations and open drafts across a refetch
prestoncabe Nov 2, 2026
9e4b283
Move focus into the explanation modal when it opens
prestoncabe Nov 2, 2026
eb4a861
Keep unsaved explanation edits from a backdrop click
prestoncabe Nov 2, 2026
594a58c
Say why an explanation failed to save
prestoncabe Nov 2, 2026
58683f4
Keep results rows in place across evaluations
prestoncabe Nov 2, 2026
2e87990
Close a tooltip when its trigger scrolls out of view
prestoncabe Nov 2, 2026
a12970b
Reposition a tooltip at most once per frame
prestoncabe Nov 2, 2026
78a26a8
Name a check the same way on every surface
prestoncabe Nov 2, 2026
b51ae17
Keep an author's wording in a check's display name
prestoncabe Nov 2, 2026
9941553
Keep an open tooltip on its trigger as results update
prestoncabe Nov 2, 2026
b65d425
Keep preview rows in place across evaluations
prestoncabe Nov 2, 2026
8b65a54
Return focus to the draft after a failed explanation save
prestoncabe Nov 2, 2026
21e5ac2
Close a tooltip when the window scrolls its trigger away
prestoncabe Nov 2, 2026
8b62d16
Build the saved explanations only when a refetch needs them
prestoncabe Nov 2, 2026
9eac136
Report a deleted benefit as missing, not its check
prestoncabe Nov 2, 2026
0068679
Tolerate a check without an ID on every check endpoint
prestoncabe Nov 2, 2026
0e168ac
Keep generated aliases consistent across concurrent parameter edits
prestoncabe Nov 2, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -13,6 +14,7 @@
import org.codeforphilly.bdt.builder.model.dto.custombenefit.AddCheckRequest;
import org.codeforphilly.bdt.builder.model.dto.custombenefit.CreateCustomBenefitRequest;
import org.codeforphilly.bdt.builder.model.dto.custombenefit.UpdateCheckAliasRequest;
import org.codeforphilly.bdt.builder.model.dto.custombenefit.UpdateCheckExplanationRequest;
import org.codeforphilly.bdt.builder.model.dto.custombenefit.UpdateCheckParametersRequest;
import org.codeforphilly.bdt.builder.model.dto.custombenefit.UpdateCustomBenefitRequest;
import org.codeforphilly.bdt.builder.persistence.EligibilityCheckRepository;
Expand All @@ -31,6 +33,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;

@Path("/api")
public class CustomBenefitResource {
Expand Down Expand Up @@ -318,7 +321,6 @@ public Response addCheckToBenefit(
}

EligibilityCheck check = checkOpt.get();
Benefit benefit = benefitOpt.get();
Map<String, Object> parameters = request.parameters() != null
? new HashMap<>(request.parameters())
: new HashMap<>();
Expand Down Expand Up @@ -358,17 +360,16 @@ public Response addCheckToBenefit(
checkConfig.setAliasGenerated(aliasName.isPresent());

// Add the check to the benefit
List<CheckConfig> checks = benefit.getChecks();
if (checks == null) {
checks = new ArrayList<>();
} else {
checks = new ArrayList<>(checks);
boolean added = screenerRepository.updateCustomBenefitChecks(screenerId, benefitId, checks -> {
List<CheckConfig> updatedChecks = new ArrayList<>(checks);
updatedChecks.add(checkConfig);
return updatedChecks;
});
if (!added) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Benefit not found"))
.build();
}
checks.add(checkConfig);
benefit.setChecks(checks);

// Save the updated benefit
screenerRepository.updateCustomBenefit(screenerId, benefit);

return Response.ok(Map.of("aliasGenerated", aliasName.isPresent())).build();
} catch (Exception e) {
Expand All @@ -394,39 +395,16 @@ public Response removeCheckFromBenefit(
}

try {
// Get the benefit
Optional<Benefit> benefitOpt = screenerRepository.getCustomBenefit(screenerId, benefitId);
if (benefitOpt.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Benefit not found"))
.build();
}

Benefit benefit = benefitOpt.get();
List<CheckConfig> checks = benefit.getChecks();

if (checks == null || checks.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
}

// Remove the check with the matching checkId
List<CheckConfig> updatedChecks = checks.stream()
.filter(check -> !check.getCheckId().equals(checkId))
.toList();
boolean removed = screenerRepository.updateCustomBenefitChecks(screenerId, benefitId, checks -> {
List<CheckConfig> updatedChecks = new ArrayList<>(checks);
return updatedChecks.removeIf(check -> checkId.equals(check.getCheckId())) ? updatedChecks : null;
});

if (updatedChecks.size() == checks.size()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
if (!removed) {
return checkOrBenefitNotFound(screenerId, benefitId);
}

benefit.setChecks(new ArrayList<>(updatedChecks));

// Save the updated benefit
screenerRepository.updateCustomBenefit(screenerId, benefit);

return Response.ok().build();
} catch (Exception e) {
Log.error(e);
Expand Down Expand Up @@ -461,49 +439,47 @@ public Response updateCheckParameters(
.build();
}

Benefit benefit = benefitOpt.get();
List<CheckConfig> checks = benefit.getChecks();

if (checks == null || checks.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
}

// Find and update the check with the matching checkId
Boolean checkUpdated = false;
boolean aliasCleared = false;
List<CheckConfig> checkListAfterUpdate = new ArrayList<>();
for (CheckConfig check : checks) {
if (check.getCheckId().equals(checkId)) {
Map<String, Object> parameters = request.parameters() != null ? request.parameters() : new HashMap<>();
boolean parametersChanged = !sameParameterValues(check.getParameters(), parameters);
check.setParameters(parameters);
// A generated alias describes the old parameter values, so refresh it.
// Hand-written aliases are left alone.
if (parametersChanged && check.isAliasGenerated()) {
Optional<String> aliasName = eligibilityCheckAliasService.generate(check.getCheckName(), parameters);
check.setAliasName(aliasName.orElse(null));
check.setAliasGenerated(aliasName.isPresent());
aliasCleared = aliasName.isEmpty();
List<CheckConfig> checks = benefitOpt.get().getChecks();
Map<String, Object> parameters = request.parameters() != null ? request.parameters() : new HashMap<>();

// A generated alias describes the old parameter values, so refresh it.
// Hand-written aliases are left alone. Generating takes seconds, too long for the
// transaction below, which keeps any check edit made in the meantime.
Optional<CheckConfig> staleAlias = (checks == null ? List.<CheckConfig>of() : checks).stream()
.filter(check -> checkId.equals(check.getCheckId()) && check.isAliasGenerated())
.filter(check -> !sameParameterValues(check.getParameters(), parameters))
.findFirst();
Optional<String> aliasName = staleAlias.isPresent()
? eligibilityCheckAliasService.generate(staleAlias.get().getCheckName(), parameters)
: Optional.empty();

boolean[] aliasCleared = { false };
boolean checkUpdated = screenerRepository.updateCustomBenefitChecks(screenerId, benefitId, storedChecks -> {
// Firestore can rerun this callback; report only the committed attempt.
aliasCleared[0] = false;
List<CheckConfig> matching = storedChecks.stream()
.filter(check -> checkId.equals(check.getCheckId()))
.toList();
for (CheckConfig check : matching) {
if (check.isAliasGenerated() && !sameParameterValues(check.getParameters(), parameters)) {
// An intervening edit may have made an initially unchanged alias stale.
// Without a preview for these parameters, use the original name rather
// than leave an alias describing a different rule.
Optional<String> replacement = staleAlias.isPresent() ? aliasName : Optional.empty();
check.setAliasName(replacement.orElse(null));
check.setAliasGenerated(replacement.isPresent());
aliasCleared[0] |= replacement.isEmpty();
}
checkUpdated = true;
check.setParameters(parameters);
}
checkListAfterUpdate.add(check);
}
return matching.isEmpty() ? null : storedChecks;
});

if (!checkUpdated) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
return checkOrBenefitNotFound(screenerId, benefitId);
}

benefit.setChecks(checkListAfterUpdate);

// Save the updated benefit
screenerRepository.updateCustomBenefit(screenerId, benefit);

return Response.ok(Map.of("aliasCleared", aliasCleared)).build();
return Response.ok(Map.of("aliasCleared", aliasCleared[0])).build();
} catch (Exception e) {
Log.error(e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
Expand All @@ -529,48 +505,18 @@ public Response updateCheckAlias(
}

try {
// Get the benefit
Optional<Benefit> benefitOpt = screenerRepository.getCustomBenefit(screenerId, benefitId);
if (benefitOpt.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Benefit not found"))
.build();
}

Benefit benefit = benefitOpt.get();
List<CheckConfig> checks = benefit.getChecks();

if (checks == null || checks.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
}

// Find and update the check with the matching checkId
Boolean checkUpdated = false;
List<CheckConfig> checkListAfterUpdate = new ArrayList<>();
for (CheckConfig check : checks) {
if (check.getCheckId().equals(checkId)) {
check.setAliasName(request.aliasName());
check.setAliasGenerated(
request.aliasName() != null && Boolean.TRUE.equals(request.aliasGenerated())
);
checkUpdated = true;
}
checkListAfterUpdate.add(check);
}
boolean checkUpdated = updateMatchingChecks(screenerId, benefitId, checkId, check -> {
check.setAliasName(request.aliasName());
check.setAliasGenerated(
request.aliasName() != null && Boolean.TRUE.equals(request.aliasGenerated())
);
});

if (!checkUpdated) {
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", "Check not found in benefit"))
.build();
return checkOrBenefitNotFound(screenerId, benefitId);
}

benefit.setChecks(checkListAfterUpdate);

// Save the updated benefit
screenerRepository.updateCustomBenefit(screenerId, benefit);

return Response.ok().build();
} catch (Exception e) {
Log.error(e);
Expand All @@ -580,6 +526,32 @@ public Response updateCheckAlias(
}
}

@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Path("/screener/{screenerId}/benefit/{benefitId}/check/{checkId}/explanation")
public Response updateCheckExplanation(
@Context SecurityIdentity identity,
@PathParam("screenerId") String screenerId,
@PathParam("benefitId") String benefitId,
@PathParam("checkId") String checkId,
@NotNull @Valid UpdateCheckExplanationRequest request
) {
if (!isUserAuthorizedForScreener(AuthUtils.getUserId(identity), screenerId)) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
try {
boolean checkUpdated = updateMatchingChecks(screenerId, benefitId, checkId,
check -> check.setExplanation(request.explanation()));
if (!checkUpdated) {
return checkOrBenefitNotFound(screenerId, benefitId);
}
return Response.ok().build();
} catch (Exception e) {
Log.error(e);
return Response.serverError().entity(Map.of("error", "Could not update check explanation")).build();
}
}

@POST
@Path("/screener/{screenerId}/benefit/{benefitId}/check/{checkId}/alias/generate")
public Response generateCheckAlias(
Expand All @@ -604,7 +576,7 @@ public Response generateCheckAlias(

List<CheckConfig> checks = benefitOpt.get().getChecks();
Optional<CheckConfig> checkOpt = (checks == null ? List.<CheckConfig>of() : checks).stream()
.filter(check -> check.getCheckId().equals(checkId))
.filter(check -> checkId.equals(check.getCheckId()))
.findFirst();
if (checkOpt.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND)
Expand All @@ -630,6 +602,28 @@ public Response generateCheckAlias(

// ========== Private Helper Methods ==========

// Updates every config with this ID, since configs can share one. False when there are none.
private boolean updateMatchingChecks(String screenerId, String benefitId, String checkId,
Consumer<CheckConfig> update) throws Exception {
return screenerRepository.updateCustomBenefitChecks(screenerId, benefitId, checks -> {
List<CheckConfig> matching = checks.stream()
.filter(check -> checkId.equals(check.getCheckId()))
.toList();
matching.forEach(update);
return matching.isEmpty() ? null : checks;
});
}

// updateCustomBenefitChecks reports both as false, and authors see this message.
private Response checkOrBenefitNotFound(String screenerId, String benefitId) throws Exception {
String error = screenerRepository.getCustomBenefit(screenerId, benefitId).isPresent()
? "Check not found in benefit"
: "Benefit not found";
return Response.status(Response.Status.NOT_FOUND)
.entity(Map.of("error", error))
.build();
}

private static boolean usesEvaluationDateDefault(EligibilityCheck check, ParameterDefinition parameter) {
return check.getEvaluationUrl() != null
&& parameter.getKey().equals("asOfDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
Map<String, Object> checkResultMap = new HashMap<>();
checkResultMap.put("name", checkConfig.getCheckName());
checkResultMap.put("aliasName", checkConfig.getAliasName());
checkResultMap.put("explanation", checkConfig.getExplanation());
checkResultMap.put("result", evaluationResult);
checkResultMap.put("module", checkConfig.getCheckModule() != null ? checkConfig.getCheckModule() : "");
checkResultMap.put("version", checkConfig.getCheckVersion() != null ? checkConfig.getCheckVersion() : "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Benefit {
private String id;
private String description;
private String name;
@Valid
private List<CheckConfig> checks;
private String ownerId;
@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.constraints.Size;

import java.util.List;
import java.util.Map;
Expand All @@ -21,6 +22,9 @@ public class CheckConfig {
private List<ParameterDefinition> parameterDefinitions;
// optional alias name for this check instance
private String aliasName;
// Plain-language guidance for the person being screened, per configured check.
@Size(max = 2000)
private String explanation;
// true when aliasName came from alias generation and hasn't been hand-edited,
// so it can be regenerated when parameters change
private boolean aliasGenerated;
Expand Down Expand Up @@ -139,6 +143,14 @@ public void setAliasName(String aliasName) {
this.aliasName = aliasName;
}

public String getExplanation() {
return explanation;
}

public void setExplanation(String explanation) {
this.explanation = explanation == null || explanation.isBlank() ? null : explanation.trim();
}

public boolean isAliasGenerated() {
return aliasGenerated;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.codeforphilly.bdt.builder.model.dto.custombenefit;

import jakarta.validation.constraints.Size;

public record UpdateCheckExplanationRequest(@Size(max = 2000) String explanation) {}
Loading
Loading