Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich committed Aug 8, 2024
2 parents 01d150c + fc2676e commit a90ff57
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 127 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-dispensing-app",
"version": "1.3.2",
"version": "1.4.0",
"license": "MPL-2.0",
"description": "Medication dispensing application",
"browser": "dist/openmrs-esm-dispensing-app.js",
Expand Down
12 changes: 1 addition & 11 deletions src/forms/dispense-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ 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 @@ -170,10 +165,6 @@ 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 @@ -218,14 +209,13 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
<MedicationDispenseReview
medicationDispense={medicationDispensePayload}
updateMedicationDispense={setMedicationDispensePayload}
quantityRemaining={currentQuantity}
quantityRemaining={quantityRemaining}
/>
{config.enableStockDispense && (
<StockDispense
inventoryItem={inventoryItem}
medicationDispense={medicationDispense}
updateInventoryItem={setInventoryItem}
updateAvailableQuantityToMedicationDispenseQuantity={setAvailableQuantity}
/>
)}
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/forms/medication-dispense-review.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
}
min={0}
max={config.dispenseBehavior.restrictTotalQuantityDispensed ? quantityRemaining : undefined}
value={
quantityRemaining <= medicationDispense.quantity.value
? quantityRemaining
: medicationDispense.quantity.value
}
value={medicationDispense.quantity.value}
onChange={(e) => {
updateMedicationDispense({
...medicationDispense,
Expand Down
9 changes: 2 additions & 7 deletions src/forms/stock-dispense/stock-dispense.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ type StockDispenseProps = {
medicationDispense: MedicationDispense;
updateInventoryItem: (inventoryItem: InventoryItem) => void;
inventoryItem: InventoryItem;
updateAvailableQuantityToMedicationDispenseQuantity: (inventoryItem: InventoryItem) => void;
};

const StockDispense: React.FC<StockDispenseProps> = ({
medicationDispense,
updateInventoryItem,
updateAvailableQuantityToMedicationDispenseQuantity,
}) => {
const StockDispense: React.FC<StockDispenseProps> = ({ medicationDispense, updateInventoryItem }) => {
const { t } = useTranslation();
const drugUuid = medicationDispense?.medicationReference?.reference?.split('/')[1];
const { inventoryItems, error, isLoading } = useDispenseStock(drugUuid);
Expand All @@ -26,6 +21,7 @@ const StockDispense: React.FC<StockDispenseProps> = ({
return new Date(dateString);
}

//check whether the drug will expire before the medication period ends
function isValidBatch(medicationToDispense, inventoryItem) {
if (medicationToDispense?.dosageInstruction && medicationToDispense?.dosageInstruction.length > 0) {
return medicationToDispense.dosageInstruction.some((instruction) => {
Expand Down Expand Up @@ -110,7 +106,6 @@ const StockDispense: React.FC<StockDispenseProps> = ({
items={validInventoryItems}
onChange={({ selectedItem }) => {
updateInventoryItem(selectedItem);
updateAvailableQuantityToMedicationDispenseQuantity(selectedItem);
}}
itemToString={(item) => (item ? toStockDispense(item) : '')}
titleText={t('stockDispense', 'Stock Dispense')}
Expand Down
Loading

0 comments on commit a90ff57

Please sign in to comment.