Skip to content

#14084 - Ensure default values for customizable fields #14129

Merged
raulbob merged 4 commits into
developmentfrom
bugfix-customizable_field_default_value_handling
Jul 3, 2026
Merged

#14084 - Ensure default values for customizable fields #14129
raulbob merged 4 commits into
developmentfrom
bugfix-customizable_field_default_value_handling

Conversation

@raulbob

@raulbob raulbob commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

#14086 - Added better handling for default value edit and validations

Summary by CodeRabbit

  • New Features
    • Automatically apply default values for customizable fields when creating/editing cases, contacts, and exposure-related data, respecting visibility rules.
    • UI now supports type-specific default value input for checkbox, yes/no/unknown, date, and date-time fields.
  • Bug Fixes
    • Missing default customizable field values are now persisted and immediately retrievable after save.
    • Exporting customizable field values now includes defaults when appropriate, while explicit clears remain null.
  • Tests
    • Added/extended tests for default-value persistence on case/contact create flows and for customizable field value group behavior.

…ntact entities

#14086 - Added better handling for default value edit and validations
@raulbob raulbob linked an issue Jul 2, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61828c17-07e8-4232-8308-c0f9f63b908e

📥 Commits

Reviewing files that changed from the base of the PR and between 7ec2f6a and aed177c.

📒 Files selected for processing (1)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java

📝 Walkthrough

Walkthrough

Default customizable-field values are now created during backend saves for cases, contacts, epi data, and exposures, with disease-aware visibility filtering. The UI field-group component also now initializes and exports values using metadata defaults, and tests cover the new behaviors.

Changes

Default Customizable Field Values

Layer / File(s) Summary
Default-value service and visibility
sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java, sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldMetadataFacadeEjb.java
Adds default-value creation for missing customizable field entries and exposes visibility-restriction parsing for reuse.
EpiData default propagation
sormas-backend/src/main/java/de/symeda/sormas/backend/epidata/EpiDataFacadeEjb.java
Uses disease-scoped visibility context to initialize default values for epi data and newly added exposures.
Case and contact save wiring
sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java, sormas-backend/src/main/java/de/symeda/sormas/backend/contact/ContactFacadeEjb.java, sormas-backend/src/test/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldFacadeEjbTest.java
Triggers default-value initialization from case and contact save flows, and extends backend tests for case/contact default persistence.
UI field defaults
sormas-ui/src/main/java/de/symeda/sormas/ui/utils/components/CustomizableFieldsGroup.java
Initializes field rows from metadata defaults and includes cleared or defaulted values when exporting field data.
UI field-group tests
sormas-ui/src/test/java/de/symeda/sormas/ui/utils/components/CustomizableFieldsGroupTest.java
Verifies default initialization, explicit clears, and empty fields without defaults.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: roldy, KarnaiahPesula

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description does not follow the required template and is missing the mandated 'Fixes #' issue reference. Rewrite the description to follow the template, starting with 'Fixes #14086' and adding the required issue details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: ensuring default values for customizable fields.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix-customizable_field_default_value_handling

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java`:
- Around line 109-130: `ensureDefaultValuesForEntity` is creating defaults for
fields that may be hidden by disease-specific visibility rules. Update this
method to apply the same `CustomizableFieldVisibilityContext`/visibility check
used by the UI before calling `createNewValue` and `ensurePersisted`, so only
visible `CustomizableFieldMetadata` entries from `getActiveFieldsForContext` are
persisted. Use the existing metadata visibility restrictions in
`CustomizableFieldValueService` and `CustomizableFieldMetadataService` to skip
fields that are not visible for the entity’s disease.

In
`@sormas-ui/src/main/java/de/symeda/sormas/ui/configuration/customizablefield/CustomizableFieldEditForm.java`:
- Around line 184-186: The default value validation in CustomizableFieldEditForm
is using dto.getFieldType(), which can be stale before binder.writeBean(dto)
runs. Update the validator for the default value field to validate against the
currently selected field type from the bound form value/component state instead
of the DTO, and use the same selected type when building
getDefaultValueErrorMessage so NUMBER/DECIMAL defaults are checked correctly
before save.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 580384d7-5c94-4d80-9400-912caac0b135

📥 Commits

Reviewing files that changed from the base of the PR and between 69d2532 and 96155aa.

📒 Files selected for processing (8)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/contact/ContactFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epidata/EpiDataFacadeEjb.java
  • sormas-backend/src/test/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldFacadeEjbTest.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/configuration/customizablefield/CustomizableFieldEditForm.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/utils/components/CustomizableFieldsGroup.java
  • sormas-ui/src/test/java/de/symeda/sormas/ui/utils/components/CustomizableFieldsGroupTest.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java`:
- Around line 149-156: The visibility filtering in CustomizableFieldValueService
is inverted, so the default-value creation loop skips visible fields and
persists hidden ones. Update the check around parseVisibilityRestrictions and
matches(visibilityContext) so the flow continues only when the restrictions do
not match the current context, and add a null guard for the parsed
CustomizableFieldVisibilityRestrictions since blank visibility strings can
return null. Keep the fix localized to the metadata visibility handling in the
default-value generation path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1302ed65-810d-44d3-93a1-bb5515858385

📥 Commits

Reviewing files that changed from the base of the PR and between 5c6ab40 and 7ec2f6a.

📒 Files selected for processing (5)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/contact/ContactFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldMetadataFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/customizablefield/CustomizableFieldValueService.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epidata/EpiDataFacadeEjb.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/contact/ContactFacadeEjb.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java

@raulbob raulbob merged commit 52b07df into development Jul 3, 2026
7 checks passed
@raulbob raulbob deleted the bugfix-customizable_field_default_value_handling branch July 3, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customizable field default value not applied - Case

2 participants