Merge pull request #3104 from alphagov/gp

Add ‘GP’ as an organisation type
This commit is contained in:
Chris Hill-Scott
2019-08-28 17:18:15 +01:00
committed by GitHub
7 changed files with 50 additions and 53 deletions
+24 -30
View File
@@ -45,6 +45,7 @@ from app.main.validators import (
ValidEmail, ValidEmail,
ValidGovEmail, ValidGovEmail,
) )
from app.models.organisation import Organisation
from app.models.roles_and_permissions import permissions, roles from app.models.roles_and_permissions import permissions, roles
from app.utils import guess_name_from_email_address from app.utils import guess_name_from_email_address
@@ -242,33 +243,23 @@ class ForgivingIntegerField(StringField):
return super().__call__(value=value, **kwargs) return super().__call__(value=value, **kwargs)
def organisation_type(label='Who runs this service?'): class OrganisationTypeField(RadioField):
return RadioField( def __init__(
label, self,
choices=[ *args,
('central', 'Central government'), include_only=None,
('local', 'Local government'), validators=None,
('nhs_central', 'NHS central government agency or public body'), **kwargs
('nhs_local', 'NHS Trust or Clinical Commissioning Group'), ):
('nhs_local', 'GP practice'), super().__init__(
('emergency_service', 'Emergency service'), *args,
('school_or_college', 'School or college'), choices=[
('other', 'Other'), (value, label) for value, label in Organisation.TYPES
], if not include_only or value in include_only
validators=[DataRequired()], ],
) validators=[DataRequired()] + (validators or []),
**kwargs
)
def nhs_organisation_type(label='Who runs this service?'):
return RadioField(
label,
choices=[
('nhs_central', 'NHS central government agency or public body'),
('nhs_local', 'NHS Trust or Clinical Commissioning Group'),
('nhs_local', 'GP practice'),
],
validators=[DataRequired()],
)
class FieldWithNoneOption(): class FieldWithNoneOption():
@@ -544,7 +535,7 @@ class RenameOrganisationForm(StripWhitespaceForm):
class OrganisationOrganisationTypeForm(StripWhitespaceForm): class OrganisationOrganisationTypeForm(StripWhitespaceForm):
organisation_type = organisation_type(label='What type of organisation is this?') organisation_type = OrganisationTypeField('What type of organisation is this?')
class OrganisationCrownStatusForm(StripWhitespaceForm): class OrganisationCrownStatusForm(StripWhitespaceForm):
@@ -605,11 +596,14 @@ class CreateServiceForm(StripWhitespaceForm):
validators=[ validators=[
DataRequired(message='Cant be empty') DataRequired(message='Cant be empty')
]) ])
organisation_type = organisation_type() organisation_type = OrganisationTypeField('Who runs this service?')
class CreateNhsServiceForm(CreateServiceForm): class CreateNhsServiceForm(CreateServiceForm):
organisation_type = nhs_organisation_type() organisation_type = OrganisationTypeField(
'Who runs this service?',
include_only={'nhs_central', 'nhs_local', 'nhs_gp'},
)
class NewOrganisationForm( class NewOrganisationForm(
+15
View File
@@ -7,6 +7,17 @@ from app.notify_client.organisations_api_client import organisations_client
class Organisation(JSONModel): class Organisation(JSONModel):
TYPES = (
('central', 'Central government'),
('local', 'Local government'),
('nhs_central', 'NHS central government agency or public body'),
('nhs_local', 'NHS Trust or Clinical Commissioning Group'),
('nhs_gp', 'GP practice'),
('emergency_service', 'Emergency service'),
('school_or_college', 'School or college'),
('other', 'Other'),
)
ALLOWED_PROPERTIES = { ALLOWED_PROPERTIES = {
'id', 'id',
'name', 'name',
@@ -98,6 +109,10 @@ class Organisation(JSONModel):
def as_info_for_branding_request(self, fallback_domain): def as_info_for_branding_request(self, fallback_domain):
return self.name or 'Cant tell (domain is {})'.format(fallback_domain) return self.name or 'Cant tell (domain is {})'.format(fallback_domain)
@property
def organisation_type_label(self):
return dict(self.TYPES).get(self.organisation_type)
@property @property
def crown_status_or_404(self): def crown_status_or_404(self):
if self.crown is None: if self.crown is None:
+4
View File
@@ -439,6 +439,10 @@ class Service(JSONModel):
def organisation_type(self): def organisation_type(self):
return self.organisation.organisation_type or self._dict['organisation_type'] return self.organisation.organisation_type or self._dict['organisation_type']
@property
def organisation_type_label(self):
return dict(Organisation.TYPES).get(self.organisation_type)
@cached_property @cached_property
def inbound_number(self): def inbound_number(self):
return inbound_number_client.get_inbound_sms_number_for_service(self.id)['data'].get('number', '') return inbound_number_client.get_inbound_sms_number_for_service(self.id)['data'].get('number', '')
@@ -25,15 +25,7 @@
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}
{{ text_field('Sector') }} {{ text_field('Sector') }}
{{ optional_text_field({ {{ optional_text_field(current_org.organisation_type_label) }}
'central': 'Central government',
'local': 'Local government',
'nhs_central': 'NHS central government agency or public body',
'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group',
'emergency_service': 'Emergency service',
'school_or_college': 'School or college',
'other': 'Other',
}.get(current_org.organisation_type)) }}
{{ edit_field( {{ edit_field(
'Change', 'Change',
url_for('.edit_organisation_type', org_id=current_org.id) url_for('.edit_organisation_type', org_id=current_org.id)
+1 -9
View File
@@ -324,15 +324,7 @@
{% endif %} {% endif %}
{% if current_service.organisation_type %} {% if current_service.organisation_type %}
<div class="hint"> <div class="hint">
{{ { {{ current_service.organisation_type_label }}
'central': 'Central government',
'local': 'Local government',
'nhs_central': 'NHS central government agency or public body',
'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group',
'emergency_service': 'Emergency service',
'school_or_college': 'School or college',
'other': 'Other'
}.get(current_service.organisation_type) }}
</div> </div>
{% endif %} {% endif %}
{% endcall %} {% endcall %}
@@ -92,7 +92,7 @@ def test_page_to_create_new_organisation(
('radio', 'organisation_type', 'local'), ('radio', 'organisation_type', 'local'),
('radio', 'organisation_type', 'nhs_central'), ('radio', 'organisation_type', 'nhs_central'),
('radio', 'organisation_type', 'nhs_local'), ('radio', 'organisation_type', 'nhs_local'),
('radio', 'organisation_type', 'nhs_local'), ('radio', 'organisation_type', 'nhs_gp'),
('radio', 'organisation_type', 'emergency_service'), ('radio', 'organisation_type', 'emergency_service'),
('radio', 'organisation_type', 'school_or_college'), ('radio', 'organisation_type', 'school_or_college'),
('radio', 'organisation_type', 'other'), ('radio', 'organisation_type', 'other'),
@@ -282,7 +282,7 @@ def test_organisation_settings_for_platform_admin(
('local', 'Local government'), ('local', 'Local government'),
('nhs_central', 'NHS central government agency or public body'), ('nhs_central', 'NHS central government agency or public body'),
('nhs_local', 'NHS Trust or Clinical Commissioning Group'), ('nhs_local', 'NHS Trust or Clinical Commissioning Group'),
('nhs_local', 'GP practice'), ('nhs_gp', 'GP practice'),
('emergency_service', 'Emergency service'), ('emergency_service', 'Emergency service'),
('school_or_college', 'School or college'), ('school_or_college', 'School or college'),
('other', 'Other'), ('other', 'Other'),
+2 -2
View File
@@ -55,7 +55,7 @@ def test_get_should_render_add_service_template(
'local', 'local',
'nhs_central', 'nhs_central',
'nhs_local', 'nhs_local',
'nhs_local', 'nhs_gp',
'emergency_service', 'emergency_service',
'school_or_college', 'school_or_college',
'other', 'other',
@@ -205,7 +205,7 @@ def test_get_should_only_show_nhs_org_types_radios_if_user_has_nhs_email(
] == [ ] == [
'nhs_central', 'nhs_central',
'nhs_local', 'nhs_local',
'nhs_local', 'nhs_gp',
] ]