-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from RyanNerd/356-reverse-rx-lookup
Users can search a drug name listing clients that take that drug
- Loading branch information
Showing
7 changed files
with
123 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Table bordered size="sm" striped> | ||
<tr> | ||
<th>Client</th> | ||
<th>Drug</th> | ||
</tr> | ||
<tbody> | ||
{lookupList.map((rxItem, index) => { | ||
const key = index || randomString(); | ||
|
||
return ( | ||
<tr id={key.toString()} key={`rx-lookup-grid-${key}`}> | ||
<td>{rxItem.FirstName.trim() + ' ' + rxItem.LastName.trim()}</td> | ||
<td>{rxItem.Drug}</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</Table> | ||
); | ||
}; | ||
|
||
export default RxLookupGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import RxLookupGrid from 'components/Pages/Grids/RxLookupGrid'; | ||
import Form from 'react-bootstrap/Form'; | ||
import React, {useEffect, 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<{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([]); | ||
} | ||
}, [clientList, medicineProvider, searchText]); | ||
|
||
if (activeTabKey !== 'rx-lookup') return null; | ||
|
||
return ( | ||
<Form> | ||
<Form.Control | ||
autoFocus | ||
id="rx-look-up-search-box" | ||
onChange={(changeEvent) => setSearchText(changeEvent.target.value)} | ||
onKeyDown={(keyboardEvent: React.KeyboardEvent<HTMLElement>) => { | ||
if (keyboardEvent.key === 'Enter') keyboardEvent.preventDefault(); | ||
}} | ||
placeholder="Drug name" | ||
style={{width: '350px'}} | ||
type="search" | ||
value={searchText} | ||
/> | ||
|
||
{rxResult.length > 0 && ( | ||
<div className="my-3"> | ||
<RxLookupGrid lookupList={rxResult} />{' '} | ||
</div> | ||
)} | ||
</Form> | ||
); | ||
}; | ||
|
||
export default RxLookup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters