Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CE-1389-Export-GIRs #916

Open
wants to merge 2 commits into
base: release/1.0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/src/external_api/cdogs/cdogs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -192,6 +195,9 @@ export class CdogsService implements ExternalApiService {
templateCode = CONFIGURATION_CODES.ERSTMPLATE;
}
break;
case "GIR":
templateCode = CONFIGURATION_CODES.GIRTMPLATE;
break;
}

try {
Expand Down
281 changes: 281 additions & 0 deletions backend/src/middleware/maps/automapper-entity-to-dto-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<GirComplaint, GeneralIncidentReportData>(
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<ReportedByCode, ReportedBy>(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<PersonComplaintXref, DelegateDto>(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@
1 change: 1 addition & 0 deletions backend/src/types/configuration-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const CONFIGURATION_CODES = {
CDTABLEVER: "CDTABLEVER",
DFLTPAGNUM: "DFLTPAGNUM",
MAXFILESZ: "MAXFILESZ",
GIRTMPLATE: "GIRTMPLATE",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ComplaintReportData } from "./complaint-report-data";

export interface GeneralIncidentReportData extends ComplaintReportData {
generalIncidentType: string;
}
10 changes: 10 additions & 0 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
applyWildlifeComplaintMap,
complaintToComplaintDtoMap,
mapAllegationReport,
mapGeneralIncidentReport,
mapWildlifeReport,
} from "../../middleware/maps/automapper-entity-to-dto-maps";

Expand Down Expand Up @@ -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<number> = [-180, -90, 180, 90];
type complaintAlias = HwcrComplaint | AllegationComplaint | GirComplaint;
@Injectable({ scope: Scope.REQUEST })
Expand Down Expand Up @@ -1761,6 +1763,7 @@ export class ComplaintService {
let data;
mapWildlifeReport(this.mapper, tz);
mapAllegationReport(this.mapper, tz);
mapGeneralIncidentReport(this.mapper, tz);
let builder: SelectQueryBuilder<complaintAlias> | SelectQueryBuilder<Complaint>;

const _getUpdates = async (id: string) => {
Expand Down Expand Up @@ -2177,6 +2180,13 @@ export class ComplaintService {
break;
}
case "GIR": {
mapGeneralIncidentReport(this.mapper, tz);

data = this.mapper.map<GirComplaint, GeneralIncidentReportData>(
result as GirComplaint,
"GirComplaint",
"GeneralIncidentReportData",
);
break;
}
case "ERS": {
Expand Down
Binary file not shown.
26 changes: 26 additions & 0 deletions migrations/migrations/V0.36.1__CE-1389.sql
Original file line number Diff line number Diff line change
@@ -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;
Loading