diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index ff03a3b13def..2ac9e2e32ef5 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -426,6 +426,13 @@ export const caseListInclude: Includeable[] = [ order: [['created', 'DESC']], separate: true, }, + { + model: Subpoena, + as: 'subpoenas', + required: false, + order: [['created', 'DESC']], + separate: true, + }, ], separate: true, }, diff --git a/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.strings.ts b/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.strings.ts index 89ece434dfc5..7745ebcf1884 100644 --- a/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.strings.ts +++ b/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.strings.ts @@ -83,4 +83,9 @@ export const strings = defineMessages({ defaultMessage: 'Afturkallað', description: 'Notað sem merki þegar mál í stöðu "Afturkallað" í málalista', }, + notYetServiced: { + id: 'judicial.system.core:tag_case_state.not_yet_serviced', + defaultMessage: 'Óbirt', + description: 'Notað sem merki þegar mál í stöðu "Óbirt" í málalista', + }, }) diff --git a/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.tsx b/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.tsx index 3e5445189f72..743f91920971 100644 --- a/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.tsx +++ b/apps/judicial-system/web/src/components/TagCaseState/TagCaseState.tsx @@ -5,11 +5,13 @@ import { Tag, TagVariant } from '@island.is/island-ui/core' import { isIndictmentCase, isInvestigationCase, + isSuccessfulServiceStatus, } from '@island.is/judicial-system/types' import { CaseIndictmentRulingDecision, CaseState, CaseType, + Defendant, IndictmentDecision, User, } from '@island.is/judicial-system-web/src/graphql/schema' @@ -30,6 +32,16 @@ interface Props { indictmentReviewer?: User | null, // TODO: Refactor so we have a more generalized interface for the info passed in to the component ) => { color: TagVariant; text: string } indictmentDecision?: IndictmentDecision | null + defendants?: Defendant[] | null +} + +const haveAllSubpoenasBeenServiced = (defendants: Defendant[]): boolean => { + return defendants.every((defendant) => { + // if at least one subpoena for each defendant was serviced, we return true + return defendant.subpoenas?.some((subpoena) => + isSuccessfulServiceStatus(subpoena.serviceStatus), + ) + }) } export const mapIndictmentCaseStateToTagVariant = ( @@ -59,6 +71,7 @@ export const mapCaseStateToTagVariant = ( isCourtRole?: boolean, indictmentRulingDecision?: CaseIndictmentRulingDecision | null, indictmentDecision?: IndictmentDecision | null, + defendants?: Defendant[] | null, ): { color: TagVariant; text: string } => { switch (state) { case CaseState.NEW: @@ -70,7 +83,18 @@ export const mapCaseStateToTagVariant = ( color: 'purple', text: formatMessage(isCourtRole ? strings.new : strings.sent), } - case CaseState.RECEIVED: + case CaseState.RECEIVED: { + if ( + isIndictmentCase(caseType) && + defendants && + scheduledDate && + !haveAllSubpoenasBeenServiced(defendants) + ) { + return { + color: 'red', + text: formatMessage(strings.notYetServiced), + } + } switch (indictmentDecision) { case IndictmentDecision.POSTPONING: case IndictmentDecision.SCHEDULING: @@ -88,6 +112,7 @@ export const mapCaseStateToTagVariant = ( return scheduledDate ? { color: 'mint', text: formatMessage(strings.scheduled) } : { color: 'blueberry', text: formatMessage(strings.received) } + } case CaseState.ACCEPTED: return isIndictmentCase(caseType) || isValidToDateInThePast @@ -129,6 +154,7 @@ const TagCaseState: FC = (props) => { indictmentRulingDecision, customMapCaseStateToTag, indictmentDecision, + defendants, } = props const tagVariant = customMapCaseStateToTag @@ -142,6 +168,7 @@ const TagCaseState: FC = (props) => { isCourtRole, indictmentRulingDecision, indictmentDecision, + defendants, ) if (!tagVariant) return null diff --git a/apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx b/apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx index 80ed5591e736..cf1e1c68910d 100644 --- a/apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx +++ b/apps/judicial-system/web/src/routes/Court/components/CasesInProgressTable/CasesInProgressTable.tsx @@ -155,9 +155,11 @@ const CasesInProgressTable: FC = (props) => { cell: (row) => ( ), }, diff --git a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx index 7a52c93d46ff..be8edb2ecdd4 100644 --- a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx +++ b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx @@ -25,7 +25,10 @@ import { SortButton, TableSkeleton, } from '@island.is/judicial-system-web/src/components/Table' -import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema' +import { + CaseListEntry, + Defendant, +} from '@island.is/judicial-system-web/src/graphql/schema' import { useCaseList, useSort, @@ -183,6 +186,7 @@ export const DefenderCasesTable: FC = ({ courtDate={column.courtDate} indictmentDecision={column.indictmentDecision} indictmentRulingDecision={column.indictmentRulingDecision} + defendants={column.defendants} /> {column.appealState && ( diff --git a/apps/judicial-system/web/src/routes/Defender/Cases/defenderCases.graphql b/apps/judicial-system/web/src/routes/Defender/Cases/defenderCases.graphql index 9c2057fd61a2..5c07fc3c2f22 100644 --- a/apps/judicial-system/web/src/routes/Defender/Cases/defenderCases.graphql +++ b/apps/judicial-system/web/src/routes/Defender/Cases/defenderCases.graphql @@ -23,6 +23,11 @@ query DefenderCases($input: CaseListQueryInput) { name noNationalId defenderChoice + subpoenas { + id + serviceStatus + subpoenaId + } } initialRulingDate rulingDate diff --git a/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx b/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx index 7e444f9327d4..29cdaa3286de 100644 --- a/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx +++ b/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx @@ -17,7 +17,10 @@ import { DefendantInfo, } from '@island.is/judicial-system-web/src/components/Table' import Table from '@island.is/judicial-system-web/src/components/Table/Table' -import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema' +import { + CaseListEntry, + Defendant, +} from '@island.is/judicial-system-web/src/graphql/schema' interface Props { cases: CaseListEntry[] @@ -105,6 +108,7 @@ const ActiveCases: FC = (props) => { courtDate={row.courtDate} indictmentDecision={row.indictmentDecision} indictmentRulingDecision={row.indictmentRulingDecision} + defendants={row.defendants} /> ), }, diff --git a/apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx b/apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx index a14415196497..6e27a56edc29 100644 --- a/apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx +++ b/apps/judicial-system/web/src/routes/Shared/Cases/MobileCase.tsx @@ -86,6 +86,7 @@ const MobileCase: FC> = ({ courtDate={theCase.courtDate} indictmentRulingDecision={theCase.indictmentRulingDecision} indictmentDecision={theCase.indictmentDecision} + defendants={theCase.defendants} />, ]} isLoading={isLoading} diff --git a/apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql b/apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql index b188cbfac1aa..b18a3131f9b5 100644 --- a/apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql +++ b/apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql @@ -30,6 +30,11 @@ query Cases { isSentToPrisonAdmin punishmentType openedByPrisonAdminDate + subpoenas { + id + serviceStatus + subpoenaId + } } defendantsPunishmentType courtDate