Skip to content

fix(datasync): link van rows to old central rows saved without VanSerialNo (STOP-862) - #215

Merged
vanitha1822 merged 1 commit into
release-3.13.0from
vb/3.13.0-visitcode-link-fallback
Dec 1, 2026
Merged

vanitha1822 merged 1 commit into
release-3.13.0from
vb/3.13.0-visitcode-link-fallback

Conversation

@vishwab1

@vishwab1 vishwab1 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

📋 Description

Since PR #201 (in release-3.13.0), central links a van's child rows (drugs, refers, vitals, …) to their
parent visit / prescription by VanID + VanSerialNo (translateVanLinks). If the parent is not found,
the child is rejected with "Linked t_prescription (van ID 556) not on central yet" and sent again next sync.

Rows uploaded while central ran 3.8.x / 3.9.x (before 31 Oct 2026) were saved without VanSerialNo
(commit 604bd64, name-based column fill). Their parents are on central, but cannot be found by VanSerialNo,
so their children are rejected on every sync. The laptop stops that table at the first rejected batch
of 30, so all newer rows wait behind them.

Example (STOP-862, Subir Van2 / VanID 525): 30 drugs of 24 Oct prescriptions rejected, 343 waiting
since 24 Oct. On central, 18,776 prescriptions on 99 vans still have no VanSerialNo.

Until now each camp needed a manual SQL fix (fill VanSerialNo from a Fleet export of the laptop).

What this PR does

When the lookup by VanID + VanSerialNo finds nothing, central looks for the old row by
VanID + VisitCode + BeneficiaryRegID with VanSerialNo IS NULL:

  • exactly one row → writes the van's ID into its VanSerialNo (for a prescription, also the central
    ID of its visit) and links the child to it;
  • two or more → writes nothing, child stays rejected with the reason (no guessing);
  • none → rejected as before (parent really not on central yet).

A visit / prescription that the van re-sends is synced onto that old row instead of being inserted as
another copy.

VisitCode and BeneficiaryRegID were stored correctly by the old code; only VanSerialNo and the visit
pointer were wrong, so the match cannot attach a row to another patient.

Switch

dataSync.claimEmptyVanLabels (default true), used only when dataSync.translateVanLinks=true
(Stop TB central). Set to false to turn it off.

Not covered

  • Same patient + VisitCode with 2+ empty-label copies (3,198 on central) and rows whose patient ID
    changed: stay rejected, need the central data correction.
  • Laptops that uploaded under another van's ID (e.g. Simalwara Van2 as 415): not matched (safe), need
    a per-laptop fix.

Tests

  • DataSyncRepositoryCentralEmptyLabelTest (new, 6): single match filled; prescription also gets its
    visit; lookup only on VanID + VisitCode + patient + empty label; several matches not guessed; row
    changed meanwhile reported; no VisitCode → nothing done.
  • GetDataFromVanAndSyncToDBVanLinksTest (+3): drug of an old prescription linked; several copies
    reported; switch off → not used.
  • All 40 data-sync tests pass.

JIRA ID: STOP-862

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

…ialNo (STOP-862)

Central 3.8.x / 3.9.x saved van visits and prescriptions without VanSerialNo.
Since translateVanLinks (PR #201) links child rows by VanID + VanSerialNo, a
drug or refer of such an old prescription/visit was rejected on every upload
("Linked t_prescription ... not on central yet"), blocking the table's queue.

When the lookup by VanSerialNo finds nothing, central now looks for the one row
of the same VanID + VisitCode + BeneficiaryRegID whose VanSerialNo is empty,
writes the van's ID into it (and, for a prescription, the central ID of its
visit) and links the child to it. Several such rows: nothing is written and the
reason is returned. A re-sent visit/prescription is synced onto that old row
instead of inserted as another copy.

Switch: dataSync.claimEmptyVanLabels (default true, only with translateVanLinks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 18d5564e-56bf-4f6a-8e09-c4a1cafc538c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment on lines +215 to +217
List<Long> ids = getJdbcTemplate().queryForList("SELECT " + idColumn + " FROM " + table
+ " WHERE VanID = ? AND VisitCode = ? AND BeneficiaryRegID = ? AND VanSerialNo IS NULL"
+ " AND (Deleted IS NULL OR Deleted = 0)", Long.class,
+ " WHERE " + idColumn + " = ? AND VanSerialNo IS NULL";
Object[] params = setVisit ? new Object[] { String.valueOf(vanSerialNo), centralBenVisitID, centralId }
: new Object[] { String.valueOf(vanSerialNo), centralId };
int updated = getJdbcTemplate().update(update, params);
@vanitha1822
vanitha1822 merged commit 07dfcc2 into release-3.13.0 Dec 1, 2026
4 of 5 checks passed
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