Repository: ministryofjustice/legal-framework-api
Pull request #1555: AP-5698: Update chances of success merits task list handling
Author: login: colinbruce
Labels: name: approved
description: Approved by code reviewers
Created: 2025-03-17T15:53:45Z | Merged: 2025-03-21T06:57:40Z

## What

[Link to story](https://dsdmoj.atlassian.net/browse/AP-5698)

Describe what you did and why.

## Checklist

Before you ask people to review this PR:

- Tests and rubocop should be passing: `bundle exec rake`.
- Github should not be reporting conflicts; you should have recently run `git rebase main`.
- The standards in the [Git Workflow document on Confluence](https://dsdmoj.atlassian.net/wiki/spaces/ATPPB/pages/4602855954/Git+Workflow) should be followed.
- There should be no unnecessary whitespace changes. These make diffs harder to read and conflicts more likely.
- The PR description should say what you changed and why, with a link to the JIRA story.
- You should have looked at the diff against main and ensured that nothing unexpected is included in your changes.
- You should have checked that the commit messages say why the change was made.



Diff:
diff --git a/app/services/questions_service.rb b/app/services/questions_service.rb
index a1030e352..43432aa8f 100644
--- a/app/services/questions_service.rb
+++ b/app/services/questions_service.rb
@@ -86,6 +86,11 @@ def applicant_or_joined_party_on_this_proceeding(proceeding)
     match.present?
   end
 
+  def unless_family_help_higher_and_or_child_subject_on_this_proceeding(proceeding)
+    match = @proceedings.find { |p| p[:ccms_code] == proceeding.ccms_code && (p[:client_involvement_type] == "W" || p[:substantive_level_of_service] == 1) }
+    match.nil?
+  end
+
   def applicant_on_this_proceeding(proceeding)
     match = @proceedings.find { |p| p[:ccms_code] == proceeding.ccms_code && p[:client_involvement_type] == "A" }
     match.present?
diff --git a/db/seed_data/proceeding_type_merits_task/section_8.yml b/db/seed_data/proceeding_type_merits_task/section_8.yml
index eab227e40..95ddd6e46 100644
--- a/db/seed_data/proceeding_type_merits_task/section_8.yml
+++ b/db/seed_data/proceeding_type_merits_task/section_8.yml
@@ -6,7 +6,8 @@
   - opponent_name
   - opponent_mental_capacity
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -25,7 +26,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -44,7 +46,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -61,7 +64,8 @@
   - opponent_name
   - opponent_mental_capacity
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -80,7 +84,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -99,7 +104,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -116,7 +122,8 @@
   - opponent_name
   - opponent_mental_capacity
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -136,7 +143,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -156,7 +164,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - prohibited_steps
@@ -176,7 +185,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -196,7 +206,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -216,7 +227,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - specific_issue
@@ -234,7 +246,8 @@
   - opponent_name
   - opponent_mental_capacity
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -252,7 +265,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -270,7 +284,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -286,7 +301,8 @@
   - opponent_name
   - opponent_mental_capacity
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -304,7 +320,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -322,7 +339,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -340,7 +358,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -359,7 +378,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -378,7 +398,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -397,7 +418,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -416,7 +438,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -435,7 +458,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -454,7 +478,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -472,7 +497,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -490,7 +516,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -508,7 +535,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -526,7 +554,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -544,7 +573,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -562,7 +592,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
@@ -580,7 +611,8 @@
   - at_least_one_domestic_abuse_with_applicant:
     - domestic_abuse_summary
   - statement_of_case
-  - chances_of_success
+  - unless_family_help_higher_and_or_child_subject_on_this_proceeding:
+      - chances_of_success
   - laspo
   - attempts_to_settle
   - why_matter_opposed
diff --git a/public/schemas/civil_merits_questions.json.erb b/public/schemas/civil_merits_questions.json.erb
index cc1cf7b03..2f30202db 100644
--- a/public/schemas/civil_merits_questions.json.erb
+++ b/public/schemas/civil_merits_questions.json.erb
@@ -31,6 +31,9 @@
           },
           "client_involvement_type": {
             "enum": <%= %w[A D W Z I].as_json %>
+          },
+          "level_of_service": {
+            "enum": [1, 3]
           }
         }
       }
diff --git a/spec/requests/civil_merits_questions_controller_swagger_spec.rb b/spec/requests/civil_merits_questions_controller_swagger_spec.rb
index 559744a17..05cc1bcee 100644
--- a/spec/requests/civil_merits_questions_controller_swagger_spec.rb
+++ b/spec/requests/civil_merits_questions_controller_swagger_spec.rb
@@ -60,8 +60,12 @@
                           client_involvement_type: { type: :string,
                                                      description: "A code uniquely identifying the client_involvement_type",
                                                      example: "A" },
+                          substantive_level_of_service: { type: :string,
+                                                          description: "A code uniquely identifying the substantive level of service, currently only supports 1 or 3",
+                                                          example: 1,
+                                                          required: false },
                         },
-                        description: "Array of CCMS codes, df_used and client involvement type of proceeding types to  be queried",
+                        description: "Array of CCMS codes, df_used and client involvement type of proceeding types to be queried",
                       },
                     },
                   },
@@ -177,7 +181,6 @@
                   ccms_code: "SE003",
                   tasks: {
                     attempts_to_settle: [],
-                    chances_of_success: [],
                     prohibited_steps: [],
                   },
                 },
diff --git a/spec/services/questions_service_spec.rb b/spec/services/questions_service_spec.rb
index 6d3bb667c..e0ec7959a 100644
--- a/spec/services/questions_service_spec.rb
+++ b/spec/services/questions_service_spec.rb
@@ -121,6 +121,22 @@
       end
     end
 
+    context "when there is a Child Section 8 proceeding with the client involvement type is Applicant" do
+      let(:proceedings) do
+        [
+          {
+            ccms_code: "SE013",
+            delegated_functions_used: true,
+            client_involvement_type: "A",
+          },
+        ]
+      end
+
+      it "returns valid response without domestic abuse/non applicant questions" do
+        expect(question_service).to eq expected_se013_applicant_response
+      end
+    end
+
     context "with Special Children Act questions" do
       context "when there is a sole SCA core proceeding" do
         let(:proceedings) do
@@ -515,6 +531,23 @@
         end
       end
     end
+
+    context "when there is a S8 proceeding with Applicant and level of service of Family Help Higher" do
+      let(:proceedings) do
+        [
+          {
+            ccms_code: "SE013",
+            delegated_functions_used: true,
+            client_involvement_type: "A",
+            substantive_level_of_service: 1,
+          },
+        ]
+      end
+
+      it "returns valid response without chances of success" do
+        expect(question_service).to eq expected_se013_applicant_with_fhh_response
+      end
+    end
   end
 
   context "when the request fails" do
@@ -596,7 +629,7 @@ def expected_da005_applicant_response
     }
   end
 
-  def expected_se013_child_subject_response
+  def expected_se013_applicant_response
     {
       request_id:,
       success: true,
@@ -607,6 +640,7 @@ def expected_se013_child_subject_response
           "opponent_mental_capacity" => [],
           "opponent_name" => [],
           "statement_of_case" => [],
+          "children_application" => [],
           "why_matter_opposed" => [],
         },
       },
@@ -615,6 +649,59 @@ def expected_se013_child_subject_response
           ccms_code: "SE013",
           tasks: {
             "chances_of_success" => [],
+            "children_proceeding" => %w[children_application],
+            "attempts_to_settle" => [],
+          },
+        },
+      ],
+    }
+  end
+
+  def expected_se013_child_subject_response
+    {
+      request_id:,
+      success: true,
+      application: {
+        tasks: {
+          "laspo" => [],
+          "nature_of_urgency" => [],
+          "opponent_mental_capacity" => [],
+          "opponent_name" => [],
+          "statement_of_case" => [],
+          "why_matter_opposed" => [],
+        },
+      },
+      proceedings: [
+        {
+          ccms_code: "SE013",
+          tasks: {
+            "attempts_to_settle" => [],
+          },
+        },
+      ],
+    }
+  end
+
+  def expected_se013_applicant_with_fhh_response
+    {
+      request_id:,
+      success: true,
+      application: {
+        tasks: {
+          "laspo" => [],
+          "nature_of_urgency" => [],
+          "opponent_mental_capacity" => [],
+          "opponent_name" => [],
+          "statement_of_case" => [],
+          "children_application" => [],
+          "why_matter_opposed" => [],
+        },
+      },
+      proceedings: [
+        {
+          ccms_code: "SE013",
+          tasks: {
+            "children_proceeding" => %w[children_application],
             "attempts_to_settle" => [],
           },
         },
diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml
index d1b008fe1..28cfb492b 100644
--- a/swagger/v1/swagger.yaml
+++ b/swagger/v1/swagger.yaml
@@ -92,7 +92,6 @@ paths:
                     - ccms_code: SE003
                       tasks:
                         attempts_to_settle: []
-                        chances_of_success: []
                         prohibited_steps: []
                   summary: Successful request without involved children questions
                   description: Request a single proceeding, SE003, for a child subject
@@ -150,8 +149,14 @@ paths:
                         type: string
                         description: A code uniquely identifying the client_involvement_type
                         example: A
+                      substantive_level_of_service:
+                        type: string
+                        description: A code uniquely identifying the substantive level
+                          of service, currently only supports 1 or 3
+                        example: 1
+                        required: false
                     description: Array of CCMS codes, df_used and client involvement
-                      type of proceeding types to  be queried
+                      type of proceeding types to be queried
   "/client_involvement_types":
     get:
       summary: Get all client involvement types


Reviews:
user: login: RoseSAK
body: Only one query, otherwise looks good 👍 
state: APPROVED
author_association: NONE
submitted_at: 2025-03-18T16:16:10Z
user: login: colinbruce
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T07:14:19Z

Review comments:
diff_hunk: @@ -121,6 +121,22 @@
       end
     end
 
+    context "when there is a Child Section 8 as Applicant" do
path: spec/services/questions_service_spec.rb
user: login: RoseSAK
body: I don't really understand what this scenario means 🤔 how can a 'Child Section 8' be an applicant?
created_at: 2025-03-18T16:15:31Z
author_association: NONE
diff_hunk: @@ -121,6 +121,22 @@
       end
     end
 
+    context "when there is a Child Section 8 as Applicant" do
path: spec/services/questions_service_spec.rb
user: login: colinbruce
body: would
```
when there is a Child Section 8 proceeding with the client involvement type is Applicant
```
make more sense?
created_at: 2025-03-19T07:14:19Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-03-19T07:23:08Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=ministryofjustice_legal-framework-api&pullRequest=1555) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=ministryofjustice_legal-framework-api&pullRequest=1555&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=ministryofjustice_legal-framework-api&pullRequest=1555&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=ministryofjustice_legal-framework-api&pullRequest=1555&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=ministryofjustice_legal-framework-api&pullRequest=1555&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=ministryofjustice_legal-framework-api&pullRequest=1555&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=ministryofjustice_legal-framework-api&pullRequest=1555)


author_association: NONE