DRY-up listing NHS organisation types

The model should be the source of truth for this.
This commit is contained in:
Ben Thorner
2022-03-22 17:01:54 +00:00
parent 8f55972aae
commit 21eea0189d
2 changed files with 13 additions and 23 deletions

View File

@@ -23,12 +23,16 @@ class Organisation(JSONModel, SortByNameMixin):
TYPE_SCHOOL_OR_COLLEGE = 'school_or_college' TYPE_SCHOOL_OR_COLLEGE = 'school_or_college'
TYPE_OTHER = 'other' TYPE_OTHER = 'other'
TYPES = ( NHS_TYPES = (
(TYPE_CENTRAL, 'Central government'),
(TYPE_LOCAL, 'Local government'),
(TYPE_NHS_CENTRAL, 'NHS central government agency or public body'), (TYPE_NHS_CENTRAL, 'NHS central government agency or public body'),
(TYPE_NHS_LOCAL, 'NHS Trust or Clinical Commissioning Group'), (TYPE_NHS_LOCAL, 'NHS Trust or Clinical Commissioning Group'),
(TYPE_NHS_GP, 'GP practice'), (TYPE_NHS_GP, 'GP practice'),
)
TYPES = (
(TYPE_CENTRAL, 'Central government'),
(TYPE_LOCAL, 'Local government'),
) + NHS_TYPES + (
(TYPE_EMERGENCY_SERVICE, 'Emergency service'), (TYPE_EMERGENCY_SERVICE, 'Emergency service'),
(TYPE_SCHOOL_OR_COLLEGE, 'School or college'), (TYPE_SCHOOL_OR_COLLEGE, 'School or college'),
(TYPE_OTHER, 'Other'), (TYPE_OTHER, 'Other'),

View File

@@ -1,5 +1,7 @@
from app.models.organisation import Organisation from app.models.organisation import Organisation
NHS_TYPES = dict(Organisation.NHS_TYPES).keys()
def get_email_choices(service): def get_email_choices(service):
organisation_branding_id = service.organisation.email_branding_id if service.organisation else None organisation_branding_id = service.organisation.email_branding_id if service.organisation else None
@@ -22,22 +24,14 @@ def get_email_choices(service):
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name)) yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
if ( if (
service.organisation_type in { service.organisation_type in NHS_TYPES
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_GP,
}
and service_branding_name != 'NHS' and service_branding_name != 'NHS'
): ):
yield ('nhs', 'NHS') yield ('nhs', 'NHS')
if ( if (
service.organisation service.organisation
and service.organisation_type not in { and service.organisation_type not in NHS_TYPES
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_GP,
}
and ( and (
service_branding_id is None service_branding_id is None
or service_branding_id != organisation_branding_id or service_branding_id != organisation_branding_id
@@ -52,22 +46,14 @@ def get_letter_choices(service):
service_branding_name = service.letter_branding_name service_branding_name = service.letter_branding_name
if ( if (
service.organisation_type in { service.organisation_type in NHS_TYPES
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_GP,
}
and service_branding_name != 'NHS' and service_branding_name != 'NHS'
): ):
yield ('nhs', 'NHS') yield ('nhs', 'NHS')
if ( if (
service.organisation service.organisation
and service.organisation_type not in { and service.organisation_type not in NHS_TYPES
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_GP,
}
and ( and (
service_branding_id is None service_branding_id is None
or service_branding_id != organisation_branding_id or service_branding_id != organisation_branding_id