Mercurial > hgweb > health
changeset 2812:a0ed9d683c19
task #14735: Upgrade to Tryton 4.6 Kernel. Migrate core module
| author | Luis Falcon <falcon@gnu.org> |
|---|---|
| date | Mon, 20 Nov 2017 17:41:31 +0000 |
| parents | e8678dd7cbca |
| children | fc5617186ca8 |
| files | tryton/health/__init__.py tryton/health/data/health_sequences.xml tryton/health/health.py |
| diffstat | 3 files changed, 127 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health/__init__.py +++ b/tryton/health/__init__.py @@ -76,6 +76,7 @@ AlternativePersonID, Product, GnuHealthSequences, + GnuHealthSequenceSetup, PatientData, PatientDiseaseInfo, Appointment,
--- a/tryton/health/data/health_sequences.xml +++ b/tryton/health/data/health_sequences.xml @@ -16,12 +16,7 @@ <field name="number_increment" eval="1"/> </record> - <record model="ir.property" id="property_patient_evaluation_sequence"> - <field name="field" - search="[('model.model', '=', 'gnuhealth.sequences'), ('name', '=', 'patient_evaluation_sequence')]"/> - <field name="value" eval="'ir.sequence,' + str(ref('seq_gnuhealth_patient_evaluation'))"/> - </record> - + <!-- Sequences for Prescriptions --> <record id="seq_type_gnuhealth_prescription" model="ir.sequence.type"> @@ -36,12 +31,6 @@ <field name="number_increment" eval="1"/> </record> - <record model="ir.property" id="property_prescription_sequence"> - <field name="field" - search="[('model.model', '=', 'gnuhealth.sequences'), ('name', '=', 'prescription_sequence')]"/> - <field name="value" eval="'ir.sequence,' + str(ref('seq_gnuhealth_prescription'))"/> - </record> - <!-- Sequences for Appointments --> <record id="seq_type_gnuhealth_appointment" model="ir.sequence.type"> @@ -55,12 +44,7 @@ <field eval="0" name="padding"/> </record> - <record model="ir.property" id="property_appointment_sequence"> - <field name="field" - search="[('model.model', '=', 'gnuhealth.sequences'), ('name', '=', 'appointment_sequence')]"/> - <field name="value" eval="'ir.sequence,' + str(ref('seq_gnuhealth_appointment'))"/> - </record> - + <!-- Sequences for Patient --> <record id="seq_type_gnuhealth_patient" model="ir.sequence.type"> @@ -73,12 +57,6 @@ <field name="prefix">PAC</field> <field name="padding">3</field> </record> - - <record model="ir.property" id="property_party_sequence"> - <field name="field" - search="[('model.model', '=', 'gnuhealth.sequences'), ('name', '=', 'patient_sequence')]"/> - <field name="value" eval="'ir.sequence,' + str(ref('seq_gnuhealth_patient'))"/> - </record> - + </data> </tryton>
--- a/tryton/health/health.py +++ b/tryton/health/health.py @@ -36,7 +36,8 @@ from sql import Literal, Join, Table, Null from sql.functions import Overlay, Position -from trytond.model import ModelView, ModelSingleton, ModelSQL, fields, Unique +from trytond.model import ModelView, ModelSingleton, ModelSQL, \ + ValueMixin, fields, Unique from trytond.wizard import Wizard, StateAction, StateView, Button from trytond.transaction import Transaction from trytond import backend @@ -44,6 +45,8 @@ from trytond.pool import Pool from trytond.tools import grouped_slice, reduce_ids from trytond.backend import name as backend_name +from trytond.tools.multivalue import migrate_property + from uuid import uuid4 import string @@ -65,7 +68,7 @@ 'Pathology', 'DiseaseMembers', 'ProcedureCode', 'BirthCertExtraInfo','DeathCertExtraInfo', 'DeathUnderlyingCondition', 'InsurancePlan', 'Insurance', 'AlternativePersonID', - 'Product', 'GnuHealthSequences', 'PatientData', + 'Product', 'GnuHealthSequences', 'GnuHealthSequenceSetup','PatientData', 'PatientDiseaseInfo','Appointment', 'AppointmentReport', 'OpenAppointmentReportStart', 'OpenAppointmentReport', 'PatientPrescriptionOrder', 'PrescriptionLine', 'PatientMedication', @@ -74,6 +77,9 @@ 'SignsAndSymptoms', 'PatientECG', 'ProductTemplate'] +sequences = ['patient_sequence', 'patient_evaluation_sequence', + 'appointment_sequence', 'prescription_sequence'] + def compute_age_from_dates(dob, deceased, dod, gender, caller, extra_date): """ Get the person's age. @@ -123,7 +129,9 @@ else: return None - + + + class DomiciliaryUnit(ModelSQL, ModelView): 'Domiciliary Unit' @@ -2526,27 +2534,133 @@ # GNU HEALTH SEQUENCES -class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView): +class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView, ValueMixin): 'Standard Sequences for GNU Health' __name__ = 'gnuhealth.sequences' - patient_sequence = fields.Property(fields.Many2One( + patient_sequence = fields.MultiValue(fields.Many2One( 'ir.sequence', 'Patient Sequence', required=True, domain=[('code', '=', 'gnuhealth.patient')])) - patient_evaluation_sequence = fields.Property(fields.Many2One( + patient_evaluation_sequence = fields.MultiValue(fields.Many2One( 'ir.sequence', 'Patient Evaluation Sequence', required=True, domain=[('code', '=', 'gnuhealth.patient.evaluation')])) - - appointment_sequence = fields.Property(fields.Many2One( + + appointment_sequence = fields.MultiValue(fields.Many2One( 'ir.sequence', 'Appointment Sequence', required=True, domain=[('code', '=', 'gnuhealth.appointment')])) - prescription_sequence = fields.Property(fields.Many2One( + prescription_sequence = fields.MultiValue(fields.Many2One( 'ir.sequence', 'Prescription Sequence', required=True, domain=[('code', '=', 'gnuhealth.prescription.order')])) + @classmethod + def multivalue_model(cls, field): + pool = Pool() + + if field in sequences: + return pool.get('gnuhealth.sequence.setup') + return super(GnuHealthSequences, cls).multivalue_model(field) + + + @classmethod + def default_patient_sequence(cls): + return cls.multivalue_model( + 'patient_sequence').default_patient_sequence() + + + @classmethod + def default_patient_evaluation_sequence(cls): + return cls.multivalue_model( + 'patient_evaluation_sequence').default_patient_evaluation_sequence() + + @classmethod + def default_appointment_sequence(cls): + return cls.multivalue_model( + 'appointment_sequence').default_appointment_sequence() + + @classmethod + def default_prescription_sequence(cls): + return cls.multivalue_model( + 'prescription_sequence').default_prescription_sequence() + + + +# SEQUENCE SETUP +class GnuHealthSequenceSetup(ModelSQL, ValueMixin): + "GNU Health Sequence Setup" + __name__ = 'gnuhealth.sequence.setup' + + patient_sequence = fields.Many2One('ir.sequence', 'Patient Sequence', + required=True, + domain=[('code', '=', 'gnuhealth.patient')]) + + + patient_evaluation_sequence = fields.Many2One('ir.sequence', + 'Patient Evaluation Sequence', required=True, + domain=[('code', '=', 'gnuhealth.patient.evaluation')]) + + + appointment_sequence = fields.Many2One('ir.sequence', + 'Appointment Sequence', required=True, + domain=[('code', '=', 'gnuhealth.appointment')]) + + prescription_sequence = fields.Many2One('ir.sequence', + 'Prescription Sequence', required=True, + domain=[('code', '=', 'gnuhealth.prescription.order')]) + + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + exist = TableHandler.table_exist(cls._table) + + super(GnuHealthSequenceSetup, cls).__register__(module_name) + + if not exist: + cls._migrate_property([], [], []) + + @classmethod + def _migrate_property(cls, field_names, value_names, fields): + field_names.extend(sequences) + value_names.extend(sequences) + migrate_property( + 'gnuhealth.sequences', field_names, cls, value_names, + fields=fields) + + @classmethod + def default_patient_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'health', 'seq_gnuhealth_patient') + + @classmethod + def default_patient_evaluation_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'health', 'seq_gnuhealth_patient_evaluation') + + @classmethod + def default_appointment_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'health', 'seq_gnuhealth_appointment') + + @classmethod + def default_prescription_sequence(cls): + pool = Pool() + ModelData = pool.get('ir.model.data') + return ModelData.get_id( + 'health', 'seq_gnuhealth_prescription') + + +# END SEQUENCE SETUP , MIGRATION FROM FIELDS.PROPERTY + + + # PATIENT GENERAL INFORMATION class PatientData(ModelSQL, ModelView): 'Patient related information'
