Skip to content

Commit c764ae5

Browse files
committed
Tie test cases to sessions
1 parent c96e7f3 commit c764ae5

1 file changed

Lines changed: 91 additions & 11 deletions

File tree

lib/create-data.js

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
RegistrationOutcome,
2222
SchoolPhase,
2323
ScreenOutcome,
24+
SessionPresetName,
2425
SessionPresets,
2526
SessionType,
2627
UploadType,
@@ -64,6 +65,7 @@ import {
6465
formatDate,
6566
removeDays,
6667
today,
68+
getAcademicYear,
6769
getCurrentAcademicYear
6870
} from '../app/utils/date.js'
6971
import { range } from '../app/utils/number.js'
@@ -720,26 +722,80 @@ const seededMmrDob = new Date('2020-09-01')
720722
function buildSeededMmrVaccination({
721723
uuid,
722724
patient_uuid,
725+
patientSession_uuid,
723726
ageMonths,
724727
ageDays = 0,
725728
given,
726-
service = false
729+
service = false,
730+
notGivenOutcome
727731
}) {
728732
const createdAt = addDays(addMonths(seededMmrDob, ageMonths), ageDays)
729733
return new Vaccination({
730734
uuid,
731735
createdAt,
736+
createdBy_uid: nurse.uid,
732737
patient_uuid,
738+
patientSession_uuid,
733739
programme_id: 'mmr',
734740
outcome: given
735-
? (service ? VaccinationOutcome.Vaccinated : VaccinationOutcome.AlreadyVaccinated)
736-
: VaccinationOutcome.Unwell,
741+
? VaccinationOutcome.Vaccinated
742+
: (notGivenOutcome || VaccinationOutcome.Unwell),
737743
source: service || !given
738744
? VaccinationSource.Service
739745
: VaccinationSource.NhsImmunisationsApi
740746
})
741747
}
742748

749+
// Seeded MMR sessions at Seva Primary. Each session date is derived from
750+
// seededMmrDob + ageMonths so that service doses land on a real session.
751+
// sessionKey groups doses across patients into the same session.
752+
const seededMmrSessions = {
753+
session_50m: {
754+
id: 'mmr-seed-s1',
755+
date: addMonths(seededMmrDob, 50),
756+
openAt: addDays(addMonths(seededMmrDob, 50), -42)
757+
},
758+
session_54m: {
759+
id: 'mmr-seed-s2',
760+
date: addMonths(seededMmrDob, 54),
761+
openAt: addDays(addMonths(seededMmrDob, 54), -42)
762+
},
763+
session_57m: {
764+
id: 'mmr-seed-s3',
765+
date: addMonths(seededMmrDob, 57),
766+
openAt: addDays(addMonths(seededMmrDob, 57), -42)
767+
},
768+
session_61m: {
769+
id: 'mmr-seed-s4',
770+
date: addMonths(seededMmrDob, 61),
771+
openAt: addDays(addMonths(seededMmrDob, 61), -42)
772+
},
773+
session_63m: {
774+
id: 'mmr-seed-s5',
775+
date: addDays(addMonths(seededMmrDob, 63), 10),
776+
openAt: addMonths(seededMmrDob, 63)
777+
}
778+
}
779+
780+
for (const [, cfg] of Object.entries(seededMmrSessions)) {
781+
const session = new Session(
782+
{
783+
id: cfg.id,
784+
createdAt: cfg.openAt,
785+
createdBy_uid: nurse.uid,
786+
date: cfg.date,
787+
openAt: cfg.openAt,
788+
academicYear: getAcademicYear(cfg.date),
789+
type: SessionType.School,
790+
school_id: seededMmrSchoolId,
791+
presetNames: [SessionPresetName.MMR],
792+
registration: true
793+
},
794+
context
795+
)
796+
context.sessions[session.id] = session
797+
}
798+
743799
const seededMmrPatients = [
744800
{
745801
uuid: 'mmr00001-0000-4000-8000-000000000001',
@@ -749,7 +805,7 @@ const seededMmrPatients = [
749805
doses: [
750806
// Case 1 — two valid doses
751807
{ uuid: 'mmr00001-v001-4000-8000-000000000001', ageMonths: 12, ageDays: 14, given: true },
752-
{ uuid: 'mmr00001-v002-4000-8000-000000000002', ageMonths: 15, ageDays: 7, given: true, service: true }
808+
{ uuid: 'mmr00001-v002-4000-8000-000000000002', ageMonths: 40, ageDays: 10, given: true }
753809
]
754810
},
755811
{
@@ -758,10 +814,13 @@ const seededMmrPatients = [
758814
firstName: 'Bilal',
759815
lastName: 'Begum',
760816
doses: [
761-
// Case 2 — two valid doses plus a failed attempt between them
817+
// Case 2 — two valid doses with repeated failed attempts between them
762818
{ uuid: 'mmr00002-v001-4000-8000-000000000001', ageMonths: 12, ageDays: 14, given: true },
763-
{ uuid: 'mmr00002-v002-4000-8000-000000000002', ageMonths: 14, ageDays: 0, given: false },
764-
{ uuid: 'mmr00002-v003-4000-8000-000000000003', ageMonths: 15, ageDays: 10, given: true }
819+
{ uuid: 'mmr00002-v002-4000-8000-000000000002', ageMonths: 50, ageDays: 0, given: false, notGivenOutcome: VaccinationOutcome.Absent, sessionKey: 'session_50m' },
820+
{ uuid: 'mmr00002-v003-4000-8000-000000000003', ageMonths: 54, ageDays: 0, given: false, notGivenOutcome: VaccinationOutcome.ConsentRefused, sessionKey: 'session_54m' },
821+
{ uuid: 'mmr00002-v004-4000-8000-000000000004', ageMonths: 57, ageDays: 0, given: false, notGivenOutcome: VaccinationOutcome.Absent, sessionKey: 'session_57m' },
822+
{ uuid: 'mmr00002-v005-4000-8000-000000000005', ageMonths: 61, ageDays: 0, given: false, notGivenOutcome: VaccinationOutcome.Refused, sessionKey: 'session_61m' },
823+
{ uuid: 'mmr00002-v006-4000-8000-000000000006', ageMonths: 63, ageDays: 10, given: true, service: true, sessionKey: 'session_63m' }
765824
]
766825
},
767826
{
@@ -770,10 +829,10 @@ const seededMmrPatients = [
770829
firstName: 'Chiamaka',
771830
lastName: 'Chen',
772831
doses: [
773-
// Case 3 — dose at 11m (ignored), then two valid doses
832+
// Case 3 — dose at 11m (ignored), then two valid doses given at school age by SAIS
774833
{ uuid: 'mmr00003-v001-4000-8000-000000000001', ageMonths: 11, ageDays: 0, given: true },
775-
{ uuid: 'mmr00003-v002-4000-8000-000000000002', ageMonths: 13, ageDays: 0, given: true },
776-
{ uuid: 'mmr00003-v003-4000-8000-000000000003', ageMonths: 15, ageDays: 7, given: true }
834+
{ uuid: 'mmr00003-v002-4000-8000-000000000002', ageMonths: 50, ageDays: 0, given: true, service: true, sessionKey: 'session_50m' },
835+
{ uuid: 'mmr00003-v003-4000-8000-000000000003', ageMonths: 54, ageDays: 0, given: true, service: true, sessionKey: 'session_54m' }
777836
]
778837
},
779838
{
@@ -791,10 +850,30 @@ const seededMmrPatients = [
791850

792851
for (const seed of seededMmrPatients) {
793852
const vaccination_uuids = []
853+
const patientSession_uuids = []
854+
794855
for (const dose of seed.doses) {
856+
let patientSession_uuid
857+
if (dose.sessionKey) {
858+
const cfg = seededMmrSessions[dose.sessionKey]
859+
const patientSession = new PatientSession(
860+
{
861+
createdAt: cfg.openAt,
862+
patient_uuid: seed.uuid,
863+
programme_id: 'mmr',
864+
session_id: cfg.id
865+
},
866+
context
867+
)
868+
context.patientSessions[patientSession.uuid] = patientSession
869+
patientSession_uuid = patientSession.uuid
870+
patientSession_uuids.push(patientSession.uuid)
871+
}
872+
795873
const vaccination = buildSeededMmrVaccination({
796874
...dose,
797-
patient_uuid: seed.uuid
875+
patient_uuid: seed.uuid,
876+
patientSession_uuid
798877
})
799878
context.vaccinations[vaccination.uuid] = vaccination
800879
vaccination_uuids.push(vaccination.uuid)
@@ -812,6 +891,7 @@ for (const seed of seededMmrPatients) {
812891
addressLevel1: 'Coventry',
813892
postalCode: 'CV1 1AA'
814893
},
894+
patientSession_uuids,
815895
vaccination_uuids
816896
})
817897
context.patients[patient.uuid] = patient

0 commit comments

Comments
 (0)