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

Add genomic indicators to processDeletion #464

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,12 @@ describe('Firebase Gene Review Service', () => {
[FIREBASE_LIST_PATH_TYPE.MUTATION_LIST]: { mutations: [0, 1] },
[FIREBASE_LIST_PATH_TYPE.TUMOR_LIST]: { 'mutations/3/tumors': [3] },
[FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST]: { 'mutations/1/tumors/0/TIs/4/treatment': [0] },
[FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]: { genomic_indicators: [0, 1] },
});
expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(1, 'mutations/1/tumors/0/TIs/4/treatment', [0]);
expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(2, 'mutations/3/tumors', [3]);
expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(3, 'mutations', [0, 1]);
expect(mockFirebaseRepository.deleteFromArray).toHaveBeenNthCalledWith(4, 'genomic_indicators', [0, 1]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class FirebaseGeneReviewService {
[FIREBASE_LIST_PATH_TYPE.MUTATION_LIST]: {},
[FIREBASE_LIST_PATH_TYPE.TUMOR_LIST]: {},
[FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST]: {},
[FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]: {},
};

let evidences: ReturnType<typeof getEvidence> = {};
Expand Down Expand Up @@ -267,7 +268,6 @@ export class FirebaseGeneReviewService {
} else {
throw new SentryError('Unexpect accept in review mode', { hugoSymbol, reviewLevel, isGermline, isAcceptAll });
}

const metaUpdateObject = this.firebaseMetaService.getUpdateObject(false, hugoSymbol, isGermline, uuid);
updateObject = { ...updateObject, ...metaUpdateObject };
}
Expand All @@ -284,25 +284,10 @@ export class FirebaseGeneReviewService {
});
}

// We are deleting last because the indices will change after deleting from array.
let hasDeletion = false;
try {
// Todo: We should use multi-location updates for deletions once all our arrays use firebase auto-generated keys
// instead of using sequential number indices.
for (const pathType of [
FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST,
FIREBASE_LIST_PATH_TYPE.TUMOR_LIST,
FIREBASE_LIST_PATH_TYPE.MUTATION_LIST,
]) {
for (const [firebasePath, deleteIndices] of Object.entries(itemsToDelete[pathType])) {
hasDeletion = true;
await this.firebaseRepository.deleteFromArray(firebasePath, deleteIndices);
}
}
// If user accepts a deletion individually, we need to refresh the ReviewPage with the latest data to make sure the indices are up to date.
if (reviewLevels.length === 1 && hasDeletion) {
return { shouldRefresh: true };
}
this.processDeletion(reviewLevels.length, itemsToDelete);
} catch (error) {
throw new SentryError('Failed to accept deletions in review mode', { hugoSymbol, reviewLevels, isGermline, itemsToDelete });
}
Expand Down Expand Up @@ -416,15 +401,16 @@ export class FirebaseGeneReviewService {

processDeletion = async (reviewLevelLength: number, itemsToDelete: ItemsToDeleteMap) => {
// We are deleting last because the indices will change after deleting from array.
// Be VERY careful, this order is important
const orderedPathTypesToDelete = [
FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST,
FIREBASE_LIST_PATH_TYPE.TUMOR_LIST,
FIREBASE_LIST_PATH_TYPE.MUTATION_LIST,
];

let hasDeletion = false;
try {
// Todo: We should use multi-location updates for deletions once all our arrays use firebase auto-generated keys
// instead of using sequential number indices.
for (const pathType of [
FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST,
FIREBASE_LIST_PATH_TYPE.TUMOR_LIST,
FIREBASE_LIST_PATH_TYPE.MUTATION_LIST,
]) {
for (const pathType of [...orderedPathTypesToDelete, FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST]) {
for (const [firebasePath, deleteIndices] of Object.entries(itemsToDelete[pathType])) {
hasDeletion = true;
await this.firebaseRepository.deleteFromArray(firebasePath, deleteIndices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export enum FIREBASE_LIST_PATH_TYPE {
MUTATION_LIST,
TUMOR_LIST,
TREATMENT_LIST,
GENOMIC_INDICATOR_LIST,
}
export const getFirebasePathType = (path: string) => {
if (/mutations\/\d+$/i.test(path)) {
Expand All @@ -58,4 +59,7 @@ export const getFirebasePathType = (path: string) => {
if (/TIs\/\d+\/treatments\/\d+$/i.test(path)) {
return FIREBASE_LIST_PATH_TYPE.TREATMENT_LIST;
}
if (/genomic_indicators\/\d+$/i.test(path)) {
return FIREBASE_LIST_PATH_TYPE.GENOMIC_INDICATOR_LIST;
}
};