From 22ea4af75d33432475da7cb1b6ae860f8ef3bbe1 Mon Sep 17 00:00:00 2001 From: Riya Kumari Date: Wed, 20 Sep 2023 17:20:07 +0530 Subject: [PATCH 1/2] GOK-367 | Add. Query param to getAllPatient api based on user input value | [Sweety/Riya] --- .../dispense/add-inventory-item/add-item-modal.jsx | 14 ++++++-------- src/utils/api-utils.js | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) 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..3a05fa3 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) { @@ -164,6 +159,9 @@ const AddItemModal = (props) => { shouldFilterItem={filterPatient} itemToString={(item) => 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..87bc2ae 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&loginLocationUuid=${locationUuid}&q=${inputValue}` \ No newline at end of file From 4afaec694fae380eef614bb4a746a7c5b3eb17d1 Mon Sep 17 00:00:00 2001 From: Riya Kumari Date: Thu, 21 Sep 2023 11:17:04 +0530 Subject: [PATCH 2/2] GOK-367 | Refactor. Add identifier query param to getAllPatient api | [Sweety/Riya] --- src/inventory/dispense/add-inventory-item/add-item-modal.jsx | 2 +- src/utils/api-utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 3a05fa3..9f61298 100644 --- a/src/inventory/dispense/add-inventory-item/add-item-modal.jsx +++ b/src/inventory/dispense/add-inventory-item/add-item-modal.jsx @@ -155,7 +155,7 @@ const AddItemModal = (props) => { getPatientName(item) ?? ''} onChange={(selectedItem) => props.setPatient(selectedItem?.selectedItem)} diff --git a/src/utils/api-utils.js b/src/utils/api-utils.js index 87bc2ae..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,inputValue) => `/openmrs/ws/rest/v1/bahmni/search/patient/lucene?filterOnAllIdentifiers=true&loginLocationUuid=${locationUuid}&q=${inputValue}` \ 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