Skip to content

Commit 46acfd0

Browse files
committed
map religious_character (and school size fields) from gias - remove flaoting gias JSON field from Organisations table
1 parent e48d17a commit 46acfd0

30 files changed

Lines changed: 181 additions & 566 deletions

app/controllers/omniauth_callbacks_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ def organisation_from_request
108108
# contained within the trust and use that instead
109109
uid = auth_hash.dig("extra", "raw_info", "organisation", "uid")
110110
contained_school = School.find_by(
111-
"gias_data->>'TrustSchoolFlag (code)' = ? AND gias_data->>'Trusts (code)' = ?",
112-
"5", # "Supported by a single-academy trust"
113-
uid,
111+
trust_school_flag_code: 5, # "Supported by a single-academy trust"
112+
trusts_code: uid,
114113
)
115114

116115
contained_school || raise("Could not find a school contained in SAT (UID #{uid})")

app/helpers/organisations_helper.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module OrganisationsHelper
33

44
OFSTED_REPORT_ENDPOINT = "https://reports.ofsted.gov.uk/oxedu_providers/full/(urn)/".freeze
55

6+
# :nocov:
67
def age_range(school)
78
return I18n.t("vacancies.listing.schools.not_given") unless school.minimum_age? && school.maximum_age?
89

910
"#{school.minimum_age} to #{school.maximum_age}"
1011
end
12+
# :nocov:
1113

1214
def full_address(organisation)
1315
address_join([organisation.address, organisation.town, organisation.county, organisation.postcode])
@@ -21,6 +23,7 @@ def ofsted_report(school)
2123
OFSTED_REPORT_ENDPOINT + school.urn
2224
end
2325

26+
# :nocov:
2427
def organisation_type(organisation)
2528
return organisation.group_type&.humanize if organisation.school_group?
2629

@@ -32,6 +35,7 @@ def organisation_type(organisation)
3235

3336
school_type_details.reject(&:blank?).reject { |str| str == I18n.t("vacancies.listing.schools.not_given") }.join(", ")
3437
end
38+
# :nocov:
3539

3640
def organisation_types(organisations)
3741
organisations.select(&:school?).group_by { |org| [org.school_type, org.religious_character] }.map do |type, orgs_by_type|
@@ -59,16 +63,17 @@ def school_or_trust_visits(organisation)
5963
end
6064
end
6165

66+
# :nocov:
6267
def school_size(school)
63-
if school.gias_data.present?
64-
return number_of_pupils(school) if school.gias_data["NumberOfPupils"].present?
65-
return school_capacity(school) if school.gias_data["SchoolCapacity"].present?
66-
end
68+
return number_of_pupils(school) if school.number_of_pupils.present?
69+
return school_capacity(school) if school.school_capacity.present?
70+
6771
I18n.t("vacancies.listing.schools.no_information")
6872
end
73+
# :nocov:
6974

7075
def school_has_school_size_data?(school)
71-
school.gias_data["NumberOfPupils"].present? || school.gias_data["SchoolCapacity"].present?
76+
school.number_of_pupils.present? || school.school_capacity.present?
7277
end
7378

7479
def school_is_part_of_a_trust?(school)
@@ -90,14 +95,14 @@ def required_profile_image(image:, missing_prompt:, alt_text:)
9095
private
9196

9297
def number_of_pupils(school)
93-
return unless (number = school.gias_data["NumberOfPupils"])
94-
95-
I18n.t("vacancies.listing.schools.size.enrolled", number: number)
98+
I18n.t("vacancies.listing.schools.size.enrolled", number: school.number_of_pupils)
9699
end
97100

101+
# :nocov:
98102
def school_capacity(school)
99-
I18n.t("vacancies.listing.schools.size.up_to", capacity: school.gias_data["SchoolCapacity"])
103+
I18n.t("vacancies.listing.schools.size.up_to", capacity: school.school_capacity)
100104
end
105+
# :nocov:
101106

102107
def missing_profile_information_notification(prompt)
103108
content_tag(:div, class: %i[govuk-inset-text govuk-inset-text--dark-blue inset-text--narrow-border]) do

app/jobs/refresh_organisations_gias_data_hash_job.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/models/organisation.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Organisation < ApplicationRecord
99
has_rich_text :description
1010

1111
SPECIAL_SCHOOL_TYPES = ["Community special school", "Foundation special school", "Non-maintained special school", "Academy special converter", "Academy special sponsor led", "Free schools special"].freeze
12-
NON_FAITH_RELIGIOUS_CHARACTER_TYPES = ["", "None", "Does not apply", "null"].freeze
12+
NON_FAITH_RELIGIOUS_CHARACTER_TYPES = ["None", "Does not apply"].freeze
1313
OUT_OF_SCOPE_DETAILED_SCHOOL_TYPES = ["Further education", "Other independent school", "Miscellaneous", "Special post 16 institution", "Other independent special school", "Higher education institutions", "Welsh establishment"].freeze
1414

1515
friendly_id :slug_candidates, use: %i[slugged history]
@@ -53,7 +53,7 @@ class Organisation < ApplicationRecord
5353

5454
scope :visible_to_jobseekers, -> { schools.not_closed.not_out_of_scope.or(Organisation.trusts).registered_for_service }
5555

56-
scope :only_faith_schools, -> { where.not("gias_data ->> 'ReligiousCharacter (name)' IN (?)", NON_FAITH_RELIGIOUS_CHARACTER_TYPES) }
56+
scope :only_faith_schools, -> { where.not(religious_character: NON_FAITH_RELIGIOUS_CHARACTER_TYPES) }
5757

5858
# This can safely ignore the 'extra' LA mappings as it is always called with a scope which excludes LAs in the first place
5959
scope :with_live_vacancies, lambda {
@@ -68,7 +68,7 @@ class Organisation < ApplicationRecord
6868

6969
validates :email, email_address: true, if: -> { email_changed? } # Allows data created prior to validation to still be valid
7070

71-
alias_attribute :data, :gias_data
71+
# alias_attribute :data, :gias_data
7272

7373
enum :phase, {
7474
not_applicable: 0,
@@ -81,6 +81,8 @@ class Organisation < ApplicationRecord
8181
through: 7,
8282
}
8383

84+
self.ignored_columns += %i[gias_data gias_data_hash]
85+
8486
def live_group_vacancies
8587
Vacancy.none
8688
end
@@ -136,13 +138,6 @@ def trust_or_la?
136138
trust? || local_authority?
137139
end
138140

139-
def refresh_gias_data_hash
140-
computed_hash = gias_data.presence && Digest::SHA256.hexdigest(gias_data.to_s)
141-
return if gias_data_hash == computed_hash
142-
143-
update(gias_data_hash: computed_hash)
144-
end
145-
146141
def has_ofsted_report?
147142
urn.present?
148143
end

app/models/school.rb

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,64 @@ class School < Organisation
1212
INDEPENDENT_SCHOOL_TYPE = "Independent schools".freeze
1313
VALID_SCHOOL_TYPES = [LA_SCHOOL_TYPE, INDEPENDENT_SCHOOL_TYPE, "Special schools", "Universities", ACADEMY_TYPE, FREE_SCHOOL_TYPE, "Welsh schools", "Other types", "Colleges", "Online provider"].freeze
1414

15-
# This is direct from GIAS (with plurals removed via singularize)
15+
# This is direct from GIAS
1616
validates :school_type, inclusion: { in: VALID_SCHOOL_TYPES }
1717

18+
CHRISTIAN_RELIGIOUS_TYPES = ["Anglican",
19+
"United Reformed Church",
20+
"Christian",
21+
"Greek Orthodox",
22+
"Anglican/Evangelical",
23+
"Anglican/Church of England",
24+
"Christian/Evangelical",
25+
"Christian/Methodist",
26+
"Christian/non-denominational",
27+
"Protestant/Evangelical",
28+
"Methodist/Church of England",
29+
"Protestant",
30+
"Reformed Baptist",
31+
"Christian Science",
32+
"Church of England",
33+
"Plymouth Brethren Christian Church",
34+
"Church of England/Methodist/United Reform Church/Baptist",
35+
"Moravian", # Protestant Christian church movement
36+
"Quaker",
37+
"Methodist",
38+
"Free Church",
39+
"Church of England/Free Church",
40+
"Church of England/Evangelical",
41+
"Church of England/United Reformed Church",
42+
"Anglican/Christian",
43+
"Inter- / non- denominational",
44+
"Seventh Day Adventist",
45+
"Church of England/Christian",
46+
"Church of England/Methodist",
47+
"Congregational Church"].freeze
48+
49+
CATHOLIC_RELIGIOUS_TYPES = ["Roman Catholic",
50+
"Catholic",
51+
"Roman Catholic/Anglican",
52+
"Roman Catholic/Church of England",
53+
"Church of England/Roman Catholic"].freeze
54+
55+
OTHER_RELIGIOUS_TYPES = [
56+
"Jewish",
57+
"Orthodox Jewish",
58+
"Charadi Jewish",
59+
"Islam",
60+
"Muslim",
61+
"Sunni Deobandi",
62+
"Buddhist",
63+
"Sikh",
64+
"Hindu",
65+
"Multi-faith",
66+
].freeze
67+
68+
validates :religious_character, inclusion: {
69+
in: NON_FAITH_RELIGIOUS_CHARACTER_TYPES + CHRISTIAN_RELIGIOUS_TYPES + CATHOLIC_RELIGIOUS_TYPES + OTHER_RELIGIOUS_TYPES,
70+
allow_nil: false,
71+
}
72+
1873
EXCLUDED_DETAILED_SCHOOL_TYPES = [
1974
"Further education",
2075
"Other independent school",
@@ -51,13 +106,6 @@ class School < Organisation
51106
through: %i[early_years ks1 ks2 ks3 ks4 ks5],
52107
}.freeze
53108

54-
def religious_character
55-
return if !respond_to?(:gias_data) || gias_data.nil?
56-
return if ["None", "Does not apply"].include?(gias_data["ReligiousCharacter (name)"])
57-
58-
gias_data["ReligiousCharacter (name)"]
59-
end
60-
61109
def live_group_vacancies
62110
if part_of_a_trust?
63111
org_ids = [trust.id] + trust.schools.pluck(:id)
@@ -71,11 +119,11 @@ def live_group_vacancies
71119
end
72120

73121
def faith_school?
74-
religious_character.present?
122+
NON_FAITH_RELIGIOUS_CHARACTER_TYPES.exclude? religious_character
75123
end
76124

77125
def catholic_school?
78-
religious_character&.include?("Catholic") || false
126+
religious_character.in? CATHOLIC_RELIGIOUS_TYPES
79127
end
80128

81129
def key_stages

app/services/gias/import_schools_and_local_authorities.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def group_data(row)
9595
local_authority_code: row["LA (code)"],
9696
name: row["LA (name)"],
9797
group_type: "local_authority",
98-
gias_data: row.to_h.slice("LA (code)", "LA (name)"),
9998
}
10099
end
101100

@@ -118,7 +117,11 @@ def school_data(row) # rubocop:disable Metrics/MethodLength
118117
town: row["Town"],
119118
phase: row["PhaseOfEducation (code)"].to_i,
120119
url: Addressable::URI.heuristic_parse(row["SchoolWebsite"]).to_s,
121-
gias_data: row.to_h,
120+
religious_character: row.fetch("ReligiousCharacter (name)").presence || "None",
121+
number_of_pupils: row.fetch("NumberOfPupils"),
122+
school_capacity: row.fetch("SchoolCapacity"),
123+
trust_school_flag_code: row.fetch("TrustSchoolFlag (code)"),
124+
trusts_code: row.fetch("Trusts (code)"),
122125
}.merge(school_location_data(row)).transform_values(&:presence)
123126
end
124127

app/services/gias/import_trusts.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def trust_data(row)
130130
group_type: row["Group Type"],
131131
town: row["Group Town"],
132132
postcode: row["Group Postcode"],
133-
gias_data: row.to_h,
134133
}
135134
end
136135

app/services/search/school_search.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ def apply_school_type_filter(scope)
108108
return scope unless school_types.present?
109109

110110
if school_types.include?("special_school") && school_types.include?("faith_school")
111-
scope.where.not("gias_data ->> 'ReligiousCharacter (name)' IN (?)", Organisation::NON_FAITH_RELIGIOUS_CHARACTER_TYPES)
111+
scope.where.not(religious_character: Organisation::NON_FAITH_RELIGIOUS_CHARACTER_TYPES)
112112
.or(scope.where(detailed_school_type: Organisation::SPECIAL_SCHOOL_TYPES))
113113
elsif school_types.include?("special_school")
114114
scope.where(detailed_school_type: Organisation::SPECIAL_SCHOOL_TYPES)
115115
elsif school_types.include?("faith_school")
116-
scope.where.not("gias_data ->> 'ReligiousCharacter (name)' IN (?)", Organisation::NON_FAITH_RELIGIOUS_CHARACTER_TYPES)
116+
scope.where.not(religious_character: Organisation::NON_FAITH_RELIGIOUS_CHARACTER_TYPES)
117117
else
118118
scope
119119
end

app/views/publishers/organisations/_organisation.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
- row.with_key text: t("publishers.organisations.organisation.school_age.label")
2323
- row.with_value text: age_range(organisation)
2424

25-
- if (text = number_of_pupils(organisation))
25+
- if organisation.number_of_pupils.present?
2626
- summary_list.with_row do |row|
2727
- row.with_key text: t("publishers.organisations.organisation.size.label")
28-
- row.with_value text: text
28+
- row.with_value text: number_of_pupils(organisation)
2929

3030
- summary_list.with_row(html_attributes: { id: "email" }) do |row|
3131
- row.with_key text: t("publishers.organisations.organisation.email.label")

config/analytics.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ shared:
261261
- address3
262262
- geopoint
263263
- uk_geopoint
264-
- gias_data
265264
- created_at
266265
- updated_at
267266
- url_override

0 commit comments

Comments
 (0)