Skip to content

Commit e5e362e

Browse files
Combine children with no known school with home-schooled children)
1 parent fed7bd6 commit e5e362e

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

app/controllers/school.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import wizard from '@x-govuk/govuk-prototype-wizard'
22
import _ from 'lodash'
33

44
import { PatientStatus } from '../enums.js'
5-
import { Patient, School } from '../models.js'
5+
import { School } from '../models.js'
66
import { generateNewSiteCode } from '../utils/location.js'
77
import { getResults, getPagination } from '../utils/pagination.js'
88
import { formatYearGroup } from '../utils/string.js'
@@ -18,7 +18,10 @@ export const schoolController = {
1818
},
1919

2020
readAll(request, response, next) {
21-
response.locals.schools = School.findAll(request.session.data)
21+
// Combine children with no known school with home-schooled children)
22+
response.locals.schools = School.findAll(request.session.data).filter(
23+
(school) => school.id !== '888888'
24+
)
2225

2326
next()
2427
},
@@ -93,17 +96,12 @@ export const schoolController = {
9396
},
9497

9598
readPatients(request, response, next) {
96-
const { school_id } = request.params
9799
const { option, programme_id, q, yearGroup } = request.query
98100
const { data } = request.session
99101
const { school } = response.locals
100102

101-
const patients = Patient.findAll(data).filter(
102-
(patient) => patient.school_id === school_id
103-
)
104-
105103
// Sort
106-
let results = _.sortBy(patients, 'lastName')
104+
let results = _.sortBy(school.patients, 'lastName')
107105

108106
// Query
109107
if (q) {
@@ -207,7 +205,7 @@ export const schoolController = {
207205

208206
// Results
209207
response.locals.school = school
210-
response.locals.patients = patients
208+
response.locals.patients = school.patients
211209
response.locals.results = getResults(results, request.query)
212210
response.locals.pages = getPagination(results, request.query)
213211

app/models/school.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export class School extends Location {
3131
this.site = options?.site
3232
this.phase = options?.phase
3333
this.yearGroups = options?.yearGroups || []
34+
this.homeOrUnknown = ['888888', '999999'].includes(this.urn)
35+
36+
if (this.homeOrUnknown) {
37+
this.name = 'No known school (including home-schooled children)'
38+
}
3439
}
3540

3641
/**
@@ -62,6 +67,13 @@ export class School extends Location {
6267
*/
6368
get patients() {
6469
if (this.context?.patients && this.id) {
70+
// Combine children with no known school with home-schooled children)
71+
if (this.homeOrUnknown) {
72+
return Object.values(this.context?.patients)
73+
.filter(({ school_id }) => ['888888', '999999'].includes(school_id))
74+
.map((patient) => new Patient(patient, this.context))
75+
}
76+
6577
return Object.values(this.context?.patients)
6678
.filter(({ school_id }) => school_id === this.id)
6779
.map((patient) => new Patient(patient, this.context))

0 commit comments

Comments
 (0)