Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] medical_clinical_impression: add impression tree view #201

Open
wants to merge 7 commits into
base: 14.0
Choose a base branch
from
18 changes: 16 additions & 2 deletions medical_clinical_impression/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
"medical_workflow",
"medical_clinical_condition",
"medical_administration_practitioner_specialty",
"web_ir_actions_act_multi",
"web_ir_actions_act_view_reload",
"medical_procedure_external",
"medical_product_request",
],
"data": [
"views/res_users.xml",
"views/medical_clinical_impression_template.xml",
"views/assets.xml",
"security/medical_security.xml",
"security/ir.model.access.csv",
Expand All @@ -27,7 +33,15 @@
"views/medical_clinical_finding.xml",
"views/medical_family_member_history.xml",
"reports/medical_impression_report.xml",
# "views/impression_view.xml",
],
"qweb": [
"static/src/xml/widget_warning_dropdown.xml",
"static/src/xml/medical_impression_view.xml",
],
"demo": [
"demo/medical_clinical_impression_template.xml",
"demo/medical_demo.xml",
"demo/medical_security.xml",
],
"qweb": ["static/src/xml/widget_warning_dropdown.xml"],
"demo": ["demo/medical_demo.xml"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 CreuBlanca
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<!-- TODO
<record model="medical.clinical.impression.template" id="medical_clinical_impression_template_demo_1">
<field name="name">...</field>
</record>
-->

</odoo>
1 change: 0 additions & 1 deletion medical_clinical_impression/demo/medical_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
</record>
<record id="encounter_01_patient_01" model="medical.encounter">
<field name="patient_id" ref="medical_base.patient_01" />
<field name="center_id" ref="medical_administration_center.partner_center_1" />
</record>
<record id="impression_01_patient_01" model="medical.clinical.impression">
<field name="fhir_state">completed</field>
Expand Down
25 changes: 25 additions & 0 deletions medical_clinical_impression/demo/medical_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2017 Eficent Business and IT Consulting Services, S.L.
Copyright 2017 Creu Blanca
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-->
<odoo>
<record id="base.user_admin" model="res.users">
<field
name="groups_id"
eval="[(4,ref('medical_base.group_medical_doctor_manager'))]"
/>
<field
name="specialty_ids"
eval="[(6, 0, [ref('medical_clinical_impression.specialty_cardiology')])]"
/>
</record>
<record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4,ref('medical_base.group_medical_doctor'))]" />
<field
name="specialty_ids"
eval="[(6, 0, [ref('medical_clinical_impression.specialty_gynecology')])]"
/>
</record>
</odoo>
3 changes: 3 additions & 0 deletions medical_clinical_impression/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
from . import medical_specialty
from . import medical_family_member_history
from . import medical_condition
from . import medical_clinical_impression_template
from . import ir_ui_view
from . import res_users
11 changes: 11 additions & 0 deletions medical_clinical_impression/models/ir_ui_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class View(models.Model):
_inherit = "ir.ui.view"

type = fields.Selection(
selection_add=[
("medical_impression", "Medical Impression Vizualisation")
]
)
65 changes: 60 additions & 5 deletions medical_clinical_impression/models/medical_clinical_impression.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MedicalClinicalImpression(models.Model):
_inherit = ["medical.event", "mail.thread", "mail.activity.mixin"]
_description = "Medical Clinical Impression"
_conditions = "condition_ids"
_order = "validation_date desc, id"
_order = "validation_date desc, id desc"
_rec_name = "internal_identifier"

@api.model
Expand Down Expand Up @@ -47,6 +47,7 @@ def _get_states(self):
# FHIR: patient

validation_date = fields.Datetime(readonly=True)

# FHIR: date

validation_user_id = fields.Many2one(
Expand Down Expand Up @@ -75,7 +76,7 @@ def _get_states(self):
related="patient_id.medical_condition_ids",
)

condition_count = fields.Integer(
medical_condition_count = fields.Integer(
related="patient_id.medical_condition_count"
)

Expand All @@ -91,6 +92,41 @@ def _get_states(self):
"of the current encounter in the tree view",
compute="_compute_current_encounter",
)
template_id = fields.Many2one(
"medical.clinical.impression.template",
domain="[('specialty_id', '=', specialty_id)]",
readonly=True,
states={"draft": [("readonly", False)]},
)

medical_procedure_external_request_ids = fields.Many2many(
"medical.procedure.external.request",
compute="_compute_procedure_external_request",
)

procedure_external_request_count = fields.Integer(
compute="_compute_procedure_external_request",
)
prueba = fields.Char()

image = fields.Binary(
string="image", store=True, copy=False, attachment=True
)

@api.depends("medical_procedure_external_request_ids")
def _compute_procedure_external_request(self):
for record in self:
record.medical_procedure_external_request_ids = self.env[
"medical.procedure.external.request"
].search([("encounter_id", "=", record.encounter_id.id)])
record.procedure_external_request_count = len(
record.medical_procedure_external_request_ids
)

@api.onchange("template_id")
def _onchange_template_id(self):
if self.template_id and self.state == "draft":
self.description = self.template_id.description

@api.model
def _get_internal_identifier(self, vals):
Expand Down Expand Up @@ -143,16 +179,16 @@ def _create_allergies_from_findings(self):
}
)

def _validate_clinical_impression_fields(self):
def _validate_clinical_impression_fields(self, **kwargs):
return {
"fhir_state": "completed",
"validation_date": fields.Datetime.now(),
"validation_user_id": self.env.user.id,
}

def validate_clinical_impression(self):
def validate_clinical_impression(self, **kwargs):
self.ensure_one()
self.write(self._validate_clinical_impression_fields())
self.write(self._validate_clinical_impression_fields(**kwargs))
self._create_conditions_from_findings()
self._create_allergies_from_findings()

Expand All @@ -173,3 +209,22 @@ def cancel_clinical_impression(self):
self.ensure_one()
self._cancel_related_conditions()
self.write(self._cancel_clinical_impression_fields())

def action_create_medical_procedure_from(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"medical_procedure_external.medical_encounter_create_procedure_external_act_window"
)
action["context"] = {
"default_encounter_id": self.encounter_id.id,
}
return action

def action_show_medical_procedure(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"medical_procedure_external.medical_procedure_external_request_act_window"
)
# TODO: relate requests directly to the impression?
action["domain"] = [("encounter_id", "=", self.encounter_id.id)]
return action
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 CreuBlanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MedicalClinicalImpressionTemplate(models.Model):

_name = "medical.clinical.impression.template"
_description = "Medical Clinical Impression Template" # TODO

name = fields.Char(required=True)
description = fields.Char(required=True)
specialty_id = fields.Many2one(
"medical.specialty",
required=False,
domain="[('specialty_id', '=', specialty_id)]",
)
2 changes: 1 addition & 1 deletion medical_clinical_impression/models/medical_encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MedicalEncounter(models.Model):
inverse_name="encounter_id",
)

impression_specialty_ids = fields.Many2many(
impression_specialty_ids = fields.One2many(
"medical.specialty", related="patient_id.impression_specialty_ids"
)

Expand Down
92 changes: 81 additions & 11 deletions medical_clinical_impression/models/medical_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MedicalPatient(models.Model):
"medical.clinical.impression",
inverse_name="patient_id",
)
impression_specialty_ids = fields.Many2many(
impression_specialty_ids = fields.One2many(
"medical.specialty", compute="_compute_impression_specialties"
)

Expand All @@ -24,16 +24,6 @@ class MedicalPatient(models.Model):
compute="_compute_family_history_count"
)

condition_ids = fields.One2many(
comodel_name="medical.condition",
string="Conditions Warning",
related="medical_impression_ids.condition_ids",
)

condition_count = fields.Integer(
related="medical_impression_ids.condition_count"
)

@api.depends("family_history_ids")
def _compute_family_history_count(self):
self.family_history_count = len(self.family_history_ids)
Expand All @@ -60,6 +50,43 @@ def action_view_clinical_impressions(self):
}
return action

def action_view_family_history_tree(self):
self.ensure_one()
view_id = self.env.ref(
"medical_clinical_impression.medical_family_member_history_view_tree"
).id
ctx = dict(self._context)
ctx["default_patient_id"] = self.id
return {
"type": "ir.actions.act_window",
"res_model": "medical.family.member.history",
"name": _("Create family member history 2"),
"view_type": "list,form",
"view_mode": "tree",
"views": [(view_id, "list"), (False, "form")],
"context": ctx,
"domain": [("patient_id", "=", self.id)],
}

def action_view_medical_procedure_tree(self):
self.ensure_one()
view_id = self.env.ref(
"medical_clinical_procedure.medical_procedure_view_tree"
).id
ctx = dict(self._context)
ctx["default_patient_id"] = self.id

return {
"type": "ir.actions.act_window",
"res_model": "medical.procedure",
"name": "Medical Procedures",
"view_type": "list",
"view_mode": "tree",
"views": [(view_id, "list")],
"context": ctx,
"domain": [("patient_id", "=", self.id)],
}

def action_view_family_history(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
Expand Down Expand Up @@ -90,3 +117,46 @@ def create_family_member_history(self):
"target": "new",
"context": ctx,
}

def get_patient_data(self):
condition_names = []
allergy_names = []
for i in self.medical_condition_ids:
if i.is_allergy:
allergy_names.append(
"%s (%s)" % (i.name, i.create_date.date())
)
else:
condition_names.append(
"%s (%s)" % (i.name, i.create_date.date())
)
gender = False
if self.gender:
for item in self._fields["gender"]._description_selection(
self.env
):
if item[0] == self.gender:
gender = item[1]
continue
return {
"name": self.name,
"condition_count": self.medical_condition_count,
"condition_names": condition_names,
"allergy_names": allergy_names,
"gender": gender,
"patient_age": self.patient_age,
}

def create_impression(self):
self.ensure_one()
ctx = self.env.context.copy()
ctx.update({"impression_view": True, "default_patient_id": self.id})
if ctx.get("default_specialty_id"):
self.env["create.impression.from.patient"].with_context(
**ctx
).create({}).generate()
return {"type": "ir.actions.act_view_reload"}
xmlid = "medical_clinical_impression.create_impression_from_patient_act_window"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
action["context"] = ctx
return action
13 changes: 10 additions & 3 deletions medical_clinical_impression/models/medical_specialty.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from odoo import fields, models
from odoo.osv import expression
from odoo.tools.safe_eval import safe_eval


class MedicalSpecialty(models.Model):
Expand All @@ -23,6 +24,11 @@ class MedicalSpecialty(models.Model):
impressions_in_progress_count = fields.Integer(
compute="_compute_impression_info"
)
specialty_id = fields.Many2one(
"medical.specialty",
required=False,
domain="[('specialty_id', '=', self.id)]",
)

def _compute_impression_info(self):
for rec in self:
Expand Down Expand Up @@ -93,17 +99,18 @@ def get_specialty_impression(self):
patient_id = encounter_id.patient_id
else:
return False
ctx_dict["default_encounter_id"] = encounter_id.id
ctx_dict["search_default_filter_not_cancelled"] = True
ctx_dict["active_id"] = patient_id.id
domain = expression.AND(
[
result["domain"],
safe_eval(result["domain"], ctx_dict),
[
("specialty_id", "=", self.id),
("patient_id", "=", patient_id.id),
],
]
)
ctx_dict["default_encounter_id"] = encounter_id.id
ctx_dict["search_default_filter_not_cancelled"] = True
result["domain"] = domain
result["context"] = ctx_dict
return result
Loading
Loading