Skip to content

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:

Screenshot_from_2026-02-11_15-07-47

analytics/medicines

Screenshot_from_2026-02-11_15-09-01

analytics/doctors

Screenshot_from_2026-02-11_15-11-15

Merge request reports

Loading