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

CRIMAPP-1597 store overall_result type rather than string #805

Merged
merged 2 commits into from
Feb 3, 2025
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem 'laa-criminal-applications-datastore-api-client',

gem 'laa-criminal-legal-aid-schemas',
github: 'ministryofjustice/laa-criminal-legal-aid-schemas',
tag: 'v1.5.2'
tag: 'v1.6.0'

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ GIT

GIT
remote: https://github.com/ministryofjustice/laa-criminal-legal-aid-schemas.git
revision: 99982c0576a5fe9defeaccab89e16f6e3c11fd93
tag: v1.5.2
revision: a47fd2b1127e5c67a2a31b52d42e13f77771c6da
tag: v1.6.0
specs:
laa-criminal-legal-aid-schemas (1.5.2)
laa-criminal-legal-aid-schemas (1.6.0)
dry-schema (~> 1.13)
dry-struct (~> 1.6.0)
json-schema (~> 4.0.0)
Expand Down
24 changes: 1 addition & 23 deletions app/aggregates/deciding/commands/set_funding_decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,7 @@ class SetFundingDecision < Command

def call
with_decision do |decision|
decision.set_funding_decision(
user_id:, funding_decision:, overall_result:
)
end
end

private

# Store the overall results string as it would appear in eForms.
def overall_result
Maat::OverallResultTranslator.translate(maat_funding_decision)
end

# Crime Review only creates decisions for Non-Means applications.
# If a funding decision is refused, we can infer that the application
# failed the IoJ test. Consequently, the MAAT funding decision
# should be recorded as FAILIOJ.
def maat_funding_decision
case funding_decision
when /granted/
'GRANTED'
when /refused/
'FAILIOJ'
decision.set_funding_decision(user_id:, funding_decision:)
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ removes redundant code. The overall result is now calculated in the same way across all application types.

end
end
Expand Down
14 changes: 9 additions & 5 deletions app/aggregates/deciding/decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(decision_id)

attr_reader :application_id, :decision_id, :funding_decision, :comment,
:state, :reference, :maat_id, :checksum, :case_id, :means, :interests_of_justice,
:court_type, :overall_result
:court_type

# When decision is drafted on Review by the caseworker (e.g. Non-means tested)
def create_draft(application_id:, user_id:, reference:)
Expand Down Expand Up @@ -51,8 +51,8 @@ def set_interests_of_justice(user_id:, interests_of_justice:)
apply InterestsOfJusticeSet.build(self, user_id:, interests_of_justice:)
end

def set_funding_decision(user_id:, funding_decision:, overall_result: nil)
apply FundingDecisionSet.build(self, user_id:, funding_decision:, overall_result:)
def set_funding_decision(user_id:, funding_decision:)
apply FundingDecisionSet.build(self, user_id:, funding_decision:)
end

def set_comment(user_id:, comment:)
Expand Down Expand Up @@ -101,7 +101,6 @@ def send_to_provider(user_id:, application_id:)

on FundingDecisionSet do |event|
@funding_decision = event.data.fetch(:funding_decision)
@overall_result = event.data.fetch(:overall_result, nil)
end

on CommentSet do |event|
Expand Down Expand Up @@ -138,10 +137,15 @@ def update_from_maat(maat_attributes)
@interests_of_justice = decision.interests_of_justice
@maat_id = decision.maat_id
@means = decision.means
@overall_result = decision.overall_result
@reference = decision.reference
end

def overall_result
return unless funding_decision

OverallResultCalculator.new(self).calculate
end

def complete?
@funding_decision.present?
end
Expand Down
60 changes: 60 additions & 0 deletions app/aggregates/deciding/overall_result_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Deciding
class OverallResultCalculator
def initialize(decision)
@decision = decision
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall result is now displayed to the user in the format funding_decision - qualification, e.g., "Granted - with contribution" or "Refused - failed IoJ".

In the datastore, these values are stored as types, such as granted_with_contribution and refused_failed_ioj.

This class determines the OverallResult type.

def calculate
return unless funding_decision

Types::OverallResult[
[funding_decision, qualification].compact.join('_')
]
end

private

attr_reader :decision

def qualification
return refusal_qualification if refused?

grant_qualification if granted?
end

def refusal_qualification
return 'failed_ioj_and_means' if failed_means? && failed_ioj?
return 'failed_ioj' if failed_ioj?

'failed_means' if failed_means?
end

def grant_qualification
return 'failed_means' if failed_means?

'with_contribution' if with_contribution?
end

delegate :funding_decision, to: :decision

def failed_means?
decision.means&.result == 'failed'
end

def granted?
funding_decision == 'granted'
end

def refused?
funding_decision == 'refused'
end

def with_contribution?
decision.means&.result == 'passed_with_contribution'
end

def failed_ioj?
decision.interests_of_justice&.result == 'failed'
end
end
end
4 changes: 3 additions & 1 deletion app/components/decision_overall_result_component.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class DecisionOverallResultComponent < ViewComponent::Base
include AppTextHelper

with_collection_parameter :decision

def initialize(decision:)
Expand All @@ -10,7 +12,7 @@ def initialize(decision:)
def call
return if overall_result.nil?

govuk_tag(text: overall_result, colour: colour)
govuk_tag(text: value_text(overall_result, scope: :decision_overall_result), colour: colour)
end

private
Expand Down
8 changes: 8 additions & 0 deletions app/models/decisions/draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class Draft < LaaCrimeSchemas::Structs::Decision
attribute? :application_id, Types::Uuid
attribute? :court_type, Types::CourtType.optional

# NOTE: Allow strings for the overall result in draft decisions
# instead of restricting them to `Types::OverallResult`.
# This flexibility enables storing the `Maat::Decision` overall_result
# in the event, allowing comparison during the initial phase of
# the Outcome Playback release. However, only the `OverallResult` type,
# not the MAAT value, is stored in the datastore.
attribute? :overall_result, Types::String.optional

def to_param
{ crime_application_id: application_id, decision_id: decision_id }
end
Expand Down
7 changes: 5 additions & 2 deletions config/locales/en/casework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,12 @@ en:
refused: Refused
decision_overall_result:
granted: Granted
refused: Refused
granted_failed_means: Granted - failed means test
granted_with_contribution: Granted - with contribution
granted_failed_means: Granted - failed means
refused: Refused
refused_failed_ioj: Refused - failed IoJ
refused_failed_ioj_and_means: Refused - failed IoJ & means
refused_failed_means: Refused - failed means
either_way: Either way
esa: Income-related Employment and Support Allowance (ESA)
guarantee_pension: Guarantee Credit element of Pension Credit
Expand Down
79 changes: 79 additions & 0 deletions spec/aggregates/deciding/overall_result_calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require 'rails_helper'

RSpec.describe Deciding::OverallResultCalculator do
describe '#calculate' do
subject do
described_class.new(decision).calculate
end

let(:decision) do
instance_double(
LaaCrimeSchemas::Structs::Decision,
means: instance_double(
LaaCrimeSchemas::Structs::TestResult, result: means_result
),
funding_decision: funding_decision,
interests_of_justice: instance_double(
LaaCrimeSchemas::Structs::TestResult, result: ioj_result
)
)
end

context 'when funding is granted' do
let(:funding_decision) { 'granted' }

context 'when means test is failed' do
let(:ioj_result) { 'passed' }
let(:means_result) { 'failed' }

it { is_expected.to eq('granted_failed_means') }
end

context 'when means test passed with contribution' do
let(:ioj_result) { 'passed' }
let(:means_result) { 'passed_with_contribution' }

it { is_expected.to eq('granted_with_contribution') }
end

context 'when means test fully passed' do
let(:ioj_result) { 'passed' }
let(:means_result) { 'passed' }

it { is_expected.to eq('granted') }
end
end

context 'when funding is refused' do
let(:funding_decision) { 'refused' }

context 'when both means and IoJ tests failed' do
let(:ioj_result) { 'failed' }
let(:means_result) { 'failed' }

it { is_expected.to eq('refused_failed_ioj_and_means') }
end

context 'when only IoJ test failed' do
let(:ioj_result) { 'failed' }
let(:means_result) { 'passed' }

it { is_expected.to eq('refused_failed_ioj') }
end

context 'when only means test failed' do
let(:ioj_result) { 'passed' }
let(:means_result) { 'failed' }

it { is_expected.to eq('refused_failed_means') }
end

context 'when neither test failed' do
let(:ioj_result) { 'passed' }
let(:means_result) { 'passed' }

it { is_expected.to eq('refused') }
end
end
end
end
2 changes: 1 addition & 1 deletion spec/aggregates/reviewing/complete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
decision_id: decision_id,
application_id: application_id,
court_type: nil,
overall_result: 'Failed IoJ'
overall_result: 'refused'
).as_json
]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/components/decision_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
interests_of_justice: nil,
means: nil,
funding_decision: 'granted',
overall_result: 'Granted',
overall_result: 'granted',
comment: nil,
maat_id: nil
)
Expand Down
26 changes: 21 additions & 5 deletions spec/components/decision_overall_result_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,42 @@

context 'when funding is "granted"' do
let(:funding_decision) { 'granted' }
let(:overall_result) { 'Granted - Passed Means Test' }
let(:overall_result) { Types::OverallResult['granted_with_contribution'] }

it { is_expected.to have_text('Granted') }
it { is_expected.to have_text('Granted - with contribution', exact: true) }
it { is_expected.to have_css('.govuk-tag--green') }
end

context 'when funding is "refused"' do
let(:funding_decision) { 'refused' }
let(:overall_result) { 'Refused - Ineligible' }
let(:overall_result) { 'refused_failed_ioj_and_means' }

it { is_expected.to have_text('Refused - Ineligible') }
it { is_expected.to have_text('Refused - failed IoJ & means', exact: true) }
it { is_expected.to have_css('.govuk-tag--red') }
end

context 'when overall_result is nil' do
let(:funding_decision) { 'refused' }
let(:overall_result) { nil }

it { is_expected.to have_text('') }
it { is_expected.to have_text('', exact: true) }
it { is_expected.not_to have_css('.govuk-tag') }
end

describe 'overall result text' do
[
'granted', 'Granted',
'granted_with_contribution', 'Granted - with contribution',
'granted_failed_means', 'Granted - failed means',
'refused', 'Refused',
'refused_failed_ioj', 'Refused - failed IoJ',
'refused_failed_ioj_and_means', 'Refused - failed IoJ & means',
'refused_failed_means', 'Refused - failed means'
].each_slice(2).each do |type, text|
it "translates #{type} to #{text}" do
expect(I18n.t(type, scope: [:values, :decision_overall_result])).to eq(text)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
'Means test result', 'Failed',
'Means test caseworker', 'Jan Blogs',
'Means test date', '02/02/2024',
'Overall result', 'Failed Means & IoJ'
'Overall result', 'Refused - failed IoJ & means'
)

expect(current_path).to eq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
'means' => nil,
'funding_decision' => 'refused',
'overall_result' => 'Failed IoJ',
'overall_result' => Types::OverallResult['refused_failed_ioj'],
'comment' => 'Test comment'
}
]
Expand Down Expand Up @@ -56,7 +56,7 @@
expect(page).to have_content('Your list (1)')
expect(summary_card('Case')).to have_rows(
'Interests of justice (IoJ) test result', 'Failed',
'Overall result', 'Failed IoJ'
'Overall result', 'Refused - failed IoJ'
)
choose_answer(send_decisions_form_prompt, 'Send decision to provider')
save_and_continue
Expand All @@ -75,7 +75,7 @@
'IoJ comments', 'reason',
'IoJ caseworker', 'Test User',
'IoJ test date', '01/10/2024',
'Overall result', 'Failed IoJ',
'Overall result', 'Refused - failed IoJ',
'Comments', 'Test comment'
)
end
Expand Down