Skip to content

Commit

Permalink
Show a Delivery Date column in the cohort samples popup (#116)
Browse files Browse the repository at this point in the history
* Modify samples query to also return cohort dates

* Expose the earliest cohort date of each sample in the cohort samples popup

* Display a Delivery Date column in the cohort samples popup

* Rename functions that extract data from samples query for clarity

* Consolidate field data getters to getSampleCohortDataFromSamplesQuery

Remove logic that get specific field data from the column definitions
and consolidate it to the getSampleCohortDataFromSamplesQuery function.
  • Loading branch information
qu8n authored Mar 27, 2024
1 parent 2e8ca2a commit ba77d40
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 27 deletions.
12 changes: 11 additions & 1 deletion frontend/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10785,7 +10785,14 @@ export type FindSamplesByInputValueQuery = {
__typename?: "SampleCohortsHasCohortSampleConnection";
edges: Array<{
__typename?: "SampleCohortsHasCohortSampleRelationship";
node: { __typename?: "Cohort"; cohortId: string };
node: {
__typename?: "Cohort";
cohortId: string;
hasCohortCompleteCohortCompletes: Array<{
__typename?: "CohortComplete";
date: string;
}>;
};
}>;
};
hasTempoTempos: Array<{
Expand Down Expand Up @@ -11280,6 +11287,9 @@ export const FindSamplesByInputValueDocument = gql`
edges {
node {
cohortId
hasCohortCompleteCohortCompletes {
date
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/cohorts/CohortsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
CohortsListColumns,
cohortSampleFilterWhereVariables,
defaultReadOnlyColDef,
getCohortDataFromSamples,
getSampleCohortDataFromSamplesQuery,
handleSearch,
} from "../../shared/helpers";
import RecordsList from "../../components/RecordsList";
Expand Down Expand Up @@ -141,7 +141,7 @@ export default function CohortsPage() {
sampleQueryParamValue &&
`${sampleQueryParamHeaderName} "${sampleQueryParamValue}"`
}
getSamplesRowData={getCohortDataFromSamples}
getSamplesRowData={getSampleCohortDataFromSamplesQuery}
samplesParentWhereVariables={
{
cohortsHasCohortSampleConnection_SOME: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/patients/PatientsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
PatientsListColumns,
SampleDetailsColumns,
defaultEditableColDef,
getMetadataFromSamples,
getSampleMetadataFromSamplesQuery,
sampleFilterWhereVariables,
} from "../../shared/helpers";
import { getUserEmail } from "../../utils/getUserEmail";
Expand Down Expand Up @@ -292,7 +292,7 @@ export default function PatientsPage({
sampleQueryParamValue &&
`${sampleQueryParamHeaderName} ${sampleQueryParamValue}`
}
getSamplesRowData={getMetadataFromSamples}
getSamplesRowData={getSampleMetadataFromSamplesQuery}
samplesParentWhereVariables={
{
OR: [
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/requests/RequestsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RequestsListColumns,
SampleDetailsColumns,
defaultEditableColDef,
getMetadataFromSamples,
getSampleMetadataFromSamplesQuery,
handleSearch,
sampleFilterWhereVariables,
} from "../../shared/helpers";
Expand Down Expand Up @@ -90,7 +90,7 @@ export default function RequestsPage() {
sampleQueryParamValue &&
`${sampleQueryParamHeaderName} ${sampleQueryParamValue}`
}
getSamplesRowData={getMetadataFromSamples}
getSamplesRowData={getSampleMetadataFromSamplesQuery}
samplesParentWhereVariables={
{
hasMetadataSampleMetadata_SOME: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/samples/SamplesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SamplesList from "../../components/SamplesList";
import {
SampleDetailsColumns,
defaultEditableColDef,
getMetadataFromSamples,
getSampleMetadataFromSamplesQuery,
sampleFilterWhereVariables,
} from "../../shared/helpers";
import { SampleWhere } from "../../generated/graphql";
Expand All @@ -16,7 +16,7 @@ export default function SamplesPage() {
<SamplesList
columnDefs={SampleDetailsColumns}
defaultColDef={defaultEditableColDef}
getRowData={getMetadataFromSamples}
getRowData={getSampleMetadataFromSamplesQuery}
refetchWhereVariables={(parsedSearchVals) => {
return {
hasMetadataSampleMetadata_SOME: {
Expand Down
72 changes: 55 additions & 17 deletions frontend/src/shared/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,40 +576,44 @@ export const CohortSamplesDetailsColumns: ColDef[] = [
headerName: "CMO Sample Name",
},
{
field: "deliveryDate",
headerName: "Delivery Date",
},
{
field: "bamCompleteDate",
headerName: "BAM Complete Date",
valueGetter: ({ data }) => data.bamComplete?.date,
},
{
field: "bamCompleteStatus",
headerName: "BAM Complete Status",
valueGetter: ({ data }) => data.bamComplete?.status,
},
{
field: "mafCompleteDate",
headerName: "MAF Complete Date",
valueGetter: ({ data }) => data.mafComplete?.date,
},
{
field: "mafCompleteNormalPrimaryId",
headerName: "MAF Complete Normal Primary ID",
valueGetter: ({ data }) => data.mafComplete?.normalPrimaryId,
},
{
field: "mafCompleteStatus",
headerName: "MAF Complete Status",
valueGetter: ({ data }) => data.mafComplete?.status,
},
{
field: "qcCompleteDate",
headerName: "QC Complete Date",
valueGetter: ({ data }) => data.qcComplete?.date,
},
{
field: "qcCompleteResult",
headerName: "QC Complete Result",
valueGetter: ({ data }) => data.qcComplete?.result,
},
{
field: "qcCompleteReason",
headerName: "QC Complete Reason",
valueGetter: ({ data }) => data.qcComplete?.reason,
},
{
field: "qcCompleteStatus",
headerName: "QC Complete Status",
valueGetter: ({ data }) => data.qcComplete?.status,
},
];

Expand Down Expand Up @@ -823,23 +827,57 @@ export function cohortSampleFilterWhereVariables(
];
}

export function getMetadataFromSamples(samples: Sample[]) {
return samples.map((s: any) => {
export function getSampleMetadataFromSamplesQuery(samples: Sample[]) {
return samples.map((s) => {
return {
...s.hasMetadataSampleMetadata[0],
revisable: s.revisable,
};
});
}

export function getCohortDataFromSamples(samples: Sample[]) {
return samples.map((s: any) => {
export function getSampleCohortDataFromSamplesQuery(samples: Sample[]) {
return samples.map((s) => {
const cohorts = s.cohortsHasCohortSampleConnection?.edges;
const cohortDates = cohorts?.flatMap((c) => {
return c.node.hasCohortCompleteCohortCompletes.map((cc) => {
return cc.date;
});
});
const deliveryDate = cohortDates?.sort()[0]; // earliest cohort date

const tempo = s.hasTempoTempos?.[0];
const bamComplete = tempo?.hasEventBamCompletes?.[0];
const { date: bamCompleteDate, status: bamCompleteStatus } =
bamComplete ?? {};

const mafComplete = tempo?.hasEventMafCompletes?.[0];
const {
date: mafCompleteDate,
status: mafCompleteStatus,
normalPrimaryId: mafCompleteNormalPrimaryId,
} = mafComplete ?? {};

const qcComplete = tempo?.hasEventQcCompletes?.[0];
const {
date: qcCompleteDate,
result: qcCompleteResult,
reason: qcCompleteReason,
status: qcCompleteStatus,
} = qcComplete ?? {};

return {
...s.hasMetadataSampleMetadata[0],
revisable: s.revisable,
bamComplete: s.hasTempoTempos[0].hasEventBamCompletes[0],
mafComplete: s.hasTempoTempos[0].hasEventMafCompletes[0],
qcComplete: s.hasTempoTempos[0].hasEventQcCompletes[0],
deliveryDate,
bamCompleteDate,
bamCompleteStatus,
mafCompleteDate,
mafCompleteStatus,
mafCompleteNormalPrimaryId,
qcCompleteDate,
qcCompleteResult,
qcCompleteReason,
qcCompleteStatus,
};
});
}
Expand Down
12 changes: 11 additions & 1 deletion graphql-server/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10784,7 +10784,14 @@ export type FindSamplesByInputValueQuery = {
__typename?: "SampleCohortsHasCohortSampleConnection";
edges: Array<{
__typename?: "SampleCohortsHasCohortSampleRelationship";
node: { __typename?: "Cohort"; cohortId: string };
node: {
__typename?: "Cohort";
cohortId: string;
hasCohortCompleteCohortCompletes: Array<{
__typename?: "CohortComplete";
date: string;
}>;
};
}>;
};
hasTempoTempos: Array<{
Expand Down Expand Up @@ -11181,6 +11188,9 @@ export const FindSamplesByInputValueDocument = gql`
edges {
node {
cohortId
hasCohortCompleteCohortCompletes {
date
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions graphql/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ query FindSamplesByInputValue(
edges {
node {
cohortId
hasCohortCompleteCohortCompletes {
date
}
}
}
}
Expand Down

0 comments on commit ba77d40

Please sign in to comment.