Skip to content

Adds Lab results (tests/samples/AST) tab to the cases view#13987

Open
roldy wants to merge 2 commits into
developmentfrom
feature/13948-lab-results-view
Open

Adds Lab results (tests/samples/AST) tab to the cases view#13987
roldy wants to merge 2 commits into
developmentfrom
feature/13948-lab-results-view

Conversation

@roldy

@roldy roldy commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #13955

Summary by CodeRabbit

  • New Features
    • Added a Laboratory results case tab to capture pathogen tests, sample details (including tests performed), and antibiotic susceptibility (AST) where available.
    • Introduced additional lab-related inputs: date other, date other details, and external laboratory comments.
    • Added localized captions and info texts, and the tab appears based on the relevant permissions/feature availability.
  • Tests
    • Added automated coverage to verify correct round-trip persistence and mapping of the new laboratory-related fields.

@coderabbitai

coderabbitai Bot commented Jun 15, 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: db135c24-cd43-4cfd-a41f-b075b9a6b033

📥 Commits

Reviewing files that changed from the base of the PR and between 320472c and 9853df3.

📒 Files selected for processing (3)
  • sormas-backend/src/main/resources/sql/sormas_schema.sql
  • sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsView.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsView.java

📝 Walkthrough

Walkthrough

Adds a "Laboratory results" tab to the Case view. Three new fields (dateOther, dateOtherDetails, externalComments) are introduced across CaseDataDto, the Case JPA entity, CaseFacadeEjb, and a SQL schema migration (version 638). A new CaseLabResultsView renders an editable header form plus three read-only grids for pathogen tests, samples, and drug susceptibility (AST) results.

Changes

Case Laboratory Results Tab

Layer / File(s) Summary
API DTO fields and i18n constants
sormas-api/src/main/java/.../caze/CaseDataDto.java, sormas-api/src/main/java/.../i18n/Captions.java, sormas-api/src/main/java/.../i18n/Strings.java, sormas-api/src/main/resources/captions.properties, sormas-api/src/main/resources/strings.properties
Adds LAB_RESULTS, DATE_OTHER, DATE_OTHER_DETAILS, and EXTERNAL_COMMENTS constants to CaseDataDto with S2S-ignore and validation annotations; registers all matching caption and string keys in Captions, Strings, and the two properties files.
Backend entity, facade mapping, and schema migration
sormas-backend/src/main/java/.../caze/Case.java, sormas-backend/src/main/java/.../caze/CaseFacadeEjb.java, sormas-backend/src/main/resources/sql/sormas_schema.sql, sormas-backend/src/test/java/.../caze/CaseFacadeEjbTest.java
Adds JPA-mapped fields and accessors to Case with temporal and column definitions; wires toCaseDto and fillOrBuildEntity in CaseFacadeEjb for bidirectional mapping; adds DDL for three new columns in cases/cases_history at schema version 638; validates with a new round-trip JUnit test.
View registration and menu wiring
sormas-ui/src/main/java/.../caze/CaseController.java, sormas-ui/src/main/java/.../caze/AbstractCaseView.java
Registers CaseLabResultsView route in registerViews gated by SAMPLES_LAB/SAMPLE_VIEW; adds the Lab Results menu entry in refreshMenu excluding unreferred port health cases.
CaseLabResultsForm and edit component
sormas-ui/src/main/java/.../caze/CaseLabResultsForm.java, sormas-ui/src/main/java/.../caze/CaseController.java
New CaseLabResultsForm defines HTML layout with read-only symptom-onset date and editable dateOther/dateOtherDetails/externalComments fields; getLabResultsEditComponent wraps the form in CommitDiscardWrapperComponent that re-fetches the case and selectively persists only lab-results fields on commit.
CaseLabResultsView grids and AST flattening
sormas-ui/src/main/java/.../caze/CaseLabResultsView.java
Implements the full view with refreshTables building three conditional grid sections; flattenDrugSusceptibility converts DrugSusceptibilityDto into AstRow entries via annotation-driven field discovery and reflection; helper methods readProperty, resolveDrug, and collectionDateOf support data extraction and Drug enum normalization; AstRow view-model holds antibiotic test data for the AST grid.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CaseLabResultsView
  participant CaseController
  participant CaseFacadeEjb
  participant SampleFacade
  participant PathogenTestFacade

  User->>CaseLabResultsView: open Lab Results tab
  CaseLabResultsView->>CaseController: getLabResultsEditComponent(caseUuid)
  CaseController->>CaseFacadeEjb: getCaseDataByUuid(caseUuid)
  CaseFacadeEjb-->>CaseController: CaseDataDto
  CaseController-->>CaseLabResultsView: CommitDiscardWrapperComponent<CaseLabResultsForm>
  CaseLabResultsView->>CaseLabResultsView: initView / refreshTables
  CaseLabResultsView->>SampleFacade: getIndexList(caseCriteria)
  SampleFacade-->>CaseLabResultsView: List<SampleIndexDto>
  CaseLabResultsView->>PathogenTestFacade: getAllByCaseUuid(caseUuid)
  PathogenTestFacade-->>CaseLabResultsView: List<PathogenTestDto>
  CaseLabResultsView->>CaseLabResultsView: buildTestsGrid / buildSamplesGrid
  CaseLabResultsView->>CaseLabResultsView: flattenDrugSusceptibility → List<AstRow>
  CaseLabResultsView->>CaseLabResultsView: buildAstGrid (conditional)
  User->>CaseLabResultsView: commit header form
  CaseLabResultsView->>CaseFacadeEjb: getCaseDataByUuid (re-fetch)
  CaseLabResultsView->>CaseFacadeEjb: saveCase(dto with dateOther/dateOtherDetails/externalComments)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • SORMAS-Foundation/SORMAS-Project#13961: This PR renders the AST drug susceptibility grid using DrugSusceptibilityDto and reflectively reads per-antibiotic susceptibility fields (method, MIC value, zone diameter, clinical/surveillance interpretation) that are modified or introduced in PR #13961.

Suggested reviewers

  • raulbob
  • obinna-h-n
  • KarnaiahPesula

Poem

🐇 Hop, hop, a new tab appears in the case,
Tests and samples all sorted by date and by place!
The antibiotic grid flattens with reflective delight,
dateOther and comments now persist day and night.
Schema version 638 — the bunny is proud,
Lab results displayed, no more lost in the crowd! 🔬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.12% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a Lab results tab with tests, samples, and AST functionality to the cases view.
Description check ✅ Passed The PR description provides the linked issue number (#13955) but lacks detailed explanation of the implementation and changes made.
Linked Issues check ✅ Passed The PR implements all acceptance criteria from issue #13955: Lab results tab with read-only onset date, date other fields, external comments, sortable tests/samples/AST tables, and access control based on user permissions.
Out of Scope Changes check ✅ Passed All changes are in scope: API DTOs and constants, backend entity/facade mappings, database schema, UI views/forms, tests, and i18n strings directly support the Lab results tab feature specified in issue #13955.

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

✨ 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 feature/13948-lab-results-view

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.43.0)
sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java

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.

@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: 6

🤖 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/resources/sql/sormas_schema.sql`:
- Around line 16298-16307: The migration metadata contains inconsistent issue
reference numbers that do not match the PR objective. Update the issue reference
number from `#13948` to `#13955` in two locations: the migration comment line
starting with "-- 2026-06-08 Laboratory results tab: date other + external
comments on case" and the INSERT INTO schema_version statement with
version_number 638. This ensures the release traceability accurately reflects
the correct issue identifier throughout the migration.

In
`@sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java`:
- Around line 3458-3466: The assertEquals assertion for dateOther in the
round-trip test is brittle because exact Date equality does not account for
database/JPA precision loss. Replace the exact equality check for the dateOther
field (at the assertEquals call comparing dateOther with
reloaded.getDateOther()) with a day-granularity comparison. Either truncate both
dates to remove time components before assertion, or use a date-granularity
assertion helper method that compares only the day portion of the dates.

In `@sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsView.java`:
- Around line 169-189: The Tests grid and AST grid in CaseLabResultsView are
missing the mandatory Comments column that is required according to the tab
specification. Add a grid.addColumn() call for the Comments field to both
affected grids at the locations mentioned (the current diff showing lines
169-189 for the Tests grid, and the sibling location at lines 250-257 for the
AST grid). Use the same pattern as the other columns being added to the grid,
retrieving the comments property from PathogenTestDto and setting an appropriate
caption using I18nProperties, so both grids match the Samples grid's
completeness.
- Around line 192-196: The grid item click listeners throughout the
CaseLabResultsView file currently require double-click to open detail views, but
the requirement specifies that selecting a row should open the corresponding
detail view (single-click behavior). Remove the isDoubleClick() condition from
the if statement in all affected grid.addItemClickListener calls so that a
single row selection triggers the edit action. This change needs to be applied
at all locations mentioned: the pathogen test controller edit call at lines
192-196, and the corresponding listener implementations for other grid types at
lines 229-233, 245-260, and 359-375. Ensure each grid's item click listener
directly calls its respective controller's edit method (such as
ControllerProvider.getPathogenTestController().edit,
ControllerProvider.getTestResultController().edit, or equivalent) without
requiring a double-click condition.
- Around line 279-306: Empty rows are being added to the results when all the
displayed data fields are null. After reading all the properties with
readProperty calls (method, mic, zoneDiameter, clinical, and surveillance), add
a check before the rows.add() call to verify that at least one of these values
is not null. If all of them are null, skip adding that row by using continue to
move to the next iteration of the loop.
- Around line 128-133: The testCountBySampleUuid calculation in the stream chain
is only counting tests from displayTests, which excludes AST results that are
displayed in a separate table below. To fix the underreporting of performed
tests, combine the test counts from both the regular tests (displayTests) and
the AST tests when calculating the grouped count by sample UUID. Identify the
collection that holds the AST tests (likely named similarly to displayTests but
for AST data) and include those tests in the groupBy operation to ensure the
performed-test count reflects all tests visible in the UI.
🪄 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: a1a8e814-57e4-48bb-9b11-085bcc55e6ab

📥 Commits

Reviewing files that changed from the base of the PR and between 3d90d96 and 320472c.

📒 Files selected for processing (13)
  • sormas-api/src/main/java/de/symeda/sormas/api/caze/CaseDataDto.java
  • sormas-api/src/main/java/de/symeda/sormas/api/i18n/Captions.java
  • sormas-api/src/main/java/de/symeda/sormas/api/i18n/Strings.java
  • sormas-api/src/main/resources/captions.properties
  • sormas-api/src/main/resources/strings.properties
  • sormas-backend/src/main/java/de/symeda/sormas/backend/caze/Case.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java
  • sormas-backend/src/main/resources/sql/sormas_schema.sql
  • sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/AbstractCaseView.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseController.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsForm.java
  • sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsView.java

Comment thread sormas-backend/src/main/resources/sql/sormas_schema.sql Outdated
Comment thread sormas-backend/src/test/java/de/symeda/sormas/backend/caze/CaseFacadeEjbTest.java Outdated
Comment thread sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseLabResultsView.java Outdated
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.

Laboratory - Add a "Laboratory results" tab to the Case View

1 participant