Skip to content

Commit

Permalink
Merge pull request #1217 from ministryofjustice/LASB-2955
Browse files Browse the repository at this point in the history
[LASB-2955] Blank defendant logging
  • Loading branch information
JHunt16 authored Feb 6, 2024
2 parents d5a768d + 238731a commit 5360010
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 1 deletion.
53 changes: 52 additions & 1 deletion app/services/common_platform/api/search_prosecution_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,65 @@ class SearchProsecutionCase < ApplicationService

def initialize(params)
@response = ProsecutionCaseSearcher.call(**params)
@blank_defendants = []
end

def call
check_response_status

check_for_blank_defendants(prosecution_cases)
record_prosecution_cases
end

def check_for_blank_defendants(prosecution_cases)
if array_not_empty(prosecution_cases)
prosecution_cases.each do |prosecution_case|
if array_not_empty(prosecution_case["defendantSummary"])
prosecution_case["defendantSummary"].each do |defendant|
if defendant_is_blank(defendant)
# Add this defendant to an array of empty defendants (we need to also verify they don't have a hearing summary further down)
@blank_defendants.push(defendant["defendantId"])
end
end
end

remove_defendant_with_hearing_summary_from_blank_defendants(prosecution_case["hearingSummary"])
log_error_for_blank_defendants
end
end
end

def remove_defendant_with_hearing_summary_from_blank_defendants(hearing_summaries)
if array_not_empty(hearing_summaries)
hearing_summaries.each do |hearing_summary|
hearing_summary["defendantIds"].each do |defendant_id|
# If this defendant_id matches one of the blank defendants already found
if @blank_defendants.try(:include?, defendant_id)
# Remove them from the blank defendants array
@blank_defendants.delete(defendant_id)
end
end
end
end
end

def log_error_for_blank_defendants
if array_not_empty(@blank_defendants)
@blank_defendants.each do |blank_defendant|
Rails.logger.error("The defendant with the defendantId [#{blank_defendant}] is blank (missing defendantFirstName, defendantLastName, defendantDOB, defendantNINO and hearingSummary)")
# Send an alert to sentry
Sentry.capture_message("The defendant with the defendantId [#{blank_defendant}] is blank (missing defendantFirstName, defendantLastName, defendantDOB, defendantNINO and hearingSummary)")
end
end
end

def array_not_empty(array)
array.present?
end

def defendant_is_blank(defendant)
!defendant["defendantFirstName"] && !defendant["defendantLastName"] && !defendant["defendantDOB"] && !defendant["defendantNINO"]
end

private

def record_prosecution_cases
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- '5432:5432'
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
redis:
image: redis:alpine
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"totalResults": 1,
"cases": [
{
"caseStatus": "ACTIVE",
"prosecutionCaseId": "793af793-c02c-4da4-a5a1-73f2b6f54749",
"prosecutionCaseReference": "10A10000000",
"defendantSummary": [
{
"proceedingsConcluded": false,
"defendantId": "77908e28-254c-4c02-858c-d012d20f1901",
"masterDefendantId": "0119b547-5179-4f8f-a920-4fee57bcc2ae",
"offenceSummary": [
{
"offenceId": "e1533e82-3ca5-40e3-8062-381d4d41d2fd",
"offenceCode": "AB12345",
"offenceTitle": "Taking the ring without consent",
"offenceLegislation": "Contrary to sections 1(1)(a) and 6 of the Mordor Protection Act 1978.",
"proceedingsConcluded": false,
"endDate": "2024-01-02",
"startDate": "2024-01-01",
"chargeDate": "2024-01-04",
"modeOfTrial": "Either Way",
"orderIndex": 1,
"wording": "between 01/01/2024 and 02/01/2024 took the one ring without consent CONTRARY TO SECTIONS 1(1)(A) AND 6 OF THE MORDOR PROTECTION ACT 1978",
"laaApplnReference": {},
"plea": []
}
]
},
{
"proceedingsConcluded": true,
"representationOrder": {},
"defendantId": "0e70b6f9-b488-4827-9658-956e4f6e3d48",
"masterDefendantId": "0119b547-5179-4f8f-a920-4fee57bcc2ae",
"defendantASN": "2011999999999999ASND",
"defendantFirstName": "Frodo",
"defendantLastName": "Baggins",
"defendantDOB": "1990-01-01",
"defendantNINO": "AB123456C",
"offenceSummary": [
{
"offenceId": "e1533e82-3ca5-40e3-8062-381d4d41d2fd",
"offenceCode": "AB12345",
"offenceTitle": "Taking the ring without consent",
"offenceLegislation": "Contrary to sections 1(1)(a) and 6 of the Mordor Protection Act 1978.",
"proceedingsConcluded": false,
"endDate": "2024-01-02",
"startDate": "2024-01-01",
"chargeDate": "2024-01-04",
"modeOfTrial": "Either Way",
"orderIndex": 1,
"wording": "between 01/01/2024 and 02/01/2024 took the one ring without consent CONTRARY TO SECTIONS 1(1)(A) AND 6 OF THE MORDOR PROTECTION ACT 1978",
"laaApplnReference": {
"applicationReference": "10000000",
"statusId": "af4f688a-23bd-4f67-b5e3-91253f00f028",
"statusCode": "AP",
"statusDescription": "Application Pending"
},
"plea": []
}
]
}
],
"hearingSummary": [
{
"hearingId": "30df467e-3b35-40f6-9063-527f1175f071",
"jurisdictionType": "MAGISTRATES",
"defendantIds": [
"0e70b6f9-b488-4827-9658-956e4f6e3d48"
],
"hearingDays": [
{
"sittingDay": "2024-01-10T13:00:00.000Z",
"listingSequence": 1,
"listedDurationMinutes": 20
}
],
"hearingType": {
"id": "aae90552-93bb-43e6-af32-4e4aab15e9cd",
"description": "First hearing"
},
"courtCentre": {
"id": "edb3379f-e4c9-3bc9-956f-928adc233086",
"name": "South Shields Magistrates' Court",
"roomId": "ea50eca0-73f0-3ae1-a98e-7c3843daa159",
"roomName": "Courtroom 02",
"code": "B10LX00"
},
"defenceCounsel": []
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"totalResults": 1,
"cases": [
{
"caseStatus": "CLOSED",
"prosecutionCaseId": "2041abf3-0d06-4dd4-8650-cf01da525a0d",
"prosecutionCaseReference": "ABCD1234100",
"defendantSummary": [
{
"proceedingsConcluded": true,
"representationOrder": {
"applicationReference": "LAA-20171234",
"effectiveFromDate": "2018-06-12",
"effectiveToDate": "2018-05-12",
"laaContractNumber": "12345678"
},
"defendantMiddleName": "Fake",
"defendantId": "4e5da043-d327-429a-bb5d-ed05734caa8e",
"defendantASN": "ARREST123",
"offenceSummary": [
{
"offenceId": "209927d2-21ae-4c03-b4dd-d1c1fa1fba57",
"offenceCode": "AB12345",
"offenceTitle": "Theft of a speeder",
"proceedingsConcluded": false,
"arrestDate": "2019-04-01",
"startDate": "2019-05-01",
"chargeDate": "2019-06-01",
"modeOfTrial": "Summary",
"orderIndex": 1,
"wording": "Test",
"laaApplnReference": {
"applicationReference": "LAA-20171234",
"statusId": "e503f839-8f2a-4046-8411-ab5e33d47c2e",
"statusCode": "G2",
"statusDescription": "Granted for Two Advocates"
}
}
]
}
],
"hearingSummary": [
{
"hearingId": "794a1a64-6c22-4bcf-a8ec-3895d37f482a",
"jurisdictionType": "MAGISTRATES",
"estimatedDuration": "20",
"defendantIds": [
"4e5da043-d327-429a-bb5d-ed05734caa8e"
],
"hearingDays": [
{
"sittingDay": "2020-02-17T15:00:00Z",
"listingSequence": 0,
"listedDurationMinutes": 20,
"hasSharedResults": true
}
],
"hearingType": {
"id": "7ebdf55a-b6c4-45c8-9306-bb5ae283274d",
"description": "First hearing"
},
"courtCentre": {
"id": "032e0250-df8b-418e-b54e-74f74e3abe64",
"name": "Dagobah Magistrates' Court",
"roomId": "94997c2d-2214-47a7-bc47-5edac3c14755",
"roomName": "Courtroom 01",
"code": "B123B12"
}
},
{
"hearingId": "ed6b4079-bc65-43ce-a0d4-bbe195c0fba4",
"jurisdictionType": "CROWN",
"defendantIds": [],
"hearingDays": [
{
"sittingDay": "2020-08-04T08:00:00Z",
"listingSequence": 2,
"listedDurationMinutes": 30,
"hasSharedResults": true
}
],
"courtCentre": {
"id": "c56f3962-2c89-4393-9173-500245739299",
"name": "Dagobah Crown Court",
"roomId": "a64d9400-5a6a-4c02-9e76-ad3c510de46c",
"roomName": "Crown Court 2-1"
},
"hearingType": {
"id": "813beb73-e420-431d-8c35-db6e42e0c400",
"description": "Plea and Trial Preparation"
}
},
{
"hearingId": "c090c95f-cc4f-4dfa-8e7e-3f489a93fd4f",
"jurisdictionType": "CROWN",
"defendantIds": [],
"hearingDays": [
{
"sittingDay": "2019-07-05T09:00:00Z",
"listingSequence": 1,
"listedDurationMinutes": 720,
"hasSharedResults": true
}
],
"courtCentre": {
"id": "03315c5f-3e19-43c0-8945-bd181bff9503",
"name": "Alderaan Magistrates' Court",
"roomId": "3e37c0ae-e887-44f0-b961-1de4199f8868",
"roomName": "Courtroom 01"
},
"hearingType": {
"id": "a98f5c8a-c5bc-40bd-8b75-2861b6783394",
"description": "Trial"
}
},
{
"hearingId": "69cdd600-c542-4818-a90e-a5caaccb7658",
"jurisdictionType": "CROWN",
"defendantIds": [
"ef90d9ca-58a3-4843-a65a-53970a252862"
],
"hearingDays": [],
"courtCentre": {
"id": "587e5998-a689-4708-b7bb-b93624d78212",
"name": "Hoth Crown Court",
"roomId": "34c69127-f26f-4543-b601-310c15461f5d",
"roomName": "Crown Court 3-1"
},
"hearingType": {
"id": "1fa3fd29-d6df-4838-a0dd-da1f90cb9b52",
"description": "Plea and Trial Preparation"
}
}
]
}
]
}
Loading

0 comments on commit 5360010

Please sign in to comment.