Skip to content

Commit

Permalink
Handle PHI search
Browse files Browse the repository at this point in the history
  • Loading branch information
qu8n committed Nov 1, 2024
1 parent 52213a6 commit 253c2bb
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 161 deletions.
55 changes: 22 additions & 33 deletions frontend/src/components/NewRecordsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@ 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,
IServerSideGetRowsRequest,
} from "ag-grid-community";
import { ColDef, IServerSideGetRowsParams } from "ag-grid-community";
import { DataName, useHookLazyGeneric } from "../shared/types";
import SamplesList, { SampleContext } from "./SamplesList";
import {
DashboardRecordFilter,
DashboardRecordSort,
PatientIdsTriplet,
QueryDashboardPatientsArgs,
SortDirection,
} from "../generated/graphql";
import { defaultColDef } from "../shared/helpers";
import { PatientIdsTriplet } from "../pages/patients/PatientsPage";
import { ErrorMessage, Toolbar } from "../shared/tableElements";
import { AgGridReact as AgGridReactType } from "ag-grid-react/lib/agGridReact";
import { BreadCrumb } from "../shared/components/BreadCrumb";
Expand All @@ -42,29 +37,19 @@ interface INewRecordsListProps {
dataName: DataName;
enableInfiniteScroll?: boolean;
lazyRecordsQuery: typeof useHookLazyGeneric;
lazyRecordsQueryAddlVariables?: Record<string, any>;
prepareDataForAgGrid?: (
data: any,
filterModel: IServerSideGetRowsRequest["filterModel"],
sortModel?: { [key: string]: SortDirection }[] | undefined
) => any;
queryFilterWhereVariables: (
parsedSearchVals: string[]
) => Record<string, any>[];
defaultSort: DashboardRecordSort;
userSearchVal: string;
setUserSearchVal: Dispatch<SetStateAction<string>>;
parsedSearchVals: string[];
setParsedSearchVals: Dispatch<SetStateAction<string[]>>;
handleSearch: () => void;
customSearchStates?: PatientIdsTriplet[];
setCustomSearchStates?: Dispatch<SetStateAction<PatientIdsTriplet[]>>;
searchInterceptor?: (userSearchVal: string) => Promise<string[]>;
showDownloadModal: boolean;
setShowDownloadModal: Dispatch<SetStateAction<boolean>>;
handleDownload: (recordCount: number) => void;
samplesColDefs: ColDef[];
sampleContext?: SampleContext;
userEmail?: string | null;
setUserEmail?: Dispatch<SetStateAction<string | null>>;
setCustomSearchVals?: Dispatch<SetStateAction<PatientIdsTriplet[]>>;
customToolbarUI?: JSX.Element;
}

Expand All @@ -76,9 +61,9 @@ export default function NewRecordsList({
defaultSort,
userSearchVal,
setUserSearchVal,
parsedSearchVals,
setParsedSearchVals,
handleSearch,
customSearchStates,
setCustomSearchStates,
searchInterceptor,
showDownloadModal,
setShowDownloadModal,
handleDownload,
Expand All @@ -87,7 +72,6 @@ export default function NewRecordsList({
userEmail,
setUserEmail,
customToolbarUI,
setCustomSearchVals,
}: INewRecordsListProps) {
const [showClosingWarning, setShowClosingWarning] = useState(false);
const [unsavedChanges, setUnsavedChanges] = useState(false);
Expand All @@ -114,7 +98,7 @@ export default function NewRecordsList({
const recordCount = data?.[recordCountQueryName]?.totalCount;

const getServerSideDatasource = useCallback(
({ userSearchVal }) => {
({ searchVals }) => {
return {
getRows: async (params: IServerSideGetRowsParams) => {
let filter: DashboardRecordFilter | undefined;
Expand All @@ -129,7 +113,7 @@ export default function NewRecordsList({
}

const fetchInput = {
searchVals: parseUserSearchVal(userSearchVal),
searchVals,
sort: params.request.sortModel[0] || defaultSort,
filter,
offset: params.request.startRow ?? -1,
Expand Down Expand Up @@ -160,11 +144,15 @@ export default function NewRecordsList({
[defaultSort, refetch, fetchMore, recordsQueryName, recordCountQueryName]
);

function refreshData(userSearchVal: string) {
const newDatasource = getServerSideDatasource({
userSearchVal,
sampleContext,
});
async function refreshData(userSearchVal: string) {
const extraSearchVals = searchInterceptor
? await searchInterceptor(userSearchVal)
: [];
const searchVals = [
...parseUserSearchVal(userSearchVal),
...extraSearchVals,
];
const newDatasource = getServerSideDatasource({ searchVals });
gridRef.current?.api.setServerSideDatasource(newDatasource); // triggers a refresh
}

Expand Down Expand Up @@ -268,11 +256,12 @@ export default function NewRecordsList({
dataName={dataName}
userSearchVal={userSearchVal}
setUserSearchVal={setUserSearchVal}
refreshData={(userSearchVal) => refreshData(userSearchVal)}
setCustomSearchStates={setCustomSearchStates}
onSearch={async (userSearchVal) => refreshData(userSearchVal)}
matchingResultsCount={`${
recordCount !== undefined ? recordCount.toLocaleString() : "Loading"
} matching ${dataName}`}
handleDownload={() => handleDownload(recordCount)}
onDownload={() => handleDownload(recordCount)}
customUIRight={customToolbarUI}
/>

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/RecordsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import {
} from "ag-grid-community";
import { DataName, useHookLazyGeneric } from "../shared/types";
import SamplesList, { SampleContext } from "./SamplesList";
import { SortDirection } from "../generated/graphql";
import { PatientIdsTriplet, SortDirection } from "../generated/graphql";
import { defaultColDef } from "../shared/helpers";
import { PatientIdsTriplet } from "../pages/patients/PatientsPage";
import {
ErrorMessage,
LoadingSpinner,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SamplesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ export default function SamplesList({
dataName={"samples"}
userSearchVal={userSearchVal}
setUserSearchVal={setUserSearchVal}
refreshData={(userSearchVal) => refreshData(userSearchVal)}
onSearch={(userSearchVal) => refreshData(userSearchVal)}
matchingResultsCount={`${
sampleCount !== undefined ? sampleCount.toLocaleString() : "Loading"
} matching samples`}
handleDownload={() => {
onDownload={() => {
if (sampleCount && sampleCount > MAX_ROWS_EXPORT) {
setAlertContent(MAX_ROWS_EXPORT_EXCEED_ALERT);
} else {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3209,9 +3209,9 @@ export type PatientHasSampleSamplesUpdateFieldInput = {

export type PatientIdsTriplet = {
__typename?: "PatientIdsTriplet";
CMO_ID?: Maybe<Scalars["String"]>;
CMO_ID: Scalars["String"];
DMP_ID?: Maybe<Scalars["String"]>;
PT_MRN?: Maybe<Scalars["String"]>;
PT_MRN: Scalars["String"];
};

export type PatientOptions = {
Expand Down Expand Up @@ -12724,9 +12724,9 @@ export type GetPatientIdsTripletsQuery = {
__typename?: "Query";
patientIdsTriplets?: Array<{
__typename?: "PatientIdsTriplet";
CMO_ID?: string | null;
CMO_ID: string;
DMP_ID?: string | null;
PT_MRN?: string | null;
PT_MRN: string;
} | null> | null;
};

Expand Down
Loading

0 comments on commit 253c2bb

Please sign in to comment.