You need to sign in or sign up before continuing.
Fix medicine quantity aggregation logic when replacement medicine existsfix(analytics): correct medicine quantity aggregation with replacement logic
Currently, medicine analytics do not correctly handle cases where a prescribed medicine is replaced by another medicine.
We need to update the aggregation logic so that replacement medicines override the original medicines during quantity calculations. fix(analytics): correct medicine quantity aggregation with replacement logic
Updated medicine aggregation logic to properly handle replaced medicines.
New behavior:
- If replaced_medicine_id is present, the original medicine quantity is ignored.
- The replaced_medicine_id receives the replaced_quantity instead.
- If no replacement exists, the original medicine_id and quantity are used.
This ensures:
- Replacement medicines override original prescriptions.
- Accurate totals in medicine-wise and doctor-wise analytics.
Also added handling to prevent double counting of replaced medicines.
analytics/analytics:
analytics/medicines
analytics/doctors


