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 bio risk codes to the labware details page #854

Merged
merged 3 commits into from
Dec 16, 2024
Merged
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
19 changes: 9 additions & 10 deletions src/components/RouteLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,20 +501,19 @@ const RouteLayout = () => {
<Route
path="/labware/:barcode"
loader={async ({ params }) => {
// the matching param will be available to the loader
if (params.barcode) {
const res = await stanCore.FindPermData({
barcode: params.barcode
});
const flagDetails = await stanCore.GetLabwareFlagDetails({
barcodes: [params.barcode]
});
const [perData, flagDetails, labwareBioRiskCodes] = await Promise.all([
stanCore.FindPermData({ barcode: params.barcode }),
stanCore.GetLabwareFlagDetails({ barcodes: [params.barcode] }),
stanCore.GetLabwareBioRiskCodes({ barcode: params.barcode })
]);
return {
...res.visiumPermData,
labwareFlagDetails: flagDetails.labwareFlagDetails
...perData.visiumPermData,
labwareFlagDetails: flagDetails.labwareFlagDetails,
labwareBioRiskCodes: labwareBioRiskCodes.labwareBioRiskCodes
};
}
}} // the loader will be called with the params object
}}
element={<LabwareDetails />}
/>
<Route element={<AuthLayout role={UserRole.Enduser} />}>
Expand Down
16 changes: 13 additions & 3 deletions src/components/dataTableColumns/sampleColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Column } from 'react-table';
import {
LabwareFieldsFragment,
LabwareType,
SampleBioRisk,
SampleFieldsFragment,
SamplePositionFieldsFragment
} from '../../types/sdk';
Expand All @@ -13,7 +14,7 @@ import MutedText from '../MutedText';
*/
export type SampleDataTableRow = SampleFieldsFragment & { slotAddress: string } & {
sectionPosition?: string;
} & { barcode?: string } & { labwareType?: LabwareType };
} & { barcode?: string } & { labwareType?: LabwareType } & { bioRiskCode?: string };

type ColumnFactory<E = any> = (meta?: E) => Column<SampleDataTableRow>;

Expand All @@ -34,7 +35,8 @@ const samplePositionMapBySampleIdSlotId = (

export function buildSampleDataTableRows(
labware: LabwareFieldsFragment,
samplePositionResults: SamplePositionFieldsFragment[]
samplePositionResults: SamplePositionFieldsFragment[],
labwareBioRiskCodes: Array<SampleBioRisk>
): SampleDataTableRow[] {
const samplePositionResultsMap = samplePositionMapBySampleIdSlotId(samplePositionResults);

Expand All @@ -43,7 +45,8 @@ export function buildSampleDataTableRows(
return {
...sample,
slotAddress: slot.address,
sectionPosition: samplePositionResultsMap[`${sample.id}-${slot.id}`]?.region
sectionPosition: samplePositionResultsMap[`${sample.id}-${slot.id}`]?.region,
bioRiskCode: labwareBioRiskCodes.find((sbr) => sbr.sampleId === sample.id)?.bioRiskCode
};
});
});
Expand Down Expand Up @@ -133,3 +136,10 @@ export const labwareType: ColumnFactory = () => {
accessor: (sample) => sample.labwareType?.name
};
};

export const bioRiskCode: ColumnFactory = () => {
return {
Header: 'Biological Risk Number',
accessor: (sample) => sample.bioRiskCode
};
};
4 changes: 4 additions & 0 deletions src/graphql/fragments/SampleBioRiskFields.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fragment SampleBioRiskFields on SampleBioRisk {
sampleId
bioRiskCode
}
5 changes: 5 additions & 0 deletions src/graphql/queries/GetLabwareBioRiskCodes.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query GetLabwareBioRiskCodes($barcode: String!) {
labwareBioRiskCodes(barcode: $barcode) {
...SampleBioRiskFields
}
}
29 changes: 26 additions & 3 deletions src/mocks/handlers/bioRiskHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import {
AddBioRiskMutationVariables,
GetBioRisksQuery,
GetBioRisksQueryVariables,
GetLabwareBioRiskCodesQuery,
GetLabwareBioRiskCodesQueryVariables,
Labware,
SetBioRiskEnabledMutation,
SetBioRiskEnabledMutationVariables
} from '../../types/sdk';
import { isEnabled } from '../../lib/helpers';
import BioRiskRepository from '../repositories/bioRiskRepository';
import bioRiskRepository from '../repositories/bioRiskRepository';
import bioRiskFactory from '../../lib/factories/bioRiskFactory';
import labwareFactory from '../../lib/factories/labwareFactory';

const bioRiskHandler = [
graphql.mutation<AddBioRiskMutation, AddBioRiskMutationVariables>('AddBioRisk', ({ variables }) => {
Expand Down Expand Up @@ -42,12 +45,32 @@ const bioRiskHandler = [
return HttpResponse.json(
{
data: {
bioRisks: BioRiskRepository.findAll().filter((bioRisk) => variables.includeDisabled || isEnabled(bioRisk))
bioRisks: bioRiskRepository.findAll().filter((bioRisk) => variables.includeDisabled || isEnabled(bioRisk))
}
},
{ status: 200 }
);
})
}),

graphql.query<GetLabwareBioRiskCodesQuery, GetLabwareBioRiskCodesQueryVariables>(
'GetLabwareBioRiskCodes',
({ variables }) => {
const labware: Labware = labwareFactory.build({ barcode: variables.barcode });
return HttpResponse.json(
{
data: {
labwareBioRiskCodes: labware.slots.map((slot) => {
return {
sampleId: slot.samples[0].id,
bioRiskCode: bioRiskFactory.build().code
};
})
}
},
{ status: 200 }
);
}
)
];

export default bioRiskHandler;
10 changes: 7 additions & 3 deletions src/pages/LabwareDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AddressPermDataFieldsFragment,
FlagDetail,
LabwareFieldsFragment,
SampleBioRisk,
SamplePositionFieldsFragment,
SlotFieldsFragment,
UserRole
Expand All @@ -30,10 +31,12 @@ type LabwareDetailsProps = {
permData?: AddressPermDataFieldsFragment[];
samplePositionResults: SamplePositionFieldsFragment[];
labwareFlagDetails: FlagDetail[];
labwareBioRiskCodes: Array<SampleBioRisk>;
};

export default function LabwareDetails() {
const { labware, permData, samplePositionResults, labwareFlagDetails } = useLoaderData() as LabwareDetailsProps;
const { labware, permData, samplePositionResults, labwareFlagDetails, labwareBioRiskCodes } =
useLoaderData() as LabwareDetailsProps;
const getPermDataForSlot = (
slot: SlotFieldsFragment,
permData: AddressPermDataFieldsFragment[]
Expand Down Expand Up @@ -123,9 +126,10 @@ export default function LabwareDetails() {
sampleColumns.donorName(),
sampleColumns.medium(),
sampleColumns.fixative(),
sampleColumns.huMFre()
sampleColumns.huMFre(),
sampleColumns.bioRiskCode()
]}
data={sampleColumns.buildSampleDataTableRows(labware, samplePositionResults)}
data={sampleColumns.buildSampleDataTableRows(labware, samplePositionResults, labwareBioRiskCodes)}
/>
</div>
</div>
Expand Down
Loading
Loading