Skip to content

Commit

Permalink
feat: call 911 disposition code
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Oct 23, 2023
1 parent 1aabd7a commit 88b30d8
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE "Call911" ADD COLUMN "dispositionCodeId" TEXT;

-- AlterTable
ALTER TABLE "CallTypeValue" ADD COLUMN "isDisposition" BOOLEAN NOT NULL DEFAULT false;

-- AddForeignKey
ALTER TABLE "Call911" ADD CONSTRAINT "Call911_dispositionCodeId_fkey" FOREIGN KEY ("dispositionCodeId") REFERENCES "CallTypeValue"("id") ON DELETE SET NULL ON UPDATE CASCADE;
17 changes: 11 additions & 6 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,14 @@ model WeaponValue {
}

model CallTypeValue {
id String @id @default(cuid())
priority String?
valueId String
value Value @relation("callTypeValueToValue", fields: [valueId], references: [id], onDelete: Cascade)
Call911 Call911[]
id String @id @default(cuid())
priority String?
valueId String
isDisposition Boolean @default(false)
value Value @relation("callTypeValueToValue", fields: [valueId], references: [id], onDelete: Cascade)
dispositionCodeToCall Call911[] @relation("dispositionCodeToCall")
callTypeToCall Call911[] @relation("callTypeToCall")
}

// notifications
Expand Down Expand Up @@ -1310,12 +1313,14 @@ model Call911 {
ended Boolean? @default(false)
situationCode StatusValue? @relation(fields: [situationCodeId], references: [id])
situationCodeId String?
dispositionCode CallTypeValue? @relation("dispositionCodeToCall", fields: [dispositionCodeId], references: [id])
dispositionCodeId String?
viaDispatch Boolean? @default(false)
divisions DivisionValue[]
departments DepartmentValue[]
events Call911Event[]
incidents LeoIncident[]
type CallTypeValue? @relation(fields: [typeId], references: [id])
type CallTypeValue? @relation("callTypeToCall", fields: [typeId], references: [id])
typeId String?
Officer Officer[] @relation("activeCall")
EmsFdDeputy EmsFdDeputy[] @relation("emsFdActiveCall")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export const typeHandlers = {
where: { id: String(id) },
...makePrismaData(ValueType.CALL_TYPE, {
priority: item.priority,
isDisposition: item.isDisposition ?? false,
value: item.value,
isDisabled: item.isDisabled,
}),
Expand Down
3 changes: 2 additions & 1 deletion apps/client/locales/en/calls.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"id": "id",
"towLogsDescription": "Here you can view all archived tow logs. This allows you to view all tow logs that have been ended/archived.",
"addAllUnits": "Add all active units",
"openCallModalAfterCreation": "Open Manage 911 call modal after call creation?"
"openCallModalAfterCreation": "Open Manage 911 call modal after call creation?",
"dispositionCode": "Disposition Code"
},
"Events": {
"unitAssignedToCall": "<span>{unit}</span> has been assigned to this call.",
Expand Down
4 changes: 3 additions & 1 deletion apps/client/locales/en/values.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
"FELONY": "Felony",
"warningApplicable": "Warning Applicable",
"warningNotApplicable": "Warning Not Applicable",
"isPrimary": "Is Primary"
"isPrimary": "Is Primary",
"isDispositionDescription": "A disposition code can be used when a call is closed. This will be used to determine the outcome of the call.",
"isDisposition": "Is Disposition"
},
"PENAL_CODE_GROUP": {
"MANAGE": "Manage Penal Code Groups",
Expand Down
12 changes: 12 additions & 0 deletions apps/client/src/components/admin/values/ManageValueModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function createInitialValues(options: CreateInitialValuesOptions) {
licenseType: value && isBaseValue(value) ? value.licenseType : null,
isDefault: value && isBaseValue(value) ? value.isDefault : undefined,
priority: value && isCallTypeValue(value) ? value.priority ?? undefined : undefined,
isDisposition: value && isCallTypeValue(value) ? value.isDisposition ?? undefined : undefined,

officerRankImageId: "",
officerRankDepartments:
Expand Down Expand Up @@ -376,6 +377,17 @@ export function ManageValueModal({ onCreate, onUpdate, type, value }: Props) {
/>
) : null}

{type === ValueType.CALL_TYPE ? (
<SwitchField
name="isDisposition"
onChange={(value) => setFieldValue("isDisposition", value)}
isSelected={values.isDisposition}
description={tValues("isDispositionDescription")}
>
{tValues("isDisposition")}
</SwitchField>
) : null}

{type === ValueType.OFFICER_RANK ? (
<>
<ImageSelectInput valueKey="officerRankImageId" image={image} setImage={setImage} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function Manage911CallForm({ call, isDisabled, setShowAlert, handleClose
departments: call?.departments?.map((dep) => ({ value: dep.id, label: dep.value.value })) ?? [],
divisions: call?.divisions?.map((dep) => ({ value: dep.id, label: dep.value.value })) ?? [],
situationCode: call?.situationCodeId ?? null,
dispositionCodeId: call?.dispositionCodeId ?? null,
type: call?.typeId ?? null,
notifyAssignedUnits: true,
openCallModalAfterCreation: true,
Expand Down Expand Up @@ -208,7 +209,7 @@ export function Manage911CallForm({ call, isDisabled, setShowAlert, handleClose
) : null}
</FormRow>

<FormRow>
<FormRow useFlex>
<ValueSelectField
isOptional
isDisabled={isDisabled}
Expand All @@ -218,6 +219,19 @@ export function Manage911CallForm({ call, isDisabled, setShowAlert, handleClose
values={codes10.values}
valueType={ValueType.CODES_10}
filterFn={(value) => value.type === StatusValueType.SITUATION_CODE}
className="w-full"
/>

<ValueSelectField
isOptional
isDisabled={isDisabled}
isClearable
label={t("dispositionCode")}
fieldName="dispositionCode"
values={callType.values}
valueType={ValueType.CALL_TYPE}
filterFn={(value) => value.isDisposition}
className="w-full"
/>

<ValueSelectField
Expand All @@ -228,9 +242,22 @@ export function Manage911CallForm({ call, isDisabled, setShowAlert, handleClose
fieldName="type"
values={callType.values}
valueType={ValueType.CALL_TYPE}
filterFn={(value) => !value.isDisposition}
className="w-full"
/>
</FormRow>

<ValueSelectField
isOptional
isDisabled={isDisabled}
isClearable
label={t("situationCode")}
fieldName="situationCode"
values={codes10.values}
valueType={ValueType.CODES_10}
filterFn={(value) => value.type === StatusValueType.SITUATION_CODE}
/>

<FormField errorMessage={errors.description} label={common("description")}>
<Editor
value={values.descriptionData}
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/components/form/inputs/value-select-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function ValueSelectField<T extends AnyValue>(props: Props<T>) {
}, [getDefaultSearchValue]);

function handleSuggestionPress(node?: Node<AnyValue> | null) {
if (node) setSearch(node?.textValue);

const fieldData = { [props.fieldName]: node?.key ?? null };
setValues({ ...values, ...fieldData });
props.onSelectionChange?.((node?.value as T | null) ?? null);
Expand Down
6 changes: 5 additions & 1 deletion apps/client/src/lib/admin/values/values.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export function useTableDataOfType(type: ValueType) {

return {
priority: v.priority ?? common("none"),
isDisposition: common(yesOrNoText(v.isDisposition)),
};
}
case ValueType.DRIVERSLICENSE_CATEGORY: {
Expand Down Expand Up @@ -275,7 +276,10 @@ export function useTableHeadersOfType(type: ValueType): ColumnDef<{ id: string }
];
}
case ValueType.CALL_TYPE: {
return [{ header: t("priority"), accessorKey: "priority" }];
return [
{ header: t("priority"), accessorKey: "priority" },
{ header: t("isDisposition"), accessorKey: "isDisposition" },
];
}
case ValueType.DRIVERSLICENSE_CATEGORY: {
return [
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/admin/values/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const QUALIFICATION_ARR = z.array(QUALIFICATION_SCHEMA).min(1);
*/
export const CALL_TYPE_SCHEMA = BASE_VALUE_SCHEMA.extend({
priority: z.string().nullish(),
isDisposition: z.boolean().nullish(),
});

export const CALL_TYPE_ARR = z.array(CALL_TYPE_SCHEMA).min(1);
Expand Down

0 comments on commit 88b30d8

Please sign in to comment.