Skip to content

Commit

Permalink
NRPT-382 Display more EPD NRIS data (#877)
Browse files Browse the repository at this point in the history
* NRPT-382 Display more EPD NRIS data

* Minor fix
  • Loading branch information
BcGovNeal authored Jul 14, 2021
1 parent d72dc57 commit 878414e
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions api/src/integrations/nris-epd/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class NrisDataSource {
return agency === 'Environmental Protection Office' ? 'Environmental Protection Division' : agency;
}

stringTransformExpandAMP(inspctResponse) {
return inspctResponse === 'AMP' ? 'Recommended for administrative monetary penalty' : inspctResponse;
}

async transformRecord(record) {
const Inspection = mongoose.model(RECORD_TYPE.Inspection._schemaName);
let newRecord = new Inspection().toObject();
Expand All @@ -199,8 +203,8 @@ class NrisDataSource {
newRecord.recordType = 'Inspection';
newRecord._sourceRefNrisId = record.assessmentId;
try {
newRecord.dateIssued = record.assessmentDate
? moment.tz(record.assessmentDate, 'America/Vancouver').toDate()
newRecord.dateIssued = record.completionDate
? moment.tz(record.completionDate, 'America/Vancouver').toDate()
: null;
} catch (error) {
defaultLog.debug(error);
Expand Down Expand Up @@ -252,6 +256,11 @@ class NrisDataSource {
`Could not create issuedTo for unexpected clientType: ${clientType} - assessmentId: ${record.assessmentId}`
);
}

const clientId = record.client[0].clientId;
if (clientId === 73892147 || clientId === 84725321) {
newRecord._epicProjectId = new mongoose.Types.ObjectId(utils.EpicProjectIds.lngCanadaId);
}
}

newRecord.location = record.location.locationDescription;
Expand All @@ -265,9 +274,30 @@ class NrisDataSource {
}

if (record.inspection && record.inspection.inspctResponse) {
newRecord.outcomeDescription += ' - ' + record.inspection.inspctResponse;
newRecord.outcomeDescription += ' - ' + this.stringTransformExpandAMP(record.inspection.inspctResponse);
}

const descriptions = [
`Trigger or reason for inspection: ${
record.reason === 'DGIR' ? 'Dangerous Goods Inspection Report' : record.reason
}`,
`Source of inspected requirement(s): ${record.requirementSource}`
];

if (record.requirementSource === 'Greenhouse Gas Industrial Reporting and Control Act') {
newRecord.issuingAgency = 'Climate Action Secretariat';
} else {
if (record.authorization && record.authorization.sourceId) {
descriptions.splice(1, 0, `Authorization Number: ${record.authorization.sourceId}`);
}

if (record.wasteType && record.wasteType.length > 0) {
descriptions.push(`Waste Discharge Type: ${record.wasteType.join(', ')}`);
}
}

newRecord.description = descriptions.join('; ');

defaultLog.info('Processed:', record.assessmentId);
return newRecord;
}
Expand Down Expand Up @@ -314,8 +344,8 @@ class NrisDataSource {

const uploadDir = process.env.UPLOAD_DIRECTORY || '/tmp/';
let fileName = res.headers['content-disposition'].split('= ').pop();
fileName = fileName.replace(/[^a-z0-9 ]/gi, '');
fileName = fileName.replace(' ', '_');
// Replace any characters outside of a-z, A-Z, -, _, ., *, ', (, and ) with _
fileName = fileName.replace(/[^a-z0-9\-_.*'()]/gi, '_');
const tempFilePath = uploadDir + fileName;
// Attempt to save locally and prepare for upload to S3.
await new Promise(resolve => {
Expand Down Expand Up @@ -453,6 +483,10 @@ class NrisDataSource {
const updateObj = { ...newRecord, _id: existingRecord._id, dateAdded: existingRecord.dateAdded };
existingRecord._flavourRecords.forEach(flavourRecord => {
updateObj[flavourRecord._schemaName] = { _id: flavourRecord._id, addRole: 'public' };

if (flavourRecord._schemaName === RECORD_TYPE.Inspection.flavours.nrced._schemaName) {
updateObj[flavourRecord._schemaName]['summary'] = updateObj.description || '';
}
});

delete updateObj._flavourRecords;
Expand Down

0 comments on commit 878414e

Please sign in to comment.