Skip to content

Commit 393c592

Browse files
authored
CDPT-954 Rehabilitation Legislation Changes (#668)
1 parent 7705af2 commit 393c592

File tree

49 files changed

+946
-271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+946
-271
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ public/assets/
3636
.DS_Store
3737

3838
rerun.txt
39+
.idea/disclosure-checker.iml
40+
.idea/misc.xml
41+
.idea/vcs.xml
42+
.idea/workspace.xml

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Check when to disclose cautions or convictions
22

3-
[![repo standards badge](https://img.shields.io/badge/dynamic/json?color=blue&style=for-the-badge&logo=github&label=MoJ%20Compliant&query=%24.data%5B%3F%28%40.name%20%3D%3D%20%22disclosure-checker%22%29%5D.status&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fgithub_repositories)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/github_repositories#disclosure-checker "Link to report")
3+
[![repo standards badge](https://img.shields.io/badge/dynamic/json?color=blue&style=for-the-badge&logo=github&label=MoJ%20Compliant&query=%24.data%5B%3F%28%40.name%20%3D%3D%20%22disclosure-checker%22%29%5D.status&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fgithub_repositories)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/disclosure-checker "Link to report")
44

55
[![CI and CD](https://github.com/ministryofjustice/disclosure-checker/actions/workflows/test-build-deploy.yml/badge.svg)](https://github.com/ministryofjustice/disclosure-checker/actions/workflows/test-build-deploy.yml)
66

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ def initialize_disclosure_check(attributes = {})
5353
end
5454

5555
def maintenance_mode
56-
render "errors/maintenance" unless Rails.env.test?
56+
render "errors/maintenance" if Rails.env.production?
5757
end
5858
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Steps
2+
module Conviction
3+
class ConvictionMultipleSentencesController < Steps::ConvictionStepController
4+
def edit
5+
@form_object = ConvictionMultipleSentencesForm.new(
6+
disclosure_check: current_disclosure_check,
7+
conviction_multiple_sentences: current_disclosure_check.conviction_multiple_sentences,
8+
)
9+
end
10+
11+
def update
12+
update_and_advance(ConvictionMultipleSentencesForm)
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Steps
2+
module Conviction
3+
class ConvictionSchedule18Controller < Steps::ConvictionStepController
4+
def edit
5+
@form_object = ConvictionSchedule18Form.new(
6+
disclosure_check: current_disclosure_check,
7+
conviction_schedule18: current_disclosure_check.conviction_schedule18,
8+
)
9+
end
10+
11+
def update
12+
update_and_advance(ConvictionSchedule18Form)
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Steps
2+
module Conviction
3+
class SingleSentenceOver4Controller < Steps::ConvictionStepController
4+
def edit
5+
@form_object = SingleSentenceOver4Form.new(
6+
disclosure_check: current_disclosure_check,
7+
single_sentence_over4: current_disclosure_check.single_sentence_over4,
8+
)
9+
end
10+
11+
def update
12+
update_and_advance(SingleSentenceOver4Form)
13+
end
14+
end
15+
end
16+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Steps
2+
module Conviction
3+
class ConvictionMultipleSentencesForm < BaseForm
4+
include SingleQuestionForm
5+
6+
yes_no_attribute :conviction_multiple_sentences
7+
end
8+
end
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Steps
2+
module Conviction
3+
class ConvictionSchedule18Form < BaseForm
4+
include SingleQuestionForm
5+
6+
yes_no_attribute :conviction_schedule18
7+
8+
def i18n_attribute
9+
"conviction_schedule18_text"
10+
end
11+
end
12+
end
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Steps
2+
module Conviction
3+
class SingleSentenceOver4Form < BaseForm
4+
include SingleQuestionForm
5+
6+
yes_no_attribute :single_sentence_over4
7+
end
8+
end
9+
end

app/models/disclosure_check.rb

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class DisclosureCheck < ApplicationRecord
22
belongs_to :check_group, default: -> { create_check_group }
33
has_one :disclosure_report, through: :check_group
44

5-
delegate :drag_through?, to: :conviction, allow_nil: true
5+
delegate :no_drag_through?, to: :conviction, allow_nil: true
66

77
enum status: {
88
in_progress: 0,
@@ -14,4 +14,30 @@ class DisclosureCheck < ApplicationRecord
1414

1515
composed_of :caution, allow_nil: true, constructor: :find_constant,
1616
mapping: [%i[caution_type value]], class_name: "CautionType"
17+
18+
def conviction_length_in_years(conviction_length)
19+
if conviction_length_type == ConvictionLengthType::MONTHS.to_s
20+
conviction_length.months.in_years
21+
elsif conviction_length_type == ConvictionLengthType::DAYS.to_s
22+
conviction_length.days.in_years
23+
elsif conviction_length_type == ConvictionLengthType::WEEKS.to_s
24+
conviction_length.weeks.in_years
25+
elsif conviction_length_type == ConvictionLengthType::YEARS.to_s
26+
conviction_length.years.in_years
27+
end
28+
end
29+
30+
def schedule18_over_4_years
31+
return nil if conviction_schedule18.blank?
32+
33+
if conviction_schedule18.inquiry.yes? && (conviction_multiple_sentences.inquiry.no? || single_sentence_over4.inquiry.yes?)
34+
"yes"
35+
else
36+
"no"
37+
end
38+
end
39+
40+
def schedule18_over_4_years?
41+
schedule18_over_4_years == "yes"
42+
end
1743
end

app/presenters/conviction_result_presenter.rb

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def question_attributes
1414
:conviction_bail_days,
1515
:compensation_payment_date,
1616
:motoring_endorsement,
17+
:schedule18_over_4_years,
1718
].freeze
1819
end
1920

@@ -24,6 +25,7 @@ def editable_attributes
2425
conviction_bail_days: ->(id) { edit_steps_conviction_conviction_bail_days_path(check_id: id, next_step: :cya) },
2526
compensation_payment_date: ->(id) { edit_steps_conviction_compensation_payment_date_path(check_id: id, next_step: :cya) },
2627
motoring_endorsement: ->(id) { edit_steps_conviction_motoring_endorsement_path(check_id: id, next_step: :cya) },
28+
schedule18_over_4_years: ->(id) { edit_steps_conviction_conviction_schedule18_path(check_id: id) },
2729
}
2830
end
2931

app/presenters/results_item_presenter.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def summary
3232
scope:,
3333
change_path: change_path(item),
3434
)
35-
}.select(&:show?)
35+
}.compact.select(&:show?)
3636
end
3737

3838
delegate :expiry_date, to: :result_service
@@ -46,7 +46,7 @@ def result_service
4646
end
4747

4848
def format_value(attr)
49-
value = disclosure_check[attr]
49+
value = disclosure_check.send(attr)
5050
return value unless value.is_a?(Date)
5151

5252
approx_attr = ["approximate", attr].join("_").to_sym

app/services/calculators/multiples/proceedings.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def expiry_dates
5959
end
6060

6161
def non_relevant_expiry_dates
62-
@non_relevant_expiry_dates ||= disclosure_checks.reject(&:drag_through?).map(
62+
@non_relevant_expiry_dates ||= disclosure_checks.reject(&:no_drag_through?).map(
6363
&method(:expiry_date_for)
6464
)
6565
end

app/services/calculators/sentence_calculator.rb

+27-52
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,46 @@
11
module Calculators
22
class SentenceCalculator < BaseCalculator
3-
NEVER_SPENT_THRESHOLD = 48
3+
UPPER_LIMIT_MONTHS = Float::INFINITY
44
BAIL_OFFSET = -1.0
55

6-
# If conviction length is 6 months or less: start date + length + 18 months
7-
# If conviction length is over 6 months and less than or equal to 30 months: start date + length + 2 years
8-
# If conviction length is over 30 months and less than or equal to 4 years: start date + length + 3.5 years
9-
# If conviction length is over 4 years: never spent
10-
#
116
class Detention < SentenceCalculator
12-
UPPER_LIMIT = Float::INFINITY
13-
14-
REHABILITATION_1 = { months: 18 }.freeze
15-
REHABILITATION_2 = { months: 24 }.freeze
16-
REHABILITATION_3 = { months: 42 }.freeze
7+
def rehabilitation_period
8+
case conviction_length_in_months
9+
when 0..12
10+
{ months: 6 }
11+
when 12..48
12+
{ months: 24 }
13+
else
14+
{ months: 42 }
15+
end
16+
end
1717
end
1818

19-
# If conviction length is 6 months or less: start date + length + 18 months
20-
# If conviction length is over 6 months and less than or equal to 24 months: start date + length + 2 years
21-
# If conviction length is over 24 months, it is considered invalid
22-
#
23-
class DetentionTraining < SentenceCalculator
24-
UPPER_LIMIT = 24
25-
26-
REHABILITATION_1 = { months: 18 }.freeze
27-
REHABILITATION_2 = { months: 24 }.freeze
19+
class DetentionTraining < Detention
20+
UPPER_LIMIT_MONTHS = 24
2821
end
2922

30-
# If conviction length is 6 months or less: start date + length + 2 years
31-
# If conviction length is over 6 months and less than or equal to 30 months: start date + length + 4 years
32-
# If conviction length is over 30 months and less than or equal to 4 years: start date + length + 7 years
33-
# If conviction length is over 4 years: never spent
34-
#
3523
class Prison < SentenceCalculator
36-
UPPER_LIMIT = Float::INFINITY
37-
38-
REHABILITATION_1 = { months: 24 }.freeze
39-
REHABILITATION_2 = { months: 48 }.freeze
40-
REHABILITATION_3 = { months: 84 }.freeze
24+
def rehabilitation_period
25+
case conviction_length_in_months
26+
when 0..12
27+
{ years: 1 }
28+
when 12..48
29+
{ years: 4 }
30+
else
31+
{ years: 7 }
32+
end
33+
end
4134
end
4235

43-
# If conviction length is 6 months or less: start date + length + 2 years
44-
# If conviction length is over 6 months and less than or equal to 24 months: start date + length + 4 years
45-
# If conviction length is over 24 months, it is considered invalid
46-
#
47-
class SuspendedPrison < SentenceCalculator
48-
UPPER_LIMIT = 24
49-
50-
REHABILITATION_1 = { months: 24 }.freeze
51-
REHABILITATION_2 = { months: 48 }.freeze
36+
class SuspendedPrison < Prison
37+
UPPER_LIMIT_MONTHS = 24
5238
end
5339

5440
def expiry_date
5541
raise InvalidCalculation unless valid?
5642

57-
if conviction_length_in_months > NEVER_SPENT_THRESHOLD
43+
if disclosure_check.schedule18_over_4_years?
5844
ResultsVariant::NEVER_SPENT
5945
else
6046
conviction_end_date.advance(rehabilitation_period).advance(bail_offset)
@@ -65,22 +51,11 @@ def expiry_date
6551
# a maximum number of months in the sentence length.
6652
#
6753
def valid?
68-
conviction_length_in_months <= self.class::UPPER_LIMIT
54+
conviction_length_in_months <= self.class::UPPER_LIMIT_MONTHS
6955
end
7056

7157
private
7258

73-
def rehabilitation_period
74-
case conviction_length_in_months
75-
when 0..6
76-
self.class::REHABILITATION_1
77-
when 6..30
78-
self.class::REHABILITATION_2
79-
else
80-
self.class::REHABILITATION_3
81-
end
82-
end
83-
8459
# The day before the end date, thus we subtract 1 day.
8560
def conviction_end_date
8661
super.advance(days: -1)

app/services/conviction_decision_tree.rb

+30-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ def destination
1919
after_conviction_length_type
2020
when :compensation_paid
2121
after_compensation_paid
22-
when :conviction_length, :compensation_payment_date
22+
when :conviction_length
23+
after_conviction_length
24+
when :conviction_schedule18
25+
after_conviction_schedule18
26+
when :conviction_multiple_sentences
27+
after_conviction_multiple_sentences
28+
when :single_sentence_over4
29+
check_your_answers
30+
when :compensation_payment_date
2331
check_your_answers
2432
else
2533
raise InvalidStep, "Invalid step '#{as || step_params}'"
@@ -28,6 +36,27 @@ def destination
2836

2937
private
3038

39+
def after_conviction_multiple_sentences
40+
return edit(:single_sentence_over4) if step_value(:conviction_multiple_sentences).inquiry.yes?
41+
42+
check_your_answers
43+
end
44+
45+
def after_conviction_schedule18
46+
return edit(:conviction_multiple_sentences) if step_value(:conviction_schedule18).inquiry.yes?
47+
48+
check_your_answers
49+
end
50+
51+
def after_conviction_length
52+
conviction_length = disclosure_check.conviction_length_in_years(step_value(:conviction_length).to_i)
53+
schedule_18_applicable = ConvictionType.new(disclosure_check.conviction_subtype).schedule_18_applicable?
54+
55+
return check_your_answers if conviction_length <= 4 || !schedule_18_applicable
56+
57+
edit(:conviction_schedule18)
58+
end
59+
3160
def after_conviction_subtype
3261
return edit(:conviction_bail) if conviction.bailable_offense?
3362
return edit(:compensation_paid) if conviction.compensation?

0 commit comments

Comments
 (0)