Skip to content
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
5 changes: 4 additions & 1 deletion app/helpers/application_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def application_form_summary_rows(
},
value: {
text:
pluralize(application_form.working_days_since_submission, "day"),
pluralize(
application_form.working_days_between_submitted_and_today,
"day",
),
},
},
{
Expand Down
105 changes: 54 additions & 51 deletions app/jobs/update_working_days_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
class UpdateWorkingDaysJob < ApplicationJob
def perform
update_application_forms_since_submission
update_application_forms_submitted_to_completed

update_assessments_since_started
update_assessments_started_to_recommendation
update_assessments_submission_to_recommendation
update_assessments_started_to_completed
update_assessments_submission_to_started
update_assessment_started_to_verification
update_assessment_submission_to_verification

update_further_information_requests_assessment_started_to_creation
update_further_information_requests_since_received
update_further_information_requests_received_to_recommendation
update_further_information_requests_assessment_started_to_requested
end

private
Expand All @@ -29,7 +29,7 @@ def update_application_forms_since_submission
.where.not(submitted_at: nil)
.find_each do |application_form|
application_form.update!(
working_days_since_submission:
working_days_between_submitted_and_today:
calendar.business_days_between(
application_form.submitted_at,
today,
Expand All @@ -38,108 +38,111 @@ def update_application_forms_since_submission
end
end

def update_application_forms_submitted_to_completed
ApplicationForm.completed_stage.find_each do |application_form|
application_form.update!(
working_days_between_submitted_and_completed:
calendar.business_days_between(
application_form.submitted_at,
application_form.awarded_at || application_form.declined_at ||
application_form.withdrawn_at,
),
)
end
end

def update_assessments_since_started
Assessment
.where.not(started_at: nil)
.find_each do |assessment|
assessment.update!(
working_days_since_started:
working_days_between_started_and_today:
calendar.business_days_between(assessment.started_at, today),
)
end
end

def update_assessments_started_to_recommendation
def update_assessments_started_to_completed
Assessment
.joins(:application_form)
.includes(:application_form)
.where(application_form: { stage: "completed" })
.where.not(started_at: nil)
.where.not(recommended_at: nil)
.find_each do |assessment|
application_form = assessment.application_form

assessment.update!(
working_days_started_to_recommendation:
working_days_between_started_and_completed:
calendar.business_days_between(
assessment.started_at,
assessment.recommended_at,
application_form.awarded_at || application_form.declined_at ||
application_form.withdrawn_at,
),
)
end
end

def update_assessments_submission_to_recommendation
def update_assessments_submission_to_started
Assessment
.joins(:application_form)
.includes(:application_form)
.where.not(application_form: { submitted_at: nil })
.where.not(recommended_at: nil)
.where.not(started_at: nil)
.find_each do |assessment|
assessment.update!(
working_days_submission_to_recommendation:
working_days_between_submitted_and_started:
calendar.business_days_between(
assessment.application_form.submitted_at,
assessment.recommended_at,
assessment.started_at,
),
)
end
end

def update_assessments_submission_to_started
def update_assessment_started_to_verification
Assessment
.joins(:application_form)
.includes(:application_form)
.where.not(application_form: { submitted_at: nil })
.where.not(started_at: nil)
.where.not(verification_started_at: nil)
.find_each do |assessment|
assessment.update!(
working_days_submission_to_started:
working_days_between_started_and_verification_started:
calendar.business_days_between(
assessment.application_form.submitted_at,
assessment.started_at,
assessment.verification_started_at,
),
)
end
end

def update_further_information_requests_assessment_started_to_creation
FurtherInformationRequest
.joins(:assessment)
.includes(:assessment)
.where.not(assessment: { started_at: nil })
.find_each do |further_information_request|
further_information_request.update!(
working_days_assessment_started_to_creation:
calendar.business_days_between(
further_information_request.assessment.started_at,
further_information_request.created_at,
),
)
end
end

def update_further_information_requests_since_received
FurtherInformationRequest
.where.not(received_at: nil)
.find_each do |further_information_request|
further_information_request.update!(
working_days_since_received:
def update_assessment_submission_to_verification
Assessment
.joins(:application_form)
.includes(:application_form)
.where.not(application_form: { submitted_at: nil })
.where.not(verification_started_at: nil)
.find_each do |assessment|
assessment.update!(
working_days_between_submitted_and_verification_started:
calendar.business_days_between(
further_information_request.received_at,
today,
assessment.application_form.submitted_at,
assessment.verification_started_at,
),
)
end
end

def update_further_information_requests_received_to_recommendation
def update_further_information_requests_assessment_started_to_requested
FurtherInformationRequest
.joins(:assessment)
.includes(:assessment)
.where.not(received_at: nil)
.where.not(assessment: { recommended_at: nil })
.where.not(assessment: { started_at: nil })
.where.not(requested_at: nil)
.find_each do |further_information_request|
further_information_request.update!(
working_days_received_to_recommendation:
working_days_between_assessment_started_to_requested:
calendar.business_days_between(
further_information_request.received_at,
further_information_request.assessment.recommended_at,
further_information_request.assessment.started_at,
further_information_request.requested_at,
),
)
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
# trs_match :jsonb
# withdrawn_at :datetime
# work_history_status :string default("not_started"), not null
# working_days_since_submission :integer
# working_days_between_submitted_and_completed :integer
# working_days_between_submitted_and_today :integer
# written_statement_confirmation :boolean default(FALSE), not null
# written_statement_optional :boolean default(FALSE), not null
# written_statement_status :string default("not_started"), not null
Expand Down
46 changes: 24 additions & 22 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
#
# Table name: assessments
#
# id :bigint not null, primary key
# age_range_max :integer
# age_range_min :integer
# age_range_note :text default(""), not null
# induction_required :boolean
# qualifications_assessor_note :text default(""), not null
# recommendation :string default("unknown"), not null
# recommendation_assessor_note :text default(""), not null
# recommended_at :datetime
# references_verified :boolean
# scotland_full_registration :boolean
# started_at :datetime
# subjects :text default([]), not null, is an Array
# subjects_note :text default(""), not null
# unsigned_consent_document_generated :boolean default(FALSE), not null
# working_days_since_started :integer
# working_days_started_to_recommendation :integer
# working_days_submission_to_recommendation :integer
# working_days_submission_to_started :integer
# created_at :datetime not null
# updated_at :datetime not null
# application_form_id :bigint not null
# id :bigint not null, primary key
# age_range_max :integer
# age_range_min :integer
# age_range_note :text default(""), not null
# induction_required :boolean
# qualifications_assessor_note :text default(""), not null
# recommendation :string default("unknown"), not null
# recommendation_assessor_note :text default(""), not null
# recommended_at :datetime
# references_verified :boolean
# scotland_full_registration :boolean
# started_at :datetime
# subjects :text default([]), not null, is an Array
# subjects_note :text default(""), not null
# unsigned_consent_document_generated :boolean default(FALSE), not null
# verification_started_at :datetime
# working_days_between_started_and_completed :integer
# working_days_between_started_and_today :integer
# working_days_between_started_and_verification_started :integer
# working_days_between_submitted_and_started :integer
# working_days_between_submitted_and_verification_started :integer
# created_at :datetime not null
# updated_at :datetime not null
# application_form_id :bigint not null
#
# Indexes
#
Expand Down
24 changes: 11 additions & 13 deletions app/models/further_information_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
#
# Table name: further_information_requests
#
# id :bigint not null, primary key
# expired_at :datetime
# received_at :datetime
# requested_at :datetime
# review_note :string default(""), not null
# review_passed :boolean
# reviewed_at :datetime
# working_days_assessment_started_to_creation :integer
# working_days_received_to_recommendation :integer
# working_days_since_received :integer
# created_at :datetime not null
# updated_at :datetime not null
# assessment_id :bigint not null
# id :bigint not null, primary key
# expired_at :datetime
# received_at :datetime
# requested_at :datetime
# review_note :string default(""), not null
# review_passed :boolean
# reviewed_at :datetime
# working_days_between_assessment_started_to_requested :integer
# created_at :datetime not null
# updated_at :datetime not null
# assessment_id :bigint not null
#
# Indexes
#
Expand Down
2 changes: 1 addition & 1 deletion app/services/submit_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call
subject_limited: region.country.subject_limited,
subjects: application_form.subjects.compact_blank,
submitted_at: Time.zone.now,
working_days_since_submission: 0,
working_days_between_submitted_and_today: 0,
)

assessment = AssessmentFactory.call(application_form:)
Expand Down
7 changes: 7 additions & 0 deletions app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def call
ActiveRecord::Base.transaction do
assessment.qualifications_assessor_note = qualifications_assessor_note
assessment.verify!
update_assessment_verification_started_at

create_professional_standing_request
create_qualification_requests
Expand Down Expand Up @@ -85,6 +86,12 @@ def create_reference_requests
end
end

def update_assessment_verification_started_at
if assessment.verification_started_at.nil?
assessment.update!(verification_started_at: Time.zone.now)
end
end

def send_references_requested_email(reference_requests)
DeliverEmail.call(
application_form:,
Expand Down
17 changes: 9 additions & 8 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
- updated_at
- withdrawn_at
- work_history_status
- working_days_since_submission
- working_days_between_submitted_and_today
- working_days_between_submitted_and_completed
- written_statement_confirmation
- written_statement_optional
- written_statement_status
Expand Down Expand Up @@ -89,10 +90,12 @@
- subjects
- unsigned_consent_document_generated
- updated_at
- working_days_since_started
- working_days_started_to_recommendation
- working_days_submission_to_recommendation
- working_days_submission_to_started
- verification_started_at
- working_days_between_started_and_today
- working_days_between_started_and_completed
- working_days_between_submitted_and_started
- working_days_between_started_and_verification_started
- working_days_between_submitted_and_verification_started
:consent_requests:
- assessment_id
- created_at
Expand Down Expand Up @@ -158,9 +161,7 @@
- review_passed
- reviewed_at
- updated_at
- working_days_assessment_started_to_creation
- working_days_received_to_recommendation
- working_days_since_received
- working_days_between_assessment_started_to_requested
:further_information_request_items:
- contact_email
- contact_job
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddVerificationStartedAtToAssessments < ActiveRecord::Migration[8.0]
def change
add_column :assessments, :verification_started_at, :datetime
end
end
Loading
Loading