diff --git a/src/config-schema.ts b/src/config-schema.ts index 3c11caa..34053ba 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -127,17 +127,17 @@ export const configSchema = { 'Enable or disable stock deduction during the dispensing process. Requires the stock management module to be installed and configured.', _default: false, }, - closeVisitOnDispense: { + endVisitOnDispense: { enabled: { _type: Type.Boolean, _description: - 'Enables or disables the automatic closure of the current visit upon medication dispensing. When set to true, the system will attempt to close the visit after a successful medication dispense, subject to the conditions specified in the "visitTypes" config.', + 'Enables or disables the ending of the current visit upon medication dispensing. When set to true, the system will attempt to end the visit after a successful medication dispense, subject to the conditions specified in the "visitTypes" config.', _default: false, }, visitTypesUuids: { _type: Type.Array, _description: - 'Specifies a list of visit type UUIDs that are eligible for automatic closure upon medication dispensing. If enabled, only visits of these types will be closed automatically. An empty array means no visit types are eligible for automatic closure. This setting is only relevant when "enabled" is set to true.', + 'Specifies a list of visit type UUIDs that are eligible for ending upon medication dispensing. If enabled, only visits of these types will be closed. An empty array means no visit types are eligible for closure. This setting is only relevant when "enabled" is set to true.', _default: [], }, }, @@ -183,7 +183,7 @@ export interface PharmacyConfig { }; }; enableStockDispense: boolean; - closeVisitOnDispense?: { + endVisitOnDispense?: { enabled: boolean; visitTypesUuids: Array; }; diff --git a/src/forms/dispense-form-handler.tsx b/src/forms/dispense-form-handler.tsx index 5d91f15..a1eab44 100644 --- a/src/forms/dispense-form-handler.tsx +++ b/src/forms/dispense-form-handler.tsx @@ -96,14 +96,14 @@ class StockDispenseHandler extends Handler { } } -class CloseCurrentVisitHandler extends Handler { +class EndCurrentVisitHandler extends Handler { async handle(request) { const { currentVisit, abortController, closeVisitOnDispense, response, t, config } = request; try { const visitTypes = await getVisitTypes().toPromise(); const shouldCloseVisit = - shouldCloseVisitOnDispense(currentVisit, visitTypes, response.status, config) && closeVisitOnDispense; + shouldEndVisitOnDispense(currentVisit, visitTypes, response.status, config) && closeVisitOnDispense; if (shouldCloseVisit) { const updateResponse = await updateVisit( @@ -170,7 +170,7 @@ class FinalResponseHandler extends Handler { const setupChain = () => { const medicationDispenseHandler = new MedicationDispenseHandler(); const stockDispenseHandler = new StockDispenseHandler(); - const closeActiveVisitHandler = new CloseCurrentVisitHandler(); + const closeActiveVisitHandler = new EndCurrentVisitHandler(); const finalResponseHandler = new FinalResponseHandler(); medicationDispenseHandler @@ -195,7 +195,7 @@ export const executeMedicationDispenseChain = (params) => { * @param {object} config - The configuration object. * @returns {boolean} - Returns true if the current visit should be closed, false otherwise. */ -function shouldCloseVisitOnDispense(currentVisit, visitTypes, status, config): boolean { +function shouldEndVisitOnDispense(currentVisit, visitTypes, status, config): boolean { if (!currentVisit || !visitTypes) return false; const hasAllowedVisitType = visitTypes.some((vt) => vt.uuid === currentVisit.visitType.uuid); diff --git a/src/forms/dispense-form.component.tsx b/src/forms/dispense-form.component.tsx index c2c0017..aca7af0 100644 --- a/src/forms/dispense-form.component.tsx +++ b/src/forms/dispense-form.component.tsx @@ -125,13 +125,13 @@ const DispenseForm: React.FC = ({ useEffect(checkIsValid, [medicationDispensePayload, quantityRemaining, inventoryItem]); const isButtonDisabled = (config.enableStockDispense ? !inventoryItem : false) || !isValid || isSubmitting; - const shouldShowCloseVisitCheckbox = useMemo(() => { + const shouldEndCurrentVisitCheckbox = useMemo(() => { return ( - config.closeVisitOnDispense && + config.endVisitOnDispense && currentVisit && - config.closeVisitOnDispense.visitTypesUuids.includes(currentVisit.visitType.uuid) + config.endVisitOnDispense.visitTypesUuids.includes(currentVisit.visitType.uuid) ); - }, [config.closeVisitOnDispense, currentVisit]); + }, [config.endVisitOnDispense, currentVisit]); const bannerState = useMemo(() => { if (patient) { @@ -178,7 +178,7 @@ const DispenseForm: React.FC = ({ updateInventoryItem={setInventoryItem} /> )} - {shouldShowCloseVisitCheckbox && ( + {shouldEndCurrentVisitCheckbox && (