From ba56bc6e9633788ca26d346a6d9615437df17f6a Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Aug 2022 05:14:55 -0600 Subject: [PATCH] =?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; } },