Skip to content

Commit

Permalink
⛲ feat PoC RxLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNerd committed Aug 18, 2022
1 parent 55c8f62 commit ba56bc6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
16 changes: 13 additions & 3 deletions src/components/Pages/LandingPage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -118,6 +122,12 @@ const LandingPage = (props: IProps) => {
</Tab.Content>
</Tab>

<Tab disabled={!apiKey} eventKey="rx-lookup" title={<Title activeKey={'rx-lookup'}>Rx Lookup</Title>}>
<Tab.Content>
<RxLookup activeTabKey={activeTabKey} />
</Tab.Content>
</Tab>

<Tab disabled={!errorDetails} eventKey="error" title={<Title activeKey="error">Diagnostics</Title>}>
<Tab.Content>
<DiagnosticPage
Expand Down
16 changes: 0 additions & 16 deletions src/components/Pages/Modals/ClientEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const ClientEdit = (props: IProps): JSX.Element | null => {
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]);
Expand Down Expand Up @@ -284,21 +283,6 @@ const ClientEdit = (props: IProps): JSX.Element | null => {
</Col>
</Form.Group>

<Form.Group as={Row}>
<Form.Label column sm="2">
EnrollmentId
</Form.Label>
<Col sm="4">
<Form.Control
autoComplete="off"
type="number"
name="EnrollmentId"
onChange={(changeEvent) => handleOnChange(changeEvent)}
value={clientInfo.EnrollmentId}
/>
</Col>
</Form.Group>

<Form.Group as={Row}>
<Form.Label column sm="2">
Notes
Expand Down
52 changes: 52 additions & 0 deletions src/components/Pages/RxLookup.tsx
Original file line number Diff line number Diff line change
@@ -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<unknown>(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 (
<>
<Button onClick={() => handleClick()}>GO</Button>
<p>{JSON.stringify(rxResult, null, '\t')}</p>
</>
);
};

export default RxLookup;
3 changes: 3 additions & 0 deletions src/providers/ClientProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},
Expand Down

0 comments on commit ba56bc6

Please sign in to comment.