Skip to content

Commit

Permalink
Fixes high cpu usage in medicines tab, pagination not working, incorr…
Browse files Browse the repository at this point in the history
…ect last modified date and type errors (#7472)

* Fixes component re-rendering issue due to change in reference

fixes #7465;

* fixes dependency on field `last_administered_on` that no longer exists

fixes #7466
  • Loading branch information
rithviknishad authored Mar 25, 2024
1 parent 906bb21 commit 1e802a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Common/hooks/useRangePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const useRangePagination = ({ bounds, perPage, ...props }: Props) => {

useEffect(() => {
setCurrentRange(getInitialBounds(bounds, perPage, props.defaultEnd));
}, [bounds, perPage, props.defaultEnd]);
}, [JSON.stringify(bounds), perPage, props.defaultEnd]);

const next = () => {
const { end } = currentRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
<SubHeading
title={is_prn ? "PRN Prescriptions" : "Prescriptions"}
lastModified={
prescriptions?.[0]?.last_administered_on ??
prescriptions?.[0]?.last_administration?.created_date ??
prescriptions?.[0]?.modified_date
}
options={
Expand Down
9 changes: 5 additions & 4 deletions src/Components/Medicine/MedicineAdministrationSheet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export function computeActivityBounds(prescriptions: Prescription[]) {
)
);

// get end by finding latest of all presciption's last_administered_on
// get end by finding latest of all presciption's last administration time
const end = new Date(
prescriptions
.filter((prescription) => prescription.last_administered_on)
.filter((prescription) => prescription.last_administration?.created_date)
.reduce(
(latest, curr) =>
curr.last_administered_on && curr.last_administered_on > latest
? curr.last_administered_on
curr.last_administration?.created_date &&
curr.last_administration?.created_date > latest
? curr.last_administration?.created_date
: latest,
prescriptions[0]?.created_date ?? new Date()
)
Expand Down

0 comments on commit 1e802a6

Please sign in to comment.