Skip to content

Commit

Permalink
Review no longer removes data for core submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkonecn committed Sep 17, 2024
1 parent 4204647 commit 49c04b0
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 31 deletions.
10 changes: 3 additions & 7 deletions src/main/webapp/app/pages/curation/review/ReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ import _ from 'lodash';
import { ReviewCollapsible } from '../collapsible/ReviewCollapsible';
import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils';
import { AsyncSaveButton } from 'app/shared/button/AsyncSaveButton';
import { DrugCollection, Gene, MetaReview } from 'app/shared/model/firebase/firebase.model';
import { IGene } from 'app/shared/model/gene.model';
import { FB_COLLECTION } from 'app/config/constants/firebase';
import { Gene, MetaReview } from 'app/shared/model/firebase/firebase.model';
import { SentryError } from 'app/config/sentry-error';

interface IReviewPageProps extends StoreProps, RouteComponentProps<{ hugoSymbol: string }> {
geneEntity: IGene;
}
interface IReviewPageProps extends StoreProps, RouteComponentProps<{ hugoSymbol: string }> {}

const ReviewPage: React.FunctionComponent<IReviewPageProps> = (props: IReviewPageProps) => {
const pathname = props.location.pathname;
Expand Down Expand Up @@ -125,7 +121,7 @@ const ReviewPage: React.FunctionComponent<IReviewPageProps> = (props: IReviewPag
isGermline,
isAcceptAll: true,
gene: geneData,
entrezGeneId: props.geneEntity.entrezGeneId,
entrezGeneId: geneEntity?.entrezGeneId as number,
drugListRef,
});
fetchFirebaseData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class FirebaseGeneReviewService {
this.evidenceClient.deleteEvidences(deleteEvidencesPayload);
}
} else if (isGeneTypeChange(reviewLevel.valuePath)) {
geneTypePayload = createGeneTypePayload(gene);
geneTypePayload = createGeneTypePayload(gene, reviewLevel.valuePath);
} else {
const args = pathToGetEvidenceArgs({
gene,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ describe('getEvidence to submit to core', () => {
lastReviewed: 'Prognostic Summary Last Reviewed',
updateTime: getTimeFromDateString('2002-01-01'),
}),
summary: 'Summary',
summary_review: createMockReview({
lastReviewed: 'Summary Last Reviewed',
updateTime: getTimeFromDateString('2002-01-01'),
}),
}),
],
}),
Expand All @@ -480,7 +485,7 @@ describe('getEvidence to submit to core', () => {
},
],
evidenceType: EvidenceEvidenceTypeEnum.PrognosticSummary,
description: 'Prognostic Summary Last Reviewed',
description: 'Prognostic Summary',
gene: {
entrezGeneId: baseArgs.entrezGeneId,
hugoSymbol,
Expand Down Expand Up @@ -618,7 +623,7 @@ describe('getEvidence to submit to core', () => {
},
],
evidenceType: EvidenceEvidenceTypeEnum.Oncogenic,
knownEffect: FIREBASE_ONCOGENICITY.YES,
knownEffect: FIREBASE_ONCOGENICITY.LIKELY,
gene: {
entrezGeneId: baseArgs.entrezGeneId,
hugoSymbol,
Expand Down Expand Up @@ -914,14 +919,19 @@ describe('getEvidence to submit to core', () => {
name: '76c75f3b-364a-418c-8661-48768fb0742a',
description: 'TI IS',
fdaLevel: FDA_LEVELS.LEVEL_FDA1,
level: TX_LEVELS.LEVEL_1,
level: TX_LEVELS.LEVEL_2,
level_review: createMockReview({
lastReviewed: TX_LEVELS.LEVEL_2,
lastReviewed: TX_LEVELS.LEVEL_1,
updatedBy: 'John Doe',
updateTime: getTimeFromDateString('2001-01-01'),
}),
propagationLiquid: TX_LEVELS.LEVEL_4,
propagation: TX_LEVELS.LEVEL_2,
propagation_review: createMockReview({
lastReviewed: TX_LEVELS.LEVEL_4,
updatedBy: 'John Doe',
updateTime: getTimeFromDateString('2001-01-01'),
}),
}),
],
}),
Expand Down Expand Up @@ -1018,6 +1028,11 @@ describe('getEvidence to submit to core', () => {
valuePath: 'mutations/0/tumors/0/summary',
gene: createMockGene({
name: hugoSymbol,
summary: '',
summary_review: createMockReview({
updateTime: getTimeFromDateString('2004-01-01'),
lastReviewed: 'Ignore summary',
}),
mutations: [
createMockMutation({
tumors: [
Expand Down Expand Up @@ -1046,7 +1061,7 @@ describe('getEvidence to submit to core', () => {
},
],
evidenceType: EvidenceEvidenceTypeEnum.TumorTypeSummary,
description: 'Tumor Type Summary Old',
description: 'Tumor Type Summary',
gene: { entrezGeneId: baseArgs.entrezGeneId, hugoSymbol },
lastEdit: getTimeFromDateString('2004-01-01').toString(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function pathToGetEvidenceArgs({
}: {
valuePath: string;
} & Pick<GetEvidenceArgs, 'gene' | 'updateTime' | 'drugListRef' | 'entrezGeneId'>): GetEvidenceArgs | undefined {
const gene = useLastReviewedOnly(originalGene);
const gene = useLastReviewedOnly(originalGene, valuePath);
if (gene === undefined) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { createGeneTypePayload } from './core-gene-type-submission';
import { GENE_TYPE } from 'app/config/constants/firebase';

describe('getGeneType', () => {
const tests: [Parameters<typeof createGeneTypePayload>[0], Required<ReturnType<typeof createGeneTypePayload>>][] = [
type CreateGeneTypePayloadParameters = Parameters<typeof createGeneTypePayload>;
const tests: [
CreateGeneTypePayloadParameters[0],
CreateGeneTypePayloadParameters[1],
Required<ReturnType<typeof createGeneTypePayload>>,
][] = [
[
{ name: 'name', type: { ocg: GENE_TYPE.ONCOGENE, tsg: GENE_TYPE.TUMOR_SUPPRESSOR } },
'type/ocg',
{
hugoSymbol: 'name',
tsg: true,
Expand All @@ -22,28 +28,55 @@ describe('getGeneType', () => {
tsg_review: { lastReviewed: '', updatedBy: '', updateTime: 0 },
},
},
'type/ocg',
{
hugoSymbol: 'name',
tsg: false,
oncogene: false,
oncogene: true,
},
],
[
{
name: 'name',
type: { ocg: GENE_TYPE.ONCOGENE, tsg: '', tsg_review: { lastReviewed: GENE_TYPE.TUMOR_SUPPRESSOR, updatedBy: '', updateTime: 0 } },
},
'type/ocg',
{
hugoSymbol: 'name',
tsg: true,
oncogene: true,
},
],
[
{
name: 'name',
type: { ocg: GENE_TYPE.ONCOGENE, tsg: '', tsg_review: { lastReviewed: GENE_TYPE.TUMOR_SUPPRESSOR, updatedBy: '', updateTime: 0 } },
},
'type/tsg',
{
hugoSymbol: 'name',
tsg: false,
oncogene: true,
},
],
[
{
name: 'name',
type: { ocg: '', ocg_review: { lastReviewed: GENE_TYPE.ONCOGENE, updatedBy: '', updateTime: 0 }, tsg: GENE_TYPE.TUMOR_SUPPRESSOR },
},
'type/ocg',
{
hugoSymbol: 'name',
tsg: true,
oncogene: false,
},
],
[
{
name: 'name',
type: { ocg: '', ocg_review: { lastReviewed: GENE_TYPE.ONCOGENE, updatedBy: '', updateTime: 0 }, tsg: GENE_TYPE.TUMOR_SUPPRESSOR },
},
'type/tsg',
{
hugoSymbol: 'name',
tsg: true,
Expand All @@ -52,6 +85,7 @@ describe('getGeneType', () => {
],
[
{ name: 'name', type: { ocg: '', tsg: GENE_TYPE.TUMOR_SUPPRESSOR } },
'type/tsg',
{
hugoSymbol: 'name',
tsg: true,
Expand All @@ -60,6 +94,7 @@ describe('getGeneType', () => {
],
[
{ name: 'name', type: { ocg: '', tsg: '' } },
'type/tsg',
{
hugoSymbol: 'name',
tsg: false,
Expand All @@ -68,7 +103,7 @@ describe('getGeneType', () => {
],
];

test.each(tests)('Should map to payload correctly %j', (args, expected) => {
expect(createGeneTypePayload(args)).toEqual(expected);
test.each(tests)('Should map to payload correctly %j with value path "%s"', (gene, valuePath, expected) => {
expect(createGeneTypePayload(gene, valuePath)).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { useLastReviewedOnly } from '../core-submission-shared/core-submission-u

export function createGeneTypePayload(
originalGene: Pick<Gene, 'name'> & { type: Pick<Gene['type'], 'ocg' | 'ocg_review' | 'tsg' | 'tsg_review'> },
valuePath: string,
): Required<Pick<GenePayload, 'hugoSymbol' | 'oncogene' | 'tsg'>> {
const gene = useLastReviewedOnly(originalGene);
const gene = useLastReviewedOnly(originalGene, valuePath);
return {
hugoSymbol: gene!.name,
oncogene: gene!.type.ocg ? true : false,
tsg: gene!.type.tsg ? true : false,
};
}

export function removeGenePayload(gene: Pick<Gene, 'name'>): Required<Pick<GenePayload, 'hugoSymbol'>> {
return {
hugoSymbol: gene.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
import { Review } from 'app/shared/model/firebase/firebase.model';

export function useLastReviewedOnly<T>(obj: T): T | undefined {
function useLastReviewedOnlyRec(curObj: T): T | undefined {
function shouldProtect(valuePath: string | undefined, path: string) {
return valuePath !== undefined && path.length > 0 && (path.startsWith(valuePath) || valuePath.startsWith(path));
}

export function useLastReviewedOnly<T>(obj: T, valuePath?: string): T | undefined {
function useLastReviewedOnlyRec(curObj: T, parentPath: string): T | undefined {
const newObj: T = {} as T;
for (const [key, value] of Object.entries(curObj as Record<string, unknown>)) {
const currentPath = `${parentPath}${parentPath.length > 0 ? '/' : ''}${key}`;
const protectCurrent = shouldProtect(valuePath, currentPath);
const protectParent = shouldProtect(valuePath, parentPath);

if (key.endsWith('_review')) {
const temp: Review = Object.assign({} as Review, value);
if (temp?.added) {
return undefined;
}
(newObj as Record<string, unknown>)[key] = temp;
} else if (Array.isArray(value)) {
const reviewObj: Review | undefined = curObj[`${key}_review`] as Review;
if (reviewObj?.added) {
if (reviewObj?.added && !protectParent) {
return undefined;
}
const arr: T[] = [];
const arr: (T | undefined)[] = [];
let i = 0;
for (const arrObj of value) {
const temp = useLastReviewedOnlyRec(arrObj);
if (temp !== undefined) {
const temp = useLastReviewedOnlyRec(arrObj, `${currentPath}/${i}`);
if (temp !== undefined || protectParent) {
arr.push(temp);
}
i++;
}
(newObj as Record<string, unknown>)[key] = arr;
} else if (typeof value === 'object') {
(newObj as Record<string, unknown>)[key] = useLastReviewedOnlyRec(value as T);
(newObj as Record<string, unknown>)[key] = useLastReviewedOnlyRec(value as T, currentPath);
} else {
const reviewObj: Review | undefined = curObj[`${key}_review`] as Review;
if (!reviewObj?.added) {
if (protectCurrent) {
(newObj as Record<string, unknown>)[key] = value;
} else if (!reviewObj?.added || protectParent) {
(newObj as Record<string, unknown>)[key] = reviewObj?.lastReviewed !== undefined ? reviewObj.lastReviewed : value;
} else {
return undefined;
Expand All @@ -36,5 +45,5 @@ export function useLastReviewedOnly<T>(obj: T): T | undefined {
}
return newObj;
}
return useLastReviewedOnlyRec(obj);
return useLastReviewedOnlyRec(obj, '');
}

0 comments on commit 49c04b0

Please sign in to comment.