From 2a8c362456635c7115ad7b0eb0d5d8441cd25c60 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sat, 29 Jun 2024 21:45:05 +0100 Subject: [PATCH 1/7] add rcpch to organisations seed --- .../constants/rcpch_organisations.py | 25 +++++++++++++++++++ .../commands/seed_functions/organisations.py | 14 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py b/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py index 52b4762..ee2c8ce 100644 --- a/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py +++ b/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py @@ -8452,6 +8452,31 @@ "Fax": "", "LocalAuthority": "", }, # Addition 22.6.2024 - Jersey is not part of the UK and is not included in the NHS Digital data. It is included here as is now a PDU + { + "OrganisationID": "", + "OrganisationCode": "8HV48", + "OrganisationType": "", + "SubType": "", + "Sector": "", + "OrganisationStatus": "", + "IsPimsManaged": "", + "OrganisationName": "ROYAL COLLEGE OF PAEDIATRICS AND CHILD HEALTH", + "Address1": "5-11 Theobalds Road", + "Address2": "", + "Address3": "", + "City": "London", + "County": "", + "Postcode": "WC1X 8SH", + "Latitude": "51.521", + "Longitude": "-0.118", + "ParentODSCode": "", + "ParentName": "", + "Phone": "020 7092 6000", + "Email": "", + "Website": "https://www.rcpch.ac.uk/", + "Fax": "", + "LocalAuthority": "", + }, # Addition 29.6.2024 - Add RCPCH! ] """ diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py index a95da78..1dc843e 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py @@ -130,6 +130,20 @@ def seed_organisations(): logger.info(f"{added+1} organisations added.") + # Add RCPCH + rcpch = Organisation.objects.create( + ods_code="8HV48", + name="Royal College of Paediatrics and Child Health", + website="https://www.rcpch.ac.uk/", + address1="5-11 Theobalds Road", + city="London", + postcode="WC1X 8SH", + latitude=51.521, + longitude=-0.1184349, + geocode_coordinates=Point(x=-0.1184349, y=51.521), + telephone="020 7092 6000", + ) + logger.info( "Updating RCPCH organisations with ICB, NHS England relationships...", ) From 114fb95449fd6c5602285bb55c98a66c4bfb6685 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 11:45:08 +0100 Subject: [PATCH 2/7] initial serializer and viewset --- .../hospitals/serializers/__init__.py | 1 + .../hospitals/serializers/organisation.py | 21 +++++++++ rcpch_nhs_organisations/hospitals/urls.py | 6 +++ .../hospitals/views/organisation.py | 46 ++++++++++++++++++- .../views/paediatric_diabetes_unit.py | 4 +- 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/rcpch_nhs_organisations/hospitals/serializers/__init__.py b/rcpch_nhs_organisations/hospitals/serializers/__init__.py index 0e4baf8..808a77f 100644 --- a/rcpch_nhs_organisations/hospitals/serializers/__init__.py +++ b/rcpch_nhs_organisations/hospitals/serializers/__init__.py @@ -23,6 +23,7 @@ NHSEnglandRegionWithNestedOrganisationsSerializer, PaediatricDiabetesUnitWithNestedOrganisationSerializer, PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer, + OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, ) from .paediatric_diabetes_unit import PaediatricDiabetesUnitSerializer from .trust import TrustSerializer diff --git a/rcpch_nhs_organisations/hospitals/serializers/organisation.py b/rcpch_nhs_organisations/hospitals/serializers/organisation.py index 3bcfdb2..5035779 100644 --- a/rcpch_nhs_organisations/hospitals/serializers/organisation.py +++ b/rcpch_nhs_organisations/hospitals/serializers/organisation.py @@ -4797,3 +4797,24 @@ class PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer( class Meta: model = PaediatricDiabetesUnit fields = ["pz_code", "organisations"] + + +@extend_schema_serializer( + examples=[ + OpenApiExample( + "paediatric_diabetes_units/organisations/extended", + value={"pz_code": "", "organisations": []}, + response_only=True, + ) + ] +) +class OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer( + serializers.ModelSerializer +): + organisations = OrganisationNoParentsSerializer( + many=True, read_only=True, source="paediatric_diabetes_unit_organisations" + ) + + class Meta: + model = PaediatricDiabetesUnit + fields = ["pz_code", "organisations"] diff --git a/rcpch_nhs_organisations/hospitals/urls.py b/rcpch_nhs_organisations/hospitals/urls.py index 0128178..d0fe9de 100644 --- a/rcpch_nhs_organisations/hospitals/urls.py +++ b/rcpch_nhs_organisations/hospitals/urls.py @@ -11,6 +11,7 @@ LondonBoroughOrganisationViewSet, NHSEnglandRegionViewSet, NHSEnglandRegionOrganisationViewSet, + OrganisationsAssociatedWithPaediatricDiabetesViewSet, PaediatricDiabetesUnitViewSet, PaediatricDiabetesUnitWithNestedOrganisationsViewSet, PaediatricDiabetesUnitForOrganisationWithParentViewSet, @@ -98,6 +99,11 @@ viewset=PaediatricDiabetesUnitWithNestedOrganisationsViewSet, basename="paediatric_diabetes_unit", ) +router.register( + r"paediatric_diabetes_units/organisations/extended", + viewset=OrganisationsAssociatedWithPaediatricDiabetesViewSet, + basename="paediatric_diabetes_unit/organisations", +) drf_routes = [ diff --git a/rcpch_nhs_organisations/hospitals/views/organisation.py b/rcpch_nhs_organisations/hospitals/views/organisation.py index b406322..3299b76 100644 --- a/rcpch_nhs_organisations/hospitals/views/organisation.py +++ b/rcpch_nhs_organisations/hospitals/views/organisation.py @@ -2,7 +2,7 @@ viewsets, serializers, # serializers here required for drf-spectacular @extend_schema ) -from rest_framework.decorators import api_view +from rest_framework.response import Response from django_filters.rest_framework import DjangoFilterBackend from drf_spectacular.utils import ( @@ -14,7 +14,11 @@ from drf_spectacular.types import OpenApiTypes from ..models import Organisation -from ..serializers import OrganisationSerializer, OrganisationNoParentsSerializer +from ..serializers import ( + OrganisationSerializer, + OrganisationNoParentsSerializer, + OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, +) @extend_schema( @@ -182,3 +186,41 @@ class OrganisationLimitedViewSet(viewsets.ReadOnlyModelViewSet): ] filter_backends = (DjangoFilterBackend,) pagination_class = None + + +@extend_schema( + request=OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, + responses={ + 200: OpenApiResponse( + response=OpenApiTypes.OBJECT, + description="Valid Response", + examples=[ + OpenApiExample( + "paediatric_diabetes_units/organisations/extended/", + external_value="external value", + value={ + "ods_code": "RGT01", + }, + response_only="true", + ), + ], + ), + }, + parameters=[ + OpenApiParameter( + name="ods_code", + description="ODS Code of the Organisation", + required=True, + type=OpenApiTypes.STR, + location=OpenApiParameter.PATH, + ), + ], + summary="This endpoint returns a list of all NHS Organisations (Acute or Community Hospitals) associated with Paediatric Diabetes Unit (with their parent), against an ODS code.", +) +class OrganisationsAssociatedWithPaediatricDiabetesUnitsViewSet(viewsets.ViewSet): + def list(self, request): + queryset = Organisation.objects.filter(paediatric_diabetes_unit__isnull=False) + serializer = OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer( + queryset, many=True + ) + return Response(serializer.data) diff --git a/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py b/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py index 7584a24..154c3e9 100644 --- a/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py +++ b/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py @@ -15,11 +15,12 @@ from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes -from ..models import PaediatricDiabetesUnit +from ..models import PaediatricDiabetesUnit, Organisation from ..serializers import ( PaediatricDiabetesUnitSerializer, PaediatricDiabetesUnitWithNestedOrganisationSerializer, PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer, + OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, ) @@ -142,7 +143,6 @@ class PaediatricDiabetesUnitWithNestedOrganisationsViewSet( class PaediatricDiabetesUnitForOrganisationWithParentViewSet(viewsets.ViewSet): def list(self, request, ods_code=None): - print(f"Hello {ods_code}") queryset = PaediatricDiabetesUnit.objects.filter( paediatric_diabetes_unit_organisations__ods_code=ods_code ) From aed850e7510dd2b4adb42cf76adf05e8a0715349 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 12:46:16 +0100 Subject: [PATCH 3/7] removes pagination, adds endpoint for all organisations with a pdu relationship, remove extra seed of rcpch as in constants --- .../commands/seed_functions/organisations.py | 14 ------- .../hospitals/serializers/__init__.py | 1 - .../hospitals/serializers/organisation.py | 21 ----------- rcpch_nhs_organisations/hospitals/urls.py | 8 ++-- .../hospitals/views/organisation.py | 37 +++++++------------ .../views/paediatric_diabetes_unit.py | 1 - rcpch_nhs_organisations/settings.py | 3 +- 7 files changed, 18 insertions(+), 67 deletions(-) diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py index 1dc843e..a95da78 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py @@ -130,20 +130,6 @@ def seed_organisations(): logger.info(f"{added+1} organisations added.") - # Add RCPCH - rcpch = Organisation.objects.create( - ods_code="8HV48", - name="Royal College of Paediatrics and Child Health", - website="https://www.rcpch.ac.uk/", - address1="5-11 Theobalds Road", - city="London", - postcode="WC1X 8SH", - latitude=51.521, - longitude=-0.1184349, - geocode_coordinates=Point(x=-0.1184349, y=51.521), - telephone="020 7092 6000", - ) - logger.info( "Updating RCPCH organisations with ICB, NHS England relationships...", ) diff --git a/rcpch_nhs_organisations/hospitals/serializers/__init__.py b/rcpch_nhs_organisations/hospitals/serializers/__init__.py index 808a77f..0e4baf8 100644 --- a/rcpch_nhs_organisations/hospitals/serializers/__init__.py +++ b/rcpch_nhs_organisations/hospitals/serializers/__init__.py @@ -23,7 +23,6 @@ NHSEnglandRegionWithNestedOrganisationsSerializer, PaediatricDiabetesUnitWithNestedOrganisationSerializer, PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer, - OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, ) from .paediatric_diabetes_unit import PaediatricDiabetesUnitSerializer from .trust import TrustSerializer diff --git a/rcpch_nhs_organisations/hospitals/serializers/organisation.py b/rcpch_nhs_organisations/hospitals/serializers/organisation.py index 5035779..3bcfdb2 100644 --- a/rcpch_nhs_organisations/hospitals/serializers/organisation.py +++ b/rcpch_nhs_organisations/hospitals/serializers/organisation.py @@ -4797,24 +4797,3 @@ class PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer( class Meta: model = PaediatricDiabetesUnit fields = ["pz_code", "organisations"] - - -@extend_schema_serializer( - examples=[ - OpenApiExample( - "paediatric_diabetes_units/organisations/extended", - value={"pz_code": "", "organisations": []}, - response_only=True, - ) - ] -) -class OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer( - serializers.ModelSerializer -): - organisations = OrganisationNoParentsSerializer( - many=True, read_only=True, source="paediatric_diabetes_unit_organisations" - ) - - class Meta: - model = PaediatricDiabetesUnit - fields = ["pz_code", "organisations"] diff --git a/rcpch_nhs_organisations/hospitals/urls.py b/rcpch_nhs_organisations/hospitals/urls.py index d0fe9de..f939ea7 100644 --- a/rcpch_nhs_organisations/hospitals/urls.py +++ b/rcpch_nhs_organisations/hospitals/urls.py @@ -11,7 +11,7 @@ LondonBoroughOrganisationViewSet, NHSEnglandRegionViewSet, NHSEnglandRegionOrganisationViewSet, - OrganisationsAssociatedWithPaediatricDiabetesViewSet, + OrganisationsAssociatedWithPaediatricDiabetesUnitsList, PaediatricDiabetesUnitViewSet, PaediatricDiabetesUnitWithNestedOrganisationsViewSet, PaediatricDiabetesUnitForOrganisationWithParentViewSet, @@ -100,9 +100,9 @@ basename="paediatric_diabetes_unit", ) router.register( - r"paediatric_diabetes_units/organisations/extended", - viewset=OrganisationsAssociatedWithPaediatricDiabetesViewSet, - basename="paediatric_diabetes_unit/organisations", + r"all-organisations-associated-with-paediatric-diabetes-units", + OrganisationsAssociatedWithPaediatricDiabetesUnitsList, + basename="organisation", ) diff --git a/rcpch_nhs_organisations/hospitals/views/organisation.py b/rcpch_nhs_organisations/hospitals/views/organisation.py index 3299b76..48b5c86 100644 --- a/rcpch_nhs_organisations/hospitals/views/organisation.py +++ b/rcpch_nhs_organisations/hospitals/views/organisation.py @@ -1,6 +1,8 @@ from rest_framework import ( viewsets, serializers, # serializers here required for drf-spectacular @extend_schema + generics, + filters, ) from rest_framework.response import Response from django_filters.rest_framework import DjangoFilterBackend @@ -17,7 +19,6 @@ from ..serializers import ( OrganisationSerializer, OrganisationNoParentsSerializer, - OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, ) @@ -189,38 +190,26 @@ class OrganisationLimitedViewSet(viewsets.ReadOnlyModelViewSet): @extend_schema( - request=OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, + request=None, # No request body expected responses={ 200: OpenApiResponse( response=OpenApiTypes.OBJECT, description="Valid Response", examples=[ OpenApiExample( - "paediatric_diabetes_units/organisations/extended/", - external_value="external value", - value={ - "ods_code": "RGT01", - }, + "all-organisations-associated-with-paediatric-diabetes-units", response_only="true", ), ], ), }, - parameters=[ - OpenApiParameter( - name="ods_code", - description="ODS Code of the Organisation", - required=True, - type=OpenApiTypes.STR, - location=OpenApiParameter.PATH, - ), - ], - summary="This endpoint returns a list of all NHS Organisations (Acute or Community Hospitals) associated with Paediatric Diabetes Unit (with their parent), against an ODS code.", + summary="This endpoint returns a list of all NHS Organisations (Acute or Community Hospitals) associated with a Paediatric Diabetes Unit (with their parent).", ) -class OrganisationsAssociatedWithPaediatricDiabetesUnitsViewSet(viewsets.ViewSet): - def list(self, request): - queryset = Organisation.objects.filter(paediatric_diabetes_unit__isnull=False) - serializer = OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer( - queryset, many=True - ) - return Response(serializer.data) +class OrganisationsAssociatedWithPaediatricDiabetesUnitsList( + viewsets.ReadOnlyModelViewSet +): + queryset = Organisation.objects.filter(paediatric_diabetes_unit__isnull=False) + serializer_class = OrganisationSerializer + filter_backends = [DjangoFilterBackend, filters.OrderingFilter] + filterset_fields = ["ods_code", "name"] + ordering_fields = ["name", "ods_code"] diff --git a/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py b/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py index 154c3e9..a1cc8dd 100644 --- a/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py +++ b/rcpch_nhs_organisations/hospitals/views/paediatric_diabetes_unit.py @@ -20,7 +20,6 @@ PaediatricDiabetesUnitSerializer, PaediatricDiabetesUnitWithNestedOrganisationSerializer, PaediatricDiabetesUnitWithNestedOrganisationAndParentSerializer, - OrganisationsAssociatedWithPaediatricDiabetesUnitSerializer, ) diff --git a/rcpch_nhs_organisations/settings.py b/rcpch_nhs_organisations/settings.py index 463b4cf..4cad667 100644 --- a/rcpch_nhs_organisations/settings.py +++ b/rcpch_nhs_organisations/settings.py @@ -160,8 +160,7 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" REST_FRAMEWORK = { - "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", - "PAGE_SIZE": 10, + "DEFAULT_PAGINATION_CLASS": None, "DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",), "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", "DEFAULT_RENDERER_CLASSES": [ From dee574d91ee19acc97c554864ea0194d3ae39d8e Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 13:13:20 +0100 Subject: [PATCH 4/7] refactor to APIListView and add swagger response example --- rcpch_nhs_organisations/hospitals/urls.py | 11 +-- .../hospitals/views/organisation.py | 92 +++++++++++++++++-- 2 files changed, 91 insertions(+), 12 deletions(-) diff --git a/rcpch_nhs_organisations/hospitals/urls.py b/rcpch_nhs_organisations/hospitals/urls.py index f939ea7..e3f6fb4 100644 --- a/rcpch_nhs_organisations/hospitals/urls.py +++ b/rcpch_nhs_organisations/hospitals/urls.py @@ -99,12 +99,6 @@ viewset=PaediatricDiabetesUnitWithNestedOrganisationsViewSet, basename="paediatric_diabetes_unit", ) -router.register( - r"all-organisations-associated-with-paediatric-diabetes-units", - OrganisationsAssociatedWithPaediatricDiabetesUnitsList, - basename="organisation", -) - drf_routes = [ # rest framework paths @@ -115,6 +109,11 @@ PaediatricDiabetesUnitForOrganisationWithParentViewSet.as_view({"get": "list"}), name="paediatric_diabetes_unit_organisation_with_parent", ), + path( + "organisations/paediatric-diabetes-units", + OrganisationsAssociatedWithPaediatricDiabetesUnitsList.as_view(), + name="organisations-associated-with-paediatric-diabetes-units", + ), path("schema/", SpectacularJSONAPIView.as_view(), name="schema"), # Swagger UI path("swagger-ui/", SpectacularSwaggerView.as_view(), name="swagger-ui"), diff --git a/rcpch_nhs_organisations/hospitals/views/organisation.py b/rcpch_nhs_organisations/hospitals/views/organisation.py index 48b5c86..5b35537 100644 --- a/rcpch_nhs_organisations/hospitals/views/organisation.py +++ b/rcpch_nhs_organisations/hospitals/views/organisation.py @@ -1,8 +1,8 @@ from rest_framework import ( viewsets, serializers, # serializers here required for drf-spectacular @extend_schema - generics, filters, + generics, ) from rest_framework.response import Response from django_filters.rest_framework import DjangoFilterBackend @@ -197,17 +197,97 @@ class OrganisationLimitedViewSet(viewsets.ReadOnlyModelViewSet): description="Valid Response", examples=[ OpenApiExample( - "all-organisations-associated-with-paediatric-diabetes-units", + "organisations/paediatric-diabetes-units/", response_only="true", + value=[ + { + "ods_code": "RGT01", + "name": "ADDENBROOKE'S HOSPITAL", + "website": "https://www.cuh.nhs.uk/", + "address1": "HILLS ROAD", + "address2": "", + "address3": "", + "telephone": "01223 245151", + "city": "CAMBRIDGE", + "county": "CAMBRIDGESHIRE", + "latitude": 52.17513275, + "longitude": 0.140753239, + "postcode": "CB2 0QQ", + "geocode_coordinates": "SRID=27700;POINT (0.140753239 52.17513275)", + "active": True, + "published_at": None, + "paediatric_diabetes_unit": {"pz_code": "PZ041"}, + "trust": { + "ods_code": "RGT", + "name": "CAMBRIDGE UNIVERSITY HOSPITALS NHS FOUNDATION TRUST", + "address_line_1": "CAMBRIDGE BIOMEDICAL CAMPUS", + "address_line_2": "HILLS ROAD", + "town": "CAMBRIDGE", + "postcode": "CB2 0QQ", + "country": "ENGLAND", + "telephone": None, + "website": None, + "active": True, + "published_at": None, + }, + "local_health_board": None, + "integrated_care_board": None, + "nhs_england_region": None, + "openuk_network": None, + "london_borough": None, + "country": { + "boundary_identifier": "E92000001", + "name": "England", + }, + }, + { + "ods_code": "RCF22", + "name": "AIREDALE GENERAL HOSPITAL", + "website": "https://www.airedaletrust.nhs.uk/", + "address1": "SKIPTON ROAD", + "address2": "STEETON", + "address3": "", + "telephone": "", + "city": "KEIGHLEY", + "county": "WEST YORKSHIRE", + "latitude": 53.8979454, + "longitude": -1.962710142, + "postcode": "BD20 6TD", + "geocode_coordinates": "SRID=27700;POINT (-1.962710142 53.8979454)", + "active": True, + "published_at": None, + "paediatric_diabetes_unit": {"pz_code": "PZ047"}, + "trust": { + "ods_code": "RCF", + "name": "AIREDALE NHS FOUNDATION TRUST", + "address_line_1": "AIREDALE GENERAL HOSPITAL", + "address_line_2": "SKIPTON ROAD", + "town": "KEIGHLEY", + "postcode": "BD20 6TD", + "country": "ENGLAND", + "telephone": None, + "website": None, + "active": True, + "published_at": None, + }, + "local_health_board": None, + "integrated_care_board": None, + "nhs_england_region": None, + "openuk_network": None, + "london_borough": None, + "country": { + "boundary_identifier": "E92000001", + "name": "England", + }, + }, + ], ), ], ), }, - summary="This endpoint returns a list of all NHS Organisations (Acute or Community Hospitals) associated with a Paediatric Diabetes Unit (with their parent).", + summary="This endpoint returns a list of all NHS Organisations (Acute or Community Hospitals) associated with a parent Paediatric Diabetes Unit.", ) -class OrganisationsAssociatedWithPaediatricDiabetesUnitsList( - viewsets.ReadOnlyModelViewSet -): +class OrganisationsAssociatedWithPaediatricDiabetesUnitsList(generics.ListAPIView): queryset = Organisation.objects.filter(paediatric_diabetes_unit__isnull=False) serializer_class = OrganisationSerializer filter_backends = [DjangoFilterBackend, filters.OrderingFilter] From af47a69a02fcf80532c4a2757da02ba579329038 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 13:22:22 +0100 Subject: [PATCH 5/7] change country for jersey hospital in seeding --- .../management/commands/seed_functions/organisations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py index a95da78..c3babbb 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/organisations.py @@ -35,6 +35,7 @@ def seed_organisations(): Country = apps.get_model("hospitals", "Country") england = Country.objects.get(boundary_identifier="E92000001") wales = Country.objects.get(boundary_identifier="W92000004") + jersey = Country.objects.get(boundary_identifier="E92000003") if Organisation.objects.all().count() >= 330: logger.info( @@ -101,8 +102,13 @@ def seed_organisations(): ods_code=rcpch_organisation["ParentODSCode"] ) organisation.trust = trust + organisation.country = england + # Jersey is a special case + if rcpch_organisation["OrganisationCode"] == "RGT1W": + organisation.country = jersey + else: raise Exception( f"No Match! {rcpch_organisation['OrganisationName']} has no parent organisation." From 071d99ca7275419918cd27b1c12035775348e462 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 13:48:02 +0100 Subject: [PATCH 6/7] allow country model gis data none --- .../hospitals/constants/country_codes.py | 2 + ...ntry_bng_e_alter_country_bng_n_and_more.py | 41 +++++++++++++++++++ .../hospitals/models/country.py | 10 ++--- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 rcpch_nhs_organisations/hospitals/migrations/0005_alter_country_bng_e_alter_country_bng_n_and_more.py diff --git a/rcpch_nhs_organisations/hospitals/constants/country_codes.py b/rcpch_nhs_organisations/hospitals/constants/country_codes.py index 8b829af..cdcaea7 100644 --- a/rcpch_nhs_organisations/hospitals/constants/country_codes.py +++ b/rcpch_nhs_organisations/hospitals/constants/country_codes.py @@ -5,3 +5,5 @@ {"country_ons_code": "S92000003", "country_ons_name": "Scotland"}, {"country_ons_code": "E92000003", "country_ons_name": "Jersey"}, ] + +# jersey = Country(boundary_identifier="E92000003", name="Jersey", welsh_name="", bng_e=None, bng_n=None, long=2.1313, lat=49.2144, globalid="", geom=None) diff --git a/rcpch_nhs_organisations/hospitals/migrations/0005_alter_country_bng_e_alter_country_bng_n_and_more.py b/rcpch_nhs_organisations/hospitals/migrations/0005_alter_country_bng_e_alter_country_bng_n_and_more.py new file mode 100644 index 0000000..7bbbe8b --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0005_alter_country_bng_e_alter_country_bng_n_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 4.2.11 on 2024-06-30 12:45 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0004_jerseyboundaries"), + ] + + operations = [ + migrations.AlterField( + model_name="country", + name="bng_e", + field=models.BigIntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name="country", + name="bng_n", + field=models.BigIntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name="country", + name="geom", + field=django.contrib.gis.db.models.fields.MultiPolygonField( + blank=True, null=True, srid=27700 + ), + ), + migrations.AlterField( + model_name="country", + name="globalid", + field=models.CharField(blank=True, max_length=38, null=True), + ), + migrations.AlterField( + model_name="country", + name="welsh_name", + field=models.CharField(blank=True, max_length=17, null=True), + ), + ] diff --git a/rcpch_nhs_organisations/hospitals/models/country.py b/rcpch_nhs_organisations/hospitals/models/country.py index 917b737..133f38a 100644 --- a/rcpch_nhs_organisations/hospitals/models/country.py +++ b/rcpch_nhs_organisations/hospitals/models/country.py @@ -19,13 +19,13 @@ class CountryBoundaries(models.Model): boundary_identifier = models.CharField(max_length=9) name = models.CharField(max_length=16) - welsh_name = models.CharField(max_length=17) - bng_e = models.BigIntegerField() - bng_n = models.BigIntegerField() + welsh_name = models.CharField(max_length=17, blank=True, null=True) + bng_e = models.BigIntegerField(blank=True, null=True) + bng_n = models.BigIntegerField(blank=True, null=True) long = models.FloatField() lat = models.FloatField() - globalid = models.CharField(max_length=38) - geom = models.MultiPolygonField(srid=27700) + globalid = models.CharField(max_length=38, blank=True, null=True) + geom = models.MultiPolygonField(srid=27700, blank=True, null=True) class Meta: abstract = True From 56caa5ea0531472c941b8d3ad30a182591f27226 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Sun, 30 Jun 2024 13:59:15 +0100 Subject: [PATCH 7/7] create jersey as country entity - note currently lacks geom data --- .../hospitals/management/commands/seed.py | 2 ++ .../commands/seed_functions/jersey.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed.py b/rcpch_nhs_organisations/hospitals/management/commands/seed.py index 0b68d0d..488cb6b 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed.py @@ -10,6 +10,7 @@ seed_pdus, ods_codes_to_abstraction_levels, load_jersey_boundaries, + create_jersey_country, ) from .image import rcpch_ascii_art @@ -55,6 +56,7 @@ def handle(self, *args, **options): self.stdout.write( B + "Adding all organisations and levels of abstraction..." + W ) + create_jersey_country() ods_codes_to_abstraction_levels() seed_trusts() seed_organisations() diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py index c910579..8900bfb 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py @@ -29,3 +29,24 @@ def load_jersey_boundaries(): encoding="iso-8859-1", ) lm.save(strict=True, verbose=True) + + +def create_jersey_country(): + """ + Create Jersey country object + Note that the geom field is not populated + """ + Country = django_apps.get_model("hospitals", "Country") + jersey = Country( + boundary_identifier="E92000003", + name="Jersey", + welsh_name="", + bng_e=None, + bng_n=None, + long=2.1313, + lat=49.2144, + globalid="", + geom=None, + ) + jersey.save() + return jersey