Skip to content

Commit a13edc5

Browse files
authored
Merge pull request #6616 from NHSDigital/add-lat-lng-to-locations
Add position column to locations
2 parents 7e913de + 5f7e0f3 commit a13edc5

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

app/models/location.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# gias_year_groups :integer default([]), not null, is an Array
1616
# name :text not null
1717
# ods_code :string
18+
# position :geography point, 4326
1819
# site :string
1920
# status :integer default("unknown"), not null
2021
# systm_one_code :string
@@ -247,9 +248,15 @@ def phase
247248
end
248249

249250
def as_json
250-
super.except("created_at", "systm_one_code", "updated_at").merge(
251+
super.except(
252+
"created_at",
253+
"systm_one_code",
254+
"updated_at",
255+
"position"
256+
).merge(
251257
"is_attached_to_team" =>
252-
team_locations.any? { it.academic_year == AcademicYear.pending }
258+
team_locations.any? { it.academic_year == AcademicYear.pending },
259+
"position" => position ? [position.x, position.y] : nil
253260
)
254261
end
255262

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddPositionToLocations < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :locations, :position, :st_point, geographic: true
6+
end
7+
end

db/schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@
536536
t.integer "gias_year_groups", default: [], null: false, array: true
537537
t.text "name", null: false
538538
t.string "ods_code"
539+
t.geography "position", limit: {srid: 4326, type: "st_point", geographic: true}
539540
t.string "site"
540541
t.integer "status", default: 0, null: false
541542
t.string "systm_one_code"

spec/factories/locations.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# gias_year_groups :integer default([]), not null, is an Array
1616
# name :text not null
1717
# ods_code :string
18+
# position :geography point, 4326
1819
# site :string
1920
# status :integer default("unknown"), not null
2021
# systm_one_code :string
@@ -52,6 +53,9 @@
5253
address_line_1 { Faker::Address.street_address }
5354
address_town { Faker::Address.city }
5455
address_postcode { Faker::Address.uk_postcode }
56+
position do
57+
"POINT(#{Faker::Address.longitude} #{Faker::Address.latitude})"
58+
end
5559
end
5660

5761
factory :community_clinic do

spec/models/location_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# gias_year_groups :integer default([]), not null, is an Array
1616
# name :text not null
1717
# ods_code :string
18+
# position :geography point, 4326
1819
# site :string
1920
# status :integer default("unknown"), not null
2021
# systm_one_code :string
@@ -432,6 +433,7 @@
432433
"is_attached_to_team" => false,
433434
"name" => location.name,
434435
"ods_code" => location.ods_code,
436+
"position" => [location.position.x, location.position.y],
435437
"site" => location.site,
436438
"status" => "unknown",
437439
"type" => "community_clinic",

0 commit comments

Comments
 (0)