diff --git a/README.md b/README.md index 1c60e34..93da651 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ php artisan import:data | Dentists (England) | [Unknown (CampaignLab)](https://github.com/CampaignLab/New-Constituency-Almanac/blob/main/data/dentists%20england%20mapped.csv) | [dentists-england.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/dentists-england.csv) | [`import:dentists`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportDentistsCommand.php) | | Hospitals (England) | [Unknown (CampaignLab)](https://github.com/CampaignLab/New-Constituency-Almanac/blob/main/data/english%20hospitals%20by%20constituency.csv) | [hospitals-england.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/hospitals-england.csv) | [`import:english-hospitals`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportEnglishHospitalsCommand.php) | | Hospitals (Scotland) | [Unknown (CampaignLab)](https://github.com/CampaignLab/New-Constituency-Almanac/blob/main/data/hospitals%20in%20scotland%20by%20constituency.csv) | [hospitals-scotland.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/hospitals-scotland.csv) | [`import:scottish-hospitals`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportScottishHospitalsCommand.php) | +| Hospitals (additional) | [Unknown (CampaignLab)](https://github.com/CampaignLab/constituency-explorer/issues/58) | [hospitals-scotland.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/additional_hospitals_20250618.csv) | [`import:additional-hospitals`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportAdditionalHospitalsCommand.php) | | Schools (England) | [Gov.uk](https://get-information-schools.service.gov.uk/Downloads) | [schools-england.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/schools-england.csv) | [`import:english-schools`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportEnglishSchoolsCommand.php) | | Schools (Scotland) | [Gov.uk](https://www.data.gov.uk/dataset/9a6f9d86-9698-4a5d-a2c8-89f3b212c52c/scottish-school-roll-and-locations) | [schools-scotland.xlsx](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/schools-scotland.xlsx) | [`import:scottish-schools`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportScottishSchoolsCommand.php) | | Community centres | - | [community-centres.csv](https://github.com/CampaignLab/constituency-explorer/blob/refs/heads/main/database/fixtures/community-centres.csv) | [`import:community-centres`](https://github.com/CampaignLab/constituency-explorer/blob/main/app/Console/Commands/ImportCommunityCentres.php) | diff --git a/app/Console/Commands/ImportAdditionalHospitalsCommand.php b/app/Console/Commands/ImportAdditionalHospitalsCommand.php new file mode 100644 index 0000000..1afe9f0 --- /dev/null +++ b/app/Console/Commands/ImportAdditionalHospitalsCommand.php @@ -0,0 +1,48 @@ +constituencies = Constituency::all()->keyBy('gss_code'); + } + + public function importRow($row) + { + $gss_code = $row['Mapped: codes.parliamentary_constituency']; + if (empty($gss_code)) { + return null; + } + + $constituency = $this->constituencies[$gss_code] ?? null; + + if (! $constituency) { + $this->warn("Constituency not found: {$gss_code}"); + return null; + } + + $existing = Hospital::where('name', $row['name'])->where('constituency_id', $constituency->id)->first(); + if ($existing) { + $this->warn("Hospital already exists: {$row['name']} ({$constituency->name})"); + return null; + } + + return Hospital::create([ + 'constituency_id' => $constituency->id, + 'name' => $row['name'], + 'address' => [trim($row['postcode'])], + 'latitude' => $row['Mapped: latitude'], + 'longitude' => $row['Mapped: longitude'], + ]); + } +} diff --git a/app/Console/Commands/ImportDataCommand.php b/app/Console/Commands/ImportDataCommand.php index 331d6c8..eb347d7 100644 --- a/app/Console/Commands/ImportDataCommand.php +++ b/app/Console/Commands/ImportDataCommand.php @@ -60,6 +60,7 @@ public function handle() $this->call(ImportDentistsCommand::class); $this->call(ImportEnglishHospitalsCommand::class); $this->call(ImportScottishHospitalsCommand::class); + $this->call(ImportAdditionalHospitalsCommand::class); $this->call(ImportEnglishSchoolsCommand::class); $this->call(ImportScottishSchoolsCommand::class); $this->call(ImportCommunityCentres::class); diff --git a/app/Console/Commands/ImportEnglishHospitalsCommand.php b/app/Console/Commands/ImportEnglishHospitalsCommand.php index b921273..d1c69be 100644 --- a/app/Console/Commands/ImportEnglishHospitalsCommand.php +++ b/app/Console/Commands/ImportEnglishHospitalsCommand.php @@ -31,6 +31,12 @@ public function importRow($row) return null; } + $existing = Hospital::where('name', $row['Name'])->where('constituency_id', $constituency->id)->first(); + if ($existing) { + $this->warn("Hospital already exists: {$row['Name']} ({$constituency->name})"); + return null; + } + return Hospital::create([ 'constituency_id' => $constituency->id, 'name' => $row['Name'], diff --git a/app/Console/Commands/ImportScottishHospitalsCommand.php b/app/Console/Commands/ImportScottishHospitalsCommand.php index cd71182..d65bf8b 100644 --- a/app/Console/Commands/ImportScottishHospitalsCommand.php +++ b/app/Console/Commands/ImportScottishHospitalsCommand.php @@ -32,6 +32,12 @@ public function importRow($row) return null; } + $existing = Hospital::where('name', $row['Location Name'])->where('constituency_id', $constituency->id)->first(); + if ($existing) { + $this->warn("Hospital already exists: {$row['Location Name']} ({$constituency->name})"); + return null; + } + return Hospital::create([ 'constituency_id' => $constituency->id, 'name' => $row['Location Name'],