Commit 7c4f36c9 authored by Ángel Ramírez Isea's avatar Ángel Ramírez Isea
Browse files

refactor: Cambiar health_inpatient por commed_inpatient.

parent c2add30c
# Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
# Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
# Copyright 2020 LabViv.
# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
from . import models
from . import wizard
# Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
# Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
# Copyright 2020 LabViv.
# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
{
'name': 'Community Medical Inpatient',
'description': """Medical hospitalization management package. Ported from
GNU Health. This module will hold all the processes related to Inpatient
(Patient hospitalization and bed assignment):
* Patient Registration
* Bed reservation
* Hospitalization
* Nursing Plan
* Discharge Plan
* Reporting""",
'version': '13.0.0.0.1',
'category': 'Medical',
'depends': [
'base',
'commed_base',
'commed_lifestyle',
'commed_procedure',
'commed_medicament',
'commed_center',
'commed_disease',
'commed_practitioner',
'commed_medication',
'commed_evaluation'
],
'Author': 'LabViv',
'website': "https://git.labviv.org.ve/",
'license': 'GPL-3',
'data': [
'data/commed_inpatient_sequence.xml',
'data/inpatient_diets.xml',
'security/access_rights.xml',
# 'security/ir.model.access.csv',
'views/commed_inpatient_menu.xml',
'views/commed_appointment_form_view_extend.xml',
'views/commed_bed_transfer_view.xml',
'views/commed_inpatient_diet_view.xml',
'views/commed_inpatient_therapeutic_diet_view.xml',
'views/commed_inpatient_meal_view.xml',
'views/commed_inpatient_meal_order_view.xml',
'views/commed_inpatient_meal_order_item_view.xml',
'views/commed_inpatient_med_admin_time_view.xml',
'views/commed_inpatient_med_log_view.xml',
'views/commed_inpatient_registration_view.xml',
# 'views/commed_patient_ecg_form_view_extend.xml',
'views/commed_patient_evaluation_form_view_extend.xml',
'views/commed_patient_form_view_extend.xml',
'views/commed_patient_tree_view_extend.xml',
'wizard/commed_bed_transfer_create_wizard_view.xml',
'wizard/commed_inpatient_evaluation_create_wizard_view.xml',
],
'installable': True,
'maintainer': 'Julio César Méndez <mendezjcx@thoriumcorp.website>',
}
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
Copyright 2020 LabViv.
License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
-->
<odoo>
<record id="seq_commed_inpatient_registration" model="ir.sequence">
<field name="name">Inpatient Registration</field>
<field name="code">commed.inpatient_registration</field>
<field name="prefix">INPAC</field>
<field name="padding">3</field>
</record>
<record id="seq_commed_inpatient_meal_order" model="ir.sequence">
<field name="name">Inpatient Meal Order</field>
<field name="code">commed.inpatient_meal_order</field>
<field name="prefix">MEAL</field>
<field name="padding">3</field>
</record>
</odoo>
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
Copyright 2020 LabViv.
License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
-->
<odoo>
<data noupdate="1">
<record model="commed.therapeutic_diet" id="NPO">
<field name="name">Nothing by Mouth / NPO</field>
<field name="code">NPO</field>
<field name="description">Nil per Os. Withhold oral food and fluids from the patient</field>
</record>
<record model="commed.therapeutic_diet" id="GB1">
<field name="name">Gastric Bypass Stage 1</field>
<field name="code">GB1</field>
<field name="description">Sugar-Free fluids</field>
</record>
<record model="commed.therapeutic_diet" id="GB2">
<field name="name">Gastric Bypass Stage 2</field>
<field name="code">GB2</field>
<field name="description">Easily digested, semi-liquid foods to be consumed in small amounts.</field>
</record>
<record model="commed.therapeutic_diet" id="GB3">
<field name="name">Gastric Bypass Stage 3</field>
<field name="code">GB3</field>
<field name="description">Soft or pureed foods that are easy to chew and digest</field>
</record>
<record model="commed.therapeutic_diet" id="GB4">
<field name="name">Gastric Bypass Stage 4</field>
<field name="code">GB4</field>
<field name="description">Soft foods such as cooked vegetables and soft or ground meats</field>
</record>
<record model="commed.therapeutic_diet" id="FLLF">
<field name="name">Full Liquid Lactose Free</field>
<field name="code">FLLF</field>
<field name="description">This diet is frequently used for GYN surgical patients. Provides foods such as
non-cream based soups, Jell-O, juice, lactaid milk, tea and coffee
</field>
</record>
<record model="commed.therapeutic_diet" id="SLL">
<field name="name">Surgical Low Lactose</field>
<field name="code">SLL</field>
<field name="description">Soft bland foods that have low fiber content. Lactose is limited.</field>
</record>
<record model="commed.therapeutic_diet" id="PGMY">
<field name="name">Post-Gastrectomy</field>
<field name="code">PGMY</field>
<field name="description">Low sugar, low fat, low lactose foods. No fluids with meals. Small frequent
feedings
</field>
</record>
<record model="commed.therapeutic_diet" id="REG">
<field name="name">Regular</field>
<field name="code">REG</field>
<field name="description">No dietary modifications required</field>
</record>
<record model="commed.therapeutic_diet" id="MS">
<field name="name">Mechanical Soft / Dental Soft</field>
<field name="code">MS</field>
<field name="description">For patients who have difficulty in chewing or swallowing</field>
</record>
<record model="commed.therapeutic_diet" id="DYSP">
<field name="name">Dysphagia Puree</field>
<field name="code">DYSP</field>
<field name="description">For patients with problems chewing and swallowing or esophageal inflammation or
varices. Food consistency is blended. Liquids must be ordered
separately as regular, nectar, or honey.
</field>
</record>
<record model="commed.therapeutic_diet" id="DYSA">
<field name="name">Dysphagia Altered</field>
<field name="code">DYSA</field>
<field name="description">Mechanically altered. Meats are ground or minced. Foods are moist, soft-textured,
and easily formed into a bolus. All vegetables
are fork-mashable. Liquids must be ordered separately as regular, nectar, or honey.
</field>
</record>
<record model="commed.therapeutic_diet" id="DYSAD">
<field name="name">Dysphagia Advanced</field>
<field name="code">DYSAD</field>
<field name="description">Foods are nearly regular textures with the exception of hard, sticky, or crunchy
foods. Foods are moist, bite-sized pieces. All
vegetables are fork-mashable. Liquids must be ordered separately as regular, nectar, or honey.
</field>
</record>
<record model="commed.therapeutic_diet" id="CARDIAC">
<field name="name">Cardiac</field>
<field name="code">Cardiac</field>
<field name="description">Provides controlled amounts of sodium, cholesterol, saturated and total fat
</field>
</record>
<record model="commed.therapeutic_diet" id="LOWFAT">
<field name="name">Low-Fat</field>
<field name="code">LOWFAT</field>
<field name="description">Provides less than 30% energy from fat.</field>
</record>
<record model="commed.therapeutic_diet" id="NAS">
<field name="name">Not Added Salt - NAS</field>
<field name="code">NAS</field>
<field name="description">4 grams Sodium. Provides a moderate sodium restriction by eliminating foods and
condiments high in sodium
</field>
</record>
<record model="commed.therapeutic_diet" id="2GS">
<field name="name">2 gram Sodium</field>
<field name="code">2GS</field>
<field name="description">Used in the treatment of conditions characterized by edema, including the
following: cirrhosis of the
liver with ascites, Congested Heart Failure - CHF, essential hypertension and renal disease.
</field>
</record>
<record model="commed.therapeutic_diet" id="RENAL">
<field name="name">RENAL</field>
<field name="code">RENAL</field>
<field name="description">Provides adequate protein (80 - 100g/d) and limited amounts of potassium (2g) and
sodium (2g) for the dialyzed patient.
</field>
</record>
<record model="commed.therapeutic_diet" id="PRERENAL">
<field name="name">PRERENAL</field>
<field name="code">PRERENAL</field>
<field name="description">Provides limited amounts of protein (40-60g/d), potassium (2g/d), and sodium
(2g/d) for the pre-dialyzed patient.
</field>
</record>
<record model="commed.therapeutic_diet" id="GISOFT">
<field name="name">GI Soft - Low Residue</field>
<field name="code">GISOFT</field>
<field name="description">The diet limits most raw, highly-seasoned and fried foods. The diet contains only
moderate amounts of fiber
</field>
</record>
<record model="commed.therapeutic_diet" id="BLAND">
<field name="name">Bland</field>
<field name="code">BLAND</field>
<field name="description">The diet eliminates seasoned foods and condiments that may stimulate gastric
discomfort and GERD
</field>
</record>
<record model="commed.therapeutic_diet" id="CCH">
<field name="name">Consistent Carbohydrate</field>
<field name="code">CCH</field>
<field name="description">1200-3000 cal/day .The diet provides consistent amount of carbohydrate based on
caloric level to allow for optimal blood glucose control. The diet provides a Bedtime snack for all
calorie levels. (45% CHO, 25% protein, 30% fat)
</field>
</record>
<record model="commed.therapeutic_diet" id="CDD">
<field name="name">Gestational Diabetic Diet</field>
<field name="code">CDD</field>
<field name="description">1800-3000 cal/day .The diet provides consistent amount of carbohydrate based on
caloric level to allow for optimal blood glucose control. Snacks provided between meals to provide
approximately 35-40% of Kcal from CHO.
</field>
</record>
<record model="commed.therapeutic_diet" id="EMESIS">
<field name="name">Hyperemesis</field>
<field name="code">EMESIS</field>
<field name="description">The diet provides bland, room temperature or cold foods separated into solids and
liquids. Patients on this diet may request additional foods they feel can be tolerated. Patients are
encouraged to separate their intake of food and drink
</field>
</record>
<record model="commed.therapeutic_diet" id="SFM">
<field name="name">Small Frequent Meals</field>
<field name="code">SFM</field>
<field name="description">The diet provides 6 small meals daily</field>
</record>
<record model="commed.therapeutic_diet" id="CLIQUID">
<field name="name">Clear Liquid</field>
<field name="code">CLIQUID</field>
<field name="description">The diet is indicated for short-term use whenever an acute illness or surgery
causes intolerance to food; or to temporarily restrict undigested material in the GI tract. The diet is
not nutritionally adequate.
</field>
</record>
<record model="commed.therapeutic_diet" id="CLIQUIDNCS">
<field name="name">Clear Liquid / NCS</field>
<field name="code">CLIQUIDNCS</field>
<field name="description">Clear liquid diet providing sugar-free products only (No Concentrated Sugar). This
diet provides very limited amounts of carbohydrate.
</field>
</record>
<record model="commed.therapeutic_diet" id="FULLLIQUID">
<field name="name">Full Liquid</field>
<field name="code">FULLLIQUID</field>
<field name="description">The diet consists of foods that are liquid at body temperature. Foods are easy to
digest and provide minimal stimulation to the GI tract. The diet is not nutritionally adequate.
</field>
</record>
<record model="commed.therapeutic_diet" id="NEUTROPENIC">
<field name="name">Neutropenic</field>
<field name="code">NEUTROPENIC</field>
<field name="description">The diet eliminates certain foods to provide a lower level of bacteria than is
present in a typical hospital diet.
</field>
</record>
<record model="commed.therapeutic_diet" id="GLUTENFREE">
<field name="name">Gluten Free</field>
<field name="code">GLUTENFREE</field>
<field name="description">The diet omits foods processed with Gluten. The diet is the primary means of
treatment for celiac sprue
</field>
</record>
<record model="commed.therapeutic_diet" id="FINGERFOOD">
<field name="name">Finger Food</field>
<field name="code">FINGERFOOD</field>
<field name="description">Indicated for patients who may not be able to use utensils or for patients
confined to a flat-lying position who require heart healthy foods.
</field>
</record>
</data>
</odoo>
# Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
# Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
# Copyright 2020 LabViv.
# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
from . import commed_inpatient
# Copyright (C) 2008-2019 Luis Falcon <falcon@gnuhealth.org>
# Copyright (C) 2011-2019 GNU Solidario <health@gnusolidario.org>
# Copyright 2020 LabViv.
# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl.html).
from datetime import datetime
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression
class CommedTherapeuticDiet(models.Model):
_description = 'Diet Therapy'
_name = "commed.therapeutic_diet"
name = fields.Char('Diet type', required=True)
code = fields.Char('Code', required=True)
description = fields.Text('Indications', required=True)
_sql_constraints = [
('code_uniq', 'unique (code)', 'The Diet code already exists!'),
]
class CommedInpatientRegistration(models.Model):
_description = 'Patient admission history'
_name = 'commed.inpatient_registration'
name = fields.Char('Registration Code')
patient_id = fields.Many2one(
'commed.patient',
'Patient',
required=True,
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
admission_type = fields.Selection(
[
('routine', 'Routine'),
('maternity', 'Maternity'),
('elective', 'Elective'),
('urgent', 'Urgent'),
('emergency', 'Emergency'),
],
'Admission type',
index=True,
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
hospitalization_date = fields.Datetime(
'Hospitalization date',
required=True,
default=datetime.now(),
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
discharge_date = fields.Datetime(
'Expected Discharge Date',
required=True,
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
attending_physician = fields.Many2one(
'commed.practitioner',
'Attending Physician',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
operating_physician = fields.Many2one(
'commed.practitioner',
'Operating Physician',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
admission_reason = fields.Many2one(
'commed.pathology',
'Reason for Admission',
index=True,
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
bed = fields.Many2one(
'hospital.bed',
'Hospital Bed',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
nursing_plan = fields.Text(
'Nursing Plan',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
medications = fields.One2many(
'commed.medication_log',
'name',
'Medications',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
therapeutic_diets = fields.One2many(
'commed.inpatient_diet',
'name',
'Meals / Diet Program',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
nutrition_notes = fields.Text(
'Nutrition notes / directions',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
discharge_plan = fields.Text(
'Discharge Plan',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
info = fields.Text(
'Notes',
states={'done': [('readonly', True)], 'finished': [('readonly', True)]}
)
state = fields.Selection(
[
('free', 'free'),
('cancelled', 'cancelled'),
('confirmed', 'confirmed'),
('hospitalized', 'hospitalized'),
('done', 'Discharged - needs cleaning'),
('finished', 'Finished'),
],
'Status',
default='free',
)
bed_transfers = fields.One2many(
'commed.bed_transfer',
'name',
'Transfer History'
)
discharged_by = fields.Many2one(
'commed.practitioner',
'Discharged by',
help="Health Professional that discharged the patient"
)
discharge_reason = fields.Selection(
[
('home', 'Home / Selfcare'),
('transfer', 'Transferred to another institution'),
('death', 'Death'),
('against_advice', 'Left against medical advice'),
],
'Discharge Reason',
states={'hospitalized': [('readonly', False)]}
)
discharge_dx = fields.Many2one(
'commed.pathology',
'Discharge Dx',
help="Code for Discharge Diagnosis",
states={'hospitalized': [('readonly', True)]}
)
institution = fields.Many2one('commed.center', 'Institution')
# puid = fields.Char(
# 'PUID',
# help="Person Unique Identifier",
# compute='_get_patient_puid',
# search='_search_patient_puid',
# )
# @api.onchange('patient_id')
# def _get_patient_puid(self):
# return self.patient.name
# def search_patient_puid(self, operator, value):
# res = []
# res.append(('patient.name', operator, value))
# return res
_sql_constraints = [
('name_uniq', 'unique (name)', 'Registration code already exists!'),
]
def button_confirmed(self):
"""Check availability and make the hospital bed reservation. Checks
that there are not overlapping dates and status of the bed/room is not
confirmed, hospitalized or done but requiring cleaning ('done')"""
self.ensure_one()
if self.discharge_date.date() < self.hospitalization_date.date():
raise UserError('Discharge date must be after the Admission date')
bed_id = self.bed.id
cursor = self.env.cr
cursor.execute(
"SELECT COUNT(*) FROM commed_inpatient_registration \
WHERE (hospitalization_date::timestamp,discharge_date::timestamp) \
OVERLAPS (timestamp %s, timestamp %s) \
AND (state = %s or state = %s or state = %s) \
AND bed = CAST(%s AS INTEGER) ", (
self.hospitalization_date, self.discharge_date, 'confirmed',
'hospitalized', 'done', str(bed_id)
)
)
res = cursor.fetchone()
if res[0] > 0:
raise UserError('Bed is not available!')
else:
self.write({'state': 'confirmed'})
self.bed.write({'state': 'reserved'})
def button_discharge(self):
self.ensure_one()
if not self.signing_hp:
raise UserError(
'No health professional associated to this user!'
)
self.write({'state': 'done', 'discharged_by': self.signing_hp})
self.bed.write({'state': 'to_clean'})
def button_bedclean(self):
self.ensure_one()
self.write({'state': 'finished'})
self.bed.write({'state': 'free'})
def button_cancel(self):
self.ensure_one()
self.write({'state': 'cancelled'})
self.bed.write({'state': 'free'})
def button_admission(self):
self.ensure_one()
self.write({'state': 'hospitalized'})
self.bed.write({'state': 'occupied'})
@api.model_create_multi
def create(self, vals_list):
vals_list = [x.copy() for x in vals_list]
for values in vals_list:
if not values.get('name'):
values['name'] = self.env['ir.sequence'].\
next_by_code('commed.inpatient_registration')
return super(CommedInpatientRegistration, self).create(vals_list)
@api.constrains('admission_reason', 'state', 'discharge_dx')
def validate(self):
super(CommedInpatientRegistration, self).validate()
for registration in self:
registration.check_discharge_context()
def check_discharge_context(self):
if (
(
not self.discharge_reason or not self.discharge_dx or not
self.admission_reason
) and self.state == 'done'
):
raise UserError(
'Need Admission and Discharge reasons as well as Discharge Dx'
)
def _get_name(self):
"""Format Registration ID: Patient:Bed"""
if self.patient:
return self.name + ':' + self.bed.rec_name + ':' + \
self.patient.rec_name
else:
return self.name
@api.model
def _name_search(
self, name, args=None, operator='ilike', limit=100, name_get_uid=None