From 6234060ffc08817791499a86196c5ba4f804602b Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 7 Nov 2022 09:46:57 -0500 Subject: [PATCH] lot name help text to assist with complicated regular expressions --- data/config.cemetery.ssm.js | 11 +++++-- data/config.cemetery.ssm.ts | 53 ++++++++++++++++--------------- helpers/functions.config.d.ts | 1 + helpers/functions.config.ts | 1 + temp/legacy.importFromCSV.js | 13 ++++---- temp/legacy.importFromCSV.ts | 60 +++++++++++++++++------------------ types/configTypes.d.ts | 1 + types/configTypes.ts | 1 + views/lot-edit.ejs | 5 +++ 9 files changed, 82 insertions(+), 64 deletions(-) diff --git a/data/config.cemetery.ssm.js b/data/config.cemetery.ssm.js index 32570739..20962181 100644 --- a/data/config.cemetery.ssm.js +++ b/data/config.cemetery.ssm.js @@ -2,7 +2,11 @@ import { config as cemeteryConfig } from "./config.cemetery.ontario.js"; export const config = Object.assign({}, cemeteryConfig); config.aliases.occupancyStartDate = "Interment Date"; config.aliases.externalReceiptNumber = "GP Receipt Number"; -config.settings.lot.lotNamePattern = /^[A-Z]{2}(-\d*[A-Z]?){3,5}$/; +config.settings.lot.lotNamePattern = + /^[\dA-Z]{2}-(B[\dA-Z]+-)?(R[\dA-Z]+-)?(L[\dA-Z]+-)?G[\dA-Z]+(, Interment \d+)?$/; +config.settings.lot.lotNameHelpText = + "Two digit cemetery-Block-Range-Lot-Grave, Interment number\n" + + "ex. XX-BA-R41-L15-G3A, Interment 1"; config.settings.lot.lotNameSortNameFunction = (lotName) => { const numericPadding = "00000"; const lotNameSplit = lotName.toUpperCase().split("-"); @@ -23,7 +27,10 @@ config.settings.lot.lotNameSortNameFunction = (lotName) => { return cleanLotNamePieces.join("-"); }; config.settings.lotOccupancy.occupantCityDefault = "Sault Ste. Marie"; -config.settings.lotOccupancy.prints = ["pdf/ssm.cemetery.contract", "pdf/ssm.cemetery.burialPermit"]; +config.settings.lotOccupancy.prints = [ + "pdf/ssm.cemetery.contract", + "pdf/ssm.cemetery.burialPermit" +]; config.settings.map.mapCityDefault = "Sault Ste. Marie"; config.settings.workOrders.workOrderNumberLength = 6; config.settings.workOrders.workOrderMilestoneDateRecentBeforeDays = 7; diff --git a/data/config.cemetery.ssm.ts b/data/config.cemetery.ssm.ts index 72a03268..ba3e5db2 100644 --- a/data/config.cemetery.ssm.ts +++ b/data/config.cemetery.ssm.ts @@ -1,44 +1,47 @@ -import { - config as cemeteryConfig -} from "./config.cemetery.ontario.js"; +import { config as cemeteryConfig } from "./config.cemetery.ontario.js"; export const config = Object.assign({}, cemeteryConfig); config.aliases.occupancyStartDate = "Interment Date"; config.aliases.externalReceiptNumber = "GP Receipt Number"; -config.settings.lot.lotNamePattern = /^[A-Z]{2}(-\d*[A-Z]?){3,5}$/; +config.settings.lot.lotNamePattern = + /^[\dA-Z]{2}-(B[\dA-Z]+-)?(R[\dA-Z]+-)?(L[\dA-Z]+-)?G[\dA-Z]+(, Interment \d+)?$/; + +config.settings.lot.lotNameHelpText = + "Two digit cemetery-Block-Range-Lot-Grave, Interment number\n" + + "ex. XX-BA-R41-L15-G3A, Interment 1"; config.settings.lot.lotNameSortNameFunction = (lotName) => { + const numericPadding = "00000"; - const numericPadding = "00000"; + const lotNameSplit = lotName.toUpperCase().split("-"); - const lotNameSplit = lotName.toUpperCase().split("-"); + const cleanLotNamePieces: string[] = []; - const cleanLotNamePieces: string[] = []; + for (const lotNamePiece of lotNameSplit) { + let numericPiece = numericPadding; + let letterPiece = ""; - for (const lotNamePiece of lotNameSplit) { - - let numericPiece = numericPadding; - let letterPiece = ""; - - for (const letter of lotNamePiece) { - - if (letterPiece === "" && "0123456789".includes(letter)) { - numericPiece += letter; - } else { - letterPiece += letter; - } + for (const letter of lotNamePiece) { + if (letterPiece === "" && "0123456789".includes(letter)) { + numericPiece += letter; + } else { + letterPiece += letter; } - - cleanLotNamePieces.push(numericPiece.slice(-1 * numericPadding.length) + letterPiece); } - return cleanLotNamePieces.join("-"); - }; + cleanLotNamePieces.push(numericPiece.slice(-1 * numericPadding.length) + letterPiece); + } + + return cleanLotNamePieces.join("-"); +}; config.settings.lotOccupancy.occupantCityDefault = "Sault Ste. Marie"; -config.settings.lotOccupancy.prints = ["pdf/ssm.cemetery.contract", "pdf/ssm.cemetery.burialPermit"]; +config.settings.lotOccupancy.prints = [ + "pdf/ssm.cemetery.contract", + "pdf/ssm.cemetery.burialPermit" +]; config.settings.map.mapCityDefault = "Sault Ste. Marie"; @@ -46,4 +49,4 @@ config.settings.workOrders.workOrderNumberLength = 6; config.settings.workOrders.workOrderMilestoneDateRecentBeforeDays = 7; config.settings.workOrders.workOrderMilestoneDateRecentAfterDays = 30; -export default config; \ No newline at end of file +export default config; diff --git a/helpers/functions.config.d.ts b/helpers/functions.config.d.ts index f6802674..280c7263 100644 --- a/helpers/functions.config.d.ts +++ b/helpers/functions.config.d.ts @@ -29,6 +29,7 @@ export declare function getProperty(propertyName: "aliases.externalReceiptNumber export declare function getProperty(propertyName: "settings.map.mapCityDefault"): string; export declare function getProperty(propertyName: "settings.map.mapProvinceDefault"): string; export declare function getProperty(propertyName: "settings.lot.lotNamePattern"): RegExp; +export declare function getProperty(propertyName: "settings.lot.lotNameHelpText"): string; export declare function getProperty(propertyName: "settings.lot.lotNameSortNameFunction"): (lotName: string) => string; export declare function getProperty(propertyName: "settings.lotOccupancy.occupancyEndDateIsRequired"): boolean; export declare function getProperty(propertyName: "settings.lotOccupancy.occupantCityDefault"): string; diff --git a/helpers/functions.config.ts b/helpers/functions.config.ts index b2150acb..74cd60d3 100644 --- a/helpers/functions.config.ts +++ b/helpers/functions.config.ts @@ -111,6 +111,7 @@ export function getProperty(propertyName: "settings.map.mapCityDefault"): string export function getProperty(propertyName: "settings.map.mapProvinceDefault"): string; export function getProperty(propertyName: "settings.lot.lotNamePattern"): RegExp; +export function getProperty(propertyName: "settings.lot.lotNameHelpText"): string; export function getProperty( propertyName: "settings.lot.lotNameSortNameFunction" diff --git a/temp/legacy.importFromCSV.js b/temp/legacy.importFromCSV.js index b4a19a74..e607123e 100644 --- a/temp/legacy.importFromCSV.js +++ b/temp/legacy.importFromCSV.js @@ -134,17 +134,16 @@ function getFeeIdByFeeDescription(feeDescription) { function buildLotName(lotNamePieces) { return (lotNamePieces.cemetery + "-" + - (lotNamePieces.block === "" ? "" : lotNamePieces.block + "-") + + (lotNamePieces.block === "" ? "" : "B" + lotNamePieces.block + "-") + (lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" ? "" - : lotNamePieces.range1 + lotNamePieces.range2 + "-") + + : "R" + lotNamePieces.range1 + lotNamePieces.range2 + "-") + (lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" ? "" - : lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + - lotNamePieces.grave1 + - lotNamePieces.grave2 + - "-" + - lotNamePieces.interment); + : "L" + lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + + ("G" + lotNamePieces.grave1 + lotNamePieces.grave2) + + ", " + + ("Interment " + lotNamePieces.interment)); } const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave"); const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium"); diff --git a/temp/legacy.importFromCSV.ts b/temp/legacy.importFromCSV.ts index c9c7b80a..907022d0 100644 --- a/temp/legacy.importFromCSV.ts +++ b/temp/legacy.importFromCSV.ts @@ -361,17 +361,16 @@ function buildLotName(lotNamePieces: { return ( lotNamePieces.cemetery + "-" + - (lotNamePieces.block === "" ? "" : lotNamePieces.block + "-") + + (lotNamePieces.block === "" ? "" : "B" + lotNamePieces.block + "-") + (lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" ? "" - : lotNamePieces.range1 + lotNamePieces.range2 + "-") + + : "R" + lotNamePieces.range1 + lotNamePieces.range2 + "-") + (lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" ? "" - : lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + - lotNamePieces.grave1 + - lotNamePieces.grave2 + - "-" + - lotNamePieces.interment + : "L" + lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + + ("G" + lotNamePieces.grave1 + lotNamePieces.grave2) + + ", " + + ("Interment " + lotNamePieces.interment) ); } @@ -435,7 +434,6 @@ const intermentWorkOrderMilestoneType = function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupant { switch (funeralHomeKey) { - case "AR": { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, @@ -447,7 +445,7 @@ function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupan occupantPostalCode: "P6A 2L9", occupantPhoneNumber: "705-759-2522", occupantEmailAddress: "" - } + }; } case "NO": { return { @@ -460,7 +458,7 @@ function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupan occupantPostalCode: "P6B 0B6", occupantPhoneNumber: "705-945-7758", occupantEmailAddress: "" - } + }; } case "OS": { return { @@ -473,7 +471,7 @@ function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupan occupantPostalCode: "P6A 1P7", occupantPhoneNumber: "705-759-8456", occupantEmailAddress: "" - } + }; } } @@ -482,7 +480,7 @@ function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupan occupantName: funeralHomeKey, occupantCity: "Sault Ste. Marie", occupantProvince: "ON" - } + }; } function importFromMasterCSV() { @@ -772,21 +770,23 @@ function importFromMasterCSV() { } if (masterRow.CM_FUNERAL_HOME !== "") { - const funeralHomeOccupant = getFuneralHome(masterRow.CM_FUNERAL_HOME); - addLotOccupancyOccupant({ - lotOccupancyId: deceasedLotOccupancyId, - lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, - occupantName: funeralHomeOccupant.occupantName, - occupantAddress1: funeralHomeOccupant.occupantAddress1, - occupantAddress2: funeralHomeOccupant.occupantAddress2, - occupantCity: funeralHomeOccupant.occupantCity, - occupantProvince: funeralHomeOccupant.occupantProvince, - occupantPostalCode: funeralHomeOccupant.occupantPostalCode, - occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, - occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress - }, user); + addLotOccupancyOccupant( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, + occupantName: funeralHomeOccupant.occupantName, + occupantAddress1: funeralHomeOccupant.occupantAddress1, + occupantAddress2: funeralHomeOccupant.occupantAddress2, + occupantCity: funeralHomeOccupant.occupantCity, + occupantProvince: funeralHomeOccupant.occupantProvince, + occupantPostalCode: funeralHomeOccupant.occupantPostalCode, + occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, + occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress + }, + user + ); /* addOrUpdateLotOccupancyField( @@ -1388,7 +1388,6 @@ function importFromWorkOrderCSV() { } if (workOrderRow.WO_DEATH_PLACE !== "") { - addOrUpdateLotOccupancyField( { lotOccupancyId: lotOccupancyId, @@ -1401,7 +1400,6 @@ function importFromWorkOrderCSV() { ); } - if (workOrderRow.WO_AGE !== "") { addOrUpdateLotOccupancyField( { @@ -1429,10 +1427,10 @@ function importFromWorkOrderCSV() { } if (workOrderRow.WO_FUNERAL_HOME !== "") { - const funeralHomeOccupant = getFuneralHome(workOrderRow.WO_FUNERAL_HOME); - addLotOccupancyOccupant({ + addLotOccupancyOccupant( + { lotOccupancyId: lotOccupancyId, lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, occupantName: funeralHomeOccupant.occupantName, @@ -1443,7 +1441,9 @@ function importFromWorkOrderCSV() { occupantPostalCode: funeralHomeOccupant.occupantPostalCode, occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress - }, user); + }, + user + ); /* addOrUpdateLotOccupancyField( diff --git a/types/configTypes.d.ts b/types/configTypes.d.ts index 2a4ee7c1..3602d810 100644 --- a/types/configTypes.d.ts +++ b/types/configTypes.d.ts @@ -35,6 +35,7 @@ export interface Config { }; lot: { lotNamePattern?: RegExp; + lotNameHelpText?: string; lotNameSortNameFunction?: (lotName: string) => string; }; lotOccupancy: { diff --git a/types/configTypes.ts b/types/configTypes.ts index 3ae9daac..2c3740e4 100644 --- a/types/configTypes.ts +++ b/types/configTypes.ts @@ -35,6 +35,7 @@ export interface Config { }; lot: { lotNamePattern?: RegExp; + lotNameHelpText?: string; lotNameSortNameFunction?: (lotName: string) => string; }; lotOccupancy: { diff --git a/views/lot-edit.ejs b/views/lot-edit.ejs index eea7fa05..ff0eacbc 100644 --- a/views/lot-edit.ejs +++ b/views/lot-edit.ejs @@ -57,6 +57,11 @@ accesskey="f" <%= (isCreate ? " autofocus" : "") %> /> + <% if (configFunctions.getProperty("settings.lot.lotNameHelpText")) { %> +

+ <%- configFunctions.getProperty("settings.lot.lotNameHelpText").replace(/\n/g, "
") %> +

+ <% } %>