From a4c0d4e94694631701cc4df665724f2d90dfdd73 Mon Sep 17 00:00:00 2001 From: Donald Kibet Date: Mon, 14 Mar 2022 20:00:21 +0300 Subject: [PATCH] (enhancement) update `useVisit` hook --- packages/framework/esm-framework/docs/API.md | 2 +- packages/framework/esm-react-utils/package.json | 4 +++- packages/framework/esm-react-utils/src/useVisit.ts | 9 ++++++++- yarn.lock | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/framework/esm-framework/docs/API.md b/packages/framework/esm-framework/docs/API.md index cf97e07c9..812b635c9 100644 --- a/packages/framework/esm-framework/docs/API.md +++ b/packages/framework/esm-framework/docs/API.md @@ -4287,7 +4287,7 @@ Object {`error` `isValidating`, `currentVisit`, `mutate`} #### Defined in -[packages/framework/esm-react-utils/src/useVisit.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-react-utils/src/useVisit.ts#L22) +[packages/framework/esm-react-utils/src/useVisit.ts:26](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-react-utils/src/useVisit.ts#L26) ___ diff --git a/packages/framework/esm-react-utils/package.json b/packages/framework/esm-react-utils/package.json index 17b257597..8ee1ea663 100644 --- a/packages/framework/esm-react-utils/package.json +++ b/packages/framework/esm-react-utils/package.json @@ -51,7 +51,8 @@ "i18next": "19.x", "react": "16.x", "react-dom": "16.x", - "react-i18next": "11.x" + "react-i18next": "11.x", + "dayjs": "1.x" }, "devDependencies": { "@openmrs/esm-api": "^3.2.0", @@ -59,6 +60,7 @@ "@openmrs/esm-error-handling": "^3.2.0", "@openmrs/esm-extensions": "^3.2.0", "@openmrs/esm-globals": "^3.2.0", + "dayjs": "^1.10.8", "i18next": "^19.6.0", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/packages/framework/esm-react-utils/src/useVisit.ts b/packages/framework/esm-react-utils/src/useVisit.ts index d05ed4368..e3e3b6a50 100644 --- a/packages/framework/esm-react-utils/src/useVisit.ts +++ b/packages/framework/esm-react-utils/src/useVisit.ts @@ -4,6 +4,10 @@ import { Visit, } from "@openmrs/esm-api"; import useSWR from "swr"; +import dayjs from "dayjs"; +import isToday from "dayjs/plugin/isToday"; + +dayjs.extend(isToday); interface VisitReturnType { error: Error; @@ -28,7 +32,10 @@ export function useVisit(patientUuid: string): VisitReturnType { ); const currentVisit = - data?.data.results.find((visit) => visit.stopDatetime === null) ?? null; + data?.data.results.find( + (visit) => + visit.stopDatetime === null && dayjs(visit.startDatetime).isToday() + ) ?? null; return { error, mutate, isValidating, currentVisit }; } diff --git a/yarn.lock b/yarn.lock index c5522f6b8..19f170f7f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7160,6 +7160,11 @@ dayjs@^1.10.4, dayjs@^1.10.7: resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.7.tgz#2cf5f91add28116748440866a0a1d26f3a6ce468" integrity sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig== +dayjs@^1.10.8: + version "1.10.8" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.8.tgz#267df4bc6276fcb33c04a6735287e3f429abec41" + integrity sha512-wbNwDfBHHur9UOzNUjeKUOJ0fCb0a52Wx0xInmQ7Y8FstyajiV1NmK1e00cxsr9YrE9r7yAChE0VvpuY5Rnlow== + de-indent@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"