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 backwards compatible kbmatch table loading #586

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions app/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type KbMatchedStatementType<T extends KbMatchType = KbMatchType> = {
kbData: {
inferred: boolean;
recruitment_status: string;
kbmatchTag: string | null;
} | null;
kbMatches: T[];
kbStatementId: string;
Expand Down
172 changes: 93 additions & 79 deletions app/views/ReportView/components/KbMatches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,64 @@ const KbMatches = ({
try {
const baseUri = `/reports/${report.ident}/kb-matches/kb-matched-statements`;
const apiCalls = new ApiCallSet([
api.get(`${baseUri}?approvedTherapy=false&category=therapeutic`, {}),
api.get(`${baseUri}?approvedTherapy=false&category=biological`, {}),
api.get(`${baseUri}?approvedTherapy=false&category=diagnostic`, {}),
api.get(`${baseUri}?approvedTherapy=false&category=prognostic`, {}),
api.get(`${baseUri}?category=unknown,novel`, {}),
api.get(`${baseUri}?approvedTherapy=true&category=therapeutic&matchedCancer=true&iprEvidenceLevel=IPR-A,IPR-B`, {}),
api.get(`/reports/${report.ident}/probe-results`, {}),
api.get(`${baseUri}?category=pharmacogenomic`, {}),
api.get(`${baseUri}?category=cancer predisposition`, {}),
api.get(`${baseUri}`, {}),
]);

const [
therapeuticResp,
biologicalResp,
diagnosticResp,
prognosticResp,
unknownResp,
highEvidenceResp,
targetedSomaticGenesResp,
pharmacogenomicResp,
cancerPredisResp,
allKbMatchesResp,
] = await apiCalls.request() as [
KbMatchedStatementType[],
KbMatchedStatementType[],
KbMatchedStatementType[],
KbMatchedStatementType[],
KbMatchedStatementType[],
KbMatchedStatementType[],
ProbeResultsType[],
KbMatchedStatementType[],
KbMatchedStatementType[],
];

// TODO this is here for backwards compatibility; consider removing after datafix
const oldStmts = allKbMatchesResp.filter(stmt => !stmt.kbData?.kbmatchTag);
const oldHighEvidence = oldStmts.filter(item =>
item.category === 'therapeutic' &&
item.approvedTherapy &&
item.matchedCancer &&
['IPR-A', 'IPR-B'].includes(item?.iprEvidenceLevel)
);

// therapeutic but not best therapeutic. might be inconsistent with existing filtering -
// currently items that are therapeutic and approved but not with high evidence level are just
// not displayed (there may currently not be any such items). the difference will be
// that some items that were not previously displayed at all might now be displayed
// in this table
const oldTherapeutic = oldStmts.filter(item =>
item.category === 'therapeutic' &&
!oldHighEvidence.some(obj => obj.ident === item.ident)
);

// might be inconsistent with existing filtering - currently items that have
// 'approvedTherapy' True but not category 'therapeutic' are not displayed.
// (there are no examples in the db currently). here, we ignore approvedTherapy
// except for therapeutic stmts, so it's possible for items that previously
// would never be displayed, to be displayed here
const oldBiological = oldStmts.filter(item => item.category === 'biological')
const oldDiagnostic = oldStmts.filter(item => item.category === 'diagnostic')
const oldPrognostic = oldStmts.filter(item => item.category === 'prognostic')
const oldPcp = oldStmts.filter(item => ['cancer-predisposition', 'pharmacogenomic'].includes(item.category))

const taggedKbMatches = allKbMatchesResp.filter((stmt) => stmt?.kbData?.kbmatchTag)

const highEvidence = coalesceEntries([...oldHighEvidence, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'bestTherapeutic')])
const therapeutic = coalesceEntries([...oldTherapeutic, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'therapeutic')])
const biological = coalesceEntries([...oldBiological, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'biological')])
const diagnostic = coalesceEntries([...oldDiagnostic, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'diagnostic')])
const prognostic = coalesceEntries([...oldPrognostic, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'prognostic')])
const targetedGermlineGenes = coalesceEntries([...oldPcp, ...taggedKbMatches.filter((stmt) => stmt?.kbData?.kbmatchTag === 'pcp')])

setGroupedMatches({
highEvidence: coalesceEntries(highEvidenceResp),
therapeutic: coalesceEntries(therapeuticResp),
biological: coalesceEntries(biologicalResp),
diagnostic: coalesceEntries(diagnosticResp),
prognostic: coalesceEntries(prognosticResp),
unknown: coalesceEntries(unknownResp),
targetedGermlineGenes: coalesceEntries([
...pharmacogenomicResp,
...cancerPredisResp.filter(({ kbMatches }) => (kbMatches as any)?.variant?.germline),
]),
highEvidence,
therapeutic,
biological,
diagnostic,
prognostic,
targetedGermlineGenes,
unknown: coalesceEntries(allKbMatchesResp.filter((stmt) => ![...highEvidence, ...therapeutic, ...biological, ...diagnostic, ...prognostic, ...targetedGermlineGenes].some(obj => obj.ident === stmt.ident))),
targetedSomaticGenes: targetedSomaticGenesResp.filter((tg) => !/germline/.test(tg?.sample)),
});
} catch (err) {
Expand Down Expand Up @@ -176,59 +190,59 @@ const KbMatches = ({
const kbMatchedTables = useMemo(() => Object.keys(TITLE_MAP).map((key) => (
<React.Fragment key={key}>
{
(
(report?.template.name !== 'probe' && report?.template.name !== 'rapid')
|| (key !== 'targetedSomaticGenes' && key !== 'targetedGermlineGenes')
) && (
<DataTable
canDelete={canEdit}
canToggleColumns
columnDefs={(key === 'targetedSomaticGenes') ? targetedColumnDefs : columnDefs}
filterText={debouncedFilterText}
isPrint={isPrint}
onDelete={handleDelete}
rowData={groupedMatches[key]}
titleText={TITLE_MAP[key]}
/>
)
}
(
(report?.template.name !== 'probe' && report?.template.name !== 'rapid')
|| (key !== 'targetedSomaticGenes' && key !== 'targetedGermlineGenes')
) && (
<DataTable
canDelete={canEdit}
canToggleColumns
columnDefs={(key === 'targetedSomaticGenes') ? targetedColumnDefs : columnDefs}
filterText={debouncedFilterText}
isPrint={isPrint}
onDelete={handleDelete}
rowData={groupedMatches[key]}
titleText={TITLE_MAP[key]}
/>
)
}
</React.Fragment>
)), [canEdit, debouncedFilterText, groupedMatches, handleDelete, isPrint, report?.template.name]);

return (
!isLoading && (
<div>
<DemoDescription>
Tumour alterations with specific therapeutic, prognostic, diagnostic or biological
associations are identified using the knowledgebase GraphKB, which integrates information
from sources including cancer databases, drug databases, clinical tests, and the literature.
Associations are listed by the level of evidence for the use of that drug in the context of
the observed alteration, including those that are approved in this or other cancer types,
and those that have early clinical or preclinical evidence.
</DemoDescription>
{!isPrint && (
<div className="kb-matches__filter">
<TextField
label="Filter Table Text"
type="text"
variant="outlined"
value={filterText}
onChange={handleFilter}
fullWidth
InputProps={{
endAdornment: (
<InputAdornment position="end">
<FilterList color="action" />
</InputAdornment>
),
}}
/>
</div>
)}
<div>
{kbMatchedTables}
<DemoDescription>
Tumour alterations with specific therapeutic, prognostic, diagnostic or biological
associations are identified using the knowledgebase GraphKB, which integrates information
from sources including cancer databases, drug databases, clinical tests, and the literature.
Associations are listed by the level of evidence for the use of that drug in the context of
the observed alteration, including those that are approved in this or other cancer types,
and those that have early clinical or preclinical evidence.
</DemoDescription>
{!isPrint && (
<div className="kb-matches__filter">
<TextField
label="Filter Table Text"
type="text"
variant="outlined"
value={filterText}
onChange={handleFilter}
fullWidth
InputProps={{
endAdornment: (
<InputAdornment position="end">
<FilterList color="action" />
</InputAdornment>
),
}}
/>
</div>
)}
<div>
{kbMatchedTables}
</div>
</div>
</div>
)
);
};
Expand Down