Skip to content

Commit

Permalink
NRPT-295: Added ERA csv importer (#791)
Browse files Browse the repository at this point in the history
* NRPT-295: Added ERA csv  importer

* fixed unit tests

* cleanup

* linting bug

* linting bug

* added record name, and required fields

* swapped client name from fullName to firstName
  • Loading branch information
MaxWardle authored Mar 1, 2021
1 parent ccdd082 commit 0e04595
Show file tree
Hide file tree
Showing 25 changed files with 933 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export class ImportCSVComponent implements OnInit {
{ displayName: 'AGRI-CMDB', value: 'cmdb-csv' },
{ displayName: 'AGRI-MIS', value: 'mis-csv' },
{ displayName: 'COORS', value: 'coors-csv' },
{ displayName: 'NRIS-FLNR', value: 'nro-csv' }
{ displayName: 'NRIS-FLNR', value: 'flnr-csv' },
{ displayName: 'NRO-ERA', value: 'era-csv' }
];

public csvTypes: any = {
'coors-csv': ['Administrative Sanction', 'Court Conviction', 'Ticket'],
'nro-csv': ['Inspection'],
'flnr-csv': ['Inspection'],
'mis-csv': ['Inspection'],
'cmdb-csv': ['Inspection'],
'alc-csv': ['Inspection']
'alc-csv': ['Inspection'],
'era-csv': ['Ticket']
};

public dataSourceType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import {
alcInspectionsCsvDateFields
} from './alc-csv-constants';

import {
eraTicketsCsvRequiredHeaders,
eraTicketsCsvRequiredFields,
eraTicketsCsvRequiredFormats,
eraTicketsCsvDateFields
} from './era-csv-constants';

/**
* Required format object to specify fields whose value must have a specific format.
*
Expand Down Expand Up @@ -293,7 +300,7 @@ export class CsvConstants {
* @static
* @memberof CsvConstants
*/
public static readonly nroInspectionCsvRequiredHeaders = [
public static readonly flnrInspectionCsvRequiredHeaders = [
'Record ID',
'Date',
'Client / Complainant',
Expand All @@ -312,7 +319,7 @@ export class CsvConstants {
* @static
* @memberof CsvConstants
*/
public static readonly nroInspectionCsvRequiredFields = ['Record ID'];
public static readonly flnrInspectionCsvRequiredFields = ['Record ID'];

/**
* Fields for NRIS FLNRO NRO Inspection csv that have a required format.
Expand All @@ -323,7 +330,7 @@ export class CsvConstants {
* @type {IRequiredFormat[]}
* @memberof CsvConstants
*/
public static readonly nroInspectionCsvRequiredFormats: IRequiredFormat[] = [
public static readonly flnrInspectionCsvRequiredFormats: IRequiredFormat[] = [
{ field: 'Date', type: 'date', format: 'YYYY-MM-DD' }
];

Expand All @@ -334,7 +341,7 @@ export class CsvConstants {
* @type {IDateField[]}
* @memberof CsvConstants
*/
public static readonly nroInspectionCsvDateFields: IDateField[] = [{ field: 'Date', format: 'YYYY-MM-DD' }];
public static readonly flnrInspectionCsvDateFields: IDateField[] = [{ field: 'Date', format: 'YYYY-MM-DD' }];

/**
* Expected headers for AGRI MIS Inspection csv.
Expand Down Expand Up @@ -459,9 +466,9 @@ export class CsvConstants {
}
}

if (dataSourceType === 'nro-csv') {
if (dataSourceType === 'flnr-csv') {
if (recordType === 'Inspection') {
return this.nroInspectionCsvRequiredHeaders;
return this.flnrInspectionCsvRequiredHeaders;
}
}

Expand All @@ -483,6 +490,12 @@ export class CsvConstants {
}
}

if (dataSourceType === 'era-csv') {
if (recordType === 'Ticket') {
return eraTicketsCsvRequiredHeaders;
}
}

return null;
}

Expand Down Expand Up @@ -518,9 +531,9 @@ export class CsvConstants {
}
}

if (dataSourceType === 'nro-csv') {
if (dataSourceType === 'flnr-csv') {
if (recordType === 'Inspection') {
return this.nroInspectionCsvRequiredFields;
return this.flnrInspectionCsvRequiredHeaders;
}
}

Expand All @@ -542,6 +555,12 @@ export class CsvConstants {
}
}

if (dataSourceType === 'era-csv') {
if (recordType === 'Ticket') {
return eraTicketsCsvRequiredFields;
}
}

return null;
}

Expand Down Expand Up @@ -577,9 +596,9 @@ export class CsvConstants {
}
}

if (dataSourceType === 'nro-csv') {
if (dataSourceType === 'flnr-csv') {
if (recordType === 'Inspection') {
return this.nroInspectionCsvRequiredFormats;
return this.flnrInspectionCsvRequiredFormats;
}
}

Expand All @@ -601,6 +620,12 @@ export class CsvConstants {
}
}

if (dataSourceType === 'era-csv') {
if (recordType === 'Ticket') {
return eraTicketsCsvRequiredFormats;
}
}

return null;
}

Expand Down Expand Up @@ -636,9 +661,9 @@ export class CsvConstants {
}
}

if (dataSourceType === 'nro-csv') {
if (dataSourceType === 'flnr-csv') {
if (recordType === 'Inspection') {
return this.nroInspectionCsvDateFields;
return this.flnrInspectionCsvDateFields;
}
}

Expand All @@ -660,6 +685,12 @@ export class CsvConstants {
}
}

if (dataSourceType === 'era-csv') {
if (recordType === 'Ticket') {
return eraTicketsCsvDateFields;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { IRequiredFormat, IDateField } from './csv-constants';

/**
* Expected headers for ALC Inspection csv.
*
* Note: sort order and letter case of headers is not important.
*/
export const eraTicketsCsvRequiredHeaders = [
'CASE_CONTRAVENTION_ID',
'ENFORCEMENT_ACTION_ID',
'FC_CLIENT_NAME',
'ACT_DESCRIPTION',
'REG_DESCRIPTION',
'SECTION',
'SUB_SECTION',
'PARAGRAPH',
'ARTICLE_DESCRIPTION',
'FINE_AMOUNT',
'SERVICE_DATE',
'REGION',
'ORG_UNIT_NAME',
'CLIENT_TYPE_CODE'
];

/**
* Required fields for ALC Inspection csv.
*
*/
export const eraTicketsCsvRequiredFields = [
'CASE_CONTRAVENTION_ID',
'ENFORCEMENT_ACTION_ID',
'FC_CLIENT_NAME',
'ACT_DESCRIPTION',
'SECTION',
'ARTICLE_DESCRIPTION',
'FINE_AMOUNT',
'SERVICE_DATE',
'ORG_UNIT_NAME',
'CLIENT_TYPE_CODE'
];

/**
* Fields for ALC Inspection csv that have a required format.
*
* @type {IRequiredFormat[]}
*/
export const eraTicketsCsvRequiredFormats: IRequiredFormat[] = [
{ field: 'SERVICE_DATE', type: 'date', format: 'MM/DD/YYYY' }
];

/**
* Fields for ALC Inspection csv that represent dates.
*
* @type {IDateField[]}
*/
export const eraTicketsCsvDateFields: IDateField[] = [{ field: 'SERVICE_DATE', format: 'MM/DD/YYYY' }];
3 changes: 3 additions & 0 deletions api/src/controllers/post/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ exports.createMaster = function(args, res, next, incomingObj, flavourIds) {
incomingObj.collectionId &&
ObjectId.isValid(incomingObj.collectionId) &&
(ticket.collectionId = new ObjectId(incomingObj.collectionId));
incomingObj._sourceRefStringId && (ticket._sourceRefStringId = incomingObj._sourceRefStringId);

// set permissions
ticket.read = utils.ApplicationAdminRoles;
Expand Down Expand Up @@ -235,6 +236,7 @@ exports.createLNG = function(args, res, next, incomingObj) {
ObjectId.isValid(incomingObj._epicMilestoneId) &&
(ticketLNG._epicMilestoneId = new ObjectId(incomingObj._epicMilestoneId));
incomingObj._sourceRefCoorsId && (ticketLNG._sourceRefCoorsId = incomingObj._sourceRefCoorsId);
incomingObj._sourceRefStringId && (ticketLNG._sourceRefStringId = incomingObj._sourceRefStringId);

// set permissions and meta
ticketLNG.read = utils.ApplicationAdminRoles;
Expand Down Expand Up @@ -377,6 +379,7 @@ exports.createNRCED = function(args, res, next, incomingObj) {
ObjectId.isValid(incomingObj._epicMilestoneId) &&
(ticketNRCED._epicMilestoneId = new ObjectId(incomingObj._epicMilestoneId));
incomingObj._sourceRefCoorsId && (ticketNRCED._sourceRefCoorsId = incomingObj._sourceRefCoorsId);
incomingObj._sourceRefStringId && (ticketNRCED._sourceRefStringId = incomingObj._sourceRefStringId);

// set permissions and meta
ticketNRCED.read = utils.ApplicationAdminRoles;
Expand Down
2 changes: 1 addition & 1 deletion api/src/importers/cmdb/inspection-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const MiscConstants = require('../../utils/constants/misc');

inspection['_sourceRefAgriCmdbId'] = csvRow['inspection id'] || '';

inspection['recordType'] = 'Inspection'; // TODO: check about inspection type field on csv? there is not currently a "Higher Risk Inspection" recordType
inspection['recordType'] = 'Inspection';
inspection['dateIssued'] = csvRow['date issued'] || null;

inspection['issuingAgency'] = 'Ministry of Agriculture';
Expand Down
Loading

0 comments on commit 0e04595

Please sign in to comment.