diff --git a/rcpch_nhs_organisations/hospitals/admin.py b/rcpch_nhs_organisations/hospitals/admin.py index 4b14753..623be23 100644 --- a/rcpch_nhs_organisations/hospitals/admin.py +++ b/rcpch_nhs_organisations/hospitals/admin.py @@ -2,6 +2,7 @@ # Register your models here. from .models import ( + Country, LocalHealthBoard, Organisation, PaediatricDiabetesNetwork, @@ -16,6 +17,8 @@ admin.site.register(PaediatricDiabetesNetwork) admin.site.register(Trust) +admin.site.register(Country) + admin.site.site_header = "RCPCH NHS Organisations" admin.site.site_title = "RCPCH NHS Organisations admin" admin.site.index_title = "RCPCH NHS Organisations" diff --git a/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py b/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py index 31c404d..cb0cdf5 100644 --- a/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py +++ b/rcpch_nhs_organisations/hospitals/constants/rcpch_organisations.py @@ -6011,7 +6011,7 @@ "Sector": "", "OrganisationStatus": "", "IsPimsManaged": "", - "OrganisationName": "SANDRINGHAM HOUSE", + "OrganisationName": "SALFORD CARE ORGANISATION", "Address1": "WINDSOR STREET", "Address2": "", "Address3": "", @@ -8203,31 +8203,31 @@ "Fax": "", "LocalAuthority": "E06000060", }, - # { - # "OrganisationID": "", - # "OrganisationCode": "R0A07", - # "OrganisationType": "", - # "SubType": "", - # "Sector": "", - # "OrganisationStatus": "", - # "IsPimsManaged": "", - # "OrganisationName": "WYTHENSHAWE HOSPITAL", - # "Address1": "SOUTHMOOR ROAD", - # "Address2": "", - # "Address3": "", - # "City": "MANCHESTER", - # "County": "GREATER MANCHESTER", - # "Postcode": "M23 9LT", - # "Latitude": "53.38911906358711", - # "Longitude": "-2.2919031193396626", - # "ParentODSCode": "RM3", - # "ParentName": "NORTHERN CARE ALLIANCE NHS FOUNDATION TRUST", - # "Phone": "", - # "Email": "", - # "Website": "", - # "Fax": "", - # "LocalAuthority": "E08000003", - # }, # Duplicate but note different ParentODSCode and ParentName. Wythenshawe Hospital is part of Manchester University NHS Foundation Trust and has never been part of Northern Care Alliance NHS Foundation Trust. + { + "OrganisationID": "", + "OrganisationCode": "RM325", + "OrganisationType": "", + "SubType": "", + "Sector": "", + "OrganisationStatus": "", + "IsPimsManaged": "", + "OrganisationName": "WYTHENSHAWE HOSPITAL", + "Address1": "SOUTHMOOR ROAD", + "Address2": "", + "Address3": "", + "City": "MANCHESTER", + "County": "GREATER MANCHESTER", + "Postcode": "M23 9LT", + "Latitude": "53.38911906358711", + "Longitude": "-2.2919031193396626", + "ParentODSCode": "RM3", + "ParentName": "NORTHERN CARE ALLIANCE NHS FOUNDATION TRUST", + "Phone": "", + "Email": "", + "Website": "", + "Fax": "", + "LocalAuthority": "E08000003", + }, { "OrganisationID": "39985", "OrganisationCode": "RA430", @@ -8354,7 +8354,7 @@ }, { "OrganisationID": "", - "OrganisationCode": "RM325", + "OrganisationCode": "R0A07", "OrganisationType": "", "SubType": "", "Sector": "", @@ -8429,29 +8429,54 @@ }, # 01/04/2023 QHL NHS BIRMINGHAM AND SOLIHULL INTEGRATED CARE BOARD, MIDLANDS, Birmingham Regional Paediatric Neurology Forum { "OrganisationID": "", - "OrganisationCode": "RGT1W", + "OrganisationCode": "RTX02", "OrganisationType": "", "SubType": "", "Sector": "", "OrganisationStatus": "", "IsPimsManaged": "", - "OrganisationName": "JERSEY GENERAL HOSPITAL", - "Address1": "The Parade", + "OrganisationName": "ROYAL LANCASTER INFIRMARY", + "Address1": "ASHTON ROAD", "Address2": "", "Address3": "", - "City": "St Helier", - "County": "", - "Postcode": "JE1 3QS", - "Latitude": "49.1877254", - "Longitude": "-2.112157", - "ParentODSCode": "RGT", - "ParentName": "CAMBRIDGE UNIVERSITY HOSPITALS NHS FOUNDATION TRUST", - "Phone": "01534 442000", + "City": "LANCASTER", + "County": "LANCASHIRE", + "Postcode": "LA1 4RP", + "Latitude": "54.04260571850475", + "Longitude": "-2.8000539872490346", + "ParentODSCode": "RTX", + "ParentName": "UNIVERSITY HOSPITALS OF MORECAMBE BAY NHS FOUNDATION TRUST", + "Phone": "", "Email": "", - "Website": "https://www.gov.je/Health/Hospitals/HospitalDepartments/pages/index.aspx", + "Website": "", + "Fax": "", + "LocalAuthority": "E07000121", + }, # 01/04/1998 QE1 NHS LANCASHIRE AND SOUTH CUMBRIA INTEGRATED CARE BOARD, Y62 NORTH WEST COMMISSIONING REGION, North West Children and Young People's Epilepsy Interest Group' (NWIG) + { + "OrganisationID": "", + "OrganisationCode": "RL131", + "OrganisationType": "", + "SubType": "", + "Sector": "", + "OrganisationStatus": "", + "IsPimsManaged": "", + "OrganisationName": "ROBERT JONES & AGNES HUNT ORTHOPAEDIC HOSPITAL", + "Address1": "GOBOWEN", + "Address2": "", + "Address3": "", + "City": "OSWESTRY", + "County": "SHROPSHIRE", + "Postcode": "SY10 7AG", + "Latitude": "52.8846159748024", + "Longitude": "-3.0335475872529485", + "ParentODSCode": "RL1", + "ParentName": "THE ROBERT JONES AND AGNES HUNT ORTHOPAEDIC HOSPITAL NHS FOUNDATION TRUST", + "Phone": "", + "Email": "", + "Website": "", "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 + }, # 01/04/1994 Region: Y60 MIDLANDS COMMISSIONING REGION, ICB: QOC NHS SHROPSHIRE, TELFORD AND WREKIN INTEGRATED CARE BOARD, OPENUK: BRPNF - Birmingham Regional Paediatric Neurology Form { "OrganisationID": "", "OrganisationCode": "8HV48", @@ -8477,83 +8502,34 @@ "Fax": "", "LocalAuthority": "", }, # Addition 29.6.2024 - Add RCPCH! - { - "OrganisationID": "", - "OrganisationCode": "RTX02", - "OrganisationType": "", - "SubType": "", - "Sector": "", - "OrganisationStatus": "", - "IsPimsManaged": "", - "OrganisationName": "ROYAL LANCASTER INFIRMARY", - "Address1": "ASHTON ROAD", - "Address2": "", - "Address3": "", - "City": "LANCASTER", - "County": "LANCASHIRE", - "Postcode": "LA1 4RP", - "Latitude": "54.04260571850475", - "Longitude": "-2.8000539872490346", - "ParentODSCode": "RTX", - "ParentName": "UNIVERSITY HOSPITALS OF MORECAMBE BAY NHS FOUNDATION TRUST", - "Phone": "", - "Email": "", - "Website": "", - "Fax": "", - "LocalAuthority": "E07000121", - }, # 01/04/1998 QE1 NHS LANCASHIRE AND SOUTH CUMBRIA INTEGRATED CARE BOARD, Y62 NORTH WEST COMMISSIONING REGION, North West Children and Young People's Epilepsy Interest Group' (NWIG) - # { COMMENTED OUT AS DUPLICATE BUT NOTE DIFFERENT PARENTODSCODE AND PARENTNAME - # "OrganisationID": "", - # "OrganisationCode": "RL114", - # "OrganisationType": "", - # "SubType": "", - # "Sector": "", - # "OrganisationStatus": "", - # "IsPimsManaged": "", - # "OrganisationName": "PRINCESS ROYAL HOSPITAL", - # "Address1": "APLEY CASTLE", - # "Address2": "APLEY", - # "Address3": "", - # "City": "TELFORD", - # "County": "SHROPSHIRE", - # "Postcode": "TF1 6TF", - # "Latitude": "52.693", - # "Longitude": "-2.471", - # "ParentODSCode": "RL1", - # "ParentName": "THE ROBERT JONES AND AGNES HUNT ORTHOPAEDIC HOSPITAL NHS FOUNDATION TRUST", - # "Phone": "01952 641222", - # "Email": "", - # "Website": "", - # "Fax": "", - # "LocalAuthority": "E07000076", - # }, # 01/10/2012 QOC NHS SHROPSHIRE, TELFORD AND WREKIN INTEGRATED CARE BOARD, Y60 MIDLANDS COMMISSIONING REGION, BRPNF - Birmingham Regional Paediatric Neurology Form - # { - # "OrganisationID": "", - # "OrganisationCode": "RL108", - # "OrganisationType": "", - # "SubType": "", - # "Sector": "", - # "OrganisationStatus": "", - # "IsPimsManaged": "", - # "OrganisationName": "ROYAL SHREWSBURY HOSPITAL", - # "Address1": "MYTTON OAK ROAD", - # "Address2": "", - # "Address3": "", - # "City": "SHREWSBURY", - # "County": "SHROPSHIRE", - # "Postcode": "SY3 8XQ", - # "Latitude": "52.699", - # "Longitude": "-2.748", - # "ParentODSCode": "RL1", - # "ParentName": "THE ROBERT JONES AND AGNES HUNT ORTHOPAEDIC HOSPITAL NHS FOUNDATION TRUST", - # "Phone": "01743 261000", - # "Email": "", - # "Website": "", - # "Fax": "", - # "LocalAuthority": "E07000076", - # }, # 01/10/2012 QOC NHS SHROPSHIRE, TELFORD AND WREKIN INTEGRATED CARE BOARD, Y60 MIDLANDS COMMISSIONING REGION, BRPNF - Birmingham Regional Paediatric Neurology Form ] +JERSEY_ORGANISATION = { + "OrganisationID": "", + "OrganisationCode": "RGT1W", + "OrganisationType": "", + "SubType": "", + "Sector": "", + "OrganisationStatus": "", + "IsPimsManaged": "", + "OrganisationName": "JERSEY GENERAL HOSPITAL", + "Address1": "THE PARADE", + "Address2": "", + "Address3": "", + "City": "ST HELIER", + "County": "JERSEY", + "Postcode": "JE1 3Q", + "Latitude": "49.18841258908002", + "Longitude": "-2.1122213730166157", + "ParentODSCode": "RGT1W", # This is a special case as it is both an organisation and a trust so the parent trust ODS code is the same as the organisation code and exists in both models. + "ParentName": "JERSEY GENERAL HOSPITAL", + "Phone": "01534 442000", + "Email": "", + "Website": "https://www.gov.je/Health/Hospitals/HospitalDepartments/pages/index.aspx", + "Fax": "", + "LocalAuthority": "", +} # 01/04/2015 - Jersey General Hospital, Jersey, Channel Islands is a special case as it is both an organisation and a trust. It is member of the South West Interest Group Paediatric Epilepsy. It has no other organisational hierarchies + """ Steps to update organisation in the console once created in the admin from django.contrib.gis.geos import Point @@ -8564,4 +8540,3 @@ from epilepsy12.common_view_functions import _seed_all_aggregation_models _seed_all_aggregation_models() """ -# Organisation.objects.create(ods_code="RGT1W",name="JERSEY GENERAL HOSPITAL",website=,address1="The Parade",address2="",address3="",telephone="",city="St Helier",county="",latitude=49.1877254,longitude=-2.112157,postcode="JE1 3QS",geocode_coordinates=Point(x=-2.112157,y=49.1877254),active=True,published_at=Date(1993,4,1),paediatric_diabetes_unit="PZ248",trust=,local_health_board,integrated_care_board,nhs_england_region,openuk_network,london_borough,country,) diff --git a/rcpch_nhs_organisations/hospitals/constants/trust.py b/rcpch_nhs_organisations/hospitals/constants/trust.py index 4196d62..7c29636 100644 --- a/rcpch_nhs_organisations/hospitals/constants/trust.py +++ b/rcpch_nhs_organisations/hospitals/constants/trust.py @@ -5,6 +5,7 @@ Does not include Wales - these are in the Local Health Boards file Some ambulance trusts are here but commented out. """ + TRUSTS = [ { "ods_code": "RVV", @@ -2185,3 +2186,13 @@ "country": "ENGLAND", }, ] + +JERSEY_NHS_TRUST = { + "ods_code": "RGT1W", + "trust_name": "JERSEY GENERAL HOSPITAL", + "address_line_1": "THE PARADE", + "address_line_2": "", + "town": "ST HELIER", + "postcode": "JE1 3Q", + "country": "JERSEY", +} # 01/04/2015 Jersey is a special case as it is both an organisation and a Trust. The ODS code is the same for both. diff --git a/rcpch_nhs_organisations/hospitals/management/commands/seed.py b/rcpch_nhs_organisations/hospitals/management/commands/seed.py index 1a702c9..803fb22 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed.py @@ -11,8 +11,7 @@ update_pdu_networks, seed_pdus, ods_codes_to_abstraction_levels, - load_jersey_boundaries, - create_jersey_country, + create_jersey_general_hospital, ) from .image import rcpch_ascii_art @@ -31,53 +30,51 @@ class Command(BaseCommand): help = "seed database with census and IMD data for England, Wales, Scotland and Northern Ireland." def add_arguments(self, parser): - parser.add_argument("--model", type=str, help="Mode") + parser.add_argument( + "--level", + type=str, + help="Level. e.g. Trust, Network, PDU. Enter 'all' to seed all. Enter --help for more information.", + ) def handle(self, *args, **options): - if options["model"] == "abstraction_levels": + if options["level"] == "abstraction_levels": self.stdout.write(B + "Adding abstraction levels..." + W) ods_codes_to_abstraction_levels() rcpch_ascii_art() - elif options["model"] == "trusts": + elif options["level"] == "trusts": self.stdout.write(B + "Adding trusts..." + W) seed_trusts() rcpch_ascii_art() - elif options["model"] == "organisations": + elif options["level"] == "organisations": self.stdout.write(B + "Adding organisations..." + W) seed_organisations() rcpch_ascii_art() - elif options["model"] == "paediatric_diabetes_networks": + elif options["level"] == "paediatric_diabetes_networks": self.stdout.write(B + "Adding paediatric diabetes networks..." + W) seed_paediatric_diabetes_networks() rcpch_ascii_art() - elif options["model"] == "pdus": + elif options["level"] == "pdus": self.stdout.write( B + "Adding paediatric diabetes units and networks..." + W ) seed_paediatric_diabetes_networks() seed_pdus() rcpch_ascii_art() - elif options["model"] == "update_pdus_with_networks": + elif options["level"] == "update_pdus_with_networks": self.stdout.write( B + "Adding paediatric diabetes units and networks..." + W ) update_pdu_networks() rcpch_ascii_art() - elif options["model"] == "jersey": - self.stdout.write(B + "Adding Jersey boundaries..." + W) - load_jersey_boundaries() - rcpch_ascii_art() - elif options["model"] == "all": + elif options["level"] == "all": self.stdout.write( B + "Adding all organisations and levels of abstraction..." + W ) - create_jersey_country() ods_codes_to_abstraction_levels() seed_trusts() seed_organisations() - + create_jersey_general_hospital() seed_pdus() - load_jersey_boundaries() rcpch_ascii_art() else: 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 8900bfb..316daa3 100644 --- a/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py +++ b/rcpch_nhs_organisations/hospitals/management/commands/seed_functions/jersey.py @@ -1,52 +1,87 @@ -from django.apps import apps as django_apps - -import os -from django.contrib.gis.utils import LayerMapping - -app_config = django_apps.get_app_config("hospitals") -app_path = app_config.path - -Jersey_Boundary_File = os.path.join(app_path, "shape_files", "Jersey", "CLC06_UK.shp") - - -def load_jersey_boundaries(): - JerseyBoundaries = django_apps.get_model("hospitals", "JerseyBoundaries") - jerseyboundaries_mapping = { - "objectid": "OBJECTID", - "shape_id": "ID", - "area_ha": "Area_Ha", - "remark": "Remark", - "code_06": "CODE_06", - "shape_leng": "Shape_Leng", - "shape_area": "Shape_Area", - "geom": "MULTIPOLYGON", - } - lm = LayerMapping( - JerseyBoundaries, - Jersey_Boundary_File, - jerseyboundaries_mapping, - transform=False, - encoding="iso-8859-1", - ) - lm.save(strict=True, verbose=True) - - -def create_jersey_country(): +# python imports +from datetime import date +import logging + +# Django imports +from django.apps import apps +from django.contrib.gis.geos import Point + +# Local imports +from rcpch_nhs_organisations.hospitals.constants import ( + JERSEY_ORGANISATION, + JERSEY_NHS_TRUST, +) + +logger = logging.getLogger(__name__) + + +def create_jersey_general_hospital(): """ - Create Jersey country object - Note that the geom field is not populated + Create the Jersey General Hospital """ - 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 + Organisation = apps.get_model("hospitals", "Organisation") + Trust = apps.get_model("hospitals", "Trust") + Country = apps.get_model("hospitals", "Country") + OPENUKNetwork = apps.get_model("hospitals", "OPENUKNetwork") + + jersey = Country.objects.get(boundary_identifier="E92000003") + swipe = OPENUKNetwork.objects.get(boundary_identifier="SWIPE") + + if Organisation.objects.filter( + ods_code=JERSEY_ORGANISATION["OrganisationCode"] + ).exists(): + logger.info("Jersey General Hospital already exists. Skipping creation.") + return + + # Create the Jersey General Hospital trust and assign it to Jersey, the country + try: + jersey_trust = Trust.objects.create( + ods_code=JERSEY_NHS_TRUST["ods_code"], + name=JERSEY_NHS_TRUST["trust_name"], + address_line_1=JERSEY_NHS_TRUST["address_line_1"], + address_line_2=JERSEY_NHS_TRUST["address_line_2"], + town=JERSEY_NHS_TRUST["town"], + postcode=JERSEY_NHS_TRUST["postcode"], + country=jersey.name, + telephone=None, + website=None, + active=True, + published_at=date(2015, 4, 1), + ) + except Exception as e: + logger.error(f"Error creating Jersey General Hospital trust: {e}") + + try: + # Create the Jersey General Hospital organisation and assign it to Jersey, the country and the Jersey General Hospital trust and the OPENUK Network + Organisation.objects.create( + ods_code=JERSEY_ORGANISATION["OrganisationCode"], + name=JERSEY_ORGANISATION["OrganisationName"], + website=JERSEY_ORGANISATION["Website"], + address1=JERSEY_ORGANISATION["Address1"], + address2=JERSEY_ORGANISATION["Address2"], + address3=JERSEY_ORGANISATION["Address3"], + city=JERSEY_ORGANISATION["City"], + county=JERSEY_ORGANISATION["County"], + latitude=float(JERSEY_ORGANISATION["Latitude"]), + longitude=float(JERSEY_ORGANISATION["Longitude"]), + postcode=JERSEY_ORGANISATION["Postcode"], + geocode_coordinates=Point( + x=float(JERSEY_ORGANISATION["Longitude"]), + y=float(JERSEY_ORGANISATION["Latitude"]), + ), + telephone=JERSEY_ORGANISATION["Phone"], + active=True, + published_at=date(2015, 4, 1), + country=jersey, + trust=jersey_trust, + local_health_board=None, + openuk_network=swipe, + nhs_england_region=None, + integrated_care_board=None, + london_borough=None, + ) + + logger.info("Jersey General Hospital created and all relationships added....") + except Exception as e: + logger.error(f"Error creating Jersey General Hospital: {e}") + pass diff --git a/rcpch_nhs_organisations/hospitals/migrations/0007_delete_jerseyboundaries.py b/rcpch_nhs_organisations/hospitals/migrations/0007_delete_jerseyboundaries.py new file mode 100644 index 0000000..6f88eab --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0007_delete_jerseyboundaries.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.11 on 2024-11-29 22:21 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0006_paediatricdiabetesnetwork_and_more"), + ] + + operations = [ + migrations.DeleteModel( + name="JerseyBoundaries", + ), + ] diff --git a/rcpch_nhs_organisations/hospitals/migrations/0008_alter_country_lat_alter_country_long.py b/rcpch_nhs_organisations/hospitals/migrations/0008_alter_country_lat_alter_country_long.py new file mode 100644 index 0000000..9fc95d9 --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0008_alter_country_lat_alter_country_long.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-11-29 22:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0007_delete_jerseyboundaries"), + ] + + operations = [ + migrations.AlterField( + model_name="country", + name="lat", + field=models.FloatField(blank=True, null=True), + ), + migrations.AlterField( + model_name="country", + name="long", + field=models.FloatField(blank=True, null=True), + ), + ] diff --git a/rcpch_nhs_organisations/hospitals/migrations/0009_add_jersey_boundaries_remap_identifier.py b/rcpch_nhs_organisations/hospitals/migrations/0009_add_jersey_boundaries_remap_identifier.py new file mode 100644 index 0000000..9a101ef --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0009_add_jersey_boundaries_remap_identifier.py @@ -0,0 +1,61 @@ +# python imports +import os + +# django imports +from django.db import migrations + +# from django.apps import apps as django_apps +from django.apps import apps as django_apps +from django.contrib.gis.utils import LayerMapping + +Country = django_apps.get_model("hospitals", "Country") + +# Auto-generated `LayerMapping` dictionary for JerseyBoundary model +jerseyboundary_mapping = { + "boundary_identifier": "GID_0", + "name": "COUNTRY", + "geom": "MULTIPOLYGON", +} + +# Get the path to the shape file +app_config = django_apps.get_app_config("hospitals") +app_path = app_config.path +jersey_shp_file_path = os.path.join( + app_path, "shape_files", "gadm41_JEY_shp", "gadm41_JEY_0.shp" +) + + +def load_jersey_shape_file_mapping(apps, schema_editor): + """ + Load the Jersey shape file mapping into the database + + This will create a new country object in the database with the boundaries of Jersey, using the unique identifier of JEY. + The boundaries are loaded from the shape file located at the path jersey_shp_file_path. + The JEY identifier needs later refactoring to E92000003 + """ + + # Load the Jersey shape file mapping into the database + lm = LayerMapping( + Country, + jersey_shp_file_path, + jerseyboundary_mapping, + transform=True, + source_srs=4326, + encoding="utf-8", + ) + # Note that the target srs is 27700 so that the boundaries are in the same projection as the rest of the boundaries + # in the database. By setting the SRID here of the source_srs to 4326, the LayerMapping will automatically transform + # the boundaries to the target srs of 27700. + + lm.save(strict=True, verbose=True) + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0008_alter_country_lat_alter_country_long"), + ] + + operations = [ + migrations.RunPython(load_jersey_shape_file_mapping), + ] diff --git a/rcpch_nhs_organisations/hospitals/migrations/0010_refactor_jersey_boundary_identifier.py b/rcpch_nhs_organisations/hospitals/migrations/0010_refactor_jersey_boundary_identifier.py new file mode 100644 index 0000000..0177889 --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0010_refactor_jersey_boundary_identifier.py @@ -0,0 +1,32 @@ +# python imports +import logging + +# Django imports +from django.db import migrations + +logger = logging.getLogger(__name__) + + +def refactor_jersey_boundary_identifier(apps, schema_editor): + """ + Refactor the Jersey Boundary Identifier from JEY to E92000003 + """ + logger.info("Refactoring Jersey Boundary Identifier from JEY to E92000003") + Country = apps.get_model("hospitals", "Country") + try: + Country.objects.filter(name="Jersey").update(boundary_identifier="E92000003") + logger.info("Jersey General Hospital created and all relationships added....") + except Exception as e: + logger.error(f"Error refactoring Jersey Boundary Identifier: {e}") + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0009_add_jersey_boundaries_remap_identifier"), + ] + + operations = [ + migrations.RunPython(refactor_jersey_boundary_identifier), + ] diff --git a/rcpch_nhs_organisations/hospitals/migrations/0011_alter_trust_ods_code.py b/rcpch_nhs_organisations/hospitals/migrations/0011_alter_trust_ods_code.py new file mode 100644 index 0000000..f77d750 --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/migrations/0011_alter_trust_ods_code.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-11-29 23:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("hospitals", "0010_refactor_jersey_boundary_identifier"), + ] + + operations = [ + migrations.AlterField( + model_name="trust", + name="ods_code", + field=models.CharField(max_length=10, unique=True), + ), + ] diff --git a/rcpch_nhs_organisations/hospitals/models/__init__.py b/rcpch_nhs_organisations/hospitals/models/__init__.py index 158cc7c..3bdd854 100644 --- a/rcpch_nhs_organisations/hospitals/models/__init__.py +++ b/rcpch_nhs_organisations/hospitals/models/__init__.py @@ -1,7 +1,6 @@ from .country import Country, CountryBoundaries from .general_practice import GeneralPractice from .integrated_care_board import IntegratedCareBoard, IntegratedCareBoardBoundaries -from .jersey_boundary import JerseyBoundaries from .local_health_board import LocalHealthBoard, LocalHealthBoardBoundaries from .london_borough import LondonBorough, LondonBoroughBoundaries from .nhs_england_region import NHSEnglandRegion, NHSEnglandRegionBoundaries diff --git a/rcpch_nhs_organisations/hospitals/models/country.py b/rcpch_nhs_organisations/hospitals/models/country.py index 133f38a..4369574 100644 --- a/rcpch_nhs_organisations/hospitals/models/country.py +++ b/rcpch_nhs_organisations/hospitals/models/country.py @@ -22,8 +22,8 @@ class CountryBoundaries(models.Model): 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() + long = models.FloatField(blank=True, null=True) + lat = models.FloatField(blank=True, null=True) globalid = models.CharField(max_length=38, blank=True, null=True) geom = models.MultiPolygonField(srid=27700, blank=True, null=True) diff --git a/rcpch_nhs_organisations/hospitals/models/jersey_boundary.py b/rcpch_nhs_organisations/hospitals/models/jersey_boundary.py deleted file mode 100644 index cfa0348..0000000 --- a/rcpch_nhs_organisations/hospitals/models/jersey_boundary.py +++ /dev/null @@ -1,26 +0,0 @@ -# This is an auto-generated Django model module created by ogrinspect. -from django.contrib.gis.db import models - - -class JerseyBoundaries(models.Model): - objectid = models.IntegerField() - shape_id = models.CharField(max_length=18) - area_ha = models.FloatField() - remark = models.CharField(max_length=20, blank=True, null=True) - code_06 = models.CharField(max_length=3, blank=True, null=True) - shape_leng = models.FloatField() - shape_area = models.FloatField() - geom = models.MultiPolygonField(srid=4326) - - -# Auto-generated `LayerMapping` dictionary for JerseyBoundaries model -jerseyboundaries_mapping = { - "objectid": "OBJECTID", - "id": "ID", - "area_ha": "Area_Ha", - "remark": "Remark", - "code_06": "CODE_06", - "shape_leng": "Shape_Leng", - "shape_area": "Shape_Area", - "geom": "MULTIPOLYGON", -} diff --git a/rcpch_nhs_organisations/hospitals/models/trust.py b/rcpch_nhs_organisations/hospitals/models/trust.py index 7c892ed..053f99f 100644 --- a/rcpch_nhs_organisations/hospitals/models/trust.py +++ b/rcpch_nhs_organisations/hospitals/models/trust.py @@ -3,7 +3,7 @@ class Trust(TimeStampAbstractBaseClass): - ods_code = models.CharField(max_length=3, unique=True) + ods_code = models.CharField(max_length=10, unique=True) name = models.CharField(max_length=100) address_line_1 = models.CharField( max_length=100, null=True, blank=True, default=None diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.dbf b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.dbf deleted file mode 100644 index 4144fd4..0000000 Binary files a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.dbf and /dev/null differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbn b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbn deleted file mode 100644 index 30f901e..0000000 Binary files a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbn and /dev/null differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbx b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbx deleted file mode 100644 index 29cda40..0000000 Binary files a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.sbx and /dev/null differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp deleted file mode 100644 index dec0ec1..0000000 --- a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e09df01c8e77b7308111162020f884e2d4507e0c266864f343759121d432d198 -size 154448096 diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp.xml b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp.xml deleted file mode 100644 index 0c7df9b..0000000 --- a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shp.xml +++ /dev/null @@ -1,2 +0,0 @@ - -20150923144604001.0FALSECLC06_UK002file://\\nerclactdb\pcusers\pcusers1\clamw\Documents\Current_projects\ILO work\CEH_Gateway\Ingestion\CORINE\CLC06_UK\CLC06_UK.shpLocal Area Network0.000GeographicGCS_WGS_1984Angular Unit: Degree (0.017453)<GeographicCoordinateSystem xsi:type='typens:GeographicCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.1'><WKT>GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;D_WGS_1984&quot;,SPHEROID[&quot;WGS_1984&quot;,6378137.0,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433],METADATA[&quot;World&quot;,-180.0,-90.0,180.0,90.0,0.0,0.0174532925199433,0.0,1262],AUTHORITY[&quot;EPSG&quot;,4326]]</WKT><XOrigin>-400</XOrigin><YOrigin>-400</YOrigin><XYScale>11258999068426.238</XYScale><ZOrigin>-100000</ZOrigin><ZScale>10000</ZScale><MOrigin>-100000</MOrigin><MScale>10000</MScale><XYTolerance>8.983152841195215e-009</XYTolerance><ZTolerance>0.001</ZTolerance><MTolerance>0.001</MTolerance><HighPrecision>true</HighPrecision><LeftLongitude>-180</LeftLongitude><WKID>4326</WKID><LatestWKID>4326</LatestWKID></GeographicCoordinateSystem>Project CLC06_UK "N:\Documents\Current_projects\ILO work\CEH_Gateway\Ingestion\CORINE\CHA2012\CLC06_GG2.shp" GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433],METADATA['World',-180.0,-90.0,180.0,90.0,0.0,0.0174532925199433,0.0,1262]] # PROJCS['Guernsey_Grid',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',47000.0],PARAMETER['False_Northing',50000.0],PARAMETER['Central_Meridian',-2.416666666666667],PARAMETER['Scale_Factor',0.999997],PARAMETER['Latitude_Of_Origin',49.5],UNIT['Meter',1.0]]Merge CLC06_GG2;CLC06_JE;CLC06_GB "N:\Documents\Current_projects\ILO work\CEH_Gateway\Ingestion\CORINE\CLC06_UK\CLC06_UK.shp" "OBJECTID "OBJECTID" true true false 9 Long 0 9 ,First,#,CLC06_GG2,OBJECTID,-1,-1,CLC06_JE,OBJECTID,-1,-1,CLC06_GB,OBJECTID,-1,-1;ID "ID" true true false 18 Text 0 0 ,First,#,CLC06_GG2,ID,-1,-1,CLC06_JE,ID,-1,-1,CLC06_GB,ID,-1,-1;Area_Ha "Area_Ha" true true false 19 Double 0 0 ,First,#,CLC06_GG2,Area_Ha,-1,-1,CLC06_JE,Area_Ha,-1,-1,CLC06_GB,Area_Ha,-1,-1;Remark "Remark" true true false 20 Text 0 0 ,First,#,CLC06_GG2,Remark,-1,-1,CLC06_JE,Remark,-1,-1,CLC06_GB,Remark,-1,-1;CODE_06 "CODE_06" true true false 3 Text 0 0 ,First,#,CLC06_GG2,CODE_06,-1,-1,CLC06_JE,CODE_06,-1,-1,CLC06_GB,CODE_06,-1,-1;Shape_Leng "Shape_Leng" true true false 19 Double 0 0 ,First,#,CLC06_GG2,Shape_Leng,-1,-1,CLC06_JE,Shape_Leng,-1,-1,CLC06_GB,Shape_Leng,-1,-1;Shape_Area "Shape_Area" true true false 19 Double 0 0 ,First,#,CLC06_GG2,Shape_Area,-1,-1,CLC06_JE,Shape_Area,-1,-1,CLC06_GB,Shape_Area,-1,-1"20150923144709002015092314470900Microsoft Windows 7 Version 6.1 (Build 7601) Service Pack 1; Esri ArcGIS 10.1.1.3143CLC06_UKShapefile0.000datasetEPSG7.11.20SimpleFALSE0FALSEFALSECLC06_UKFeature Class0FIDFIDOID400Internal feature number.EsriSequential unique whole numbers that are automatically generated.OBJECTIDOBJECTIDInteger990Internal feature number.EsriSequential unique whole numbers that are automatically generated.ShapeShapeGeometry000Feature geometry.EsriCoordinates defining the features.IDIDString1800Area_HaArea_HaDouble1900RemarkRemarkString2000CODE_06CODE_06String300Shape_LengShape_LengDouble1900Shape_AreaShape_AreaDouble1900Area of feature in internal units squared.EsriPositive real numbers that are automatically generated.20150923 diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shx b/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shx deleted file mode 100644 index 0f67508..0000000 Binary files a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.shx and /dev/null differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.cpg b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.cpg new file mode 100644 index 0000000..3ad133c --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.dbf b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.dbf new file mode 100644 index 0000000..67c62f3 Binary files /dev/null and b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.dbf differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.prj b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.prj similarity index 58% rename from rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.prj rename to rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.prj index 79a08dc..f45cbad 100644 --- a/rcpch_nhs_organisations/hospitals/shape_files/Jersey/CLC06_UK.prj +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.prj @@ -1 +1 @@ -GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433],METADATA["World",-180.0,-90.0,180.0,90.0,0.0,0.0174532925199433,0.0,1262]] \ No newline at end of file +GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] \ No newline at end of file diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shp b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shp new file mode 100644 index 0000000..a6d4add --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23866ac71b9cc7fd84ed70bf77a9ad742aafe96753ab7a7b3d0e583ecb3fd650 +size 42356 diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shx b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shx new file mode 100644 index 0000000..fdf50b3 Binary files /dev/null and b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_0.shx differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.cpg b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.cpg new file mode 100644 index 0000000..3ad133c --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.dbf b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.dbf new file mode 100644 index 0000000..4cf277f Binary files /dev/null and b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.dbf differ diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.prj b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.prj new file mode 100644 index 0000000..f45cbad --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.prj @@ -0,0 +1 @@ +GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] \ No newline at end of file diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shp b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shp new file mode 100644 index 0000000..eb478c0 --- /dev/null +++ b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2da566860d54a76deb951d78117e01d07718894442f314ab159f6fe5a486cef8 +size 63916 diff --git a/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shx b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shx new file mode 100644 index 0000000..7271e04 Binary files /dev/null and b/rcpch_nhs_organisations/hospitals/shape_files/gadm41_JEY_shp/gadm41_JEY_1.shx differ