Skip to content

[17.0][MIG] ni_observation: Migration to 17.0 - #156

Merged
piruin merged 83 commits into
nirun-life:17.0from
wasud:17.0-mig-p1-observation
Oct 21, 2026
Merged

piruin merged 83 commits into
nirun-life:17.0from
wasud:17.0-mig-p1-observation

Conversation

@wasud

@wasud wasud commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Decisions to review

  • D7, list widget: ob_section_and_note_one2many is re-ported from core account 17 section_and_note_fields_backend (registry descriptors, @odoo/owl, useEffect on the edited record), not patched from the 16 port. The Nirun parts are kept: category sections and the value columns.
  • D8, badge: ni_observation installs and validates on a fresh DB without web_notebook_advance; only the counter on the Vital Signs/Laboratory tabs is missing. Kept as a soft dependency and noted in the README.
  • Behaviour fix, wizard: the encounter domain on ni.observation.wizard.encounter_id used parent_id, which does not exist on ni.encounter, through a Field object, so it never filtered. It now filters on patient_id.

What changed

  • ni_observation history replayed, then [IMP] pre-commit and [MIG] ni_observation: Migration to 17.0.
  • Display names:
    • name_get → _compute_display_name on reference range and sheet (depends_context("show_occurrence")).
    • The patient _name_get() extension now has @api.depends("blood_group").
  • Counts: read_group → _read_group(..., ["__count"]) with the tuple results (patient, encounter, type).
  • Wizard:
    • states="1"/"2" → invisible expressions.
    • String domains.
    • company_id added to the line list, which 17 requires for the check_company domain on encounter_id.
  • Encounter: the non-stored compute assigns its fields instead of calling write().
  • Views:
    • attrs → expressions (migrator).
    • Hidden list fields use column_invisible.
    • always_reload dropped.
    • A hidden company_id sits next to the group-restricted one.
  • The "New Observation" context no longer sends [False] as default_category_ids when no category is selected. 17 tried to create a nameless category.
  • Other:
    • fields.Datetime.now.
    • <odoo noupdate> without <data>.
    • Asset paths without the leading /.
    • Named translation placeholders, lint backlog.
  • th.po regenerated, 16.0 translations merged back, UI terms filled (lab test names and units stay in English, as in Thai clinical use).

Why

Part of #139 (P1-4, epic #131).

Migration notes

How tested

  • Unit/integration tests: 25 tests pass on 17 (fresh DB with ni_observation), plus 57 with ni_coding,ni_patient,ni_observation.
  • Manual check (browser, Odoo 17 with demo data):
    • Observation sheet:
      • sections per category and hidden technical columns;
      • entering systolic/diastolic: interpretation colours update live;
      • save computes BP "150 / 95".
    • Encounter: Vital Signs tab (latest values, BMI), Observation tab with category filter.
    • Wizard: New → category → line list → value → Save; the reading lands on the encounter with the right interpretation.
    • Observation list, date filter, pivot; patient Observation tab.
    • Display names: sheet with show_occurrence, reference range Type [low-high].
    • No JS console errors.
  • pre-commit clean on ni_observation (two eslint warnings that come from the core account code).

Documentation

  • Module README.md updated (17.0, display names, list widget, D8 soft dependency)

Notes for reviewer

@piruin piruin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review

No blockers.

Checked, OK

  • read_group → _read_group(..., ["__count"]) reads the tuple results correctly (patient, encounter, type).
  • The _compute_display_name override in ni_patient with @api.depends("blood_group") works: Odoo merges the depends of every override, so ni_patient's depends_context keys still apply.
  • The wizard domain fix (parent_id → patient_id, string domains) is correct.
  • The encounter compute now assigns values instead of calling write().
  • The list widget is re-ported with field descriptors, @odoo/owl imports, isNew and useEffect on the edited record.
  • The latest-observation [FIX] was done the epic's way: fixed on 16.0 in #163 (merged), then carried forward.
  • CI is green, and the series ends with [IMP] pre-commit auto fixes + [MIG].

Minor

  • report/ still uses SELECT DISTINCT ON … *, as noted in the PR body.

@wasud
wasud force-pushed the 17.0-mig-p1-observation branch from f799211 to 315d1f6 Compare October 19, 2026 05:09
piruin and others added 24 commits October 21, 2026 08:26
* [IMP] ni_device: Update required field

* [IMP] ni_device: add devie_usage_log

* [IMP] ni_community_care: update usage log views

* [IMP] ni_community_care: update usage log views

* [IMP] ni_careplan: multi company rule

* [IMP] ni_community_care: update approval careplan report

* [IMP] ni_community_care: update cron id for Create Backfill Approvals

* [IMP] ni_community_care: improve approval report template to avoid printing reports with no data

* [IMP] ni_observation: Add Observation wizard for better UX

* [IMP] ni_observation: remove ni_observation_value_code.type_id use only type_ids

* [IMP] ni_community_care: update approval_category_report_template

* [FIX] ni_careplan: not deleted on form

* [FIX] ni_careplan: resource created by careplan not check period_start

* [IMP] ni_community_care: add pivot view

* [IMP] ni_observation: add parent_id for observation category

* [IMP] ni_observation: observation wizard action from patient

* [FIX] ni_observation: error on select blood_abo

* [FIX] ni_observation: invalid domain for  blood_rh

Took 16 minutes

* [IMP] ni_community_care_attendance: optimize get_employee_dashboard

* [IMP] ni_device: update manifest

* [IMP] ni_device,ni_observation: update device logs

* [IMP] ni_device: update device logs

* [IMP] ni_observation,ni_device: update device logs

* [IMP] ni_observation,ni_device: update device logs

* [IMP] ni_device,ni_observation: update device usage

* [IMP] ni_device,ni_observation: update device usage

* [IMP] ni_device: update ni_device_usage_view_kanban re-direct to res_model form

* [IMP] ni_device: add ni_device_definition

* [IMP] ni_device: update ni_device_definition

* [IMP] ni_device: update device_label_layout_template

* [IMP] ni_device: add compute fields and update views

* [IMP] ni_device : add tracking important fields, add report device lost workflow

* [IMP] ni_device : add employee search by device name, identifier, serial_number

* [FIX] ni_device : fix holder not updated when submitting request_hold

* [IMP] ni_device: All text has been translated into English.

* [IMP] ni_device: All text has been translated into English.

* [IMP] ni_device: translated into Thai and add active_repair_state

* [IMP] ni_device: translated into Thai

* [IMP] ni_device: Update required field

* [IMP] ni_device: add devie_usage_log

* [IMP] ni_community_care: update usage log views

* [IMP] ni_community_care: update usage log views

* [IMP] ni_device: update manifest

* [IMP] ni_observation,ni_device: update device logs

* [IMP] ni_device,ni_observation: update device usage

* [IMP] ni_device,ni_observation: update device usage

* [IMP] ni_device: add ni_device_definition

* [IMP] ni_device: update ni_device_definition

* [IMP] ni_device: update ni_observation_sheet_view_form_inherit

* [IMP] ni_device: rebased 16.0-device branch

* [IMP] ni_device: Update from Thai to English.

* [IMP] ni_device: update device usage log

* [ADD] ni_community_care_device: add commu device to update ni_patient_view_form_simp

* [IMP] ni_device: Update from Thai to English.

* [IMP] ni_community_care: update device kanban

* [IMP] ni_community_care: polish device views

* [IMP] ni_device: Update from Thai to English.

* [IMP] ni_device: Translate thai

* [IMP] ni_device: update ni_device_usage_view_kanban

* [IMP] ni_community_care: fix pre-commit failed

* [IMP] ni_community_care_device: remove init models

---------

Co-authored-by: Piruin P. <piruin.p@gmail.com>
Co-authored-by: BesTinG <79839187+bestiing@users.noreply.github.com>
Use int(float(value)) so that strings like "42.5" are accepted and
truncated to 42, instead of raising ValueError. Add unit tests for
_inverse_value covering all value types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… social history categories with reference ranges

Adds 22 new observation types across lipid panel (CHOL, LDL, HDL, TG), CBC
(WBC, RBC, Hb, Hct, PLT), kidney function (Cr, BUN, eGFR, UA), liver enzymes
(ALT, AST, ALP), electrolytes (Na, K, Cl), GCS (exam), and smoking/alcohol
status (social history). Includes 96 reference ranges with gender-specific
splits where clinically relevant, plus 6 new UOM categories and units.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… unit tests

- Set body-weight and body-height as children of type_bmi so _eval_compute_types
  resolves them via child_ids (consistent with the BP pattern)
- Apply textwrap.dedent + strip before safe_eval so multi-line / indented code
  stored in XML text nodes evaluates without IndentationError
- Add TestComputeCode: 11 tests covering float/char results, update-on-write,
  no-duplicate idempotency, empty-input skip, None result, missing assignment,
  exception safety, and seeded BP/BMI integration tests

Adds a compute_code Text field on ni.observation.type that lets users write
Python expressions (via ace editor) to derive a type's value from its child
component observations — analogous to ir.cron's code field.

Evaluation logic lives in ObservationSheet._eval_compute_types(), triggered
after ni.observation create/write on value fields. The skip_compute_eval
context flag prevents recursion when writing back the computed result.

Seeds compute_code on type_bp ("SYS / DIA") and type_bmi as reference examples.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…de tests; link input observations as child_ids on computed observation

Replace fragile parent_id mutations on shared fixtures with child_ids in the
create call, and give each edge-case test its own isolated input type.

_eval_compute_types now sets child_ids on the computed ni.observation record
to the component observations used in the calculation. This lets callers verify
which inputs drove a given computed value (e.g. bp_s/bp_d for BP, weight/height
for BMI).

Also fixes three bugs in the partial ni.observation parent/child field definitions:
- ondelete="" → ondelete="set null"
- child_ids pointed to wrong model "ni.patient.observation" → "ni.observation"
- @api.depends("child_count") → @api.depends("child_ids")
- Missing _ in imports

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
type_body_weight and type_body_height referenced type_bmi via parent_id
before it was defined, causing a forward-reference error on module load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
parent_id/parent_path follow the same pattern already used by
ni.observation.category and ni.condition.category, enabling real
child_of/parent_of matching against coded observation values (e.g.
ni_goal targets) instead of a flat set.

Took 1 hour 49 minutes

Took 15 minutes
…'s event/request id

WorkflowMixin._to_workflow() wrote the parent record's own id into
ni.workflow.event.parent_id / ni.workflow.request.parent_id, but those
fields reference other ni.workflow.event/request rows, not the source
model's own id. This either raised a foreign key violation or silently
linked to an unrelated workflow row, depending on whether the id happened
to collide with an existing workflow row.

Surfaced via ni_observation: an observation type with a computed parent
(e.g. Systolic/Diastolic Blood Pressure -> Blood Pressure) hit this as
soon as both child values were saved, since ni.observation.sheet links
the children to the newly computed parent via child_ids, which re-writes
each child's parent_id and re-triggers the workflow mirror write.

Fixes nirun-life#109. Also fixes ni_device's
test_requires_supported_observation_type, which tried to clear a
device's observation_type_ids via its definition + recompute, but
_compute_from_definition only ever fills a device's observation_type_ids
from a non-empty definition and never clears it.
`default=fields.Datetime.now()` (and, in ni_reception, the stdlib
`fields.datetime.now()`) is evaluated once when the model class is
defined, freezing every record's default to that one moment instead
of the actual creation time. Pass the bare callable so it evaluates
per record.

Affected: ni_observation (observation wizard), ni_document_ref,
ni_medication (suggest wizard), ni_reception, and ni_patient's
ni.workflow.event.mixin (shared by every clinical event model:
procedures, immunizations, medication dispenses, etc).
`ref_range__hba1c__HU` spanned 6.4-100.0 while `ref_range__hba1c__HH`
spanned 7.0-100.0, so any HbA1c >= 7.0 matched both "Significantly
High" and "Critical High" at once. Cap HU at 7.0 so it hands off to
HH, matching the boundary-continuity pattern every other multi-tier
range in this file follows.
The observation_ids editable tree relied on field-level context
(default_sheet_id, default_patient_id, default_encounter_id,
default_occurrence) to fill a manually-added line, but the web client
only applies context defaults for fields declared in that tree's own
arch. Declare them as invisible fields so a new line stays linked to
the sheet/patient being edited.
The form had three inner groups inside a two-column outer group, so the
third one wrapped onto a second row and left the cell beside it empty - a
hole in the middle of the form with nothing to put in it.

Two columns now: what was measured on the left, who it was measured on -
and, for the layers that add them, with which device and where - on the
right.

The value row printed the number twice ("128.0  128.00  mmHg"): `value`
is the Char computed from the typed field beside it and had no modifier,
so both showed. It stays in the arch for the case where value_type is
empty, and for the inverse that writes the typed field back.

Occurrence joins the form, readonly once the reading belongs to a sheet -
_check_occurrence() puts the sheet's own back, so an edit there would be
silently undone. user_id is read from the sheet, so a reading opened on
its own still says who took it.
On small screens the x2many falls back to kanban, and the sheet only
had an inline tree, so readings were cramped on phones. Inline kanban
and form give each reading a card: numbers stack value over unit,
text and choices get a full-width line clamped to 3 lines, and the
type icon falls back per value type when none is set.

Took 3 hours 23 minutes
The latest-observation views keep one row per patient (or encounter) and type
with DISTINCT ON, ordered by occurrence only. When two observations of a type
share an occurrence (created in the same transaction, for example by two
questionnaires mapped to the same type), PostgreSQL may return either row. The
patient and encounter forms then read a row that the next query no longer
returns, and fail with "records ... cannot be found". Break the tie by id.

Found by the Phase 1 data migration pilot (nirun-life#141); 16.0 has the same views.
@wasud
wasud force-pushed the 17.0-mig-p1-observation branch from 315d1f6 to 7d4318b Compare October 21, 2026 01:40
@piruin
piruin merged commit 6dde686 into nirun-life:17.0 Oct 21, 2026
4 checks passed
@wasud wasud mentioned this pull request Nov 2, 2026
5 tasks
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.

4 participants