Skip to content

Commit

Permalink
add genomic indicators to processDeletion (#464)
Browse files Browse the repository at this point in the history
* add genomic indicators to processDeletion

* ensure order of deletions is correct
  • Loading branch information
bprize15 authored Oct 28, 2024
1 parent 93e8a6d commit 4160079
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
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;
}
};

0 comments on commit 4160079

Please sign in to comment.