Skip to content

Commit

Permalink
Merge branch 'O3-3557-2' into fix-dispensing-module
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKiprotich350 authored Jul 18, 2024
2 parents b5b5eff + c01e083 commit 810ec0d
Show file tree
Hide file tree
Showing 5 changed files with 1,769 additions and 791 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'@openmrs/esm-framework': '@openmrs/esm-framework/mock',
'\\.(s?css)$': 'identity-obj-proxy',
'^lodash-es/(.*)$': 'lodash/$1',
'^lodash-es$': 'lodash',
'^uuid$': '<rootDir>/node_modules/uuid/dist/index.js',
dexie: require.resolve('dexie'),
},
Expand Down
2 changes: 1 addition & 1 deletion src/declarations.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ declare module '*.css';
declare module '*.scss';
declare module '*.svg';
declare module '@carbon/react';
declare type SideNavProps = {};

12 changes: 11 additions & 1 deletion src/forms/dispense-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
// to prevent duplicate submits
const [isSubmitting, setIsSubmitting] = useState(false);

//track quantity to dispense
const [currentQuantity, setCurrentQuantity] = useState(
quantityRemaining ? quantityRemaining : medicationDispense?.quantity?.value,
);

// Submit medication dispense form
const handleSubmit = () => {
if (!isSubmitting) {
Expand Down Expand Up @@ -165,6 +170,10 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
}
};

const setAvailableQuantity = (batch) => {
setCurrentQuantity(Number(batch.quantity));
};

// initialize the internal dispense payload with the dispenses passed in as props
useEffect(() => setMedicationDispensePayload(medicationDispense), [medicationDispense]);

Expand Down Expand Up @@ -209,13 +218,14 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
<MedicationDispenseReview
medicationDispense={medicationDispensePayload}
updateMedicationDispense={setMedicationDispensePayload}
quantityRemaining={quantityRemaining}
quantityRemaining={currentQuantity}
/>
{config.enableStockDispense && (
<StockDispense
inventoryItem={inventoryItem}
medicationDispense={medicationDispense}
updateInventoryItem={setInventoryItem}
updateAvailableQuantityToMedicationDispenseQuantity={setAvailableQuantity}
/>
)}
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/forms/stock-dispense/stock-dispense.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ type StockDispenseProps = {
medicationDispense: MedicationDispense;
updateInventoryItem: (inventoryItem: InventoryItem) => void;
inventoryItem: InventoryItem;
updateAvailableQuantityToMedicationDispenseQuantity: (inventoryItem: InventoryItem) => void;
};

const StockDispense: React.FC<StockDispenseProps> = ({ medicationDispense, updateInventoryItem }) => {
const StockDispense: React.FC<StockDispenseProps> = ({
medicationDispense,
updateInventoryItem,
updateAvailableQuantityToMedicationDispenseQuantity,
}) => {
const { t } = useTranslation();
const drugUuid = medicationDispense?.medicationReference?.reference?.split('/')[1];
const { inventoryItems, error, isLoading } = useDispenseStock(drugUuid);
Expand Down
Loading

0 comments on commit 810ec0d

Please sign in to comment.