diff --git a/src/inventory/dispense/add-inventory-item/add-item-modal.jsx b/src/inventory/dispense/add-inventory-item/add-item-modal.jsx index 619d456..9f61298 100644 --- a/src/inventory/dispense/add-inventory-item/add-item-modal.jsx +++ b/src/inventory/dispense/add-inventory-item/add-item-modal.jsx @@ -26,17 +26,12 @@ import styles from './add-item-modal.module.scss'; const AddItemModal = (props) => { const { itemStock } = useItemStockContext(); const [cookies] = useCookies(); - const locationUuid = cookies[locationCookieName].uuid; - const [inventoryItem, setInventoryItem] = useState([]); - - const { data: allPatientList, error: allPatientListError } = useSWR( - getAllPatient(locationUuid), - fetcher, - ); - const [rows, setRows] = useState([{ id: 1, drugName: '', avlQty: 0, dispQty: 0 }]); + const [inputValue, setInputValue] = useState(''); + + const { data: allPatientList } = useSWR(inputValue.length > 1 ? getAllPatient(locationUuid, inputValue) : null, fetcher); useEffect(() => { if (itemStock) { @@ -160,10 +155,13 @@ const AddItemModal = (props) => { getPatientName(item) ?? ''} onChange={(selectedItem) => props.setPatient(selectedItem?.selectedItem)} + onInputChange={(inputValue) => { + setInputValue(inputValue); + }} invalid={!props.patient} invalidText='Please select a patient' style={{ fontWeight: 'bolder' }} diff --git a/src/utils/api-utils.js b/src/utils/api-utils.js index c0a7181..cd34f67 100644 --- a/src/utils/api-utils.js +++ b/src/utils/api-utils.js @@ -74,4 +74,4 @@ export const stockOperationURL = "/openmrs/ws/rest/v2/inventory/stockOperation" export const stockOperationTypeURL = (stockOperationType) => `/openmrs/ws/rest/v2/inventory/stockOperationType?v=full&q=${stockOperationType}` export const inventoryItemByNameURL = (itemName) => `/openmrs/ws/rest/v2/inventory/item?v=full&q=${itemName}` export const sessionURL = '/openmrs/ws/rest/v1/session?v=custom:(uuid)' -export const getAllPatient = (locationUuid) => `/openmrs/ws/rest/v1/bahmni/search/patient/lucene?filterOnAllIdentifiers=true&loginLocationUuid=${locationUuid}` \ No newline at end of file +export const getAllPatient = (locationUuid,inputValue) => `/openmrs/ws/rest/v1/bahmni/search/patient/lucene?filterOnAllIdentifiers=true&identifier=${inputValue}&loginLocationUuid=${locationUuid}&q=${inputValue}` \ No newline at end of file