|
| 1 | +# Copyright 2021 Creu Blanca |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 3 | + |
| 4 | +from odoo import _, fields, models |
| 5 | + |
| 6 | + |
| 7 | +class MedicalEncounter(models.Model): |
| 8 | + |
| 9 | + _inherit = "medical.encounter" |
| 10 | + |
| 11 | + medical_impression_ids = fields.One2many( |
| 12 | + "medical.clinical.impression", |
| 13 | + inverse_name="encounter_id", |
| 14 | + ) |
| 15 | + |
| 16 | + impression_specialty_ids = fields.Many2many( |
| 17 | + "medical.specialty", related="patient_id.impression_specialty_ids" |
| 18 | + ) |
| 19 | + |
| 20 | + family_history_ids = fields.One2many( |
| 21 | + "medical.family.member.history", |
| 22 | + related="patient_id.family_history_ids", |
| 23 | + ) |
| 24 | + |
| 25 | + family_history_count = fields.Integer(related="patient_id.family_history_count") |
| 26 | + |
| 27 | + def action_view_clinical_impressions(self): |
| 28 | + self.ensure_one() |
| 29 | + action = self.env["ir.actions.act_window"]._for_xml_id( |
| 30 | + "medical_clinical_impression." "medical_clinical_impression_act_window" |
| 31 | + ) |
| 32 | + action["domain"] = [ |
| 33 | + ("patient_id", "=", self.patient_id.id), |
| 34 | + ] |
| 35 | + action["context"] = { |
| 36 | + "default_encounter_id": self.id, |
| 37 | + "search_default_filter_not_cancelled": True, |
| 38 | + } |
| 39 | + return action |
| 40 | + |
| 41 | + def action_view_family_history(self): |
| 42 | + self.ensure_one() |
| 43 | + action = self.env["ir.actions.act_window"]._for_xml_id( |
| 44 | + "medical_clinical_impression." "medical_family_member_history_action" |
| 45 | + ) |
| 46 | + action["domain"] = [ |
| 47 | + ("patient_id", "=", self.patient_id.id), |
| 48 | + ] |
| 49 | + action["context"] = {"default_patient_id": self.patient_id.id} |
| 50 | + return action |
| 51 | + |
| 52 | + def create_family_member_history(self): |
| 53 | + self.ensure_one() |
| 54 | + view_id = self.env.ref( |
| 55 | + "medical_clinical_impression.medical_family_member_history_view_form" |
| 56 | + ).id |
| 57 | + ctx = dict(self._context) |
| 58 | + ctx["default_patient_id"] = self.patient_id.id |
| 59 | + return { |
| 60 | + "type": "ir.actions.act_window", |
| 61 | + "res_model": "medical.family.member.history", |
| 62 | + "name": _("Create family member history"), |
| 63 | + "view_type": "form", |
| 64 | + "view_mode": "form", |
| 65 | + "views": [(view_id, "form")], |
| 66 | + "target": "new", |
| 67 | + "context": ctx, |
| 68 | + } |
0 commit comments