Skip to content

Commit

Permalink
feat: CE-1326 Add Quantity for Equipment (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayr974 authored Feb 4, 2025
1 parent c0affd0 commit de4139c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 36 deletions.
73 changes: 37 additions & 36 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ model equipment_code {
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
is_trap_ind Boolean @default(true)
has_quantity_ind Boolean @default(false)
equipment_equipment_equipment_codeToequipment_code equipment[] @relation("equipment_equipment_codeToequipment_code")
}

Expand All @@ -151,8 +152,8 @@ model threat_level_code {
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
wildlife_wildlife_threat_level_codeTothreat_level_code wildlife[] @relation("wildlife_threat_level_codeTothreat_level_code")
case_file case_file[]
wildlife_wildlife_threat_level_codeTothreat_level_code wildlife[] @relation("wildlife_threat_level_codeTothreat_level_code")
}

model configuration {
Expand Down Expand Up @@ -280,27 +281,27 @@ model case_file {
action_not_required_ind Boolean?
note_text String?
review_required_ind Boolean?
create_user_id String @db.VarChar(32)
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String? @db.VarChar(32)
update_utc_timestamp DateTime? @db.Timestamp(6)
complainant_contacted_ind Boolean?
attended_ind Boolean?
case_location_code String? @db.VarChar(10)
case_conflict_history_code String? @db.VarChar(10)
case_threat_level_code String? @db.VarChar(10)
create_user_id String @db.VarChar(32)
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String? @db.VarChar(32)
update_utc_timestamp DateTime? @db.Timestamp(6)
action action[]
authorization_permit authorization_permit[]
case_code_case_file_case_codeTocase_code case_code @relation("case_file_case_codeTocase_code", fields: [case_code], references: [case_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__case_code")
inaction_reason_code_case_file_inaction_reason_codeToinaction_reason_code inaction_reason_code? @relation("case_file_inaction_reason_codeToinaction_reason_code", fields: [inaction_reason_code], references: [inaction_reason_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__inaction_reason_code")
agency_code agency_code @relation(fields: [owned_by_agency_code], references: [agency_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__owned_by_agency_code")
case_file__conflict_history_code conflict_history_code? @relation(fields: [case_conflict_history_code], references: [conflict_history_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__case_conflict_history_code")
case_file__case_location_code case_location_code? @relation(fields: [case_location_code], references: [case_location_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__case_location_code")
case_file__threat_level_code threat_level_code? @relation(fields: [case_threat_level_code], references: [threat_level_code], onDelete: NoAction, onUpdate: NoAction, map: "FK_case_file__case_threat_level_code")
decision decision[]
lead lead[]
site site[]
wildlife wildlife[]
case_file__case_location_code case_location_code? @relation(fields: [case_location_code], references: [case_location_code], map: "FK_case_file__case_location_code")
case_file__conflict_history_code conflict_history_code? @relation(fields: [case_conflict_history_code], references: [conflict_history_code], map: "FK_case_file__case_conflict_history_code")
case_file__threat_level_code threat_level_code? @relation(fields: [case_threat_level_code], references: [threat_level_code], map: "FK_case_file__case_threat_level_code")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
Expand Down Expand Up @@ -372,6 +373,7 @@ model equipment {
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
was_animal_captured String @default("U") @db.Char(1)
quantity Int? @db.SmallInt
action action[]
equipment_code_equipment_equipment_codeToequipment_code equipment_code? @relation("equipment_equipment_codeToequipment_code", fields: [equipment_code], references: [equipment_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_equipment__equipment_code")
}
Expand All @@ -390,7 +392,7 @@ model drug_administered {
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
active_ind Boolean?
additional_comments_text String? @db.VarChar(1000)
additional_comments_text String?
drug_code_drug_administered_drug_codeTodrug_code drug_code @relation("drug_administered_drug_codeTodrug_code", fields: [drug_code], references: [drug_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_drug_administered__drug_code")
drug_method_code_drug_administered_drug_method_codeTodrug_method_code drug_method_code @relation("drug_administered_drug_method_codeTodrug_method_code", fields: [drug_method_code], references: [drug_method_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_drug_administered__drug_method_code")
drug_remaining_outcome_code_drug_administered_drug_remaining_outcome_codeTodrug_remaining_outcome_code drug_remaining_outcome_code? @relation("drug_administered_drug_remaining_outcome_codeTodrug_remaining_outcome_code", fields: [drug_remaining_outcome_code], references: [drug_remaining_outcome_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_drug_administered__drug_remaining_outcome_code")
Expand Down Expand Up @@ -434,28 +436,27 @@ model ear_tag_h {

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model wildlife {
wildlife_guid String @id(map: "PK_wildlife_guid") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
case_file_guid String @db.Uuid
threat_level_code String? @db.VarChar(10)
sex_code String? @db.VarChar(10)
age_code String? @db.VarChar(10)
hwcr_outcome_code String? @db.VarChar(10)
species_code String @db.VarChar(10)
create_user_id String @db.VarChar(32)
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
active_ind Boolean?
identifying_features String? @db.VarChar(4000)
action action[]
drug_administered drug_administered[]
ear_tag ear_tag[]
age_code_wildlife_age_codeToage_code age_code? @relation("wildlife_age_codeToage_code", fields: [age_code], references: [age_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__age_code")
case_file case_file @relation(fields: [case_file_guid], references: [case_file_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__case_file_guid")
hwcr_outcome_code_wildlife_hwcr_outcome_codeTohwcr_outcome_code hwcr_outcome_code? @relation("wildlife_hwcr_outcome_codeTohwcr_outcome_code", fields: [hwcr_outcome_code], references: [hwcr_outcome_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__hwcr_outcome_code")
sex_code_wildlife_sex_codeTosex_code sex_code? @relation("wildlife_sex_codeTosex_code", fields: [sex_code], references: [sex_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__sex_code")
threat_level_code_wildlife_threat_level_codeTothreat_level_code threat_level_code? @relation("wildlife_threat_level_codeTothreat_level_code", fields: [threat_level_code], references: [threat_level_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__threat_level_code")
wildlife_guid String @id(map: "PK_wildlife_guid") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
case_file_guid String @db.Uuid
threat_level_code String? @db.VarChar(10)
sex_code String? @db.VarChar(10)
age_code String? @db.VarChar(10)
hwcr_outcome_code String? @db.VarChar(10)
species_code String @db.VarChar(10)
create_user_id String @db.VarChar(32)
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
active_ind Boolean?
identifying_features String? @db.VarChar(4000)
action action[]
drug_administered drug_administered[]
ear_tag ear_tag[]
age_code_wildlife_age_codeToage_code age_code? @relation("wildlife_age_codeToage_code", fields: [age_code], references: [age_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__age_code")
case_file case_file @relation(fields: [case_file_guid], references: [case_file_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__case_file_guid")
hwcr_outcome_code_wildlife_hwcr_outcome_codeTohwcr_outcome_code hwcr_outcome_code? @relation("wildlife_hwcr_outcome_codeTohwcr_outcome_code", fields: [hwcr_outcome_code], references: [hwcr_outcome_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__hwcr_outcome_code")
sex_code_wildlife_sex_codeTosex_code sex_code? @relation("wildlife_sex_codeTosex_code", fields: [sex_code], references: [sex_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__sex_code")
threat_level_code_wildlife_threat_level_codeTothreat_level_code threat_level_code? @relation("wildlife_threat_level_codeTothreat_level_code", fields: [threat_level_code], references: [threat_level_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_wildlife__threat_level_code")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
Expand Down Expand Up @@ -616,13 +617,13 @@ model site_h {

model case_location_code {
case_location_code String @id(map: "PK_case_location_code") @db.VarChar(10)
short_description String @db.VarChar(50)
short_description String? @db.VarChar(50)
long_description String? @db.VarChar(250)
display_order Int
active_ind Boolean
display_order Int?
active_ind Boolean?
create_user_id String @db.VarChar(32)
create_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String @db.VarChar(32)
update_utc_timestamp DateTime @db.Timestamp(6)
update_user_id String? @db.VarChar(32)
update_utc_timestamp DateTime? @db.Timestamp(6)
case_file case_file[]
}
4 changes: 4 additions & 0 deletions backend/src/case_file/case_file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ export class CaseFileService {
equipment_code: createEquipmentInput.equipment[0].typeCode,
equipment_location_desc: createEquipmentInput.equipment[0].address,
was_animal_captured: createEquipmentInput.equipment[0].wasAnimalCaptured,
quantity: createEquipmentInput.equipment[0].quantity,
// exclude equipment_geometry_point because prisma can't handle this =gracefully
};

Expand Down Expand Up @@ -1528,6 +1529,7 @@ export class CaseFileService {
equipment_location_desc: equipmentRecord.address,
active_ind: equipmentRecord.actionEquipmentTypeActiveIndicator,
was_animal_captured: equipmentRecord.wasAnimalCaptured,
quantity: equipmentRecord.quantity,
};

// Update the equipment record
Expand Down Expand Up @@ -1678,6 +1680,7 @@ export class CaseFileService {
equipment_location_desc: true,
create_utc_timestamp: true,
was_animal_captured: true,
quantity: true,
equipment_code_equipment_equipment_codeToequipment_code: {
select: {
short_description: true,
Expand Down Expand Up @@ -1757,6 +1760,7 @@ export class CaseFileService {
createDate: create_utc_timestamp,
actions: [],
wasAnimalCaptured: equipment.was_animal_captured,
quantity: equipment.quantity,
} as Equipment);

// Append the action to this equipment's list of actions
Expand Down
1 change: 1 addition & 0 deletions backend/src/case_file/case_file_inputs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ input EquipmentDetailsInput {
yCoordinate: String
actions: [EquipmentActionInput]!
wasAnimalCaptured: String
quantity: Int
}

input EquipmentActionInput {
Expand Down
1 change: 1 addition & 0 deletions backend/src/case_file/case_file_types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type EquipmentDetails {
createDate: Date
actions: [CaseFileAction]
wasAnimalCaptured: String
quantity: Int
}

type Wildlife {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface CreateEquipmentDetailsInput {
equipmentTypeActiveIndicator: boolean;
actions: EquipmentActionItem[];
wasAnimalCaptured: string;
quantity?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface UpdateEquipmentDetailsInput {
actionEquipmentTypeActiveIndicator: boolean;
actions: EquipmentActionItem[];
wasAnimalCaptured: string;
quantity?: number;
}
1 change: 1 addition & 0 deletions backend/src/case_file/entities/equipment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export class Equipment {
createDate: Date;
actions: CaseFileAction[];
wasAnimalCaptured: string;
quantity?: number;
}
1 change: 1 addition & 0 deletions backend/src/equipment_code/equipment_code.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type EquipmentCode {
displayOrder: Int
activeIndicator: Boolean
isTrapIndicator: Boolean
hasQuantityIndicator: Boolean
}

type Query {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/equipment_code/equipment_code.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class EquipmentCodeService {
display_order: true,
active_ind: true,
is_trap_ind: true,
has_quantity_ind: true,
},
orderBy: {
display_order: "asc",
Expand All @@ -28,6 +29,7 @@ export class EquipmentCodeService {
displayOrder: prismaEquipmentCodes.display_order,
activeIndicator: prismaEquipmentCodes.active_ind,
isTrapIndicator: prismaEquipmentCodes.is_trap_ind,
hasQuantityIndicator: prismaEquipmentCodes.has_quantity_ind,
}));

return equipmentCodes;
Expand Down
9 changes: 9 additions & 0 deletions migrations/sql/R__code-table-data.sql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5550,6 +5550,14 @@ DELETE FROM
WHERE
equipment_code = 'NKSNR';

update equipment_code
set
has_quantity_ind = true
where
active_ind = true
and
equipment_code in ('FTRAP', 'SNR', 'SIGNG', 'TRCAM', 'LTRAP');

--------------------------
-- Outcome code updates
-------------------------
Expand Down Expand Up @@ -5643,3 +5651,4 @@ SET
configuration_value = cast(configuration_value as INTEGER) + 1
WHERE
configuration_code = 'CDTABLEVER';

17 changes: 17 additions & 0 deletions migrations/sql/V1.36.0__CE-1326.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ALTER TABLE case_management.equipment
ADD COLUMN IF NOT EXISTS quantity smallint;

ALTER TABLE case_management.equipment_code
ADD COLUMN IF NOT EXISTS has_quantity_ind boolean NOT NULL DEFAULT false;

UPDATE case_management.configuration
SET configuration_value = cast(configuration_value as INTEGER)+1 WHERE configuration_code = 'CDTABLEVER';

comment on column case_management.equipment.quantity is 'Indicates the number of EQUIPMENT used. Values should be a positive integer or null if not applicable. ';
comment on column case_management.equipment_code.has_quantity_ind is 'Indicates if the type of equipment allows a quantity to be speciofied. Default to ''false''. ';

UPDATE case_management.equipment SET quantity = 1
WHERE
active_ind = true
AND
equipment_code IN ('FTRAP', 'SNR', 'SIGNG', 'TRCAM', 'LTRAP');

0 comments on commit de4139c

Please sign in to comment.