Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cohort filtering in ParticipantsDeclarationsQuery #4794

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 18 additions & 34 deletions app/services/api/v3/participant_declarations_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,58 +76,42 @@ def npq_lead_provider

def declarations_scope
scope = ParticipantDeclaration.for_lead_provider(cpd_lead_provider)

if cohort_years.present?
scope = ecf_cohort_for(scope).or(npq_cohort_for(scope))
end

scope
end

def ecf_cohort_for(scope)
return ParticipantDeclaration.none if lead_provider.blank?

with_joins(scope).where(participant_profile: { induction_records: { cohorts: { start_year: cohort_years } } })
end

def npq_cohort_for(scope)
return ParticipantDeclaration.none if npq_lead_provider.blank?

with_joins(scope).where(participant_profile: { type: "ParticipantProfile::NPQ", schedule: { cohorts: { start_year: cohort_years } } })
.left_outer_joins(:cohort)
filter_cohorts(scope)
end

def ecf_previous_declarations_scope
scope = with_joins(ParticipantDeclaration)
scope = ParticipantDeclaration
.left_outer_joins(
:cohort,
participant_profile: [
{ induction_records: [
{ induction_programme: :partnership },
] },
],
)
.where(participant_profile: { induction_records: { induction_programme: { partnerships: { lead_provider_id: lead_provider&.id } } } })
.where(participant_profile: { induction_records: { induction_status: "active" } }) # only want induction records that are the winning latest ones
.where(state: %w[submitted eligible payable paid])

if cohort_years.present? && lead_provider.present?
scope = scope.where(participant_profile: { induction_records: { cohorts: { start_year: cohort_years } } })
end
scope = filter_cohorts(scope) if lead_provider.present?

scope
end

def filter_cohorts(scope)
return scope if cohort_years.blank?

scope.where(cohort: { start_year: cohort_years })
end

def participant_ids
filter[:participant_id]&.split(",")
end

def delivery_partner_ids
filter[:delivery_partner_id]&.split(",")
end

def with_joins(scope)
scope.left_outer_joins(
participant_profile: [
[schedule: :cohort],
{ induction_records: [
:cohort,
{ induction_programme: :partnership },
] },
],
)
end
end
end
end
15 changes: 15 additions & 0 deletions docs/source/release-notes.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ weight: 8

If you have any questions or comments about these notes, please contact DfE via Slack or email.

## 5 June 2024

We're addressing a potential confusion for providers filtering participant declarations by cohort.

Currently, filtering by a participant's current cohort (for example, 2022) returns all their declarations, even those made when the participant was in an earlier cohort (for example, 2021).

For instance, if a participant is in the 2022 cohort, but has declarations in both 2021 and 2022, all declarations are returned when filtering by 2022, and none when filtering by 2021.

Going forward, we’ll now return only the declarations made during the specified cohort. For example:

- filtering by 2021 will return only the declarations made while a participant was in the 2021 cohort
- filtering by 2022 will return only the declarations made while a participant was in the 2022 cohort

We’ve released this in the API v3 Live environment.

## 24 May 2024

We’ve added the schedules and contract data for the 2024/25 intake of early career teachers and mentors to the [test (sandbox) environment](https://sb.manage-training-for-early-career-teachers.education.gov.uk/).
Expand Down
3 changes: 2 additions & 1 deletion spec/factories/services/npq/npq_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
declaration_type: "started",
participant_profile: npq_application.profile,
course_identifier: npq_application.npq_course.identifier,
cpd_lead_provider: npq_application.npq_lead_provider.cpd_lead_provider)
cpd_lead_provider: npq_application.npq_lead_provider.cpd_lead_provider,
cohort: npq_application.cohort)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/requests/api/v3/participant_declarations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.cohort,
)
end
let!(:participant_declaration2) do
Expand All @@ -57,6 +58,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile2,
delivery_partner: delivery_partner2,
cohort: participant_profile2.cohort,
)
end
let!(:participant_declaration3) do
Expand All @@ -70,6 +72,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile3,
delivery_partner: delivery_partner2,
cohort: participant_profile3.cohort,
)
end
let!(:participant_declaration4) do
Expand All @@ -83,6 +86,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: participant_profile4,
delivery_partner: delivery_partner1,
cohort: participant_profile4.cohort,
)
end

Expand Down
11 changes: 11 additions & 0 deletions spec/services/api/v3/participant_declarations_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -56,6 +57,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile2,
delivery_partner: delivery_partner2,
cohort: participant_profile2.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -70,6 +72,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile3,
delivery_partner: delivery_partner2,
cohort: participant_profile3.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -84,6 +87,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: participant_profile4,
delivery_partner: delivery_partner1,
cohort: participant_profile4.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand All @@ -110,6 +114,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: transfer_induction_record.participant_profile,
delivery_partner: delivery_partner1,
cohort: transfer_induction_record.participant_profile.schedule.cohort,
)

ParticipantDeclaration.where(id: declaration.id).select(:id, :created_at).first
Expand Down Expand Up @@ -300,6 +305,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)
end
end
Expand All @@ -312,6 +318,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile2,
delivery_partner: delivery_partner2,
cohort: participant_profile2.schedule.cohort,
)
end
end
Expand All @@ -324,6 +331,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile3,
delivery_partner: delivery_partner2,
cohort: participant_profile3.schedule.cohort,
)
end
end
Expand All @@ -336,6 +344,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: participant_profile4,
delivery_partner: delivery_partner1,
cohort: participant_profile4.schedule.cohort,
)
end
end
Expand Down Expand Up @@ -373,6 +382,7 @@
cpd_lead_provider: cpd_lead_provider1,
participant_profile: participant_profile1,
delivery_partner: delivery_partner1,
cohort: participant_profile1.schedule.cohort,
)
end

Expand Down Expand Up @@ -402,6 +412,7 @@
cpd_lead_provider: cpd_lead_provider2,
participant_profile: transfer_induction_record.participant_profile,
delivery_partner: delivery_partner1,
cohort: transfer_induction_record.participant_profile.schedule.cohort,
)
end

Expand Down
Loading