Skip to content

Commit

Permalink
refresh administrations upon archive
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Nov 10, 2023
1 parent 6c4f151 commit f0a888b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ interface Props {
administrations: MedicineAdministrationRecord[];
interval: { start: Date; end: Date };
prescription: Prescription;
refetch: () => void;
}

export default function AdministrationEventCell({
administrations,
interval: { start, end },
prescription,
refetch,
}: Props) {
const [showTimeline, setShowTimeline] = useState(false);
// Check if cell belongs to an administered prescription
Expand Down Expand Up @@ -55,6 +57,7 @@ export default function AdministrationEventCell({
interval={{ start, end }}
prescription={prescription}
showPrescriptionDetails
onRefetch={refetch}
/>
</DialogModal>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ export default function MedicineAdministrationTableRow({
const [showAdminister, setShowAdminister] = useState(false);
const [showDiscontinue, setShowDiscontinue] = useState(false);

const { data, loading } = useQuery(MedicineRoutes.listAdministrations, {
pathParams: { consultation },
query: {
prescription: prescription.id,
administered_date_after: formatDateTime(
props.intervals[0].start,
"YYYY-MM-DD"
),
administered_date_before: formatDateTime(
props.intervals[props.intervals.length - 1].end,
"YYYY-MM-DD"
),
archived: false,
},
key: `${prescription.last_administered_on}`,
});
const { data, loading, refetch } = useQuery(
MedicineRoutes.listAdministrations,
{
pathParams: { consultation },
query: {
prescription: prescription.id,
administered_date_after: formatDateTime(
props.intervals[0].start,
"YYYY-MM-DD"
),
administered_date_before: formatDateTime(
props.intervals[props.intervals.length - 1].end,
"YYYY-MM-DD"
),
archived: false,
},
key: `${prescription.last_administered_on}`,
}
);

return (
<tr
Expand Down Expand Up @@ -220,6 +223,7 @@ export default function MedicineAdministrationTableRow({
administrations={data.results}
interval={{ start, end }}
prescription={prescription}
refetch={refetch}
/>
)}
</td>
Expand Down
7 changes: 6 additions & 1 deletion src/Components/Medicine/PrescrpitionTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ interface Props {
interval: { start: Date; end: Date };
prescription: Prescription;
showPrescriptionDetails?: boolean;
onRefetch?: () => void;
}

export default function PrescrpitionTimeline({
prescription,
interval,
onRefetch,
}: Props) {
const consultation = useSlug("consultation");
const { data, refetch, loading } = useQuery(
Expand Down Expand Up @@ -82,7 +84,10 @@ export default function PrescrpitionTimeline({
<MedicineAdministeredNode
key={`activity-${event.type}-${prescription.id}`}
event={event}
onArchived={refetch}
onArchived={() => {
onRefetch?.();
refetch();
}}
isLastNode={index === events.length - 1}
hideArchive={prescription.discontinued}
/>
Expand Down

0 comments on commit f0a888b

Please sign in to comment.