-
Notifications
You must be signed in to change notification settings - Fork 7
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
Use reviewed content only #430
Changes from 7 commits
bda4656
4f1e315
b5585a5
260028a
d91679c
7774361
eb4677d
ba32091
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import _ from 'lodash'; | ||
import { Drug, Gene, Mutation, Review, Treatment, Tumor, Vus, DrugCollection } from '../../model/firebase/firebase.model'; | ||
import { useLastReviewedOnly } from '../core-submission-shared/core-submission-utils'; | ||
|
||
export function getGeneData(geneData: Gene, onlyReviewedContent: boolean, drugList: DrugCollection): true | Gene { | ||
const gene = _.cloneDeep(geneData); | ||
processData(gene, ['summary', 'background'], onlyReviewedContent); | ||
processData(gene.type, ['tsg', 'ocg'], onlyReviewedContent); | ||
export function getGeneData(geneData: Gene, drugList: DrugCollection): Gene | undefined { | ||
const gene = useLastReviewedOnly(geneData); | ||
if (gene === undefined) { | ||
return undefined; | ||
} | ||
processData(gene, ['summary', 'background']); | ||
processData(gene.type, ['tsg', 'ocg']); | ||
const tempMutations: Mutation[] = []; | ||
for (const mutation of gene.mutations ?? []) { | ||
const tempTumors: Tumor[] = []; | ||
if (shouldExclude(onlyReviewedContent, mutation.name_review)) { | ||
if (shouldExclude(mutation.name_review)) { | ||
tempMutations.push(mutation); | ||
continue; | ||
} | ||
processData(mutation, ['name'], onlyReviewedContent); | ||
processData(mutation.mutation_effect, ['oncogenic', 'effect', 'description'], onlyReviewedContent); | ||
processData(mutation, ['name']); | ||
processData(mutation.mutation_effect, ['oncogenic', 'effect', 'description']); | ||
for (const tumor of mutation.tumors ?? []) { | ||
if (shouldExclude(onlyReviewedContent, tumor.cancerTypes_review)) { | ||
if (shouldExclude(tumor.cancerTypes_review)) { | ||
tempTumors.push(tumor); | ||
continue; | ||
} | ||
// process tumor cancerTypes | ||
processData(tumor, ['summary', 'diagnosticSummary', 'prognosticSummary'], onlyReviewedContent); | ||
processData(tumor.diagnostic, ['level', 'description', 'excludedRCTs'], onlyReviewedContent); | ||
processData(tumor.prognostic, ['level', 'description', 'excludedRCTs'], onlyReviewedContent); | ||
processData(tumor, ['summary', 'diagnosticSummary', 'prognosticSummary']); | ||
processData(tumor.diagnostic, ['level', 'description', 'excludedRCTs']); | ||
processData(tumor.prognostic, ['level', 'description', 'excludedRCTs']); | ||
for (const ti of tumor.TIs) { | ||
type TempTreatment = Omit<Treatment, 'name'> & { name: ReturnType<typeof drugUuidToDrug> | string }; | ||
const tempTreatments: TempTreatment[] = []; | ||
for (const treatment of ti.treatments ?? []) { | ||
if (shouldExclude(onlyReviewedContent, treatment.name_review)) { | ||
if (shouldExclude(treatment.name_review)) { | ||
tempTreatments.push(treatment); | ||
return true; | ||
return undefined; | ||
} | ||
(treatment as TempTreatment).name = drugUuidToDrug(treatment.name, drugList); | ||
processData( | ||
treatment, | ||
['level', 'propagation', 'propagationLiquid', 'indication', 'description', 'fdaLevel'], | ||
onlyReviewedContent, | ||
); | ||
processData(treatment, ['level', 'propagation', 'propagationLiquid', 'indication', 'description', 'fdaLevel']); | ||
} | ||
for (const item of tempTreatments) { | ||
const index = ti.treatments.indexOf(item as Treatment); | ||
|
@@ -62,20 +62,18 @@ export function getGeneData(geneData: Gene, onlyReviewedContent: boolean, drugLi | |
return gene; | ||
} | ||
|
||
function processData<T, K extends keyof T & string>(data: T | undefined, keys: K[], onlyReviewedContent: boolean) { | ||
function processData<T, K extends keyof T & string>(data: T | undefined, keys: K[]) { | ||
if (data !== undefined) { | ||
for (const key of keys) { | ||
delete data?.[key + '_comments']; | ||
const reviewKey = key + '_review'; | ||
const maybeReview = data?.[reviewKey]; | ||
if ( | ||
data !== null && | ||
onlyReviewedContent && | ||
typeof maybeReview === 'object' && | ||
maybeReview !== null && | ||
'lastReviewed' in maybeReview | ||
) { | ||
data[key] = maybeReview.lastReviewed; | ||
const maybeReview: Review | null | undefined = data?.[reviewKey]; | ||
if (data !== null && typeof maybeReview === 'object' && maybeReview !== null) { | ||
if (maybeReview.added) { | ||
delete data[key]; | ||
} else if ('lastReviewed' in maybeReview) { | ||
data[key] = maybeReview.lastReviewed as (T & object)[K]; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -91,12 +89,8 @@ export function getVUSData(vus: Vus[]) { | |
return vusDataArray; | ||
} | ||
|
||
function shouldExclude(onlyReviewedContent: boolean, reviewObj: Review | undefined) { | ||
return ( | ||
reviewObj && | ||
((onlyReviewedContent && reviewObj.added === true && reviewObj.promotedToMutation === true && reviewObj.initialUpdate === true) || | ||
(!onlyReviewedContent && reviewObj.removed === true)) | ||
); | ||
function shouldExclude(reviewObj: Review | undefined) { | ||
return reviewObj && reviewObj.added === true && reviewObj.promotedToMutation === true && reviewObj.initialUpdate === true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the comment in firebase.model.ts, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this appears to be the case. I also couldn't find where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
function drugUuidToDrug(key: string | undefined, drugList: DrugCollection): Drug[][] | Record<string, unknown> { | ||
|
@@ -138,10 +132,13 @@ export function getDriveAnnotations( | |
{ gene, vus, releaseGene }: { gene: Gene | undefined; vus: Vus[] | undefined; releaseGene: boolean }, | ||
): DriveAnnotation { | ||
const params: DriveAnnotation = { gene: undefined, vus: undefined, releaseGene: false }; | ||
if (gene) { | ||
params.gene = JSON.stringify(getGeneData(gene, true, drugList)); | ||
if (gene !== undefined) { | ||
const geneData = getGeneData(gene, drugList); | ||
if (geneData !== undefined) { | ||
params.gene = JSON.stringify(geneData); | ||
} | ||
} | ||
if (vus) { | ||
if (vus !== undefined) { | ||
params.vus = JSON.stringify(getVUSData(vus)); | ||
} | ||
if (releaseGene) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.