diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 7c157c73..8f34ca40 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -179,8 +179,10 @@ model action { update_utc_timestamp DateTime? @db.Timestamp(6) equipment_guid String? @db.Uuid wildlife_guid String? @db.Uuid + decision_guid String? @db.Uuid case_file case_file @relation(fields: [case_guid], references: [case_file_guid], onDelete: NoAction, onUpdate: NoAction, map: "FK_action__case_guid") action_type_action_xref action_type_action_xref @relation(fields: [action_type_action_xref_guid], references: [action_type_action_xref_guid], onDelete: NoAction, onUpdate: NoAction, map: "FK_action_action_type_action_xref") + decision decision? @relation(fields: [decision_guid], references: [decision_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_action__decision_guid") equipment equipment? @relation(fields: [equipment_guid], references: [equipment_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_action__equipment_guid") wildlife wildlife? @relation(fields: [wildlife_guid], references: [wildlife_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_action__wildlife_guid") } @@ -283,6 +285,7 @@ model case_file { 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") + decision decision[] lead lead[] wildlife wildlife[] } @@ -453,3 +456,117 @@ model wildlife_h { operation_executed_at DateTime @default(now()) @db.Timestamp(6) data_after_executed_operation Json? } + +/// 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 decision { + decision_guid String @id(map: "PK_decision_guid") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid + case_file_guid String @db.Uuid + schedule_sector_xref_guid String @db.Uuid + discharge_code String @db.VarChar(10) + rationale_code String? @db.VarChar(10) + inspection_number Int? + lead_agency String? @db.VarChar(10) + non_compliance_decision_matrix_code String @db.VarChar(10) + 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) + action action[] + case_file case_file @relation(fields: [case_file_guid], references: [case_file_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_decision__case_file_guid") + discharge_code_decision_discharge_codeTodischarge_code discharge_code @relation("decision_discharge_codeTodischarge_code", fields: [discharge_code], references: [discharge_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_decision__discharge_code") + rationale_code_decision_rationale_codeTorationale_code rationale_code? @relation("decision_rationale_codeTorationale_code", fields: [rationale_code], references: [rationale_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_decision__rationale_code") + schedule_sector_xref schedule_sector_xref @relation(fields: [schedule_sector_xref_guid], references: [schedule_sector_xref_guid], onDelete: NoAction, onUpdate: NoAction, map: "fk_decision__schedule_sector_xref_guid") +} + +model decision_h { + h_decision_guid String @id(map: "PK_h_decision") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid + target_row_id String @db.Uuid + operation_type String @db.Char(1) + operation_user_id String @default(dbgenerated("CURRENT_USER")) @db.VarChar(32) + operation_executed_at DateTime @default(now()) @db.Timestamp(6) + data_after_executed_operation Json? +} + +/// 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 discharge_code { + discharge_code String @id(map: "PK_discharge_code") @db.VarChar(10) + short_description String @db.VarChar(50) + long_description String? @db.VarChar(250) + 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) + decision_decision_discharge_codeTodischarge_code decision[] @relation("decision_discharge_codeTodischarge_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 +model non_compliance_decision_matrix_code { + non_compliance_decision_matrix_code String @id(map: "PK_non_compliance_decision_matrix_code") @db.VarChar(10) + short_description String @db.VarChar(50) + long_description String? @db.VarChar(250) + 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) +} + +/// 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 rationale_code { + rationale_code String @id(map: "PK_rationale_code") @db.VarChar(10) + short_description String @db.VarChar(50) + long_description String? @db.VarChar(250) + 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) + decision_decision_rationale_codeTorationale_code decision[] @relation("decision_rationale_codeTorationale_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 +model schedule_code { + schedule_code String @id(map: "PK_schedule_code") @db.VarChar(10) + short_description String @db.VarChar(50) + long_description String? @db.VarChar(250) + 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) + schedule_sector_xref_schedule_sector_xref_schedule_codeToschedule_code schedule_sector_xref[] @relation("schedule_sector_xref_schedule_codeToschedule_code") +} + +model schedule_sector_xref { + schedule_sector_xref_guid String @id(map: "PK_schedule_sector_xref_guid") @default(dbgenerated("uuid_generate_v4()")) @db.Uuid + schedule_code String @db.VarChar(10) + sector_code String @db.VarChar(10) + 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) + decision decision[] + schedule_code_schedule_sector_xref_schedule_codeToschedule_code schedule_code @relation("schedule_sector_xref_schedule_codeToschedule_code", fields: [schedule_code], references: [schedule_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_schedule_sector_xref__schedule_code") + sector_code_schedule_sector_xref_sector_codeTosector_code sector_code @relation("schedule_sector_xref_sector_codeTosector_code", fields: [sector_code], references: [sector_code], onDelete: NoAction, onUpdate: NoAction, map: "fk_schedule_sector_xref__sector_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 +model sector_code { + sector_code String @id(map: "PK_sector_code") @db.VarChar(10) + short_description String @db.VarChar(50) + long_description String? @db.VarChar(250) + 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) + schedule_sector_xref_schedule_sector_xref_sector_codeTosector_code schedule_sector_xref[] @relation("schedule_sector_xref_sector_codeTosector_code") +} diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 8d1b564d..476b8442 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -24,6 +24,12 @@ import { InactionJustificationTypeModule } from "./inaction_justification_type/i import { DateScalar } from "./common/custom_scalars"; import { HWCRPreventionActionModule } from "./hwcr_prevention_action/hwcr_prevention_action.module"; import { HWCRAssessmentActionModule } from "./hwcr_assessment_action/hwcr_assessment_action.module"; +import { ScheduleCodeModule } from "./code-tables/schedule_code/schedule_code.module"; +import { DischargeCodeModule } from "./code-tables/discharge_code/discharge_code,module"; +import { NonComplianceCodeModule } from "./code-tables/non_compliance_code/non_compliance_code.module"; +import { RationaleCodeModule } from "./code-tables/rationale_code/rationale_code.module"; +import { SectorCodeModule } from "./code-tables/sector_code/sector_code.module"; +import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_action.module"; @Module({ imports: [ @@ -49,6 +55,12 @@ import { HWCRAssessmentActionModule } from "./hwcr_assessment_action/hwcr_assess HWCRPreventionActionModule, CaseFileModule, InactionJustificationTypeModule, + ScheduleCodeModule, + DischargeCodeModule, + NonComplianceCodeModule, + RationaleCodeModule, + SectorCodeModule, + CEEBDecisionActionModule, ], controllers: [AppController], providers: [AppService, DateScalar], diff --git a/backend/src/case_file/case_file.resolver.ts b/backend/src/case_file/case_file.resolver.ts index e04046ad..f2393ab9 100644 --- a/backend/src/case_file/case_file.resolver.ts +++ b/backend/src/case_file/case_file.resolver.ts @@ -14,6 +14,8 @@ import { DeleteEquipmentInput } from "./dto/equipment/delete-equipment.input"; import { CreateWildlifeInput } from "./dto/wildlife/create-wildlife-input"; import { DeleteWildlifeInput } from "./dto/wildlife/delete-wildlife-input"; import { UpdateWildlifeInput } from "./dto/wildlife/update-wildlife-input"; +import { CreateDecisionInput } from "./dto/ceeb/decision/create-decsion-input"; +import { UpdateDecisionInput } from "./dto/ceeb/decision/update-decsion-input"; @UseGuards(JwtRoleGuard) @Resolver("CaseFile") @@ -39,13 +41,13 @@ export class CaseFileResolver { } @Query("getCaseFile") - @Roles(Role.COS_OFFICER) + @Roles(Role.COS_OFFICER, Role.CEEB) findOne(@Args("caseIdentifier") caseIdentifier: string) { return this.caseFileService.findOne(caseIdentifier); } @Query("getCaseFileByLeadId") - @Roles(Role.COS_OFFICER) + @Roles(Role.COS_OFFICER, Role.CEEB) findOneByLeadId(@Args("leadIdentifier") leadIdentifier: string) { return this.caseFileService.findOneByLeadId(leadIdentifier); } @@ -121,4 +123,16 @@ export class CaseFileResolver { deleteWildlife(@Args("input") input: DeleteWildlifeInput) { return this.caseFileService.deleteWildlife(input); } + + @Mutation("createDecision") + @Roles(Role.CEEB) + createDecision(@Args("input") input: CreateDecisionInput) { + return this.caseFileService.createDecision(input); + } + + @Mutation("updateDecision") + @Roles(Role.CEEB) + updateDecision(@Args("input") input: UpdateDecisionInput) { + return this.caseFileService.updateDecision(input); + } } diff --git a/backend/src/case_file/case_file.service.ts b/backend/src/case_file/case_file.service.ts index 1cd380b1..64e1ac53 100644 --- a/backend/src/case_file/case_file.service.ts +++ b/backend/src/case_file/case_file.service.ts @@ -24,6 +24,11 @@ import { Wildlife } from "./entities/wildlife-entity"; import { SubjectQueryResult } from "./dto/subject-query-result"; import { DeleteWildlifeInput } from "./dto/wildlife/delete-wildlife-input"; import { UpdateWildlifeInput } from "./dto/wildlife/update-wildlife-input"; +import { CreateDecisionInput } from "./dto/ceeb/decision/create-decsion-input"; +import { DecisionInput } from "./dto/ceeb/decision/decision-input"; +import { randomUUID } from "crypto"; +import { Decision } from "./entities/decision-entity"; +import { UpdateDecisionInput } from "./dto/ceeb/decision/update-decsion-input"; @Injectable() export class CaseFileService { @@ -48,21 +53,17 @@ export class CaseFileService { let caseFileGuid: string; try { - let case_file = await db.case_file.create({ - data: { - agency_code: { - connect: { - agency_code: input.agencyCode, - }, - }, - create_user_id: input.createUserId, - create_utc_timestamp: new Date(), - case_code_case_file_case_codeTocase_code: { - connect: { - case_code: input.caseCode, - }, - }, - }, + const caseRecord = { + case_code: input.caseCode, + owned_by_agency_code: input.agencyCode, + create_user_id: input.createUserId, + update_user_id: input.createUserId, + create_utc_timestamp: new Date(), + update_utc_timestamp: new Date(), + }; + + const case_file = await db.case_file.create({ + data: caseRecord, }); caseFileGuid = case_file.case_file_guid; @@ -76,6 +77,7 @@ export class CaseFileService { }, }); } catch (exception) { + this.logger.warn(exception); throw new GraphQLError("Exception occurred. See server log for details", exception); } return caseFileGuid; @@ -288,6 +290,25 @@ export class CaseFileService { }, }, }, + decision: { + where: { + active_ind: true, + }, + select: { + decision_guid: true, + discharge_code: true, + rationale_code: true, + inspection_number: true, + lead_agency: true, + non_compliance_decision_matrix_code: true, + schedule_sector_xref: { + select: { + schedule_code: true, + sector_code: true, + }, + }, + }, + }, }, }); @@ -352,6 +373,37 @@ export class CaseFileService { caseFile.subject = await this._getCaseFileSubjects(queryResult); } + //-- add the decision if its returned in the query result + if (queryResult.decision && queryResult.decision.length !== 0) { + const { decision } = queryResult; + + const action = await this.caseFileActionService.findActionsByCaseIdAndType( + caseFileId, + ACTION_TYPE_CODES.CEEBACTION, + ); + + let record: Decision = { + id: decision[0].decision_guid, + schedule: decision[0].schedule_sector_xref.schedule_code, + sector: decision[0].schedule_sector_xref.sector_code, + discharge: decision[0].discharge_code, + nonCompliance: decision[0].non_compliance_decision_matrix_code, + rationale: decision[0].rationale_code, + assignedTo: action[0].actor, + actionTaken: action[0].actionCode, + actionTakenDate: action[0].date, + }; + + if (decision[0].inspection_number) { + record = { ...record, inspectionNumber: decision[0].inspection_number.toString() }; + } + if (decision[0].lead_agency) { + record = { ...record, leadAgency: decision[0].lead_agency }; + } + + caseFile.decision = record; + } + return caseFile; }; @@ -2365,6 +2417,366 @@ export class CaseFileService { } }; + //-- + //-- decision outcomes + //-- + createDecision = async (model: CreateDecisionInput): Promise => { + let caseFileId = ""; + + //-- + //-- creates a new decision record and returns the decision_guid + //-- + const _addDecision = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + caseId: string, + decision: DecisionInput, + scheduleSectorXref: string, + userId: string, + ): Promise => { + try { + const { discharge, nonCompliance, rationale } = decision; + + let record: any = { + decision_guid: randomUUID(), + case_file_guid: caseId, + schedule_sector_xref_guid: scheduleSectorXref, + discharge_code: discharge, + rationale_code: rationale, + non_compliance_decision_matrix_code: nonCompliance, + active_ind: true, + create_user_id: userId, + update_user_id: userId, + create_utc_timestamp: new Date(), + update_utc_timestamp: new Date(), + }; + + if (decision.inspectionNumber) { + record = { ...record, inspection_number: parseInt(decision.inspectionNumber) }; + } + + if (decision.leadAgency) { + record = { ...record, lead_agency: decision.leadAgency }; + } + + const result = await db.decision.create({ + data: record, + }); + + return result?.decision_guid; + } catch (exception) { + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + //-- + //-- creates a schedule/sector xref record and returns the schedule_sector_xref_guid + //-- + const _addWdrXref = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + decision: DecisionInput, + userId: string, + ): Promise => { + try { + const { sector, schedule } = decision; + + let record: any = { + schedule_sector_xref_guid: randomUUID(), + sector_code: sector, + schedule_code: schedule, + active_ind: true, + create_user_id: userId, + update_user_id: userId, + create_utc_timestamp: new Date(), + update_utc_timestamp: new Date(), + }; + + const result = await db.schedule_sector_xref.create({ + data: record, + }); + + return result?.schedule_sector_xref_guid; + } catch (exception) { + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + //-- + //-- creates an action_type_action xref + //-- + const _applyAction = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + caseFileId: string, + decision: DecisionInput, + userId: string, + ): Promise => { + try { + const { actionTaken, assignedTo, actionTakenDate } = decision; + + //-- get the action_type_action xref + const xref = await this._getActionXref(db, actionTaken, ACTION_TYPE_CODES.CEEBACTION); + + let record: any = { + action_guid: randomUUID(), + case_guid: caseFileId, + action_type_action_xref_guid: xref, + actor_guid: assignedTo, + action_date: actionTakenDate, + active_ind: true, + create_user_id: userId, + update_user_id: userId, + create_utc_timestamp: new Date(), + update_utc_timestamp: new Date(), + }; + + const result = await db.action.create({ + data: record, + }); + + return result?.action_guid; + } catch (exception) { + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + try { + let result: CaseFile; + + await this.prisma.$transaction(async (db) => { + const { leadIdentifier, agencyCode, caseCode, createUserId, decision } = model; + + const caseFile = await this.findOneByLeadId(leadIdentifier); + + if (caseFile && caseFile?.caseIdentifier) { + caseFileId = caseFile.caseIdentifier; + } else { + const caseInput: CreateCaseInput = { ...model }; + caseFileId = await this.createCase(db, caseInput); + } + + //-- create sector/schedule xref + const xref = await _addWdrXref(db, decision, createUserId); + + //-- apply action + const actionId = await _applyAction(db, caseFileId, decision, createUserId); + + //-- add decision + const decsionId = await _addDecision(db, caseFileId, decision, xref, createUserId); + }); + + result = await this.findOne(caseFileId); + + return result; + } catch (error) { + console.log("exception: unable to create wildlife ", error); + throw new GraphQLError("Exception occurred. See server log for details", {}); + } + }; + + //-- + //-- returns the action_type_action_xref_guid for a action_code/action_type_code pair + //-- + _getActionXref = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + actionCode: string, + actionTypeCode: string, + ): Promise => { + const query = await this.prisma.action_type_action_xref.findFirst({ + where: { + action_code: actionCode, + action_type_code: actionTypeCode, + }, + select: { + action_type_action_xref_guid: true, + }, + }); + + return query.action_type_action_xref_guid; + }; + + updateDecision = async (model: UpdateDecisionInput): Promise => { + const { caseIdentifier, updateUserId, decision } = model; + const { id: decisonId } = decision; + + //-- + //-- updates an existing decision record and returns the decision + //-- + const _updateDecision = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + decision: DecisionInput, + updateUserId: string, + current: Date, + ): Promise => { + try { + const { id, discharge, rationale, nonCompliance, leadAgency, inspectionNumber, actionTaken } = decision; + + let data: any = { + discharge_code: discharge, + rationale_code: rationale, + non_compliance_decision_matrix_code: nonCompliance, + update_user_id: updateUserId, + update_utc_timestamp: current, + }; + + if (actionTaken === "FWDLEADAGN") { + data = { ...data, inspection_number: null, lead_agency: leadAgency }; + } + + if (actionTaken === "RESPREC") { + data = { ...data, lead_agency: null, inspection_number: parseInt(inspectionNumber) }; + } + + if (actionTaken !== "RESPREC" && actionTaken !== "FWDLEADAGN") { + data = { ...data, inspection_number: null, lead_agency: null }; + } + + const result = await db.decision.update({ + where: { decision_guid: id }, + data, + }); + + return result; + } catch (exception) { + this.logger.error(exception); + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + //-- + //-- updates an existing sector/schedule xref record and returns the xref + //-- + const _updateWdrXref = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + id: string, + decision: DecisionInput, + updateUserId: string, + current: Date, + ): Promise => { + try { + const { sector, schedule } = decision; + + let data: any = { + schedule_sector_xref_guid: id, + sector_code: sector, + schedule_code: schedule, + update_user_id: updateUserId, + update_utc_timestamp: current, + }; + + const result = db.schedule_sector_xref.update({ + where: { schedule_sector_xref_guid: id }, + data, + }); + + return result; + } catch (exception) { + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + //-- + //-- updates an existing action record and returns the result + //-- + const _updateAction = async ( + db: Omit< + PrismaClient, + "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends" + >, + id: string, + decision: DecisionInput, + updateUserId: string, + current: Date, + ): Promise => { + try { + const { actionTaken, actionTakenDate, assignedTo } = decision; + + //-- get the action_type_action xref + const xref = await this._getActionXref(db, actionTaken, ACTION_TYPE_CODES.CEEBACTION); + + const source = await db.action.findFirst({ + where: { + case_guid: caseIdentifier, + }, + select: { + action_guid: true, + }, + }); + + let data: any = { + action_type_action_xref_guid: xref, + actor_guid: assignedTo, + update_user_id: updateUserId, + update_utc_timestamp: current, + }; + + const result = db.action.update({ + where: { action_guid: source.action_guid }, + data, + }); + + return result; + } catch (exception) { + throw new GraphQLError("Exception occurred. See server log for details", exception); + } + }; + + try { + let result: CaseFile; + const current = new Date(); + + await this.prisma.$transaction(async (db) => { + //-- find the decision record first, if there is a record, + //-- apply updates to it + const source = await db.decision.findUnique({ + where: { + case_file_guid: caseIdentifier, + decision_guid: decisonId, + }, + }); + + if (source) { + let update = await _updateDecision(db, decision, updateUserId, current); + + //-- if the update was successful update the sector/schedule xref + //-- and action taken + const xrefResult = await _updateWdrXref( + db, + source.schedule_sector_xref_guid, + decision, + updateUserId, + current, + ); + + const actionResult = await _updateAction(db, caseIdentifier, decision, updateUserId, current); + } + }); + + result = await this.findOne(caseIdentifier); + + return result; + } catch (error) { + console.log("exception: unable to create wildlife ", error); + throw new GraphQLError("Exception occurred. See server log for details", {}); + } + }; + //-- //-- not implemented //-- diff --git a/backend/src/case_file/case_file_functions.graphql b/backend/src/case_file/case_file_functions.graphql index da8cbea1..ef18169b 100644 --- a/backend/src/case_file/case_file_functions.graphql +++ b/backend/src/case_file/case_file_functions.graphql @@ -24,4 +24,7 @@ type Mutation { createWildlife(input: CreateWildlifeInput!): CaseFile! updateWildlife(input: UpdateWildlifeInput!): CaseFile! deleteWildlife(input: DeleteWildlifeInput!): CaseFile! + + createDecision(input: CreateDecisionInput!): CaseFile! + updateDecision(input: UpdateDecisionInput!): CaseFile! } diff --git a/backend/src/case_file/case_file_inputs.graphql b/backend/src/case_file/case_file_inputs.graphql index c31ce91c..abe48160 100644 --- a/backend/src/case_file/case_file_inputs.graphql +++ b/backend/src/case_file/case_file_inputs.graphql @@ -205,3 +205,35 @@ input WildlifeActionInput { action: String activeIndicator: Boolean } + +input CreateDecisionInput { + leadIdentifier: String + agencyCode: String + caseCode: String + actor: String + createUserId: String + decision: DecisionInput +} + +input UpdateDecisionInput { + caseIdentifier: String + agencyCode: String + caseCode: String + actor: String + updateUserId: String + decision: DecisionInput +} + +input DecisionInput { + id: String + schedule: String + sector: String + discharge: String + nonCompliance: String + rationale: String + inspectionNumber: String + leadAgency: String + assignedTo: String + actionTaken: String + actionTakenDate: Date +} diff --git a/backend/src/case_file/case_file_types.graphql b/backend/src/case_file/case_file_types.graphql index e0dc78fa..5b2f1fec 100644 --- a/backend/src/case_file/case_file_types.graphql +++ b/backend/src/case_file/case_file_types.graphql @@ -10,6 +10,7 @@ type CaseFile { isReviewRequired: Boolean reviewComplete: CaseFileAction subject: [Wildlife] + decision: Decision } type Assessment { @@ -75,3 +76,17 @@ type Drug { discardMethod: String order: Int } + +type Decision { + id: String + schedule: String + sector: String + discharge: String + nonCompliance: String + rationale: String + inspectionNumber: String + leadAgency: String + assignedTo: String + actionTaken: String + actionTakenDate: Date +} diff --git a/backend/src/case_file/dto/ceeb/decision/create-decsion-input.ts b/backend/src/case_file/dto/ceeb/decision/create-decsion-input.ts new file mode 100644 index 00000000..0efe16e8 --- /dev/null +++ b/backend/src/case_file/dto/ceeb/decision/create-decsion-input.ts @@ -0,0 +1,10 @@ +import { DecisionInput } from "./decision-input"; + +export class CreateDecisionInput { + leadIdentifier: string; + agencyCode: string; + caseCode: string; + createUserId: string; + decision: DecisionInput; +} +// diff --git a/backend/src/case_file/dto/ceeb/decision/decision-input.ts b/backend/src/case_file/dto/ceeb/decision/decision-input.ts new file mode 100644 index 00000000..8d948020 --- /dev/null +++ b/backend/src/case_file/dto/ceeb/decision/decision-input.ts @@ -0,0 +1,13 @@ +export interface DecisionInput { + id?: string; + schedule: string; + sector: string; + discharge: string; + nonCompliance: string; + rationale: string; + inspectionNumber?: string; + leadAgency?: string; + assignedTo: string; + actionTaken: string; + actionTakenDate: Date | null; +} diff --git a/backend/src/case_file/dto/ceeb/decision/update-decsion-input.ts b/backend/src/case_file/dto/ceeb/decision/update-decsion-input.ts new file mode 100644 index 00000000..6c288399 --- /dev/null +++ b/backend/src/case_file/dto/ceeb/decision/update-decsion-input.ts @@ -0,0 +1,10 @@ +import { DecisionInput } from "./decision-input"; + +export class UpdateDecisionInput { + caseIdentifier: string; + agencyCode: string; + caseCode: string; + updateUserId: string; + decision: DecisionInput; +} +// diff --git a/backend/src/case_file/entities/case_file.entity.ts b/backend/src/case_file/entities/case_file.entity.ts index e0c3496f..9b03d092 100644 --- a/backend/src/case_file/entities/case_file.entity.ts +++ b/backend/src/case_file/entities/case_file.entity.ts @@ -1,4 +1,5 @@ import { Assessment } from "./assessment.entity"; +import { Decision } from "./decision-entity"; import { Equipment } from "./equipment.entity"; import { Prevention } from "./prevention.entity"; import { ReviewComplete } from "./review_complete"; @@ -15,4 +16,5 @@ export class CaseFile { isReviewRequired?: boolean; reviewComplete?: ReviewComplete; subject?: Array; + decision?: Decision; } diff --git a/backend/src/case_file/entities/decision-entity.ts b/backend/src/case_file/entities/decision-entity.ts new file mode 100644 index 00000000..a354be29 --- /dev/null +++ b/backend/src/case_file/entities/decision-entity.ts @@ -0,0 +1,13 @@ +export interface Decision { + id?: string; + schedule: string; + sector: string; + discharge: string; + nonCompliance: string; + rationale: string; + inspectionNumber?: string; + leadAgency?: string; + assignedTo: string; + actionTaken: string; + actionTakenDate: Date; +} diff --git a/backend/src/ceeb_decision_action/ceeb_decision_action.graphql b/backend/src/ceeb_decision_action/ceeb_decision_action.graphql new file mode 100644 index 00000000..0c30dc46 --- /dev/null +++ b/backend/src/ceeb_decision_action/ceeb_decision_action.graphql @@ -0,0 +1,3 @@ +type Query { + CEEBDecisionActions: [CaseFileAction]! +} diff --git a/backend/src/ceeb_decision_action/ceeb_decision_action.module.ts b/backend/src/ceeb_decision_action/ceeb_decision_action.module.ts new file mode 100644 index 00000000..d29c86a1 --- /dev/null +++ b/backend/src/ceeb_decision_action/ceeb_decision_action.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { ActionCodeService } from "../action_code/action_code.service"; +import { CEEBDecisionActionResolver } from "./ceeb_decision_action.resolver"; + +@Module({ + imports: [PrismaModule], + providers: [CEEBDecisionActionResolver, ActionCodeService], +}) +export class CEEBDecisionActionModule {} diff --git a/backend/src/ceeb_decision_action/ceeb_decision_action.resolver.ts b/backend/src/ceeb_decision_action/ceeb_decision_action.resolver.ts new file mode 100644 index 00000000..dc37531f --- /dev/null +++ b/backend/src/ceeb_decision_action/ceeb_decision_action.resolver.ts @@ -0,0 +1,19 @@ +import { Resolver, Query, Args } from "@nestjs/graphql"; +import { JwtRoleGuard } from "../auth/jwtrole.guard"; +import { UseGuards } from "@nestjs/common"; +import { Role } from "../enum/role.enum"; +import { Roles } from "../auth/decorators/roles.decorator"; +import { ActionCodeService } from "../action_code/action_code.service"; +import { ACTION_TYPE_CODES } from "../common/action_type_codes"; + +@UseGuards(JwtRoleGuard) +@Resolver("CEEBDecisionAction") +export class CEEBDecisionActionResolver { + constructor(private readonly actionCodeService: ActionCodeService) {} + + @Query("CEEBDecisionActions") + @Roles(Role.COS_OFFICER, Role.CEEB) + find() { + return this.actionCodeService.findAllCodesByType(ACTION_TYPE_CODES.CEEBACTION); + } +} diff --git a/backend/src/code-tables/discharge_code/discharge_code,module.ts b/backend/src/code-tables/discharge_code/discharge_code,module.ts new file mode 100644 index 00000000..bed4bb2a --- /dev/null +++ b/backend/src/code-tables/discharge_code/discharge_code,module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { DischargeCodeService } from "./discharge_code.service"; +import { DischargeCodeResolver } from "./discharge_code.resolver"; + +@Module({ + imports: [PrismaModule], + providers: [DischargeCodeResolver, DischargeCodeService], +}) +export class DischargeCodeModule {} diff --git a/backend/src/code-tables/discharge_code/discharge_code.graphql b/backend/src/code-tables/discharge_code/discharge_code.graphql new file mode 100644 index 00000000..6096e182 --- /dev/null +++ b/backend/src/code-tables/discharge_code/discharge_code.graphql @@ -0,0 +1,11 @@ +type DischargeCode { + dischargeCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + dischargeCodes: [DischargeCode]! +} diff --git a/backend/src/code-tables/discharge_code/discharge_code.resolver.ts b/backend/src/code-tables/discharge_code/discharge_code.resolver.ts new file mode 100644 index 00000000..7a6500b9 --- /dev/null +++ b/backend/src/code-tables/discharge_code/discharge_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query } from "@nestjs/graphql"; +import { UseGuards } from "@nestjs/common"; +import { JwtRoleGuard } from "src/auth/jwtrole.guard"; +import { Roles } from "src/auth/decorators/roles.decorator"; +import { Role } from "src/enum/role.enum"; +import { DischargeCodeService } from "./discharge_code.service"; + +@UseGuards(JwtRoleGuard) +@Resolver("DischargeCode") +export class DischargeCodeResolver { + constructor(private readonly service: DischargeCodeService) {} + + @Query("dischargeCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.service.findAll(); + } +} diff --git a/backend/src/code-tables/discharge_code/discharge_code.service.ts b/backend/src/code-tables/discharge_code/discharge_code.service.ts new file mode 100644 index 00000000..6ccc3084 --- /dev/null +++ b/backend/src/code-tables/discharge_code/discharge_code.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { DischargeCode } from "./entities/discharge_code.entity"; + +@Injectable() +export class DischargeCodeService { + constructor(private prisma: PrismaService) {} + + findAll = async (): Promise> => { + const codes = await this.prisma.discharge_code.findMany({ + select: { + discharge_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + }); + + return codes.map(({ discharge_code, short_description, long_description, display_order, active_ind }) => ({ + dischargeCode: discharge_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + activeIndicator: active_ind, + })); + }; +} diff --git a/backend/src/code-tables/discharge_code/entities/discharge_code.entity.ts b/backend/src/code-tables/discharge_code/entities/discharge_code.entity.ts new file mode 100644 index 00000000..2a9c81c7 --- /dev/null +++ b/backend/src/code-tables/discharge_code/entities/discharge_code.entity.ts @@ -0,0 +1,7 @@ +export class DischargeCode { + dischargeCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/code-tables/non_compliance_code/entities/non_compliance_code.entity.ts b/backend/src/code-tables/non_compliance_code/entities/non_compliance_code.entity.ts new file mode 100644 index 00000000..75dd4916 --- /dev/null +++ b/backend/src/code-tables/non_compliance_code/entities/non_compliance_code.entity.ts @@ -0,0 +1,7 @@ +export class NonComplianceCode { + nonComplianceCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/code-tables/non_compliance_code/non_compliance.resolver.ts b/backend/src/code-tables/non_compliance_code/non_compliance.resolver.ts new file mode 100644 index 00000000..0cddbb55 --- /dev/null +++ b/backend/src/code-tables/non_compliance_code/non_compliance.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query } from "@nestjs/graphql"; +import { UseGuards } from "@nestjs/common"; +import { JwtRoleGuard } from "src/auth/jwtrole.guard"; +import { Roles } from "src/auth/decorators/roles.decorator"; +import { Role } from "src/enum/role.enum"; +import { NonComplianceCodeService } from "./non_compliance_code.service"; + +@UseGuards(JwtRoleGuard) +@Resolver("NonComplianceCode") +export class NonComplianceCodeResolver { + constructor(private readonly service: NonComplianceCodeService) {} + + @Query("nonComplianceCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.service.findAll(); + } +} diff --git a/backend/src/code-tables/non_compliance_code/non_compliance_code.graphql b/backend/src/code-tables/non_compliance_code/non_compliance_code.graphql new file mode 100644 index 00000000..20ebe79a --- /dev/null +++ b/backend/src/code-tables/non_compliance_code/non_compliance_code.graphql @@ -0,0 +1,11 @@ +type NonComplianceCode { + nonComplianceCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + nonComplianceCodes: [NonComplianceCode]! +} diff --git a/backend/src/code-tables/non_compliance_code/non_compliance_code.module.ts b/backend/src/code-tables/non_compliance_code/non_compliance_code.module.ts new file mode 100644 index 00000000..183b17e1 --- /dev/null +++ b/backend/src/code-tables/non_compliance_code/non_compliance_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { NonComplianceCodeService } from "./non_compliance_code.service"; +import { NonComplianceCodeResolver } from "./non_compliance.resolver"; + +@Module({ + imports: [PrismaModule], + providers: [NonComplianceCodeResolver, NonComplianceCodeService], +}) +export class NonComplianceCodeModule {} diff --git a/backend/src/code-tables/non_compliance_code/non_compliance_code.service.ts b/backend/src/code-tables/non_compliance_code/non_compliance_code.service.ts new file mode 100644 index 00000000..9e819b80 --- /dev/null +++ b/backend/src/code-tables/non_compliance_code/non_compliance_code.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { NonComplianceCode } from "./entities/non_compliance_code.entity"; + +@Injectable() +export class NonComplianceCodeService { + constructor(private prisma: PrismaService) {} + + findAll = async (): Promise> => { + const codes = await this.prisma.non_compliance_decision_matrix_code.findMany({ + select: { + non_compliance_decision_matrix_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + }); + + return codes.map( + ({ non_compliance_decision_matrix_code, short_description, long_description, display_order, active_ind }) => ({ + nonComplianceCode: non_compliance_decision_matrix_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + activeIndicator: active_ind, + }), + ); + }; +} diff --git a/backend/src/code-tables/rationale_code/entities/rationale_code.entity.ts b/backend/src/code-tables/rationale_code/entities/rationale_code.entity.ts new file mode 100644 index 00000000..3966c30b --- /dev/null +++ b/backend/src/code-tables/rationale_code/entities/rationale_code.entity.ts @@ -0,0 +1,7 @@ +export class RationaleCode { + rationaleCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/code-tables/rationale_code/rationale_code.graphql b/backend/src/code-tables/rationale_code/rationale_code.graphql new file mode 100644 index 00000000..999dacf4 --- /dev/null +++ b/backend/src/code-tables/rationale_code/rationale_code.graphql @@ -0,0 +1,11 @@ +type RationaleCode { + rationaleCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + rationaleCodes: [RationaleCode]! +} diff --git a/backend/src/code-tables/rationale_code/rationale_code.module.ts b/backend/src/code-tables/rationale_code/rationale_code.module.ts new file mode 100644 index 00000000..083d4619 --- /dev/null +++ b/backend/src/code-tables/rationale_code/rationale_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { RationaleCodeService } from "./rationale_code.service"; +import { RationaleCodeResolver } from "./rationale_code.resolver"; + +@Module({ + imports: [PrismaModule], + providers: [RationaleCodeResolver, RationaleCodeService], +}) +export class RationaleCodeModule {} diff --git a/backend/src/code-tables/rationale_code/rationale_code.resolver.ts b/backend/src/code-tables/rationale_code/rationale_code.resolver.ts new file mode 100644 index 00000000..03dc9deb --- /dev/null +++ b/backend/src/code-tables/rationale_code/rationale_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query } from "@nestjs/graphql"; +import { UseGuards } from "@nestjs/common"; +import { JwtRoleGuard } from "src/auth/jwtrole.guard"; +import { Roles } from "src/auth/decorators/roles.decorator"; +import { Role } from "src/enum/role.enum"; +import { RationaleCodeService } from "./rationale_code.service"; + +@UseGuards(JwtRoleGuard) +@Resolver("RationaleCode") +export class RationaleCodeResolver { + constructor(private readonly service: RationaleCodeService) {} + + @Query("rationaleCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.service.findAll(); + } +} diff --git a/backend/src/code-tables/rationale_code/rationale_code.service.ts b/backend/src/code-tables/rationale_code/rationale_code.service.ts new file mode 100644 index 00000000..aa497975 --- /dev/null +++ b/backend/src/code-tables/rationale_code/rationale_code.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { RationaleCode } from "./entities/rationale_code.entity"; + +@Injectable() +export class RationaleCodeService { + constructor(private prisma: PrismaService) {} + + findAll = async (): Promise> => { + const codes = await this.prisma.rationale_code.findMany({ + select: { + rationale_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + }); + + return codes.map(({ rationale_code, short_description, long_description, display_order, active_ind }) => ({ + rationaleCode: rationale_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + activeIndicator: active_ind, + })); + }; +} diff --git a/backend/src/code-tables/schedule_code/entities/sechedule_code.entity.ts b/backend/src/code-tables/schedule_code/entities/sechedule_code.entity.ts new file mode 100644 index 00000000..5d574390 --- /dev/null +++ b/backend/src/code-tables/schedule_code/entities/sechedule_code.entity.ts @@ -0,0 +1,7 @@ +export class ScheduleCode { + scheduleCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/code-tables/schedule_code/schedule_code.graphql b/backend/src/code-tables/schedule_code/schedule_code.graphql new file mode 100644 index 00000000..08012dc0 --- /dev/null +++ b/backend/src/code-tables/schedule_code/schedule_code.graphql @@ -0,0 +1,11 @@ +type ScheduleCode { + scheduleCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + scheduleCodes: [ScheduleCode]! +} diff --git a/backend/src/code-tables/schedule_code/schedule_code.module.ts b/backend/src/code-tables/schedule_code/schedule_code.module.ts new file mode 100644 index 00000000..3cd7ec61 --- /dev/null +++ b/backend/src/code-tables/schedule_code/schedule_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { ScheduleCodeResolver } from "./schedule_code.resolver"; +import { ScheduleCodeService } from "./schedule_code.service"; + +@Module({ + imports: [PrismaModule], + providers: [ScheduleCodeResolver, ScheduleCodeService], +}) +export class ScheduleCodeModule {} diff --git a/backend/src/code-tables/schedule_code/schedule_code.resolver.ts b/backend/src/code-tables/schedule_code/schedule_code.resolver.ts new file mode 100644 index 00000000..68024b5e --- /dev/null +++ b/backend/src/code-tables/schedule_code/schedule_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query } from "@nestjs/graphql"; +import { UseGuards } from "@nestjs/common"; +import { ScheduleCodeService } from "./schedule_code.service"; +import { JwtRoleGuard } from "src/auth/jwtrole.guard"; +import { Roles } from "src/auth/decorators/roles.decorator"; +import { Role } from "src/enum/role.enum"; + +@UseGuards(JwtRoleGuard) +@Resolver("ScheduleCode") +export class ScheduleCodeResolver { + constructor(private readonly service: ScheduleCodeService) {} + + @Query("scheduleCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.service.findAll(); + } +} diff --git a/backend/src/code-tables/schedule_code/schedule_code.service.ts b/backend/src/code-tables/schedule_code/schedule_code.service.ts new file mode 100644 index 00000000..71554cc1 --- /dev/null +++ b/backend/src/code-tables/schedule_code/schedule_code.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { ScheduleCode } from "./entities/sechedule_code.entity"; + +@Injectable() +export class ScheduleCodeService { + constructor(private prisma: PrismaService) {} + + findAll = async (): Promise> => { + const codes = await this.prisma.schedule_code.findMany({ + select: { + schedule_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + }); + + return codes.map(({ schedule_code, short_description, long_description, display_order, active_ind }) => ({ + scheduleCode: schedule_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + activeIndicator: active_ind, + })); + }; +} diff --git a/backend/src/code-tables/sector_code/entities/sector_code.entity.ts b/backend/src/code-tables/sector_code/entities/sector_code.entity.ts new file mode 100644 index 00000000..153eaff5 --- /dev/null +++ b/backend/src/code-tables/sector_code/entities/sector_code.entity.ts @@ -0,0 +1,7 @@ +export class SectorCode { + sectorCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/code-tables/sector_code/sector_code.graphql b/backend/src/code-tables/sector_code/sector_code.graphql new file mode 100644 index 00000000..8095ffe6 --- /dev/null +++ b/backend/src/code-tables/sector_code/sector_code.graphql @@ -0,0 +1,11 @@ +type SectorCode { + sectorCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + sectorCodes: [SectorCode]! +} diff --git a/backend/src/code-tables/sector_code/sector_code.module.ts b/backend/src/code-tables/sector_code/sector_code.module.ts new file mode 100644 index 00000000..b3e9113b --- /dev/null +++ b/backend/src/code-tables/sector_code/sector_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { PrismaModule } from "nestjs-prisma"; +import { SectorCodeService } from "./sector_code.service"; +import { SectorCodeResolver } from "./sector_code.resolver"; + +@Module({ + imports: [PrismaModule], + providers: [SectorCodeResolver, SectorCodeService], +}) +export class SectorCodeModule {} diff --git a/backend/src/code-tables/sector_code/sector_code.resolver.ts b/backend/src/code-tables/sector_code/sector_code.resolver.ts new file mode 100644 index 00000000..9c1fc617 --- /dev/null +++ b/backend/src/code-tables/sector_code/sector_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query, Args } from "@nestjs/graphql"; +import { UseGuards } from "@nestjs/common"; +import { JwtRoleGuard } from "src/auth/jwtrole.guard"; +import { Roles } from "src/auth/decorators/roles.decorator"; +import { Role } from "src/enum/role.enum"; +import { SectorCodeService } from "./sector_code.service"; + +@UseGuards(JwtRoleGuard) +@Resolver("SectorCode") +export class SectorCodeResolver { + constructor(private readonly service: SectorCodeService) {} + + @Query("sectorCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.service.findAll(); + } +} diff --git a/backend/src/code-tables/sector_code/sector_code.service.ts b/backend/src/code-tables/sector_code/sector_code.service.ts new file mode 100644 index 00000000..2df77132 --- /dev/null +++ b/backend/src/code-tables/sector_code/sector_code.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { SectorCode } from "./entities/sector_code.entity"; + +@Injectable() +export class SectorCodeService { + constructor(private prisma: PrismaService) {} + + findAll = async (): Promise> => { + const codes = await this.prisma.sector_code.findMany({ + select: { + sector_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + }); + + return codes.map(({ sector_code, short_description, long_description, display_order, active_ind }) => ({ + sectorCode: sector_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + activeIndicator: active_ind, + })); + }; +} diff --git a/backend/src/common/action_type_codes.ts b/backend/src/common/action_type_codes.ts index 812bb89b..af1649f8 100644 --- a/backend/src/common/action_type_codes.ts +++ b/backend/src/common/action_type_codes.ts @@ -4,4 +4,5 @@ export const ACTION_TYPE_CODES = { EQUIPMENT: "EQUIPMENT", CASEACTION: "CASEACTION", WILDLIFE: "WILDLIFE", + CEEBACTION: "CEEBACTION", }; diff --git a/migrations/sql/R__insert_CEEB_decision_codes.sql b/migrations/sql/R__insert_CEEB_decision_codes.sql new file mode 100644 index 00000000..3427f321 --- /dev/null +++ b/migrations/sql/R__insert_CEEB_decision_codes.sql @@ -0,0 +1,1624 @@ +-- +-- INSERT sector_code values +-- +INSERT INTO + case_management.sector_code ( + sector_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'ABRASIVESI', + 'ABRASIVESI', + 'Abrasives Industry', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AGRICULOP', + 'AGRICULOP', + 'Agricultural Operations', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ALUMINUMPR', + 'ALUMINUMPR', + 'Aluminum and Aluminum Alloy Products Industry', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ANTICHEMM', + 'ANTICHEMM', + 'Antisapstain Chemicals Management', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AQUALANDI', + 'AQUALANDI', + 'Aquaculture - Land-based Industry', + 50, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AQUAMARINE', + 'AQUAMARINE', + 'Aquaculture - Marine-based Industry', + 60, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ASBESTOSMI', + 'ASBESTOSMI', + 'Asbestos Mining Industry', + 70, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ASPHALTPI', + 'ASPHALTPI', + 'Asphalt Plant Industry', + 80, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ASPHALTROO', + 'ASPHALTROO', + 'Asphalt Roof Manufacturing Industry', + 90, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'BEVERAGEIN', + 'BEVERAGEIN', + 'Beverage Industry', + 100, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'BIOTECHIN', + 'BIOTECHIN', + 'Biotechnology Industry', + 110, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'BURNVEGED', + 'BURNVEGED', + 'Burning of Vegetative Debris', + 120, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'BURNWASTE', + 'BURNWASTE', + 'Burning or Incineration of Waste', + 130, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'BURNWOODR', + 'BURNWOODR', + 'Burning or Incineration of Wood Residue', + 140, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CEMENTLIME', + 'CEMENTLIME', + 'Cement and Lime Manufacturing Industry', + 150, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CHEMPRIND', + 'CHEMPRIND', + 'Chemical and Chemical Products Industry', + 160, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CLAYINDUST', + 'CLAYINDUST', + 'Clay Industry', + 170, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'COALGASIN', + 'COALGASIN', + 'Coalbed Gas Exploration and Production Industry', + 180, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'COMWASTEIN', + 'COMWASTEIN', + 'Commercial Waste Management or Waste Disposal Industry', + 190, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'COMPOSTIN', + 'COMPOSTIN', + 'Composting Operations', + 200, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CONCRETEP', + 'CONCRETEP', + 'Concrete and Concrete Products Industry', + 210, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CONTSITEM', + 'CONTSITEM', + 'Contaminated Site Contaminant Management', + 220, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'DAIRYPROD', + 'DAIRYPROD', + 'Dairy Products Industry', + 230, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'DEEPWELLD', + 'DEEPWELLD', + 'Deep Well Disposal', + 240, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ELECPRODI', + 'ELECPRODI', + 'Electrical or Electronic Products Industry', + 250, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ELECPOWER', + 'ELECPOWER', + 'Electrical Power Industry', + 260, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'FISHPRODI', + 'FISHPRODI', + 'Fish Products Industry', + 270, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'FLOURFEED', + 'FLOURFEED', + 'Flour Prepared Cereal Food and Feed Industry', + 280, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'FRUITVEGI', + 'FRUITVEGI', + 'Fruit and Vegetable Processing Industry', + 290, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'GLASSPROD', + 'GLASSPROD', + 'Glass and Glass Products Industry', + 300, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'HAZWASTEM', + 'HAZWASTEM', + 'Hazardous Waste Management', + 310, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'INDFASTEN', + 'INDFASTEN', + 'Industrial Fastener Industry', + 320, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'NONHAZWST', + 'NONHAZWST', + 'Industrial Non-hazardous Waste Landfills', + 330, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MEATBYPROD', + 'MEATBYPROD', + 'Meat By-product Processing Industry', + 340, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'METALPROC', + 'METALPROC', + 'Metal Processing and Metal Products Manufacturing Industry', + 350, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'METALSMEL', + 'METALSMEL', + 'Metal Smelting Iron and Steel Foundry and Metal Refining Industry', + 360, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MININGCOA', + 'MININGCOA', + 'Mining and Coal Mining Industry', + 370, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MUNSEWMAN', + 'MUNSEWMAN', + 'Municipal Sewage Management', + 380, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MUNSOLWST', + 'MUNSOLWST', + 'Municipal Solid Waste Management', + 390, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MUNWASTEI', + 'MUNWASTEI', + 'Municipal Waste Incineration or Burning Industry', + 400, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'NORADMATM', + 'NORADMATM', + 'Naturally Occurring Radioactive Materials Management', + 410, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'NONMETMIN', + 'NONMETMIN', + 'Non-Metallic Mineral Products Industry', + 420, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'OILNATGASL', + 'OILNATGASL', + 'Oil and Natural Gas Industry - Large', + 430, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'OILNATGSS', + 'OILNATGSS', + 'Oil and Natural Gas Industry - Small', + 440, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'OZONEMANG', + 'OZONEMANG', + 'Ozone Depleting Substances and other Halocarbons Management', + 450, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PAPERINDU', + 'PAPERINDU', + 'Paper Industry', + 460, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PAPERBOAR', + 'PAPERBOAR', + 'Paperboard Industry', + 470, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PARTWAFAI', + 'PARTWAFAI', + 'Particle and Wafer Board Industry', + 480, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PETROSTOR', + 'PETROSTOR', + 'Petroleum Storage', + 490, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PIPETRANA', + 'PIPETRANA', + 'Pipeline Transport Industry with Approved Operating Plan', + 500, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PIPETRANI', + 'PIPETRANI', + 'Pipeline Transport Industry', + 510, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PLACERMIN', + 'PLACERMIN', + 'Placer Mining Industry', + 520, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PLASTRESI', + 'PLASTRESI', + 'Plastic and Synthetic Resin Manufacturing Industry', + 530, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PLASTCOMP', + 'PLASTCOMP', + 'Plastics and Composite Products Industry', + 540, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'POULTRYPR', + 'POULTRYPR', + 'Poultry Processing Industry', + 550, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PRODSTORAG', + 'PRODSTORAG', + 'Product Storage - Bulk Solids', + 560, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PULPINDUST', + 'PULPINDUST', + 'Pulp Industry', + 570, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'REFPETPRO', + 'REFPETPRO', + 'Refined Petroleum and Coal Products Industry', + 580, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SGENRODEN', + 'SGENRODEN', + 'SECOND-GENERATION ANTICOAGULANT RODENTICIDES-GENERAL', + 590, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SLAUGHTER', + 'SLAUGHTER', + 'SLAUGHTER Industry', + 600, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SOILENHAN', + 'SOILENHAN', + 'Soil Enhancement Using Wastes', + 610, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SUGARPROD', + 'SUGARPROD', + 'Sugar Processing and Refining Industry', + 620, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRAERGEN', + 'USRAERGEN', + 'user/service- AERIAL- GENERAL', + 630, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRAGRGEN', + 'USRAGRGEN', + 'user/service- AGRICULTURE GENERAL', + 640, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRAGRICU', + 'USRAGRICU', + 'user/service- AGRICULTURE', + 650, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRAGGENE', + 'USRAGGENE', + 'user/service- AGRICULTURE-GENERAL', + 660, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORENU', + 'USRFORENU', + 'user/service- FORESTRY- NURSERY', + 670, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORE50H', + 'USRFORE50H', + 'user/service- FORESTRY PESTICIDE USE LESS THAN 50 HA PER YEAR', + 680, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORE500', + 'USRFORE500', + 'user/service- FORESTRY PESTICIDE USE LESS THAN 500 HA PER YEAR', + 690, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFOREMOR', + 'USRFOREMOR', + 'user/service- FORESTRY PESTICIDE USE ON MORE THAN 500 HA PER YEAR', + 700, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFUMCON', + 'USRFUMCON', + 'user/service- FUMIGATION- CONTAINER', + 710, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFUMSHS', + 'USRFUMSHS', + 'user/service- FUMIGATION- SHIPS & STRUCTURESFUMIGATION- SOIL', + 720, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRINDPAVE', + 'USRINDPAVE', + 'user/service- INDUSTRIAL VEGETATION & NOXIOUS WEED- PAVERS', + 730, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRINDGEN', + 'USRINDGEN', + 'user/service- INDUSTRIAL VEGETATION & NOXIOUS WEED-GENERAL', + 740, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRLANDGEN', + 'USRLANDGEN', + 'user/service- LANDSCAPE- GENERAL', + 750, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRMOSBIT', + 'USRMOSBIT', + 'user/service- MOSQUITO & BITING FLY', + 760, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRMOSAEBA', + 'USRMOSAEBA', + 'user/service- MOSQUITO- AERIAL APPLICATION OF GRANULAR BACTERIAL PESTICIDES', + 770, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRMOSGRBA', + 'USRMOSGRBA', + 'user/service- MOSQUITO- GROUND APPLICATION OF BACTERIAL PESTICIDES & GROWTH REGULATORS', + 780, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRNETTRE', + 'USRNETTRE', + 'user/service- NET TREATMENT PRODUCTS', + 790, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRNOXGEN', + 'USRNOXGEN', + 'user/service- NOXIOUS WEED- GENERAL', + 800, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRPESTNS', + 'USRPESTNS', + 'user/service- PESTICIDE USER- NON-SERVICE', + 810, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRPESTPL', + 'USRPESTPL', + 'user/service- PESTICIDE USER- PUBLIC LAND', + 820, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRPESTSE', + 'USRPESTSE', + 'user/service- PESTICIDE USER- SERVICE', + 830, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRRESTBE', + 'USRRESTBE', + 'user/service- RESTRICTED TO COMMERCIAL BEEKEEPING PRODUCTS', + 840, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRSTRGEN', + 'USRSTRGEN', + 'user/service- STRUCTURAL- GENERAL', + 850, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRSTRWOO', + 'USRSTRWOO', + 'user/service- STRUCTURAL- INDUSTRIAL WOOD PRESERVATION', + 860, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORMAG', + 'USRFORMAG', + 'user/service-FORESTRY- MANAGEMENT; GENERAL', + 870, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORMNB', + 'USRFORMNB', + 'user/service-FORESTRY- MANAGEMENT; NON-BROADCAST', + 880, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORNU2', + 'USRFORNU2', + 'user/service-FORESTRY- NURSERY', + 890, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFORSEO', + 'USRFORSEO', + 'user/service-FORESTRY- SEED ORCHARD', + 900, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'USRFUMCO2', + 'USRFUMCO2', + 'user/service-FUMIGATION- C02', + 910, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VEHDISREC', + 'VEHDISREC', + 'Vehicle Dismantling and Recycling Industry', + 920, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VEHINDPAR', + 'VEHINDPAR', + ' Vehicle Industrial Machinery and Parts and Accessories Manufacturing Industry', + 930, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENDDOM100', + 'VENDDOM100', + 'vendor- DOMESTIC AND UP TO 100 KG COMMERCIAL PESTICIDES', + 940, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENDGENERA', + 'VENDGENERA', + 'vendor- GENERAL', + 950, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENDGENCO', + 'VENDGENCO', + 'vendor- GENERAL; COMMERCIAL PESTICIDES', + 960, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENDGENDOM', + 'VENDGENDOM', + 'vendor- GENERAL; DOMESTIC PESTICIDES', + 970, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENDGENLAN', + 'VENDGENLAN', + 'vendor- GENERAL; DOMESTIC PESTICIDES- LANDSCAPE- GENERAL', + 980, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'VENEERPLY', + 'VENEERPLY', + 'Veneer and Plywood Industry', + 990, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'WOODPRIMA', + 'WOODPRIMA', + 'Wood Processing Industry - Primary', + 1000, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'WOODSECON', + 'WOODSECON', + 'Wood Processing Industry - Secondary', + 1010, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'WOODTREIN', + 'WOODTREIN', + 'Wood Treatment Industry', + 1020, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT schedule_code values +-- +INSERT INTO + case_management.schedule_code ( + schedule_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'WDR1', + 'WDR schedule 1', + 'WDR schedule 1', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'WDR2', + 'WDR schedule 2', + 'WDR schedule 2', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'OTHER', + 'Other', + 'Other', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'IPM', + 'IPM sector type', + 'IPM sector type', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT new action_type_code values +-- +INSERT INTO + case_management.action_type_code ( + action_type_code, + short_description, + long_description, + active_ind, + create_user_id, + create_utc_timestamp + ) +VALUES + ( + 'CEEBACTION', + 'CEEB Actions', + 'CEEB Actions', + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT new action_code values +-- +INSERT INTO + case_management.action_code ( + action_code, + short_description, + long_description, + active_ind, + create_user_id, + create_utc_timestamp + ) +VALUES + ( + 'FWDLEADAGN', + 'FWDLEADAGN', + 'Forward to lead agency', + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RESPNFA', + 'RESPNFA', + 'Responded - no further action', + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RESPAUTO', + 'RESPAUTO', + 'Responded - auto-response/ed/promotion', + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RESPREC', + 'RESPREC', + 'Responded - recommend for inspection', + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT new action_type_action_xref values +-- +INSERT INTO + case_management.action_type_action_xref ( + action_type_code, + action_code, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +VALUES + ( + 'CEEBACTION', + 'FWDLEADAGN', + 1, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CEEBACTION', + 'RESPNFA', + 2, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CEEBACTION', + 'RESPAUTO', + 3, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'CEEBACTION', + 'RESPREC', + 4, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT non_compliance_decision_matrix_code values +-- +INSERT INTO + case_management.non_compliance_decision_matrix_code ( + non_compliance_decision_matrix_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'INCOMP', + '0 In Compliance', + '0 In Compliance', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'NOIMPCT', + '1 No impact likely', + '1 No impact likely', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MINIMPCT', + '2 Minor temporary impact likely', + '2 Minor temporary impact likely', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'MODIMPCT', + '3 Moderate temporary impact likely', + '3 Moderate temporary impact likely', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SIGIMPCT', + '4 Significant impact likely', + '4 Significant impact likely', + 50, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'SVRIMPCT', + '5 Severe human health impact demonstrated/likely', + '5 Severe human health impact demonstrated/likely', + 60, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'ND', + 'Not determined', + 'Not determined', + 70, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT rationale values +-- +INSERT INTO + case_management.rationale_code ( + rationale_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'RATIONAL01', + 'RATIONAL_01', + 'Rationale 01', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RATIONAL02', + 'RATIONAL_02', + 'Rationale 02', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RATIONAL03', + 'RATIONAL_03', + 'Rational 03', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- INSERT discharge_code values +-- +INSERT INTO + case_management.discharge_code ( + discharge_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'AIR_BURN', + 'AIR_BURN', + 'Air – burning', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AIR_ODOUR', + 'AIR_ODOUR', + 'Air – odour', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AIR_EMSSN', + 'AIR_EMSSN', + 'Air – emission', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'AIR_DST', + 'AIR_DST', + 'Air – dust', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'EFFLNT', + 'EFFLNT', + 'Effluent', + 50, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RFS_DMP', + 'RFS_DMP', + 'Refuse – Dumping', + 60, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'RFS_OTHR', + 'RFS_OTHR', + 'Refuse - Other', + 70, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ), + ( + 'PSTCD', + 'PSTCD', + 'Pesticides', + 80, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- add new EPO agency code +-- +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +values + ( + 'EPO', + 'CEEB', + 'Compliance and Environmental Enforcement Branch', + true, + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; + +-- +-- add new ERS case_code +-- +insert into + case_management.case_code ( + case_code, + short_description, + long_description, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +values + ( + 'ERS', + 'Enforcement Complaint', + 'Enforcement Complaint', + true, + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT +DO NOTHING; \ No newline at end of file diff --git a/migrations/sql/V1.22.0__CE-977.sql b/migrations/sql/V1.22.0__CE-977.sql new file mode 100644 index 00000000..a2178755 --- /dev/null +++ b/migrations/sql/V1.22.0__CE-977.sql @@ -0,0 +1,275 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- +-- creates new tables to support CEEB decisions +-- +-- +-- CREATE TABLE decision +-- +CREATE TABLE + case_management.decision ( + decision_guid uuid NOT NULL DEFAULT uuid_generate_v4 (), + case_file_guid uuid NOT NULL, + schedule_sector_xref_guid uuid NOT NULL, + discharge_code varchar(10) NOT NULL, + rationale_code varchar(10), + inspection_number int4, + lead_agency varchar(10), + non_compliance_decision_matrix_code varchar(10) NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_decision_guid" PRIMARY KEY (decision_guid) + ); + +comment on table case_management.decision is 'As a CEEB Compliance Coordinator or Officer, I need to be able to capture decision information to ensure that all information necessary in the decision making process can be captured in the complaint.'; + +comment on column case_management.decision.decision_guid is 'Unique identifier for the decision'; + +comment on column case_management.decision.case_file_guid is 'Assoiciates the decision record to an existing case file'; + +comment on column case_management.decision.schedule_sector_xref_guid is 'Defines the combination of a WDR_SCHEDULE_CODE and a SECTOR_CATEGORY_CODE'; + +comment on column case_management.decision.discharge_code is 'The discharge code related to a decision'; + +comment on column case_management.decision.rationale_code is 'The rationale code related to a CEEB decision'; + +comment on column case_management.decision.inspection_number is 'The NRIS inspection number for a CEEB decision'; + +comment on column case_management.decision.non_compliance_decision_matrix_code is ''; + +comment on column case_management.decision.active_ind is 'A boolean indicator to determine if the case management action is active.'; + +comment on column case_management.decision.create_user_id is 'The id of the user that created the case management action.'; + +comment on column case_management.decision.create_utc_timestamp is 'The timestamp when the case management action was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.decision.update_user_id is 'The id of the user that updated the case management action.'; + +comment on column case_management.decision.update_utc_timestamp is 'The timestamp when the case management action was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE discharge_code +-- +CREATE TABLE + case_management.discharge_code ( + discharge_code varchar(10) NOT NULL, + short_description varchar(50) NOT NULL, + long_description varchar(250) NULL, + display_order int4 NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_discharge_code" PRIMARY KEY (discharge_code) + ); + +comment on table case_management.discharge_code is 'Contains a list of all possible discharge codes for a CEEB decision'; + +comment on column case_management.discharge_code.discharge_code is 'A human readable code used to identify a discharge code.'; + +comment on column case_management.discharge_code.short_description is 'The short description of a case management discharge_code.'; + +comment on column case_management.discharge_code.long_description is 'The long description of a case management discharge_code.'; + +comment on column case_management.discharge_code.active_ind is 'A boolean indicator to determine if the case management discharge_code is active.'; + +comment on column case_management.discharge_code.create_user_id is 'The id of the user that created the case management discharge_code.'; + +comment on column case_management.discharge_code.create_utc_timestamp is 'The timestamp when the case management discharge_code was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.discharge_code.update_user_id is 'The id of the user that updated the case management discharge_code.'; + +comment on column case_management.discharge_code.update_utc_timestamp is 'The timestamp when the case management discharge_code was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE non_compliance_decision_matrix_code +-- +CREATE TABLE + case_management.non_compliance_decision_matrix_code ( + non_compliance_decision_matrix_code varchar(10) NOT NULL, + short_description varchar(50) NOT NULL, + long_description varchar(250) NULL, + display_order int4 NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_non_compliance_decision_matrix_code" PRIMARY KEY (non_compliance_decision_matrix_code) + ); + +comment on table case_management.non_compliance_decision_matrix_code is 'Contains a list of all possible non_compliance_decision_matrix_code codes for a CEEB decision'; + +comment on column case_management.non_compliance_decision_matrix_code.non_compliance_decision_matrix_code is 'A human readable code used to identify a non_compliance_decision_matrix_code code.'; + +comment on column case_management.non_compliance_decision_matrix_code.short_description is 'The short description of a case management non_compliance_decision_matrix_code.'; + +comment on column case_management.non_compliance_decision_matrix_code.long_description is 'The long description of a case management non_compliance_decision_matrix_code.'; + +comment on column case_management.non_compliance_decision_matrix_code.active_ind is 'A boolean indicator to determine if the case management non_compliance_decision_matrix_code is active.'; + +comment on column case_management.non_compliance_decision_matrix_code.create_user_id is 'The id of the user that created the case management non_compliance_decision_matrix_code.'; + +comment on column case_management.non_compliance_decision_matrix_code.create_utc_timestamp is 'The timestamp when the case management non_compliance_decision_matrix_code was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.non_compliance_decision_matrix_code.update_user_id is 'The id of the user that updated the case management non_compliance_decision_matrix_code.'; + +comment on column case_management.non_compliance_decision_matrix_code.update_utc_timestamp is 'The timestamp when the case management non_compliance_decision_matrix_code was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE sector_code +-- +CREATE TABLE + case_management.sector_code ( + sector_code varchar(10) NOT NULL, + short_description varchar(50) NOT NULL, + long_description varchar(250) NULL, + display_order int4 NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_sector_code" PRIMARY KEY (sector_code) + ); + +comment on table case_management.sector_code is 'Contains a list of all possible sector_code codes for a CEEB decision'; + +comment on column case_management.sector_code.sector_code is 'A human readable code used to identify a ipm_secord_code'; + +comment on column case_management.sector_code.short_description is 'The short description of a case management sector_code.'; + +comment on column case_management.sector_code.long_description is 'The long description of a case management sector_code.'; + +comment on column case_management.sector_code.active_ind is 'A boolean indicator to determine if the case management sector_code is active.'; + +comment on column case_management.sector_code.create_user_id is 'The id of the user that created the case management sector_code.'; + +comment on column case_management.sector_code.create_utc_timestamp is 'The timestamp when the case management sector_code was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.sector_code.update_user_id is 'The id of the user that updated the case management sector_code.'; + +comment on column case_management.sector_code.update_utc_timestamp is 'The timestamp when the case management sector_code was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE rational_code +-- +CREATE TABLE + case_management.rationale_code ( + rationale_code varchar(10) NOT NULL, + short_description varchar(50) NOT NULL, + long_description varchar(250) NULL, + display_order int4 NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_rationale_code" PRIMARY KEY (rationale_code) + ); + +comment on table case_management.rationale_code is 'Contains a list of all possible rationale_code codes for a CEEB decision'; + +comment on column case_management.rationale_code.rationale_code is 'A human readable code used to identify a rationale code.'; + +comment on column case_management.rationale_code.short_description is 'The short description of a case management rationale_code.'; + +comment on column case_management.rationale_code.long_description is 'The long description of a case management rationale_code.'; + +comment on column case_management.rationale_code.active_ind is 'A boolean indicator to determine if the case management rationale_code is active.'; + +comment on column case_management.rationale_code.create_user_id is 'The id of the user that created the case management rationale_code.'; + +comment on column case_management.rationale_code.create_utc_timestamp is 'The timestamp when the case management rationale_code was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.rationale_code.update_user_id is 'The id of the user that updated the case management rationale_code.'; + +comment on column case_management.rationale_code.update_utc_timestamp is 'The timestamp when the case management rationale_code was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE schedule_code +-- +CREATE TABLE + case_management.schedule_code ( + schedule_code varchar(10) NOT NULL, + short_description varchar(50) NOT NULL, + long_description varchar(250) NULL, + display_order int4 NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_schedule_code" PRIMARY KEY (schedule_code) + ); + +comment on table case_management.schedule_code is 'Contains a list of all possible schedule_code codes for a CEEB decision'; + +comment on column case_management.schedule_code.schedule_code is 'A human readable code used to identify a wdr schedule code'; + +comment on column case_management.schedule_code.short_description is 'The short description of a case management schedule_code.'; + +comment on column case_management.schedule_code.long_description is 'The long description of a case management schedule_code.'; + +comment on column case_management.schedule_code.active_ind is 'A boolean indicator to determine if the case management schedule_code is active.'; + +comment on column case_management.schedule_code.create_user_id is 'The id of the user that created the case management schedule_code.'; + +comment on column case_management.schedule_code.create_utc_timestamp is 'The timestamp when the case management schedule_code was created. The timestamp is stored in UTC with no Offset.'; + +comment on column case_management.schedule_code.update_user_id is 'The id of the user that updated the case management schedule_code.'; + +comment on column case_management.schedule_code.update_utc_timestamp is 'The timestamp when the case management schedule_code was updated. The timestamp is stored in UTC with no Offset.'; + +-- +-- CREATE TABLE schedule_sector_xref +-- +-- CREATE TABLE +-- case_management.schedule_sector_xref ( +-- schedule_sector_xref_guid uuid NOT NULL DEFAULT case_management.uuid_generate_v4 (), +-- schedule_code varchar(10) NOT NULL, +-- sector_code varchar(10) NOT NULL, +-- active_ind bool NOT NULL, +-- create_user_id varchar(32) NOT NULL, +-- create_utc_timestamp timestamp NOT NULL, +-- update_user_id varchar(32) NOT NULL, +-- update_utc_timestamp timestamp NOT NULL, +-- CONSTRAINT "PK_schedule_sector_xref_guid" PRIMARY KEY (schedule_sector_xref_guid) +-- ); +CREATE TABLE + case_management.schedule_sector_xref ( + schedule_sector_xref_guid uuid NULL DEFAULT case_management.uuid_generate_v4 (), + schedule_code varchar(10) NOT NULL, + sector_code varchar(10) NOT NULL, + active_ind bool NOT NULL, + create_user_id varchar(32) NOT NULL, + create_utc_timestamp timestamp NOT NULL, + update_user_id varchar(32) NOT NULL, + update_utc_timestamp timestamp NOT NULL, + CONSTRAINT "PK_schedule_sector_xref_guid" PRIMARY KEY (schedule_sector_xref_guid) + ); + +-- +-- create table relationships +-- +ALTER TABLE case_management.schedule_sector_xref +ADD CONSTRAINT FK_schedule_sector_xref__schedule_code FOREIGN KEY (schedule_code) REFERENCES case_management.schedule_code (schedule_code); + +ALTER TABLE case_management.schedule_sector_xref +ADD CONSTRAINT FK_schedule_sector_xref__sector_code FOREIGN KEY (sector_code) REFERENCES case_management.sector_code (sector_code); + +ALTER TABLE case_management.decision +ADD CONSTRAINT FK_decision__schedule_sector_xref_guid FOREIGN KEY (schedule_sector_xref_guid) REFERENCES case_management.schedule_sector_xref (schedule_sector_xref_guid); + +ALTER TABLE case_management.decision +ADD CONSTRAINT FK_decision__case_file_guid FOREIGN KEY (case_file_guid) REFERENCES case_management.case_file (case_file_guid); + +ALTER TABLE case_management.decision +ADD CONSTRAINT FK_decision__discharge_code FOREIGN KEY (discharge_code) REFERENCES case_management.discharge_code (discharge_code); + +ALTER TABLE case_management.decision +ADD CONSTRAINT FK_decision__rationale_code FOREIGN KEY (rationale_code) REFERENCES case_management.rationale_code (rationale_code); \ No newline at end of file diff --git a/migrations/sql/V1.22.1__CE-977.sql b/migrations/sql/V1.22.1__CE-977.sql new file mode 100644 index 00000000..2a1d5b2a --- /dev/null +++ b/migrations/sql/V1.22.1__CE-977.sql @@ -0,0 +1,33 @@ +-- +-- create history tables +-- +CREATE TABLE + case_management.decision_h ( + h_decision_guid uuid NOT NULL DEFAULT uuid_generate_v4 (), + target_row_id uuid NOT NULL, + operation_type char(1) NOT NULL, + operation_user_id varchar(32) NOT NULL DEFAULT current_user, + operation_executed_at timestamp NOT NULL DEFAULT now(), + data_after_executed_operation jsonb, + CONSTRAINT "PK_h_decision" PRIMARY KEY (h_decision_guid) + ); + +CREATE +OR REPLACE TRIGGER decision_history_trigger BEFORE INSERT +OR DELETE +OR +UPDATE ON case_management.decision FOR EACH ROW +EXECUTE PROCEDURE audit_history ('decision_h', 'decision_guid'); + +-- +-- alter action table, add new column and reference to the decision table +-- +ALTER TABLE case_management.action +ADD COLUMN decision_guid uuid; + +ALTER TABLE case_management.decision +ALTER COLUMN decision_guid +SET DEFAULT case_management.uuid_generate_v4 (); + +ALTER TABLE case_management.action +ADD CONSTRAINT FK_action__decision_guid FOREIGN KEY (decision_guid) REFERENCES case_management.decision (decision_guid); \ No newline at end of file