From ba56bc6e9633788ca26d346a6d9615437df17f6a Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Aug 2022 05:14:55 -0600 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9B=B2=20feat=20PoC=20RxLookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Pages/LandingPage.tsx | 16 +++++-- src/components/Pages/Modals/ClientEdit.tsx | 16 ------- src/components/Pages/RxLookup.tsx | 52 ++++++++++++++++++++++ src/providers/ClientProvider.ts | 3 ++ 4 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 src/components/Pages/RxLookup.tsx diff --git a/src/components/Pages/LandingPage.tsx b/src/components/Pages/LandingPage.tsx index 9f1ebef..1b8cb06 100644 --- a/src/components/Pages/LandingPage.tsx +++ b/src/components/Pages/LandingPage.tsx @@ -1,5 +1,6 @@ import ClientPage from 'components/Pages/ClientPage'; import ManagementPage from 'components/Pages/ManagementPage'; +import RxLookup from 'components/Pages/RxLookup'; import RxPage from 'components/Pages/RxPage'; import {ReactNode} from 'react'; import Tab from 'react-bootstrap/Tab'; @@ -48,11 +49,14 @@ const LandingPage = (props: IProps) => { // Observer to show / hide tabs based on if logged in and if a client has been selected useEffect(() => { - ['resident', 'medicine', 'management'].map((tab) => { + ['resident', 'medicine', 'management', 'rx-lookup'].map((tab) => { const element = document.getElementById('landing-page-tabs-tab-' + tab); if (element) { - if (tab === 'resident' || tab === 'management') element.style.display = apiKey ? 'block' : 'none'; - else element.style.display = apiKey && activeClient ? 'block' : 'none'; + if (tab === 'resident' || tab === 'management' || tab === 'rx-lookup') { + element.style.display = apiKey ? 'block' : 'none'; + } else { + element.style.display = apiKey && activeClient ? 'block' : 'none'; + } } }); }, [activeClient, apiKey]); @@ -118,6 +122,12 @@ const LandingPage = (props: IProps) => { + Rx Lookup}> + + + + + Diagnostics}> { if (info.Notes === null) info.Notes = ''; if (info.Nickname === null) info.Nickname = ''; if (info.HMIS === null) info.HMIS = 0; - if (info.EnrollmentId === null) info.EnrollmentId = 0; setClientInfo(info); } }, [props.clientInfo]); @@ -284,21 +283,6 @@ const ClientEdit = (props: IProps): JSX.Element | null => { - - - EnrollmentId - - - handleOnChange(changeEvent)} - value={clientInfo.EnrollmentId} - /> - - - Notes diff --git a/src/components/Pages/RxLookup.tsx b/src/components/Pages/RxLookup.tsx new file mode 100644 index 0000000..be841e4 --- /dev/null +++ b/src/components/Pages/RxLookup.tsx @@ -0,0 +1,52 @@ +import Button from 'react-bootstrap/Button'; +import React, {useGlobal, useState} from 'reactn'; + +interface IProps { + activeTabKey: string; +} + +const RxLookup = (props: IProps) => { + const activeTabKey = props.activeTabKey; + const [providers] = useGlobal('providers'); + const [clientList] = useGlobal('clientList'); + const medicineProvider = providers.medicineProvider; + const [rxResult, setRxResult] = useState(null); + + const findRx = async (drugName: string) => { + const result = []; + const medicineSearchCriteria = { + where: [['Drug', 'LIKE', drugName + '%']], + orderBy: [['ResidentId']] + }; + const meds = await medicineProvider.search(medicineSearchCriteria); + + for (const m of meds) { + if (m.ResidentId) { + const client = clientList.find((c) => c.Id === m.ResidentId); + + if (client?.Id) { + // eslint-disable-next-line no-console + console.log('client', client); + result.push({firstName: client.FirstName, lastName: client.LastName, Drug: m.Drug}); + } + } + } + return result; + }; + + if (activeTabKey !== 'rx-lookup') return null; + + const handleClick = async () => { + const rxFound = await findRx('Hy'); + setRxResult(rxFound); + }; + + return ( + <> + +

{JSON.stringify(rxResult, null, '\t')}

+ + ); +}; + +export default RxLookup; diff --git a/src/providers/ClientProvider.ts b/src/providers/ClientProvider.ts index 2840656..c83b35a 100644 --- a/src/providers/ClientProvider.ts +++ b/src/providers/ClientProvider.ts @@ -111,6 +111,9 @@ const ClientProvider = (url: string): IClientProvider => { if (response.success) { return response.data as ClientRecord; } else { + if (response.status === 404) { + return {} as ClientRecord; + } throw response; } }, From dc92296bd477184e9e83d120748324795f0e20e8 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 19 Aug 2022 01:51:50 -0600 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9B=B2=20feat=20Users=20can=20search=20a?= =?UTF-8?q?=20drug=20name=20listing=20clients=20that=20take=20that=20drug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Pages/ClientPage.tsx | 2 +- src/components/Pages/Grids/RxLookupGrid.tsx | 34 +++++++++ src/components/Pages/RxLookup.tsx | 84 +++++++++++++-------- src/types/RecordTypes.ts | 1 - 4 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 src/components/Pages/Grids/RxLookupGrid.tsx diff --git a/src/components/Pages/ClientPage.tsx b/src/components/Pages/ClientPage.tsx index 1aba569..bf147fe 100644 --- a/src/components/Pages/ClientPage.tsx +++ b/src/components/Pages/ClientPage.tsx @@ -163,7 +163,7 @@ const ClientPage = (props: IProps): JSX.Element | null => { setSearchText(changeEvent.target.value)} onKeyDown={(keyboardEvent: React.KeyboardEvent) => { diff --git a/src/components/Pages/Grids/RxLookupGrid.tsx b/src/components/Pages/Grids/RxLookupGrid.tsx new file mode 100644 index 0000000..1883c04 --- /dev/null +++ b/src/components/Pages/Grids/RxLookupGrid.tsx @@ -0,0 +1,34 @@ +import Table from 'react-bootstrap/Table'; +import React from 'reactn'; +import {randomString} from 'utility/common'; + +interface IProps { + lookupList: {Drug: string; LastName: string; FirstName: string}[]; +} + +const RxLookupGrid = (props: IProps) => { + const lookupList = props.lookupList; + + return ( + + + + + + + {lookupList.map((rxItem, index) => { + const key = index || randomString(); + + return ( + + + + + ); + })} + +
ClientDrug
{rxItem.FirstName.trim() + ' ' + rxItem.LastName.trim()}{rxItem.Drug}
+ ); +}; + +export default RxLookupGrid; diff --git a/src/components/Pages/RxLookup.tsx b/src/components/Pages/RxLookup.tsx index be841e4..a2bc23d 100644 --- a/src/components/Pages/RxLookup.tsx +++ b/src/components/Pages/RxLookup.tsx @@ -1,5 +1,6 @@ -import Button from 'react-bootstrap/Button'; -import React, {useGlobal, useState} from 'reactn'; +import RxLookupGrid from 'components/Pages/Grids/RxLookupGrid'; +import Form from 'react-bootstrap/Form'; +import React, {useEffect, useGlobal, useState} from 'reactn'; interface IProps { activeTabKey: string; @@ -10,42 +11,61 @@ const RxLookup = (props: IProps) => { const [providers] = useGlobal('providers'); const [clientList] = useGlobal('clientList'); const medicineProvider = providers.medicineProvider; - const [rxResult, setRxResult] = useState(null); - - const findRx = async (drugName: string) => { - const result = []; - const medicineSearchCriteria = { - where: [['Drug', 'LIKE', drugName + '%']], - orderBy: [['ResidentId']] - }; - const meds = await medicineProvider.search(medicineSearchCriteria); - - for (const m of meds) { - if (m.ResidentId) { - const client = clientList.find((c) => c.Id === m.ResidentId); - - if (client?.Id) { - // eslint-disable-next-line no-console - console.log('client', client); - result.push({firstName: client.FirstName, lastName: client.LastName, Drug: m.Drug}); + const [rxResult, setRxResult] = useState<{Drug: string; LastName: string; FirstName: string}[] | []>([]); + const [searchText, setSearchText] = useState(''); + + useEffect(() => { + if (searchText.length > 1) { + const findRx = async (drugName: string) => { + const result = [] as {Drug: string; LastName: string; FirstName: string}[]; + const medicineSearchCriteria = { + where: [['Drug', 'LIKE', drugName + '%']], + orderBy: [['ResidentId']] + }; + const meds = await medicineProvider.search(medicineSearchCriteria); + + for (const m of meds) { + if (m.ResidentId) { + const client = clientList.find((c) => c.Id === m.ResidentId); + + if (client?.Id) { + // eslint-disable-next-line no-console + console.log('client', client); + result.push({FirstName: client.FirstName, LastName: client.LastName, Drug: m.Drug}); + } + } } - } + setRxResult(result); + }; + findRx(searchText); + } else { + setRxResult([]); } - return result; - }; + }, [clientList, medicineProvider, searchText]); if (activeTabKey !== 'rx-lookup') return null; - const handleClick = async () => { - const rxFound = await findRx('Hy'); - setRxResult(rxFound); - }; - return ( - <> - -

{JSON.stringify(rxResult, null, '\t')}

- +
+ setSearchText(changeEvent.target.value)} + onKeyDown={(keyboardEvent: React.KeyboardEvent) => { + if (keyboardEvent.key === 'Enter') keyboardEvent.preventDefault(); + }} + placeholder="Drug name" + style={{width: '350px'}} + type="search" + value={searchText} + /> + + {rxResult.length > 0 && ( +
+ {' '} +
+ )} + ); }; diff --git a/src/types/RecordTypes.ts b/src/types/RecordTypes.ts index 9443896..80bcbed 100644 --- a/src/types/RecordTypes.ts +++ b/src/types/RecordTypes.ts @@ -10,7 +10,6 @@ export type ClientRecord = { Nickname: string; Notes: string; HMIS: number; - EnrollmentId: number; Updated?: null | Date; UserId?: number; deleted_at?: null | Date;