Skip to content

Commit

Permalink
Fix: duplicate records on Patients page (#119)
Browse files Browse the repository at this point in the history
* Modify RecordsList to accept an optional prepareDataForAgGrid function

* Modify PatientsList query to return Patients, not PatientAliases

* Render unique Patients on the Patients page

* Remove nodeName prop from RecordsList component

* Render Samples popup on Patients page by smilePatientId

* Decouple value getters from Patients' AG Grid column definitions

* Temporarily rename Patient Sample view's heading to Viewing Patient's Samples

* Do minor cleanups

* Update the MRN column definition to correctly access CMO Patient ID
  • Loading branch information
qu8n authored Apr 23, 2024
1 parent 93882e1 commit 31df4fa
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 419 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function App() {
<PatientsPage userEmail={userEmail} setUserEmail={setUserEmail} />
}
>
<Route path=":cmoPatientId" />
<Route path=":smilePatientId" />
</Route>
<Route path="/samples" element={<SamplesPage />} />
<Route
Expand Down
39 changes: 24 additions & 15 deletions frontend/src/components/RecordsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ import styles from "./records.module.scss";
import "ag-grid-community/styles/ag-grid.css";
import "ag-grid-community/styles/ag-theme-alpine.css";
import "ag-grid-enterprise";
import { ColDef, IServerSideGetRowsParams } from "ag-grid-community";
import {
ColDef,
IServerSideDatasource,
IServerSideGetRowsParams,
} from "ag-grid-community";
import { DataName, useHookLazyGeneric } from "../shared/types";
import SamplesList from "./SamplesList";
import { Sample, SampleWhere } from "../generated/graphql";
import { defaultColDef } from "../shared/helpers";
import {
defaultColDef,
prepareSampleMetadataForAgGrid,
} from "../shared/helpers";
import { PatientIdsTriplet } from "../pages/patients/PatientsPage";
import { ErrorMessage, LoadingSpinner, Toolbar } from "../shared/tableElements";

interface IRecordsListProps {
colDefs: ColDef[];
dataName: DataName;
nodeName?: string;
lazyRecordsQuery: typeof useHookLazyGeneric;
lazyRecordsQueryAddlVariables?: Record<string, any>;
prepareDataForAgGrid?: (data: any) => any;
queryFilterWhereVariables: (
parsedSearchVals: string[]
) => Record<string, any>[];
Expand All @@ -36,7 +43,7 @@ interface IRecordsListProps {
setShowDownloadModal: Dispatch<SetStateAction<boolean>>;
handleDownload: () => void;
samplesQueryParam: string | undefined;
getSamplesRowData: (samples: Sample[]) => any[];
prepareSamplesDataForAgGrid?: (samples: Sample[]) => any[];
samplesColDefs: ColDef[];
samplesParentWhereVariables: SampleWhere;
samplesRefetchWhereVariables: (
Expand All @@ -52,9 +59,9 @@ interface IRecordsListProps {
export default function RecordsList({
colDefs,
dataName,
nodeName = dataName,
lazyRecordsQuery,
lazyRecordsQueryAddlVariables,
prepareDataForAgGrid,
queryFilterWhereVariables,
userSearchVal,
setUserSearchVal,
Expand All @@ -65,7 +72,7 @@ export default function RecordsList({
setShowDownloadModal,
handleDownload,
samplesQueryParam,
getSamplesRowData,
prepareSamplesDataForAgGrid = prepareSampleMetadataForAgGrid,
samplesColDefs,
samplesParentWhereVariables,
samplesRefetchWhereVariables,
Expand All @@ -89,17 +96,17 @@ export default function RecordsList({
},
});

const totalCountNodeName = `${nodeName}Connection`;
const totalCountNodeName = `${dataName}Connection`;

const datasource = useMemo(() => {
const datasource: IServerSideDatasource = useMemo(() => {
return {
// called by the grid when more rows are required
getRows: (params: IServerSideGetRowsParams) => {
const fetchInput = {
where: {
OR: queryFilterWhereVariables(parsedSearchVals),
},
[`${nodeName}ConnectionWhere2`]: {
[`${dataName}ConnectionWhere2`]: {
OR: queryFilterWhereVariables(parsedSearchVals),
},
options: {
Expand All @@ -120,10 +127,12 @@ export default function RecordsList({
variables: fetchInput,
});

return thisFetch.then((d: any) => {
return thisFetch.then((d) => {
let data = d.data;
if (prepareDataForAgGrid) data = prepareDataForAgGrid(data);
params.success({
rowData: d.data[nodeName],
rowCount: d.data?.[totalCountNodeName]?.totalCount,
rowData: data[dataName],
rowCount: data[totalCountNodeName].totalCount,
});
});
},
Expand Down Expand Up @@ -161,11 +170,11 @@ export default function RecordsList({
},
},
}).then(({ data }: any) => {
return CSVFormulate(data[nodeName], colDefs);
return CSVFormulate(data[dataName], colDefs);
});
}}
onComplete={() => setShowDownloadModal(false)}
exportFileName={`${nodeName}.tsv`}
exportFileName={`${dataName}.tsv`}
/>
)}

Expand Down Expand Up @@ -218,7 +227,7 @@ export default function RecordsList({
<div className={styles.popupHeight}>
<SamplesList
columnDefs={samplesColDefs}
getRowData={getSamplesRowData}
prepareDataForAgGrid={prepareSamplesDataForAgGrid}
parentWhereVariables={samplesParentWhereVariables}
refetchWhereVariables={samplesRefetchWhereVariables}
setUnsavedChanges={setUnsavedChanges}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/SamplesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const max_rows = 500;

interface ISampleListProps {
columnDefs: ColDef[];
getRowData: (samples: Sample[]) => any[];
prepareDataForAgGrid: (samples: Sample[]) => any[];
setUnsavedChanges?: (unsavedChanges: boolean) => void;
parentWhereVariables?: SampleWhere;
refetchWhereVariables: (parsedSearchVals: string[]) => SampleWhere;
Expand All @@ -45,7 +45,7 @@ interface ISampleListProps {

export default function SamplesList({
columnDefs,
getRowData,
prepareDataForAgGrid,
parentWhereVariables,
refetchWhereVariables,
setUnsavedChanges,
Expand Down Expand Up @@ -206,7 +206,7 @@ export default function SamplesList({
<DownloadModal
loader={() => {
return Promise.resolve(
CSVFormulate(getRowData(samples), columnDefs)
CSVFormulate(prepareDataForAgGrid(samples), columnDefs)
);
}}
onComplete={() => {
Expand Down Expand Up @@ -312,7 +312,7 @@ export default function SamplesList({
},
}}
columnDefs={columnDefs}
rowData={getRowData(samples)}
rowData={prepareDataForAgGrid(samples)}
onCellEditRequest={onCellValueChanged}
readOnlyEdit={true}
defaultColDef={defaultColDef}
Expand Down
Loading

0 comments on commit 31df4fa

Please sign in to comment.