Skip to content

Commit

Permalink
(enhancement) update useVisit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldkibet authored and brandones committed Mar 14, 2022
1 parent c6c4f76 commit a4c0d4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/framework/esm-framework/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

___

Expand Down
4 changes: 3 additions & 1 deletion packages/framework/esm-react-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@
"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",
"@openmrs/esm-config": "^3.2.0",
"@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",
Expand Down
9 changes: 8 additions & 1 deletion packages/framework/esm-react-utils/src/useVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 };
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a4c0d4e

Please sign in to comment.