diff --git a/backend/src/external_api/cdogs/cdogs.service.ts b/backend/src/external_api/cdogs/cdogs.service.ts index 08d14ef5b..c5be60451 100644 --- a/backend/src/external_api/cdogs/cdogs.service.ts +++ b/backend/src/external_api/cdogs/cdogs.service.ts @@ -135,6 +135,9 @@ export class CdogsService implements ExternalApiService { case "CEEBTMPLAT": template = "templates/complaint/CDOGS-CEEB-COMPLAINT-TEMPLATE-v1.docx"; break; + case "GIRTMPLATE": + template = "templates/complaint/CDOGS-GIR-COMPLAINT-TEMPLATE-v1.docx"; + break; default: this.logger.error(`exception: unable to find template: ${template}`); break; @@ -192,6 +195,9 @@ export class CdogsService implements ExternalApiService { templateCode = CONFIGURATION_CODES.ERSTMPLATE; } break; + case "GIR": + templateCode = CONFIGURATION_CODES.GIRTMPLATE; + break; } try { diff --git a/backend/src/middleware/maps/automapper-entity-to-dto-maps.ts b/backend/src/middleware/maps/automapper-entity-to-dto-maps.ts index b2e27e4e7..d9db32fbe 100644 --- a/backend/src/middleware/maps/automapper-entity-to-dto-maps.ts +++ b/backend/src/middleware/maps/automapper-entity-to-dto-maps.ts @@ -37,6 +37,7 @@ import { GirTypeCode } from "../../v1/gir_type_code/entities/gir_type_code.entit import { AllegationReportData } from "../../types/models/reports/complaints/allegation-report-data"; import { WildlifeReportData } from "../../types/models/reports/complaints/wildlife-report-data"; import { formatPhonenumber } from "../../common/methods"; +import { GeneralIncidentReportData } from "src/types/models/reports/complaints/general-incident-report-data"; // @SONAR_STOP@ //-- define entity -> model mapping @@ -1796,4 +1797,284 @@ export const mapAllegationReport = (mapper: Mapper, tz: string = "America/Vancou ); }; +export const mapGeneralIncidentReport = (mapper: Mapper, tz: string = "America/Vancouver") => { + reportedByCodeToReportedByDto(mapper); + violationCodeToViolationDto(mapper); + personComplaintToDelegateDtoMap(mapper); + cosGeoOrgUnitToOrganizationDtoMap(mapper); + agencyCodeToAgencyDto(mapper); + + createMap( + mapper, + "GirComplaint", + "GeneralIncidentReportData", + + forMember( + (destination) => destination.complaintMethodReceivedCode, + mapFrom((source) => { + const { complaint_identifier } = source; + const { comp_mthd_recv_cd_agcy_cd_xref } = complaint_identifier || {}; + + if (comp_mthd_recv_cd_agcy_cd_xref) { + const { complaint_method_received_code } = comp_mthd_recv_cd_agcy_cd_xref; + return complaint_method_received_code?.long_description || null; + } + + return null; + }), + ), + forMember( + (destination) => destination.referenceNumber, + mapFrom((source) => source.complaint_identifier.reference_number), + ), + forMember( + (destination) => destination.webeocId, + mapFrom((source) => source.complaint_identifier.webeoc_identifier), + ), + forMember( + (destination) => destination.generalIncidentType, + mapFrom((src) => { + if (src.gir_type_code) { + return src.gir_type_code.long_description; + } + return ""; + }), + ), + forMember( + (destination) => destination.privacyRequested, + mapFrom((source) => { + if (source.complaint_identifier.is_privacy_requested === "Y") { + return "Yes"; + } else if (source.complaint_identifier.is_privacy_requested === "N") { + return "No"; + } else { + return null; + } + }), + ), + forMember( + (destination) => destination.reportedBy, + mapFrom((source) => { + const { + complaint_identifier: { reported_by_code: reported_by }, + } = source; + if (reported_by) { + const code = mapper.map(reported_by, "ReportedByCode", "ReportedByCodeDto"); + return code.longDescription; + } + + return ""; + }), + ), + forMember( + (destination) => destination.address, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + return complaint.caller_address !== null ? complaint.caller_address : ""; + }), + ), + forMember( + (destination) => destination.email, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + return complaint.caller_email !== null ? complaint.caller_email : ""; + }), + ), + forMember( + (destination) => destination.phone3, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + const { caller_phone_3: phone } = complaint; + + try { + if (phone) { + return formatPhonenumber(phone); + } + } catch (error) { + return phone; + } + + return ""; + }), + ), + forMember( + (destination) => destination.phone2, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + const { caller_phone_2: phone } = complaint; + + try { + if (phone) { + return formatPhonenumber(phone); + } + } catch (error) { + return phone; + } + + return ""; + }), + ), + forMember( + (destination) => destination.phone1, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + const { caller_phone_1: phone } = complaint; + + try { + if (phone) { + return formatPhonenumber(phone); + } + } catch (error) { + return phone; + } + + return ""; + }), + ), + forMember( + (destination) => destination.name, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + return complaint.caller_name !== null ? complaint.caller_name : ""; + }), + ), + forMember( + (destination) => destination.description, + mapFrom((source) => { + const { complaint_identifier: complaint } = source; + return complaint.detail_text !== null ? complaint.detail_text : ""; + }), + ), + forMember( + (destination) => destination.locationDescription, + mapFrom((source) => source.complaint_identifier.location_detailed_text), + ), + forMember( + (destination) => destination.region, + mapFrom((source) => { + const { + complaint_identifier: { cos_geo_org_unit: sourceOrganization }, + } = source; + + return sourceOrganization.region_name; + }), + ), + forMember( + (destination) => destination.zone, + mapFrom((source) => { + const { + complaint_identifier: { cos_geo_org_unit: sourceOrganization }, + } = source; + + return sourceOrganization.zone_name; + }), + ), + forMember( + (destination) => destination.office, + mapFrom((source) => { + const { + complaint_identifier: { cos_geo_org_unit: sourceOrganization }, + } = source; + + return sourceOrganization.office_location_name; + }), + ), + forMember( + (destination) => destination.community, + mapFrom((source) => { + const { + complaint_identifier: { cos_geo_org_unit: sourceOrganization }, + } = source; + + return sourceOrganization.area_name; + }), + ), + forMember( + (destination) => destination.longitude, + mapFrom((source) => { + const { + complaint_identifier: { + location_geometry_point: { coordinates }, + }, + } = source; + return coordinates[0].toString(); + }), + ), + forMember( + (destination) => destination.latitude, + mapFrom((source) => { + const { + complaint_identifier: { + location_geometry_point: { coordinates }, + }, + } = source; + return coordinates[1].toString(); + }), + ), + forMember( + (destination) => destination.location, + mapFrom((source) => source.complaint_identifier.location_summary_text), + ), + forMember( + (destination) => destination.incidentDateTime, + mapFrom((source) => source.complaint_identifier.incident_utc_datetime), + ), + forMember( + (destination) => destination.status, + mapFrom((source) => { + return source.complaint_identifier.complaint_status_code.short_description; + }), + ), + forMember( + (destination) => destination.officerAssigned, + mapFrom((source) => { + const { + complaint_identifier: { person_complaint_xref: people }, + } = source; + + const delegates = mapper.mapArray(people, "PersonComplaintXref", "Delegate"); + + if (delegates.length === 0) { + return "Not Assigned"; + } else { + const assignee = delegates.find((item) => item.type === "ASSIGNEE"); + if (!assignee) { + return "Not Assigned"; + } else { + const { + person: { firstName, lastName }, + } = assignee; + return `${firstName} ${lastName}`; + } + } + }), + ), + forMember( + (destination) => destination.updatedOn, + mapFrom((source) => source.complaint_identifier.update_utc_timestamp), + ), + forMember( + (destination) => destination.reportedOn, + mapFrom((source) => { + const { + complaint_identifier: { incident_reported_utc_timestmp: reported }, + } = source; + return reported || ""; + }), + ), + forMember( + (destination) => destination.ownedBy, + mapFrom((source) => source.complaint_identifier.owned_by_agency_code.agency_code), + ), + forMember( + (destination) => destination.createdBy, + mapFrom((source) => source.create_user_id), + ), + forMember( + (destination) => destination.id, + mapFrom((source) => source.complaint_identifier.complaint_identifier), + ), + ); +}; + // @SONAR_START@ diff --git a/backend/src/types/configuration-codes.ts b/backend/src/types/configuration-codes.ts index f63b9244d..d2face518 100644 --- a/backend/src/types/configuration-codes.ts +++ b/backend/src/types/configuration-codes.ts @@ -5,4 +5,5 @@ export const CONFIGURATION_CODES = { CDTABLEVER: "CDTABLEVER", DFLTPAGNUM: "DFLTPAGNUM", MAXFILESZ: "MAXFILESZ", + GIRTMPLATE: "GIRTMPLATE", }; diff --git a/backend/src/types/models/reports/complaints/general-incident-report-data.ts b/backend/src/types/models/reports/complaints/general-incident-report-data.ts new file mode 100644 index 000000000..7aba1f889 --- /dev/null +++ b/backend/src/types/models/reports/complaints/general-incident-report-data.ts @@ -0,0 +1,5 @@ +import { ComplaintReportData } from "./complaint-report-data"; + +export interface GeneralIncidentReportData extends ComplaintReportData { + generalIncidentType: string; +} diff --git a/backend/src/v1/complaint/complaint.service.ts b/backend/src/v1/complaint/complaint.service.ts index 942547665..8643ef1df 100644 --- a/backend/src/v1/complaint/complaint.service.ts +++ b/backend/src/v1/complaint/complaint.service.ts @@ -14,6 +14,7 @@ import { applyWildlifeComplaintMap, complaintToComplaintDtoMap, mapAllegationReport, + mapGeneralIncidentReport, mapWildlifeReport, } from "../../middleware/maps/automapper-entity-to-dto-maps"; @@ -76,6 +77,7 @@ import { SpeciesCode } from "../species_code/entities/species_code.entity"; import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service"; import { Attachment, AttachmentType } from "../../types/models/general/attachment"; import { getFileType } from "../../common/methods"; +import { GeneralIncidentReportData } from "src/types/models/reports/complaints/general-incident-report-data"; const WorldBounds: Array = [-180, -90, 180, 90]; type complaintAlias = HwcrComplaint | AllegationComplaint | GirComplaint; @Injectable({ scope: Scope.REQUEST }) @@ -1761,6 +1763,7 @@ export class ComplaintService { let data; mapWildlifeReport(this.mapper, tz); mapAllegationReport(this.mapper, tz); + mapGeneralIncidentReport(this.mapper, tz); let builder: SelectQueryBuilder | SelectQueryBuilder; const _getUpdates = async (id: string) => { @@ -2177,6 +2180,13 @@ export class ComplaintService { break; } case "GIR": { + mapGeneralIncidentReport(this.mapper, tz); + + data = this.mapper.map( + result as GirComplaint, + "GirComplaint", + "GeneralIncidentReportData", + ); break; } case "ERS": { diff --git a/backend/templates/complaint/CDOGS-GIR-COMPLAINT-TEMPLATE-v1.docx b/backend/templates/complaint/CDOGS-GIR-COMPLAINT-TEMPLATE-v1.docx new file mode 100644 index 000000000..82f5eb897 Binary files /dev/null and b/backend/templates/complaint/CDOGS-GIR-COMPLAINT-TEMPLATE-v1.docx differ diff --git a/migrations/migrations/V0.36.1__CE-1389.sql b/migrations/migrations/V0.36.1__CE-1389.sql new file mode 100644 index 000000000..6d80cce5b --- /dev/null +++ b/migrations/migrations/V0.36.1__CE-1389.sql @@ -0,0 +1,26 @@ +-- +-- Insert new configuration values for CDOGS API for document generation +-- + +INSERT INTO + configuration ( + configuration_code, + configuration_value, + long_description, + active_ind, + create_user_id, + create_utc_timestamp, + update_user_id, + update_utc_timestamp + ) +VALUES + ( + 'GIRTMPLATE', + '', + 'CDOGS Hash for GIR Template', + true, + CURRENT_USER, + CURRENT_TIMESTAMP, + CURRENT_USER, + CURRENT_TIMESTAMP + ) ON CONFLICT DO NOTHING; \ No newline at end of file