Skip to content

[18.0][MIG] ni_observation: Migration to 18.0 - #157

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

piruin merged 85 commits into
nirun-life:18.0from
wasud:18.0-mig-p1-observation

Conversation

@wasud

@wasud wasud commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Decisions to review

  • Security: the read rules without a group on observation reference data are split into base.group_user + base.group_portal + base.group_public rows, the same as P1-1 ([MIG 19.0][P1-1] Foundation: ni_period, ni_identifier, ni_coding, partner_age, partner_gender, partner_religion, uom_alias #136). Access is unchanged, but the security file changes.

  • Field labels: 18 warns on duplicate labels, and the template's checklog-odoo fails CI on any warning. Renamed labels:

    • "Value (Text)", "Value (Integer)", "Value (Decimal)", "Value (Code)";
    • "Effective Date" (effective_date), "Observation Code" (code_id);
    • "Sheet Name" (sheet name), "Sheet Created by/on" (wizard).

    Views that show a single value column keep the label "Value". Graph and pivot measures now show "Value (Decimal)"/"Value (Integer)".

  • D7, list widget: re-ported from core account 18 (static template/components, this.columns, the new <attribute add> syntax).

What changed

  • [IMP] pre-commit and [MIG] ni_observation: Migration to 18.0 on top of the 17.0 PR.
  • Migrator: tree → list, kanban-box → card (rename only), unaccent=False removed, version.
  • Kanban (manual):
    • Sheet kanban: no oe_kanban_global_click wrapper, kanban_image → many2one_avatar_user in a <footer>, quick_add removed (not a kanban attribute).
    • Sheet line cards (mobile): wrapper removed.
    • Latest-observation kanbans (report/):
      • rewritten with highlight_color, <templates> and <footer>;
      • the 16 view used <template> and kanban_color.
  • Models:
    • group_operator → aggregator.
    • _check_recursion() → _has_cycle(), with odoo.exceptions.ValidationError.
    • Related display_class and the report value_type no longer redefine the selection (18 warnings).
    • Report sequence drops the inherited default ("Redundant default").
    • SQL views use SQL() and SQL.identifier.
  • Other:
    • Cron without numbercall/doall.
    • default_period="year,year-1" (the 17 ids this_year,last_year fail validation on 18).
    • SCSS selector .o_kanban_record.
    • JS without the @odoo-module header.
  • Bug fixed: _('Not found match value for "%s"!' % value) formatted the string before translating it. It now uses a named placeholder.
  • th.po regenerated, 17.0 translations merged, distinct Thai labels for the renamed fields.

Why

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

Migration notes

  • Effort: M.
  • What the migrator did: tree/view_mode, the kanban-box rename, unaccent.
  • Manual work:
    • Kanban cards.
    • aggregator, _has_cycle, cron.
    • Duplicate labels and selection warnings.
    • ACL groups, default_period, D7 renderer.
  • Surprises:
    • The issue says ace → code_editor, but 18 and 19 have no code_editor widget; ace (alias code) is still registered, so it stays.
    • default_period ids changed again in 18.
    • Fresh install is clean, but -u showed "Redundant default" warnings, which the template checklog would catch.

How tested

  • Unit/integration tests: 25 tests pass on 18 (fresh DB); install and -u log have no WARNING lines (checklog-equivalent).
  • Manual check (browser, Odoo 18 with demo data):
    • sheet form: sections, value columns, interpretation, BP computes "150 / 95";
    • sheet kanban card (vital signs summary, recorder);
    • encounter Vital Signs tab, "New Vital Sign" (sheet with preset category);
    • Observation wizard with two categories → line list → Save;
    • mobile width: latest-observation cards in the encounter, sheet line cards;
    • no JS console errors.
  • pre-commit clean on ni_observation.

Documentation

  • Module README.md updated (18.0, field labels, security)

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

  • The access rules that had no group become base.group_user + base.group_portal + base.group_public rows, which gives the same access as before.
  • aggregator replaces group_operator, and _has_cycle() raises odoo.exceptions.ValidationError. The SQL views use SQL() / SQL.identifier.
  • The translation bug _('…' % value) now uses a named placeholder.
  • Dropping the selection list from the report's value_type is safe: it inherits the list from ni.observation.abstract.
  • CI is green, and the series ends with [IMP] pre-commit auto fixes + [MIG].

Minor

  • display_class (related) lost default="text", so a line with no interpretation now has False instead of "text". Please check that no view's decoration-* or class expression depended on "text".

@wasud
wasud force-pushed the 18.0-mig-p1-observation branch from 5a4237c to 9299666 Compare October 19, 2026 05:09
@wasud

wasud commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Checked the display_class minor item: no change needed.

  • display_class is a non-stored related field (interpretation_id.display_class). With no interpretation the related compute gives False on 16/17 as well, and the old default="text" only applied to a new record before the compute ran. So stored data and saved records behave the same.
  • No view depends on "text": every decoration-* compares with danger/info/muted/primary/success/warning, and the only class expression (sheet kanban, ni_observation_sheet_views.xml:286) already treats 'text' and false the same (text-body).
  • ni_questionnaire copies interpretation_id.display_class (the stored field on ni.observation.interpretation) into survey.grade.color_class, so it does not read this field.

piruin and others added 27 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 18.0-mig-p1-observation branch from 9299666 to 799c947 Compare October 21, 2026 01:40
@piruin
piruin merged commit cb37aad into nirun-life:18.0 Oct 21, 2026
4 checks passed
@piruin piruin mentioned this pull request Oct 21, 2026
6 tasks done
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