@@ -17,7 +17,7 @@ def seed_vaccines
1717end
1818
1919def create_gp_practices
20- FactoryBot . create_list ( :gp_practice , 30 )
20+ Location . import! ( FactoryBot . build_list ( :gp_practice , 30 ) )
2121end
2222
2323def create_team ( ods_code :, workgroup : nil , type : :point_of_care )
@@ -79,20 +79,16 @@ def create_community_clinics_for(team)
7979 FactoryBot . create_list ( :community_clinic , 5 , team :)
8080end
8181
82- def attach_specific_school_to_team_if_present ( team :, urn :)
83- Location . find_by ( urn :) &.attach_to_team! (
84- team ,
85- academic_year : AcademicYear . current
86- )
87- end
88-
8982def create_session ( user , team , programmes :, completed : false , year_groups : nil )
9083 year_groups ||= programmes . flat_map ( &:default_year_groups ) . uniq
9184
92- Vaccine
93- . active
94- . for_programmes ( programmes )
95- . find_each { |vaccine | FactoryBot . create ( :batch , team :, vaccine :) }
85+ Batch . import! (
86+ Vaccine
87+ . active
88+ . for_programmes ( programmes )
89+ . find_each
90+ . map { |vaccine | FactoryBot . build ( :batch , team :, vaccine :) }
91+ )
9692
9793 location = FactoryBot . create ( :school , team :, gias_year_groups : year_groups )
9894 date = completed ? 1 . week . ago . to_date : Date . current
@@ -161,9 +157,8 @@ def create_session(user, team, programmes:, completed: false, year_groups: nil)
161157 traits << :partially_vaccinated_triage_needed if programme . td_ipv?
162158
163159 traits . each do |trait |
164- FactoryBot . create_list (
160+ FactoryBot . create (
165161 :patient ,
166- 1 ,
167162 trait ,
168163 programmes : [ programme ] ,
169164 session :,
@@ -308,11 +303,6 @@ def create_team_sessions(user, team)
308303 )
309304end
310305
311- set_feature_flags
312-
313- seed_vaccines
314- create_gp_practices
315-
316306def create_nurse_joy_team
317307 team = create_team ( ods_code : "R1L" )
318308 user = create_user ( :nurse , team :, email : "nurse.joy@example.com" )
@@ -324,19 +314,31 @@ def create_nurse_joy_team
324314 attach_sample_of_schools_to ( team )
325315 create_community_clinics_for ( team )
326316
327- # Bohunt School Wokingham - used by automated tests
328- attach_specific_school_to_team_if_present ( team :, urn : "142181" )
329-
330- # Barn End Centre - used by automated tests
331- attach_specific_school_to_team_if_present ( team :, urn : "118239" )
332-
333317 Audited . audit_class . as_user ( user ) { create_team_sessions ( user , team ) }
334318 setup_clinic ( team )
335319 create_patients ( team )
336320 create_imports ( user , team )
337321 create_school_moves ( team )
338322end
339323
324+ def create_upload_patients_and_vaccination_records ( user )
325+ patients =
326+ FactoryBot . create_list ( :patient , 50 , :archived , team : user . teams . first )
327+
328+ immunisation_import =
329+ ImmunisationImport . find_by ( type : "national_reporting" , status : "processed" )
330+
331+ patients . each do |patient |
332+ FactoryBot . create (
333+ :vaccination_record ,
334+ :sourced_from_national_reporting ,
335+ immunisation_import :,
336+ patient :,
337+ performed_by : user
338+ )
339+ end
340+ end
341+
340342def create_national_reporting_team
341343 team =
342344 FactoryBot . create (
@@ -355,51 +357,42 @@ def create_national_reporting_team
355357 create_upload_patients_and_vaccination_records ( user )
356358end
357359
358- def create_upload_patients_and_vaccination_records ( user )
359- patients =
360- FactoryBot . create_list ( :patient , 50 , :archived , team : user . teams . first )
360+ def create_a9a5a_team
361+ # CIS2 team - the ODS code and user UID need to match the values in the CIS2 env
362+ team = create_team ( ods_code : "A9A5A" )
363+ user = create_user ( :nurse , team :, uid : "555057896106" )
361364
362- immunisation_import =
363- ImmunisationImport . find_by ( type : "national_reporting" , status : "processed" )
365+ attach_sample_of_schools_to ( team )
366+ create_community_clinics_for ( team )
364367
365- patients . each do |patient |
366- FactoryBot . create (
367- :vaccination_record ,
368- :sourced_from_national_reporting ,
369- immunisation_import :,
370- patient :,
371- performed_by : user
372- )
373- end
368+ Audited . audit_class . as_user ( user ) { create_team_sessions ( user , team ) }
369+ setup_clinic ( team )
370+ create_patients ( team )
371+ create_imports ( user , team )
372+ create_school_moves ( team )
374373end
375374
376- unless Settings . cis2 . enabled
377- # Don't create Nurse Joy's team on a CIS2 env, because password authentication
378- # is not available and password= fails to run.
379- create_nurse_joy_team
380-
381- create_national_reporting_team
375+ def create_support_team
376+ support_team =
377+ create_team (
378+ ods_code : CIS2Info ::SUPPORT_ORGANISATION ,
379+ workgroup : CIS2Info ::SUPPORT_WORKGROUP
380+ )
381+ create_user ( :support , team : support_team , email : "support@example.com" )
382382end
383383
384- # CIS2 team - the ODS code and user UID need to match the values in the CIS2 env
385- team = create_team ( ods_code : "A9A5A" )
386- user = create_user ( :nurse , team :, uid : "555057896106" )
387-
388- support_team =
389- create_team (
390- ods_code : CIS2Info ::SUPPORT_ORGANISATION ,
391- workgroup : CIS2Info ::SUPPORT_WORKGROUP
392- )
393- create_user ( :support , team : support_team , email : "support@example.com" )
384+ set_feature_flags
394385
395- attach_sample_of_schools_to ( team )
396- create_community_clinics_for ( team )
386+ seed_vaccines
387+ create_gp_practices
397388
398- Audited . audit_class . as_user ( user ) { create_team_sessions ( user , team ) }
399- setup_clinic ( team )
400- create_patients ( team )
401- create_imports ( user , team )
402- create_school_moves ( team )
389+ if Settings . cis2 . enabled
390+ create_a9a5a_team
391+ create_support_team
392+ else
393+ create_nurse_joy_team
394+ create_national_reporting_team
395+ end
403396
404397PatientTeamUpdater . call
405398PatientStatusUpdater . call
0 commit comments