Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ni_observation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Observation",
"summary": "Clinical observations including vital signs, lab results, and measurements",
"version": "16.0.0.6.2",
"version": "16.0.0.6.3",
"development_status": "Alpha",
"category": "Healthcare",
"author": "NSTDA, Piruin P.",
Expand Down
4 changes: 2 additions & 2 deletions ni_observation/models/ni_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _compute_history(self):
for rec in self:
rec.history_ids = self.env["ni.observation"].search(
[
("patient_id", "=", self.patient_id.id),
("type_id", "=", self.type_id.get_display_type().ids),
("patient_id", "=", rec.patient_id.id),
("type_id", "in", rec.type_id.get_display_type().ids),
("value", "!=", False),
],
order="occurrence desc",
Expand Down
1 change: 1 addition & 0 deletions ni_observation/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import test_compute_code
from . import test_inverse_value
from . import test_latest_observation
from . import test_observation_history
56 changes: 56 additions & 0 deletions ni_observation/tests/test_observation_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2026 NSTDA

from odoo import fields
from odoo.tests import common


class TestObservationHistory(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
partner = cls.env["res.partner"].create({"name": "History Test Patient"})
cls.patient = cls.env["ni.patient"].create({"partner_id": partner.id})
cls.encounter = cls.env["ni.encounter"].create(
{
"patient_id": cls.patient.id,
"class_id": cls.env.ref("ni_patient.class_IMP").id,
"period_start": fields.Datetime.now(),
}
)
cls.type_a, cls.type_b = cls.env["ni.observation.type"].create(
[
{
"name": f"History Test {code}",
"code": f"test-history-{code}",
"value_type": "int",
"min": 0,
"max": 100,
}
for code in ("a", "b")
]
)

def _observe(self, obs_type, value, occurrence):
return self.env["ni.observation"].create(
{
"patient_id": self.patient.id,
"encounter_id": self.encounter.id,
"type_id": obs_type.id,
"occurrence": occurrence,
"value_int": value,
}
)

def test_history_of_several_observations(self):
"""Each observation's history holds its own type only, also when
several observations are read together."""
a1 = self._observe(self.type_a, 1, "2025-01-01 08:00:00")
a2 = self._observe(self.type_a, 2, "2025-01-02 08:00:00")
b1 = self._observe(self.type_b, 3, "2025-01-02 08:00:00")
self.env.invalidate_all()
observations = a2 | b1
observations.mapped("history_ids")
self.assertEqual(a2.history_ids, a2 | a1)
self.assertEqual(a2.history_count, 2)
self.assertEqual(b1.history_ids, b1)
self.assertEqual(b1.history_count, 1)
Loading