Mercurial > hgweb > health
changeset 875:baca8849e0ae
health : Add scripts for prepare upgrade to version 2.0. Task #12696.
https://savannah.gnu.org/task/?12696
| author | Bruno M. Villasanti <bvillasanti@thymbra.com> |
|---|---|
| date | Wed, 03 Jul 2013 15:05:53 -0300 |
| parents | 1129f65b2a8e |
| children | 170b98bebb80 |
| files | tryton/health/__init__.py tryton/health/health.py tryton/scripts/upgrade/2.0/README tryton/scripts/upgrade/2.0/pre.py |
| diffstat | 4 files changed, 191 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health/__init__.py +++ b/tryton/health/__init__.py @@ -50,6 +50,8 @@ AlternativePersonID, PartyPatient, PartyAddress, + ProductCategory, + ProductTemplate, Product, GnuHealthSequences, PatientData,
--- a/tryton/health/health.py +++ b/tryton/health/health.py @@ -34,14 +34,15 @@ 'DomiciliaryUnit', 'MedicamentCategory', 'Medicament', 'PathologyCategory', 'PathologyGroup', 'Pathology', 'DiseaseMembers', 'ProcedureCode', 'InsurancePlan', 'Insurance', 'AlternativePersonID', - 'PartyPatient', 'PartyAddress', 'Product', 'GnuHealthSequences', - 'PatientData', 'PatientDiseaseInfo', 'Appointment', - 'AppointmentReport', 'OpenAppointmentReportStart', 'OpenAppointmentReport', - 'PatientMedication', 'PatientVaccination', 'PatientPrescriptionOrder', - 'PrescriptionLine', 'PatientEvaluation', 'Directions', - 'SecondaryCondition', 'DiagnosticHypothesis', 'SignsAndSymptoms', - 'HospitalBuilding', 'HospitalUnit', 'HospitalOR', 'HospitalWard', - 'HospitalBed'] + 'PartyPatient', 'PartyAddress', 'ProductCategory', 'ProductTemplate', + 'Product', 'GnuHealthSequences', 'PatientData', 'PatientDiseaseInfo', + 'Appointment', 'AppointmentReport', 'OpenAppointmentReportStart', + 'OpenAppointmentReport', 'PatientMedication', 'PatientVaccination', + 'PatientPrescriptionOrder', 'PrescriptionLine', 'PatientEvaluation', + 'Directions', 'SecondaryCondition', 'DiagnosticHypothesis', + 'SignsAndSymptoms', 'HospitalBuilding', 'HospitalUnit', 'HospitalOR', + 'HospitalWard', 'HospitalBed'] + class DrugDoseUnits(ModelSQL, ModelView): 'Drug Dose Unit' @@ -402,6 +403,18 @@ string='Children') @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + super(MedicamentCategory, cls).__register__(module_name) + + # Upgrade from GNU Health 1.8.1: moved who essential medicines + cursor.execute("UPDATE ir_model_data " + "SET module = REPLACE(module, %s, %s) " + "WHERE (fs_id like 'em%%' OR fs_id = 'medicament') " + " AND module = %s", + ('health', 'health_who_essential_medicines', module_name,)) + + @classmethod def __setup__(cls): super(MedicamentCategory, cls).__setup__() cls._order.insert(0, ('name', 'ASC')) @@ -483,6 +496,17 @@ storage = fields.Text('Storage Conditions') notes = fields.Text('Extra Info') + @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + super(Medicament, cls).__register__(module_name) + + # Upgrade from GNU Health 1.8.1: moved who essential medicines + cursor.execute("UPDATE ir_model_data " + "SET module = REPLACE(module, %s, %s) " + "WHERE fs_id like 'meds_em%%' AND module = %s", + ('health', 'health_who_essential_medicines', module_name,)) + def get_rec_name(self, name): return self.name.name @@ -815,6 +839,41 @@ address") +class ProductCategory(ModelSQL, ModelView): + 'Product Category' + __name__ = 'product.category' + + @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + super(ProductCategory, cls).__register__(module_name) + + # Upgrade from GNU Health 1.8.1: moved who essential medicines + cursor.execute("UPDATE ir_model_data " + "SET module = REPLACE(module, %s, %s) " + "WHERE fs_id like 'prod_medicament%%' AND module = %s", + ('health', 'health_who_essential_medicines', module_name,)) + + +class ProductTemplate(ModelSQL, ModelView): + 'Product Template' + __name__ = 'product.template' + + @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + super(ProductTemplate, cls).__register__(module_name) + + # Upgrade from GNU Health 1.8.1: moved who essential medicines + cursor.execute("UPDATE ir_model_data " + "SET module = REPLACE(module, %s, %s), " + " fs_id = REPLACE(fs_id, 'prod_em', 'templ_em') " + "WHERE fs_id like 'prod_em%%' AND module = %s " + " AND model = %s", + ('health', 'health_who_essential_medicines', module_name, + 'product.template',)) + + class Product(ModelSQL, ModelView): 'Product' __name__ = 'product.product' @@ -831,6 +890,19 @@ help='Check if the product is an insurance plan') @classmethod + def __register__(cls, module_name): + cursor = Transaction().cursor + super(Product, cls).__register__(module_name) + + # Upgrade from GNU Health 1.8.1: moved who essential medicines + cursor.execute("UPDATE ir_model_data " + "SET module = REPLACE(module, %s, %s) " + "WHERE fs_id like 'prod_em%%' AND module = %s " + " AND model = %s", + ('health', 'health_who_essential_medicines', module_name, + 'product.product',)) + + @classmethod def check_xml_record(cls, records, values): return True
new file mode 100644 --- /dev/null +++ b/tryton/scripts/upgrade/2.0/README @@ -0,0 +1,56 @@ +GNU Health migration to version 2.0 +=================================== + +This document describes the steps to follow to migrate from a version +1.8.1 of GNU Health to a version 2.0.0 + +Warning: the migration scripts involved in this migration are only meant +for a standard Tryton installation. It might not work or even break some +data if you added or modified some code to the default Tryton +distribution. + + +Preliminary task +---------------- + +As you know, before to any migration task, you should: + + - Stop Tryton server. In this case is the version 2.6.x, which is + related to GNU Health 1.8.1 + + + - And backup your database. + + For example: pg_dump gnuhealth181 > backup181.sql + + +Migration +--------- + + - Run the pre.py script (located in this directory). + + You might need to pass it some optional arguments so that it can connect + to the database. + + The connection parameters can be specified either as a 'libpq connection + string' [1] using the dsn parameter. For Example: + + python pre.py --pg="dbname=gnuhealth181 user=gnuhealth password=secret" + + The basic connection parameters are: + + dbname – the database name (only in the dsn string) + user – user name used to authenticate + password – password used to authenticate + host – database host address (defaults to UNIX socket if not provided) + port – connection port number (defaults to 5432 if not provided) + + [1] http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING + + + - Run Tryton server 2.8.x with "-d gnuhealth181 -u all" in the parameters. + + For example: ./trytond.py -d gnuhealth181 -u all + + + - You are ready to work with the new version.
new file mode 100644 --- /dev/null +++ b/tryton/scripts/upgrade/2.0/pre.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +############################################################################## +# +# GNU Health: The Free Health and Hospital Information System +# Copyright (C) 2008-2013 Luis Falcon <lfalcon@gnusolidario.org> +# Bruno M. Villasanti <bvillasanti@thymbra.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## +import optparse +import psycopg2 + + +def main(pg_cursor): + pg_cursor.execute('UPDATE "ir_model_data" ' + 'SET inherit = %s ' + 'WHERE fs_id like \'prod_em%%\' ' + ' AND model = %s AND module = %s ', + (False, 'product.template', 'health',)) + +if __name__ == '__main__': + parser = optparse.OptionParser(version='0.1') + parser.add_option('--pg', dest='dsn', help='dsn for PostgreSQL') + + opt, args = parser.parse_args() + pg_conn = None + pg_cursor = None + try: + print ">> Attempting to connect..." + pg_conn = psycopg2.connect(opt.dsn) + print ">> Contected!" + pg_cursor = pg_conn.cursor() + main(pg_cursor) + pg_conn.commit() + print ">> Successfully prepared for migration!" + finally: + if pg_cursor: + pg_cursor.close() + if pg_conn: + pg_conn.close()
