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

1174 followup #727

Merged
merged 2 commits into from
Jan 23, 2025
Merged
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
82 changes: 80 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
34 changes: 18 additions & 16 deletions utils/firestore.js
Original file line number Diff line number Diff line change
@@ -2694,32 +2694,34 @@ 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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the link!

if(physicalAddressLineOne && !poBoxRegex.test(physicalAddressLineOne)) {
addressObj = {
address_1: record[physicalAddress1],
address_2: record[physicalAddress2] || '',
city: record[physicalCity],
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;