-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the Funding Decision data model
- Loading branch information
Showing
45 changed files
with
806 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
app/aggregates/deciding/commands/update_from_maat_decision.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,28 @@ | ||
module Maat | ||
class Decision < LaaCrimeSchemas::Structs::Decision | ||
attribute :maat_id, Types::Integer | ||
attribute? :case_id, Types::String.optional | ||
attribute :funding_decision, Types::FundingDecisionResult.optional | ||
class Decision < Dry::Struct | ||
transform_keys(&:to_sym) | ||
|
||
def checksum | ||
Digest::MD5.hexdigest(to_json) | ||
end | ||
attribute? :maat_ref, Types::MaatId | ||
attribute? :usn, Types::ApplicationReference.optional | ||
attribute? :case_id, Types::String | ||
attribute? :case_type, Types::String | ||
attribute? :app_created_date, Types::DateTime.optional | ||
|
||
alias decision_id maat_id | ||
attribute? :ioj_result, Types::String.optional | ||
attribute? :ioj_reason, Types::String.optional | ||
attribute? :ioj_assessor_name, Types::String.optional | ||
|
||
class << self | ||
def build(response) | ||
new( | ||
reference: response['usn'], | ||
maat_id: response['maat_ref'], | ||
case_id: response['case_id'], | ||
funding_decision: funding_decision(response['funding_decision']), | ||
interests_of_justice: interests_of_justice(response), | ||
means: means(response) | ||
) | ||
end | ||
attribute? :ioj_appeal_result, Types::String.optional | ||
|
||
def funding_decision(maat_value) | ||
return nil if maat_value.blank? | ||
attribute? :means_result, Types::String.optional | ||
attribute? :means_assessor_name, Types::String.optional | ||
attribute? :date_means_created, Types::DateTime.optional | ||
|
||
maat_value.downcase | ||
end | ||
attribute? :passport_result, Types::String.optional | ||
attribute? :passport_assessor_name, Types::String.optional | ||
attribute? :date_passport_created, Types::DateTime.optional | ||
|
||
def interests_of_justice(response) | ||
return nil if response['ioj_result'].blank? | ||
|
||
{ | ||
result: response['ioj_result'].downcase, | ||
details: response['ioj_reason'], | ||
assessed_by: response['ioj_assessor_name'], | ||
assessed_on: response['app_created_date'] | ||
} | ||
end | ||
|
||
def result(maat_result); end | ||
|
||
def means(response) | ||
return nil if response['means_result'].blank? | ||
|
||
{ | ||
result: response['means_result'].downcase, | ||
assessed_by: response['means_assessor_name'], | ||
assessed_on: response['date_means_created'] | ||
} | ||
end | ||
end | ||
attribute? :funding_decision, Types::String.optional | ||
attribute? :cc_rep_decision, Types::String.optional | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Maat | ||
class BaseTranslator | ||
def initialize(original:) | ||
@original = original | ||
end | ||
|
||
class << self | ||
def translate(original) | ||
new(original:).translate | ||
end | ||
end | ||
|
||
# :nocov: | ||
def translate | ||
raise 'implement in subclasses' | ||
end | ||
# :nocov: | ||
# | ||
|
||
private | ||
|
||
attr_reader :original | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Maat | ||
class CrownCourtDecisionTranslator < BaseTranslator | ||
def translate | ||
return nil if funding_decision.blank? | ||
|
||
Types::FundingDecision[funding_decision] | ||
end | ||
|
||
private | ||
|
||
def funding_decision | ||
case original | ||
when /Granted/ | ||
'grant' | ||
when /Refused|Failed/ | ||
'refuse' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Maat | ||
class DecisionTranslator | ||
def initialize(maat_decision:) | ||
@maat_decision = maat_decision | ||
end | ||
|
||
class << self | ||
def translate(maat_decision) | ||
new(maat_decision:).translate | ||
end | ||
end | ||
|
||
def translate | ||
Decisions::Draft.new( | ||
maat_id:, case_id:, reference:, interests_of_justice:, | ||
means:, funding_decision:, decision_id: | ||
) | ||
end | ||
|
||
private | ||
|
||
def maat_id | ||
maat_decision.maat_ref | ||
end | ||
alias decision_id maat_id | ||
|
||
def reference | ||
maat_decision.usn | ||
end | ||
|
||
def interests_of_justice | ||
InterestsOfJusticeTranslator.translate(maat_decision) | ||
end | ||
|
||
def means | ||
MeansTranslator.translate(maat_decision) | ||
end | ||
|
||
def funding_decision | ||
return crown_court_decision if crown_court_decision | ||
return nil unless maat_decision.funding_decision | ||
|
||
FundingDecisionTranslator.translate(maat_decision.funding_decision) | ||
end | ||
|
||
delegate :case_id, to: :maat_decision | ||
|
||
def crown_court_decision | ||
CrownCourtDecisionTranslator.translate(maat_decision.cc_rep_decision) | ||
end | ||
|
||
attr_reader :maat_decision | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Maat | ||
class FundingDecisionTranslator < BaseTranslator | ||
def translate | ||
return nil if funding_decision.blank? | ||
|
||
Types::FundingDecision[funding_decision] | ||
end | ||
|
||
private | ||
|
||
def funding_decision | ||
case original | ||
when /PASS|GRANTED|FULL/ | ||
'grant' | ||
when /INEL|FAIL/ | ||
'refuse' | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.