From 66e71593a3f5b727023126df2e596a93c895ee44 Mon Sep 17 00:00:00 2001 From: amber-emmes Date: Thu, 23 Jan 2025 13:28:26 -0500 Subject: [PATCH 1/2] Home mouthwash kit now defaults to physical address if provided at all, vs. only when mailing address is a PO Box --- test/test.js | 82 ++++++++++++++++++++++++++++++++++++++++++++-- utils/firestore.js | 36 ++++++++++---------- 2 files changed, 99 insertions(+), 19 deletions(-) diff --git a/test/test.js b/test/test.js index e7d8f5f4..3c6b9ca5 100644 --- a/test/test.js +++ b/test/test.js @@ -630,7 +630,7 @@ describe('biospecimen', async () => { }); describe('processParticipantHomeMouthwashKitData', () => { - const { collectionDetails, baseline, bioKitMouthwash, firstName, lastName, isPOBox, address1, address2, physicalAddress1, physicalAddress2, city, state, zip, physicalCity, physicalState, physicalZip, yes } = fieldToConceptIdMapping; + const { collectionDetails, baseline, bioKitMouthwash, firstName, lastName, isPOBox, address1, address2, physicalAddress1, physicalAddress2, city, state, zip, physicalCity, physicalState, physicalZip, yes, no } = fieldToConceptIdMapping; it('Should return null for PO boxes', () => { const result1 = firestore.processParticipantHomeMouthwashKitData({ [address1]: 'PO Box 1033' @@ -749,6 +749,35 @@ describe('biospecimen', async () => { assert.equal(result.connect_id, record['Connect_ID']); }); + it('Should use physical address if physical address is provided even if mailing address is not a PO Box', () => { + const result1 = firestore.processParticipantHomeMouthwashKitData({ + [firstName]: 'First', + [lastName]: 'Last', + [isPOBox]: no, + [address1]: '321 Physical Street', + [physicalAddress1]: '123 Fake St', + [physicalCity]: 'City', + [physicalState]: 'PA', + [physicalZip]: '19104', + 'Connect_ID': 123456789, + [collectionDetails]: { + [baseline]: { + [bioKitMouthwash]: undefined + } + } + }, true); + assert.deepEqual(result1, { + first_name: 'First', + last_name: 'Last', + connect_id: 123456789, + address_1: '123 Fake St', + address_2: '', + city: 'City', + state: 'PA', + zip_code: '19104' + }); + }); + it('Should use physical address if primary address is marked as PO box', () => { const result1 = firestore.processParticipantHomeMouthwashKitData({ [firstName]: 'First', @@ -806,7 +835,39 @@ describe('biospecimen', async () => { }); }); - it('Should return null if physical address is a PO Box', () => { + it('Should use mailing address if physical address is a PO Box and mailing is not', () => { + const result1 = firestore.processParticipantHomeMouthwashKitData({ + [firstName]: 'First', + [lastName]: 'Last', + [isPOBox]: no, + [address1]: '123 Fake St', + [city]: 'City', + [state]: 'PA', + [zip]: '19104', + [physicalAddress1]: 'PO Box 1033', + [physicalCity]: 'City', + [physicalState]: 'PA', + [physicalZip]: '17102', + 'Connect_ID': 123456789, + [collectionDetails]: { + [baseline]: { + [bioKitMouthwash]: undefined + } + } + }, true); + assert.deepEqual(result1, { + first_name: 'First', + last_name: 'Last', + connect_id: 123456789, + address_1: '123 Fake St', + address_2: '', + city: 'City', + state: 'PA', + zip_code: '19104' + }); + }); + + it('Should return null if physical address and mailing addresses are PO Boxes', () => { const result1 = firestore.processParticipantHomeMouthwashKitData({ [firstName]: 'First', [lastName]: 'Last', @@ -822,7 +883,24 @@ describe('biospecimen', async () => { } } }, true); + const result2 = firestore.processParticipantHomeMouthwashKitData({ + [firstName]: 'First', + [lastName]: 'Last', + [isPOBox]: yes, + [address1]: 'PznO Box 1033', + [physicalAddress1]: 'PO Box 1033', + [physicalCity]: 'City', + [physicalState]: 'PA', + [physicalZip]: '19104', + 'Connect_ID': 123456789, + [collectionDetails]: { + [baseline]: { + [bioKitMouthwash]: undefined + } + } + }, true); assert.equal(result1, null); + assert.equal(result2, null); }); }); diff --git a/utils/firestore.js b/utils/firestore.js index 9f150c18..60bb5be0 100644 --- a/utils/firestore.js +++ b/utils/firestore.js @@ -1,6 +1,6 @@ const admin = require('firebase-admin'); const { Transaction, FieldPath, FieldValue } = require('firebase-admin/firestore'); -admin.initializeApp(); +admin.initializeApp(functions.config().firebase); const db = admin.firestore(); db.settings({ ignoreUndefinedProperties: true }); // Skip keys with undefined values instead of erroring const { tubeConceptIds, collectionIdConversion, swapObjKeysAndValues, batchLimit, listOfCollectionsRelatedToDataDestruction, createChunkArray, twilioErrorMessages, cidToLangMapper, printDocsCount, getFiveDaysAgoDateISO, conceptMappings } = require('./shared'); @@ -2694,25 +2694,14 @@ const processParticipantHomeMouthwashKitData = (record, printLabel) => { return null; } - const addressLineOne = record?.[address1]; const poBoxRegex = /^(?:P\.?O\.?\s*(?:Box|B\.?)?|Post\s+Office\s+(?:Box|B\.?)?)\s*(\s*#?\s*\d*)((?:\s+(.+))?$)$/i; - const isPOBoxMatch = poBoxRegex.test(addressLineOne) || record?.[isPOBox] === yes; - let addressObj = { - address_1: record[address1], - address_2: record[address2] || '', - city: record[city], - state: record[state], - zip_code: record[zip], - }; - - if (isPOBoxMatch) { - // Handle physical address - const physicalAddressLineOne = record[physicalAddress1]; - // If physical address is missing or also a PO Box, make this invalid - if(!physicalAddressLineOne || poBoxRegex.test(physicalAddressLineOne)) - return null; + const physicalAddressLineOne = record[physicalAddress1]; + let addressObj = {}; + // If there is a physical address, default to it unless it's a PO Box + // (Behavior clarified in the notes on [1174](https://github.com/episphere/connect/issues/1174)) + if(physicalAddressLineOne && !poBoxRegex.test(physicalAddressLineOne)) { addressObj = { address_1: record[physicalAddress1], address_2: record[physicalAddress2] || '', @@ -2720,6 +2709,19 @@ const processParticipantHomeMouthwashKitData = (record, printLabel) => { state: record[physicalState], zip_code: record[physicalZip], }; + } else { + const addressLineOne = record?.[address1]; + const isPOBoxMatch = poBoxRegex.test(addressLineOne) || record?.[isPOBox] === yes; + if(isPOBoxMatch) { + return null; + } + addressObj = { + address_1: record[address1], + address_2: record[address2] || '', + city: record[city], + state: record[state], + zip_code: record[zip], + }; } const hasMouthwash = record[collectionDetails][baseline][bioKitMouthwash] !== undefined; From 4d06937772ec29835775f596f644dcb4dfaf07f5 Mon Sep 17 00:00:00 2001 From: amber-emmes Date: Thu, 23 Jan 2025 13:44:51 -0500 Subject: [PATCH 2/2] Removed functions.config call --- utils/firestore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/firestore.js b/utils/firestore.js index 60bb5be0..1e33b2a3 100644 --- a/utils/firestore.js +++ b/utils/firestore.js @@ -1,6 +1,6 @@ const admin = require('firebase-admin'); const { Transaction, FieldPath, FieldValue } = require('firebase-admin/firestore'); -admin.initializeApp(functions.config().firebase); +admin.initializeApp(); const db = admin.firestore(); db.settings({ ignoreUndefinedProperties: true }); // Skip keys with undefined values instead of erroring const { tubeConceptIds, collectionIdConversion, swapObjKeysAndValues, batchLimit, listOfCollectionsRelatedToDataDestruction, createChunkArray, twilioErrorMessages, cidToLangMapper, printDocsCount, getFiveDaysAgoDateISO, conceptMappings } = require('./shared');