Mercurial > hgweb > health
changeset 5009:ac497c880320
health: migrate raise_user_error methods
| author | Luis Falcon <falcon@gnuhealth.org> |
|---|---|
| date | Mon, 24 Jan 2022 14:01:14 +0000 |
| parents | ef54abef7fba |
| children | 754c5341bbb7 |
| files | tryton/health/data/messages/messages.xml tryton/health/exceptions.py tryton/health/health.py |
| diffstat | 3 files changed, 58 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health/data/messages/messages.xml +++ b/tryton/health/data/messages/messages.xml @@ -30,5 +30,20 @@ <record model="ir.message" id="msg_no_appointment_selected"> <field name="text">SM-CORE-0009: You need to select one appointment</field> </record> + <record model="ir.message" id="msg_must_be_a_person"> + <field name="text">SM-CORE-0010: The Person field must be set if the party is a health professional or a patient</field> + </record> + <record model="ir.message" id="msg_dup_official_name"> + <field name="text">SM-CORE-0011: The person can have only one official name</field> + </record> + <record model="ir.message" id="msg_fed_account_mismatch"> + <field name="text">SM-CORE-0012: The account differs from the person federation account</field> + </record> + <record model="ir.message" id="msg_birth_cert_date_mismatch"> + <field name="text">SM-CORE-0013: The date on the Party differs from the certificate</field> + </record> + <record model="ir.message" id="msg_can_not_modify_vaccination"> + <field name="text">SM-CORE-0014: This vaccination is at state DONE. You can no longer modify it</field> + </record> </data> </tryton>
--- a/tryton/health/exceptions.py +++ b/tryton/health/exceptions.py @@ -1,6 +1,6 @@ # This file is part of GNU Health. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond.exceptions import UserError, UserWarning +from trytond.exceptions import UserError from trytond.model.exceptions import ValidationError @@ -35,5 +35,26 @@ class EvaluationEndBeforeStart(ValidationError): pass + +class MustBeAPerson(ValidationError): + pass + + +class DupOfficialName(ValidationError): + pass + + +class FedAccountMismatch(ValidationError): + pass + + +class BirthCertDateMismatch(ValidationError): + pass + + class NoAppointmentSelected(UserError): pass + + +class CanNotModifyVaccination(UserError): + pass
--- a/tryton/health/health.py +++ b/tryton/health/health.py @@ -53,7 +53,9 @@ from .exceptions import ( WrongDateofBirth, DateHealedBeforeDx, EndTreatmentDateBeforeStart, MedEndDateBeforeStart, NextDoseBeforeFirst, DrugPregnancySafetyCheck, - EvaluationEndBeforeStart, NoAssociatedHealthProfessional + EvaluationEndBeforeStart, MustBeAPerson, NoAssociatedHealthProfessional, + DupOfficialName, FedAccountMismatch, BirthCertDateMismatch, + CanNotModifyVaccination ) from .core import (get_institution, compute_age_from_dates, @@ -843,9 +845,9 @@ # are unchecked when is_person is False if not self.is_person and (self.is_patient or self.is_healthprof): - self.raise_user_error( - "The Person field must be set if the party is a health" - " professional or a patient") + raise MustBeAPerson( + gettext('health.msg_must_be_a_person') + ) def validate_official_name(self): # Only allow one official name on the party name @@ -854,8 +856,9 @@ [("party", "=", self.id), ("use", "=", 'official')],) if (officialnames > 1): - self.raise_user_error( - "The person can have only one official name") + raise DupOfficialName( + gettext('health.msg_dup_official_name') + ) @classmethod def view_attributes(cls): @@ -1049,8 +1052,9 @@ def validate_account(self): if (self.person.federation_account != self.federation_account): - self.raise_user_error( - "The account differs from the person federation account !") + raise FedAccountMismatch( + gettext('health.msg_fed_account_mismatch') + ) @classmethod def create(cls, vlist): @@ -2396,9 +2400,6 @@ # and write the name of the certifying health professional signing_hp = get_health_professional() - if not signing_hp: - cls.raise_user_error( - "No health professional associated to this user !") cls.write(certificates, { 'state': 'signed', @@ -2476,9 +2477,6 @@ party = [] signing_hp = get_health_professional() - if not signing_hp: - cls.raise_user_error( - "No health professional associated to this user !") cls.write(certificates, { 'state': 'signed', @@ -2683,8 +2681,9 @@ def validate_dob(self): if (self.name.dob != self.dob): - self.raise_user_error( - "The date on the Party differs from the certificate !") + raise BirthCertDateMismatch( + gettext('health.birth_cert_date_mismatch') + ) class DeathCertificate (ModelSQL, ModelView): @@ -3996,9 +3995,9 @@ def write(cls, vaccinations, vals): # Don't allow to modify the record if the vaccination has been signed if vaccinations[0].state == 'done': - cls.raise_user_error( - "This vaccination is at state Done\n" - "You can no longer modify it.") + raise CanNotModifyVaccination( + gettext('health.can_not_modify_vaccination') + ) return super(PatientVaccination, cls).write(vaccinations, vals) @classmethod @@ -4909,7 +4908,9 @@ def check_health_professional(self): if not self.healthprof: - self.raise_user_error('health_professional_warning') + raise NoAssociatedHealthProfessional(gettext( + ('health.msg_no_associated_health_professional')) + ) @staticmethod def default_healthprof():
