diff --git a/src/service/save-receipt.js b/src/service/save-receipt.js index e0eff17..625c427 100644 --- a/src/service/save-receipt.js +++ b/src/service/save-receipt.js @@ -3,6 +3,7 @@ import { getRequest, stockOperationURL, stockOperationTypeURL, + inventoryItemByDrugIdURL, } from '../utils/api-utils'; import { getFormattedDate } from '../utils/date-utils'; @@ -12,8 +13,7 @@ const saveReceipt = async (items, outwardNumber, destinationUuid) => { const itemsArray = []; await Promise.all( items.map(async (item) => { - const itemName = encodeURIComponent(item.item); - const response = await getRequest(`/openmrs/ws/rest/v2/inventory/item?v=full&q=${itemName}`); + const response = await getRequest(inventoryItemByDrugIdURL(item.itemId)); const itemUuid = response.results[0]?.uuid; itemsArray.push({ @@ -50,8 +50,7 @@ const inwardSaveReceipt = async (items, institutionId, stockInwardDate, destinat const itemsArray = []; await Promise.all( items.map(async (item) => { - const itemName = encodeURIComponent(item.item); - const response = await getRequest(`/openmrs/ws/rest/v2/inventory/item?v=full&q=${itemName}`); + const response = await getRequest(inventoryItemByDrugIdURL(item.itemId)); const itemUuid = response.results[0]?.uuid; itemsArray.push({ item: itemUuid, diff --git a/src/utils/api-utils.js b/src/utils/api-utils.js index ca41814..c9edbcf 100644 --- a/src/utils/api-utils.js +++ b/src/utils/api-utils.js @@ -74,6 +74,7 @@ export const dispenseConceptURL = '/openmrs/ws/rest/v1/concept?q=Dispensed&limit 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 inventoryItemByDrugIdURL = (drugId) => `/openmrs/ws/rest/v2/inventory/item?v=full&drugId=${drugId}` export const sessionURL = '/openmrs/ws/rest/v1/session?v=custom:(uuid)' export const stockTakeURL = '/openmrs/ws/rest/v2/inventory/inventoryStockTake' export const getAllPatient = (locationUuid,inputValue) => `/openmrs/ws/rest/v1/bahmni/search/patient/lucene?filterOnAllIdentifiers=true&identifier=${inputValue}&loginLocationUuid=${locationUuid}&q=${inputValue}`