import { MedicationAdministrationRecordDose } from './MedicationAdministrationRecordDose';
const recalculateAndApplyInvoiceQuantity = async (instance)=>{
    const { models } = instance.sequelize;
    const prescription = await models.Prescription.findOne({
        include: [
            {
                model: models.MedicationAdministrationRecord,
                as: 'medicationAdministrationRecords',
                where: {
                    id: instance.marId
                },
                required: true
            },
            {
                model: models.EncounterPrescription,
                as: 'encounterPrescription',
                required: true,
                include: [
                    {
                        model: models.Encounter,
                        as: 'encounter',
                        required: true
                    }
                ]
            }
        ]
    });
    if (prescription) {
        await prescription.recalculateAndApplyInvoiceQuantity(instance.recordedByUserId);
    }
};
export const afterCreateHook = async (instance)=>{
    await recalculateAndApplyInvoiceQuantity(instance);
};
export const afterUpdateHook = async (instance)=>{
    await recalculateAndApplyInvoiceQuantity(instance);
};
export const afterDestroyHook = async (instance)=>{
    await recalculateAndApplyInvoiceQuantity(instance);
};
export const afterBulkCreateHook = async (instances)=>{
    for (const instance of instances){
        await recalculateAndApplyInvoiceQuantity(instance);
    }
};
export const afterBulkUpdateHook = async (options)=>{
    const { where } = options;
    const instances = await MedicationAdministrationRecordDose.findAll({
        where
    });
    for (const instance of instances){
        await recalculateAndApplyInvoiceQuantity(instance);
    }
};
export const afterBulkDestroyHook = async (options)=>{
    const { where } = options;
    const instances = await MedicationAdministrationRecordDose.findAll({
        where,
        paranoid: false
    });
    for (const instance of instances){
        await recalculateAndApplyInvoiceQuantity(instance);
    }
};

//# sourceMappingURL=hooks.js.map