Skip to content

[16.0][FIX] ni_patient: validate encounter transfer date without a TypeError - #167

Closed
wasud wants to merge 1 commit into
nirun-life:16.0from
wasud:16.0-fix-encounter-origin-date
Closed

wasud wants to merge 1 commit into
nirun-life:16.0from
wasud:16.0-fix-encounter-origin-date

Conversation

@wasud

@wasud wasud commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

What changed

  • ni.encounter.check_origin_date now raises ValidationError. Before, it raised the translated string itself.
  • The transfer date (origin_date, a Date) is compared with the encounter start date in the user's timezone. Before, it was compared with period_start, a UTC Datetime. The check is skipped when the encounter has no start.
  • New tests/test_ni_encounter_origin_date.py.
  • ni_patient 16.0.0.4.0 → 16.0.0.4.1.

Why

Both branches of the constraint fail with a TypeError instead of a validation error:

  • raise _("...") raises a plain string ("exceptions must derive from BaseException").
  • Date > Datetime raises on every encounter that has both a transfer date and a start, and on encounters with a transfer date but no start.

Reported by piruin in the review of the 19.0 migration (#155), who asked for the fix on 16.0 and a forward-port. Part of P0-4 (#135), epic #131.

How tested

  • -i ni_patient --test-tags /ni_patient on a fresh 16.0 DB: 29 tests, 0 failed.
  • pre-commit clean on the changed files.

Notes for reviewer

check_origin_date raised the translated message itself, a plain string, so
setting a transfer date without a transfer source failed with "exceptions must
derive from BaseException" instead of a validation error. It also compared the
transfer date (a Date) with the encounter start (a Datetime), which fails with
a TypeError on every encounter that has both, and on encounters without a start.

Raise ValidationError, and compare the transfer date with the start date in
the user's timezone, skipping the check when the encounter has no start.

Reported in the review of the 19.0 migration (nirun-life#155).
@piruin

piruin commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closing as a duplicate of #166. The check_origin_date fix, tests/test_ni_encounter_origin_date.py and the ni_patient 16.0.0.4.1 bump here are identical to row 1 of #166's ni_patient commit.

If both were merged:

  • ni_patient/tests/__init__.py would conflict;
  • the same fix would be in 16.0 twice, in different commits, which doubles the oca-port work for 17/18/19;
  • ni_patient would stay at 16.0.0.4.1 after the second merge, even though that merge adds more changes.

The fix is still wanted: it lands with #166, and its forward-ports follow #166's commits.

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.

2 participants