Skip to content

Commit

Permalink
💊 Medicine Checkout Feature
Browse files Browse the repository at this point in the history
- Added missing DocBlocks
- Refactored MedicineCheckout to use `getCheckoutList()` in common.ts
  • Loading branch information
RyanNerd committed Jan 22, 2021
1 parent cc78f62 commit 5fb0338
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/components/Pages/MedicineCheckout.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import React, {useGlobal} from 'reactn';
import {Button, ListGroup} from "react-bootstrap";
import DrugLogGrid from "../Pages/Grids/DrugLogGrid";
import {clientFullName, getFormattedDate, isToday} from "../../utility/common";
import {DrugLogRecord} from "../../types/RecordTypes";
import {clientFullName, getCheckoutList, getFormattedDate} from "../../utility/common";

/**
* MedicineCheckout page
* Displays a table of drugLogList records that have In or Out values > 0 and were entered/updated today.
* @return {JSX.Element | null}
* @constructor
*/
const MedicineCheckout = () => {
const [drugLogList] = useGlobal('drugLogList');
const [medicineList] = useGlobal('medicineList');
const [activeTabKey] = useGlobal('activeTabKey');
const [activeResident] = useGlobal('activeResident');
const clientName = activeResident ? clientFullName(activeResident) : '';
const now = new Date();
const today = getFormattedDate(now);

// Prevent render if the active tab isn't medicine-checkout or there are no drugLogList or medicineList records.
if (activeTabKey !== 'medicine-checkout' ||
!drugLogList || drugLogList.length <=0 ||
!medicineList || medicineList.length <= 0) {
return null;
}

const checkoutList = drugLogList.filter((drug) => {
const isThisDay = (drug: DrugLogRecord) => {
return drug && drug.Updated && isToday(new Date(drug.Updated));
}
return (drug.Out && drug.Out > 0) && isThisDay(drug);
});
const now = new Date();
const today = getFormattedDate(now);
const checkoutList = getCheckoutList(drugLogList);

return (
<ListGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/utility/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,16 @@ export const searchDrugs = (searchText: string, drugList: MedicineRecord[]) => {
return null;
}

/**
* Given the drugLogList this returns a filtered list of drugLogList records that are populated with In or Out
* for today's date.
* @param {DrugLogRecord[]} drugLogList
*/
export const getCheckoutList = (drugLogList: DrugLogRecord[]) => {
return drugLogList.filter((drug) => {
const isThisDay = (drug: DrugLogRecord) => {
return drug && drug.Updated && isToday(new Date(drug.Updated));
}
return (drug.Out && drug.Out > 0) && isThisDay(drug);
return ((drug.Out && drug.Out > 0) || (drug.In && drug.In > 0)) && isThisDay(drug);
});
}

0 comments on commit 5fb0338

Please sign in to comment.