Skip to content

Commit 5a445cb

Browse files
authored
(feat) O3-4571 : Make batch validity check configurable (#155)
1 parent 131f0f1 commit 5a445cb

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/config-schema.ts

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ export const configSchema = {
113113
'Enable or disable stock deduction during the dispensing process. Requires the stock management module to be installed and configured.',
114114
_default: false,
115115
},
116+
validateBatch: {
117+
_type: Type.Boolean,
118+
_description:
119+
'Enable or disable stock item batch number validation. Requires the stock management module to be installed and configured.',
120+
_default: true,
121+
},
116122
};
117123

118124
export interface PharmacyConfig {
@@ -156,4 +162,6 @@ export interface PharmacyConfig {
156162
};
157163
};
158164
enableStockDispense: boolean;
165+
166+
validateBatch: boolean;
159167
}

src/forms/stock-dispense/stock-dispense.component.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from 'react';
22
import { ComboBox, InlineLoading, InlineNotification, Layer } from '@carbon/react';
33
import { type MedicationDispense, type InventoryItem } from '../../types';
44
import { useDispenseStock } from './stock.resource';
5-
import { formatDate } from '@openmrs/esm-framework';
5+
import { formatDate, useConfig } from '@openmrs/esm-framework';
66
import { useTranslation } from 'react-i18next';
7+
import { type PharmacyConfig } from '../../config-schema';
78

89
type StockDispenseProps = {
910
medicationDispense: MedicationDispense;
@@ -13,6 +14,8 @@ type StockDispenseProps = {
1314

1415
const StockDispense: React.FC<StockDispenseProps> = ({ medicationDispense, updateInventoryItem }) => {
1516
const { t } = useTranslation();
17+
const config = useConfig<PharmacyConfig>();
18+
1619
const drugUuid = medicationDispense?.medicationReference?.reference?.split('/')[1];
1720
const { inventoryItems, error, isLoading } = useDispenseStock(drugUuid);
1821
const validInventoryItems = inventoryItems.filter((item) => isValidBatch(medicationDispense, item));
@@ -31,6 +34,9 @@ const StockDispense: React.FC<StockDispenseProps> = ({ medicationDispense, updat
3134

3235
//check whether the drug will expire before the medication period ends
3336
function isValidBatch(medicationToDispense, inventoryItem) {
37+
if (typeof config !== 'undefined' && !config.validateBatch) {
38+
return true;
39+
}
3440
if (medicationToDispense?.dosageInstruction && medicationToDispense?.dosageInstruction.length > 0) {
3541
return medicationToDispense.dosageInstruction.some((instruction) => {
3642
if (

src/location/location.resource.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const pharmacyConfig: PharmacyConfig = {
3434
substitutionType: { uuid: '' },
3535
},
3636
enableStockDispense: false,
37+
validateBatch: false,
3738
};
3839

3940
describe('Location Resource tests', () => {

0 commit comments

Comments
 (0)