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-907] Translate MAAT decisions #777

Merged
merged 1 commit into from
Dec 30, 2024
Merged

[CRIMAPP-907] Translate MAAT decisions #777

merged 1 commit into from
Dec 30, 2024

Conversation

timpeat
Copy link
Member

@timpeat timpeat commented Dec 13, 2024

Description of change

Introduce translators to the MAAT decision adapter.

Link to relevant ticket

Notes for reviewer

Translating MAAT decisions has become more complex as we now handle both Magistrates' and Crown Court decisions, along with workarounds like IoJ appeals and passporting versus standard means decisions. This PR introduces translators to address this complexity.

Additionally, it simplifies the Crime Apply/Review decision data model types to better reflect their context, as opposed to previously copying the types directly from MAAT.

Screenshots of changes (if applicable)

Before changes:

After changes:

How to manually test the feature

@timpeat timpeat changed the title Spike latest apiv3 CRIMAPP-907 Spike latest MAAT api Dec 13, 2024
@timpeat timpeat force-pushed the spike-latest-apiv3 branch 2 times, most recently from 48ff1e9 to f3ec6d1 Compare December 16, 2024 17:49
Gemfile Outdated
@@ -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.4.3'
tag: 'v1.5.0'
Copy link
Member Author

@timpeat timpeat Dec 16, 2024

Choose a reason for hiding this comment

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

Use version of schema locked down to a simplified version of the Funding Decision data model.

@@ -1,7 +1,7 @@
module Deciding
class SetFundingDecision < Command
attribute :user_id, Types::Uuid
attribute :funding_decision, Types::FundingDecisionResult
attribute :funding_decision, Types::FundingDecision

Copy link
Member Author

@timpeat timpeat Dec 16, 2024

Choose a reason for hiding this comment

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

The FundingDecisionResult field has been renamed to FundingDecision and its values simplified.

Previously, it supported all 11 MAAT decision types for Magistrates' Court and Crown Court. Now, it only allows two values: grant, refuse

https://github.com/ministryofjustice/laa-criminal-legal-aid-schemas/pull/222/files#diff-a0939f79f4e37686df77707ace12fbd73e929dd2df816902ebf967f2e243e99a

attribute :user_id, Types::Uuid

def call
with_decision do |decision|
decision.sync_with_maat(maat_decision:, user_id:)
raise MaatRecordNotChanged unless maat_decision.checksum != decision.checksum

Copy link
Member Author

Choose a reason for hiding this comment

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

Move this guard to the command from the aggregate as it is not required in all contexts.

else
'green'
end
{ 'grant' => 'green', 'refuse' => 'red' }.fetch(result, nil)
Copy link
Member Author

Choose a reason for hiding this comment

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

There are now only two possible Funding Decisions

attribute :maat_id, Types::Integer
attribute? :case_id, Types::String.optional
attribute :funding_decision, Types::FundingDecisionResult.optional
class Decision < Dry::Struct
Copy link
Member Author

Choose a reason for hiding this comment

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

This struct represents the untranslated MAAT record. Additional work is now required to clean up and translate the MAAT decision into the Apply/Review context. To facilitate this, dedicated translators for the Decision and associated tests have been created.

@timpeat timpeat changed the title CRIMAPP-907 Spike latest MAAT api [CRIMAPP-907] Translate MAAT decisions Dec 17, 2024
@timpeat timpeat force-pushed the spike-latest-apiv3 branch 2 times, most recently from d07f41e to 605cd1a Compare December 23, 2024 14:40
@@ -13,16 +13,16 @@ en:
success:
assigned_to_self: You assigned this application to your list
completed: You marked the application as complete
completed_with_decisions: Application complete. Decision sent to provider.
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry about the linting changes. I have fixed my LSP......

@timpeat timpeat force-pushed the spike-latest-apiv3 branch 3 times, most recently from 942cec9 to e49e577 Compare December 23, 2024 15:11
@timpeat timpeat marked this pull request as ready for review December 23, 2024 15:22
@timpeat timpeat requested a review from a team as a code owner December 23, 2024 15:22
@@ -2,7 +2,7 @@ module Deciding
class CreateDraftFromMaat < Command
attribute :application_id, Types::Uuid
attribute :application_type, Types::ApplicationType
attribute :maat_decision, Maat::Decision
Copy link
Member Author

Choose a reason for hiding this comment

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

We now use the Decisions::Draft struct in commands.

Copy link
Contributor

@hiboabd hiboabd left a comment

Choose a reason for hiding this comment

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

LGTM

@timpeat timpeat merged commit be00ce6 into main Dec 30, 2024
7 checks passed
@timpeat timpeat deleted the spike-latest-apiv3 branch December 30, 2024 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants