Skip to content

#13771 - Corrections to epipulse export queries & mappings#13866

Merged
roldy merged 2 commits intodevelopmentfrom
bugfix-13771-correct-value-mapping
Mar 13, 2026
Merged

#13771 - Corrections to epipulse export queries & mappings#13866
roldy merged 2 commits intodevelopmentfrom
bugfix-13771-correct-value-mapping

Conversation

@roldy
Copy link
Contributor

@roldy roldy commented Feb 28, 2026

Fixes #

Summary by CodeRabbit

  • New Features

    • Added pneumonia as a reported complication in disease exports.
    • Added dry blood as a recognized sample material.
    • Updated Epipulse case importation status codes.
  • Bug Fixes

    • Improved ordering of test results when primary timestamps are missing for more consistent exports.
  • Tests

    • Added unit tests covering sample material → Epipulse code mappings.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8c29fda9-ba4b-4bf8-9080-12d3bab9ee55

📥 Commits

Reviewing files that changed from the base of the PR and between 646d860 and f3d3df0.

📒 Files selected for processing (2)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/IpiExportStrategy.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeniExportStrategy.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeniExportStrategy.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/IpiExportStrategy.java

📝 Walkthrough

Walkthrough

Adds pneumonia handling to Epipulse complication mapping, adjusts sample-material and import-status code mappings, makes SQL ordering null-safe via COALESCE in multiple CTEs, and adds unit tests for laboratory sample material mappings.

Changes

Cohort / File(s) Summary
Laboratory mapper & tests
sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java, sormas-api/src/test/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapperTest.java
Added pneumonia parameter to mapSymptomsToComplicationCodes; changed sample material mappings (added DRY_BLOOD -> "DRYBLOSP", treat CLINICAL_SAMPLE as "OTH"); updated imported-status code mappings (IMPORT_RELATED_CASE -> "IMPREL", UNKNOWN_IMPORTATION_STATUS -> "IMPUNK", NOT_IMPORTED_CASE -> "NOTIMP"). New unit tests cover sample material mapping cases.
Measles export strategy
sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeaslesExportStrategy.java
Extracts and propagates new pneumonia field through CTEs and selects; updates call to mapSymptomsToComplicationCodes to include pneumonia; adjusts sample/serology subqueries and expands accepted test types for detection/serology.
SQL timestamp ordering (CTEs)
sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/EpipulseSqlCteBuilder.java, sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/IpiExportStrategy.java, sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeniExportStrategy.java
Replaced ORDER BY on testdatetime with COALESCE(testdatetime, reportdate, creationdate) (NULL-safe fallback) and added deterministic tie-breakers (e.g., pt.id DESC) across several CTEs for serotype, detection method, and AST selections.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • obinna-h-n
  • raulbob

Poem

🐰
I hopped through mappers, codes in tow,
Added "PNEU" where breathings show,
COALESCE blankets dates so fine,
Dry blood labeled in a single line,
Exports hum, the data grows.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete—it only contains the repository template with an empty 'Fixes #' reference and lacks substantive details about the changes, objectives, or rationale. Add a detailed description explaining the bug fixes, the issue number being addressed, and the impact of the changes to epipulse export mappings and queries.
Docstring Coverage ⚠️ Warning Docstring coverage is 34.48% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main changes: corrections to epipulse export queries and mappings, which matches the modifications across multiple mapper and strategy files.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix-13771-correct-value-mapping
📝 Coding Plan
  • Generate coding plan for human review comments

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

🧹 Nitpick comments (1)
sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java (1)

249-266: Mapping corrections look good.

The updated codes (IMPREL, IMPUNK, NOTIMP) align with the Javadoc documentation. Note that mapMeniImportedStatus (lines 886-903) now has an identical implementation—consider extracting shared logic if these mappings are expected to remain consistent.

,

♻️ Optional: Extract shared mapping logic
// Both methods could delegate to a shared private helper if they should stay in sync:
private static String mapCaseImportedStatusCode(CaseImportedStatus importedStatus) {
    if (importedStatus == null) {
        return null;
    }
    switch (importedStatus) {
    case IMPORTED_CASE:
        return "IMP";
    case IMPORT_RELATED_CASE:
        return "IMPREL";
    case UNKNOWN_IMPORTATION_STATUS:
        return "IMPUNK";
    case NOT_IMPORTED_CASE:
        return "NOTIMP";
    default:
        return null;
    }
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java`
around lines 249 - 266, Both mapCaseImportedStatusToEpipulseCode and
mapMeniImportedStatus contain identical switch logic; extract the mapping into a
single private helper (e.g., mapCaseImportedStatusCode) that takes
CaseImportedStatus and returns the code, then have both
mapCaseImportedStatusToEpipulseCode and mapMeniImportedStatus delegate to that
helper to avoid duplication and ensure consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/IpiExportStrategy.java`:
- Line 225: The ORDER BY expressions using COALESCE(pt.testdatetime,
pt.reportdate, pt.creationdate) in IpiExportStrategy are currently "DESC" which
in Postgres treats NULLs as first; update each such ORDER BY (the occurrences in
the SQL strings inside IpiExportStrategy) to append "NULLS LAST" and add a
deterministic tiebreaker (e.g. ", pt.id" or ", pt.uuid") after the COALESCE
expression so LIMIT 1 / DISTINCT ON pick the most recent non-null row
consistently; modify the three SQL fragments that contain "ORDER BY
COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC" to "ORDER BY
COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) DESC NULLS LAST,
pt.id" (or pt.uuid) as appropriate.

In
`@sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeniExportStrategy.java`:
- Line 256: In MeniExportStrategy, the ORDER BY expressions that use DESC on
COALESCE(pt.testdatetime, pt.reportdate, pt.creationdate) must append "NULLS
LAST" so rows with all-null timestamps aren't chosen as the "latest" (update
both occurrences referenced in the MENI CTE SQL strings inside class
MeniExportStrategy to use COALESCE(... ) DESC NULLS LAST); keep the exact
COALESCE expression and only add "NULLS LAST" to the ORDER BY clauses to
preserve behavior for non-null timestamps.

---

Nitpick comments:
In
`@sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java`:
- Around line 249-266: Both mapCaseImportedStatusToEpipulseCode and
mapMeniImportedStatus contain identical switch logic; extract the mapping into a
single private helper (e.g., mapCaseImportedStatusCode) that takes
CaseImportedStatus and returns the code, then have both
mapCaseImportedStatusToEpipulseCode and mapMeniImportedStatus delegate to that
helper to avoid duplication and ensure consistency.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bde5f20 and 646d860.

📒 Files selected for processing (6)
  • sormas-api/src/main/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapper.java
  • sormas-api/src/test/java/de/symeda/sormas/api/epipulse/EpipulseLaboratoryMapperTest.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/EpipulseSqlCteBuilder.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/IpiExportStrategy.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeaslesExportStrategy.java
  • sormas-backend/src/main/java/de/symeda/sormas/backend/epipulse/strategy/MeniExportStrategy.java

@sormas-vitagroup
Copy link
Contributor

@sormas-vitagroup
Copy link
Contributor

@roldy roldy merged commit a3b69fb into development Mar 13, 2026
8 of 13 checks passed
@roldy roldy deleted the bugfix-13771-correct-value-mapping branch March 13, 2026 13:15
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.

3 participants