From 8bacf9aa86af909b145585fef1ee848519febd5f Mon Sep 17 00:00:00 2001 From: Felix Kiprotich <72152368+FelixKiprotich350@users.noreply.github.com> Date: Tue, 17 Dec 2024 05:22:07 -0800 Subject: [PATCH] sorted the batches expiry date from the most nearing expiring to the furthest expiring ind sipensing module (#139) Co-authored-by: Felix Kiprotich --- src/forms/stock-dispense/stock-dispense.component.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/forms/stock-dispense/stock-dispense.component.tsx b/src/forms/stock-dispense/stock-dispense.component.tsx index aab8783..3e1d0fa 100644 --- a/src/forms/stock-dispense/stock-dispense.component.tsx +++ b/src/forms/stock-dispense/stock-dispense.component.tsx @@ -16,6 +16,14 @@ const StockDispense: React.FC = ({ medicationDispense, updat const drugUuid = medicationDispense?.medicationReference?.reference?.split('/')[1]; const { inventoryItems, error, isLoading } = useDispenseStock(drugUuid); const validInventoryItems = inventoryItems.filter((item) => isValidBatch(medicationDispense, item)); + const validInventoryItemss = inventoryItems + .filter((item) => isValidBatch(medicationDispense, item)) + .sort((a, b) => { + const dateA = new Date(a.expiration); + const dateB = new Date(b.expiration); + + return dateA.getDate() - dateB.getDate(); + }); function parseDate(dateString) { return new Date(dateString);