Skip to content

Conversation

@raulbob
Copy link
Contributor

@raulbob raulbob commented Jan 21, 2026

Fixes #13775

Summary by CodeRabbit

  • Refactor

    • Treatment-related fields moved from therapy records into case records, consolidating storage and APIs.
  • New Features

    • Notifier forms and side views now read and update treatment data at the case level so notifier edits apply directly to case treatment state.
  • Documentation

    • Added/updated notification and diagnostic date labels and informational messages for clearer guidance.
  • Chores

    • Database migration added to transfer treatment data from therapy to cases.

✏️ Tip: You can customize this high-level summary in your review settings.

- Corrected some hard-coded strings in the notifier UI
@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

📝 Walkthrough

Walkthrough

This PR moves treatment-related fields (treatmentStarted, treatmentNotApplicable, treatmentStartDate) from Therapy to Case across API DTOs, backend entities/facades, DB schema/migration, external-message processing, and notifier UI; it updates mappings, SQL migration, and related UI/processing signatures.

Changes

Cohort / File(s) Summary
API DTOs
sormas-api/src/main/java/de/symeda/sormas/api/caze/CaseDataDto.java, sormas-api/src/main/java/de/symeda/sormas/api/therapy/TherapyDto.java
Added treatment constants/fields/accessors to CaseDataDto; removed same members from TherapyDto.
Backend Entities
sormas-backend/src/main/java/de/symeda/sormas/backend/caze/Case.java, sormas-backend/src/main/java/de/symeda/sormas/backend/therapy/Therapy.java
Added JPA-annotated treatment fields to Case; removed treatment fields/accessors from Therapy.
Backend Facades
sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java, .../therapy/TherapyFacadeEjb.java
CaseFacadeEjb maps new treatment fields between entity and DTO; TherapyFacadeEjb no longer propagates these fields.
Database Schema / Migration
sormas-backend/src/main/resources/sql/sormas_schema.sql
Adds treatment columns to cases/cases_history, migrates data from therapy, drops columns from therapy/therapy_history, inserts schema version 603.
External Message Processing
sormas-api/src/main/java/de/symeda/sormas/api/externalmessage/.../AbstractDoctorDeclarationMessageProcessingFlow.java
Removed postBuildCaseTherapy; constructor visibility reduced; postBuildCaseData now sets treatment fields directly on CaseDataDto.
Notifier UI (form/view/controller)
sormas-ui/src/main/java/de/symeda/sormas/ui/caze/notifier/...
Replaced TherapyDto usage with CaseDataDto across form, side view, and controller; adjusted constructors/signatures and updated treatment read/write to case-level fields; added i18n and validation tweaks.
i18n / Strings
sormas-api/src/main/java/de/symeda/sormas/api/i18n/*, sormas-api/src/main/resources/*.properties
Added caption/string keys for notifier information and notification/diagnosis date descriptions; updated properties files.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant External as ExternalMessage
participant Flow as AbstractDoctorDeclarationMessageProcessingFlow
participant DTO as CaseDataDto
participant Facade as CaseFacadeEjb
participant DB as Database
External->>Flow: deliver doctor declaration
Flow->>DTO: set treatmentStarted / treatmentStartDate / treatmentNotApplicable
DTO->>Facade: pass DTO for persistence
Facade->>DB: persist treatment fields on cases table (after migration)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • obinna-h-n
  • KarnaiahPesula

Poem

🐇 I hopped through code and fields today,
I carried treatment from burrow to bay,
From Therapy tunnels to Case's bright lawn,
Now data rests snug by the early dawn. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains 'Fixes #13775' without explaining the changes, implementation details, or rationale. It fails to follow the template structure with proper context. Expand the description to explain what changes were made, why they were necessary, and how the treatment fields were migrated from Therapy to Case entity.
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: moving treatment fields from the therapy entity to the case entity, which aligns with the primary objective.
Linked Issues check ✅ Passed The PR successfully addresses the core requirement: moving treatment fields (treatmentStarted, treatmentNotApplicable, treatmentStartDate) from Therapy entity to Case entity, and updating Doctor Declaration and Case Notification flows.
Out of Scope Changes check ✅ Passed All changes are directly related to moving treatment fields from Therapy to Case. The i18n additions for notification captions and the constructor visibility change in AbstractDoctorDeclarationMessageProcessingFlow are supporting changes for the core objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sormas-ui/src/main/java/de/symeda/sormas/ui/caze/notifier/CaseNotifierSideViewController.java (1)

146-158: Dead code: unused therapy variable.

The therapy variable is fetched on line 148 but is never used after the refactoring removed the therapy parameter from openEditWindow(). This should be removed.

🧹 Proposed fix
         // We only edit the current version
         NotifierDto notifier = FacadeProvider.getNotifierFacade().getByUuid(caze.getNotifier().getUuid());
-        TherapyDto therapy = caze.getTherapy();

         openEditWindow(
🤖 Fix all issues with AI agents
In `@sormas-backend/src/main/resources/sql/sormas_schema.sql`:
- Around line 15069-15084: The migration leaves treatmentnotapplicable NULL for
existing rows because DEFAULT false doesn't backfill and the UPDATE only touches
rows where therapy columns are non‑NULL; update the migration to backfill and
enforce NOT NULL by (a) using COALESCE when setting treatmentnotapplicable from
the therapy row in the UPDATE cases ... FROM therapy t statement (use
COALESCE(t.treatmentnotapplicable, false)), (b) run equivalent backfill for
cases_history (or a second UPDATE setting treatmentnotapplicable = false WHERE
treatmentnotapplicable IS NULL), and then (c) ALTER TABLE cases and ALTER TABLE
cases_history to set treatmentnotapplicable NOT NULL so the column cannot be
tri‑state going forward.

In
`@sormas-ui/src/main/java/de/symeda/sormas/ui/caze/notifier/CaseNotifierForm.java`:
- Around line 240-250: populateFields() reads caze (calls
caze.isTreatmentNotApplicable() and caze.getTreatmentStarted()) without guarding
against null, causing an NPE when setValue(NotifierDto) calls populateFields()
before caze is initialized; fix by adding a null-check for caze at the start of
populateFields() (e.g., if (caze == null) return;) or ensure
setValue(NotifierDto) assigns the NotifierDto's caze to the class field before
invoking populateFields(); update references to treatmentGroup,
TreatmentOption.forValue(...) and YesNoUnknown accordingly so they only execute
when caze is non-null.
🧹 Nitpick comments (2)
sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java (1)

3446-3448: Normalize treatment flags to avoid contradictory state.

Consider clearing treatmentStarted/treatmentStartDate when treatmentNotApplicable is true to keep persisted data consistent.

♻️ Suggested adjustment
 target.setTreatmentStarted(source.getTreatmentStarted());
 target.setTreatmentNotApplicable(source.isTreatmentNotApplicable());
 target.setTreatmentStartDate(source.getTreatmentStartDate());
+if (source.isTreatmentNotApplicable()) {
+    target.setTreatmentStarted(null);
+    target.setTreatmentStartDate(null);
+}
sormas-ui/src/main/java/de/symeda/sormas/ui/caze/notifier/CaseNotifierSideViewController.java (1)

251-294: Method name and Javadoc are misleading after refactoring.

The method updateTherapyBasedOnSelection now updates the CaseDataDto, not a TherapyDto. The name and documentation (line 255: "the case data containing the therapy") should be updated to reflect the new behavior.

♻️ Suggested rename
     /**
-     * Updates therapy data based on selected treatment option.
+     * Updates case treatment data based on selected treatment option.
      *
      * `@param` caze
-     *            the case data containing the therapy
+     *            the case data to update
      * `@param` selectedOption
      *            the selected treatment option from the form
      */
-    private void updateTherapyBasedOnSelection(CaseDataDto caze, TreatmentOption selectedOption) {
+    private void updateCaseTreatmentBasedOnSelection(CaseDataDto caze, TreatmentOption selectedOption) {

@sormas-vitagroup
Copy link
Contributor

@sormas-vitagroup
Copy link
Contributor

@sormas-vitagroup
Copy link
Contributor

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.

Treatment started is currently stored in Therapy entity should be either moved to Case entity - DoctorDeclaration - Case Notification

3 participants