← Back to the lab

Simulation

Medicine supply digital twin (11/14): how often to count the warehouse

The system and the shelf drift apart through small errors nobody sees. A monthly drift model, its equilibrium and why counting a little often beats counting everything once a year. And the probability behind the blind second count.

By ·

Everything the series has computed so far (forecast, order, allocation) starts from one number: the stock the system shows. If the system says 500 units and the shelf holds 320, the order goes wrong, the allocation goes wrong and someone discovers the shortage when it’s too late.

The system and the shelf drift apart on their own. In the twin, each warehouse location accumulates errors at rates per thousand movements: an issue that wasn’t recorded, an entry in boxes instead of units, something put in the next location over, a wrong lot, breakage without a report, a receipt entered twice. None of them is visible at the time. Only a physical count reveals them.

A drift model

Let ete_t be the share of locations with some discrepancy at the end of month tt. Each month, a share rr of the locations that were right go wrong. A share ftf_t of locations is also counted; counting fixes the discrepancy, unless the count itself is wrong, with probability ε\varepsilon:

et+1=(et+r (1−et))(1−ft)+ft εe_{t+1} = \big(e_t + r\,(1 - e_t)\big)(1 - f_t) + f_t\,\varepsilon

Counting only once a year

If nothing is counted during the year (f=0f = 0), the recurrence becomes 1−et+1=(1−r)(1−et)1 - e_{t+1} = (1 - r)(1 - e_t), so

et=1−(1−r)te_t = 1 - (1 - r)^t

With r=3 %r = 3\ \% a month, after 11 months 1−0.9711=28.5 %1 - 0.97^{11} = 28.5\ \% of locations have a discrepancy. The annual count fixes them all, but for almost the whole year you’re working with an increasingly unreliable system: on average 15 % of locations are wrong.

Counting a little every month

With a rotating count, a twelfth is counted each month, f=1/12f = 1/12, and every location gets counted during the year. Drift no longer grows forever: it reaches an equilibrium where what goes wrong each month equals what gets fixed. That fixed point comes from setting et+1=et=e∗e_{t+1} = e_t = e^*:

e∗=r (1−f)+f εr (1−f)+fe^* = \frac{r\,(1 - f) + f\,\varepsilon}{r\,(1 - f) + f}

The general rule can be read from the formula: when ε\varepsilon is small, e∗≈r(1−f)/(r(1−f)+f)e^* \approx r(1-f)/\big(r(1-f) + f\big), which mostly depends on the ratio between how fast the warehouse drifts and how fast it’s counted. To keep discrepancies below 5 % with r=3 %r = 3\ \%, solve 0.03(1−f)×0.95=0.05 f0.03(1-f) \times 0.95 = 0.05\,f for ff: count about 36 % of locations every month, or concentrate counts where they matter most: the highest-value locations and controlled drugs, which in the twin are always counted.

The CEDIS in 3D: turn on the count-tag layer (“Marbetes”) to see the location counts and their differences against the system. (Interface in Spanish.) · Open full screen

The blind second count

Each location is counted on a count tag, a numbered label where the quantity is written down. Then another person counts again without seeing the first number. If they match, it’s accepted; if not, there’s a third count.

Untick the second count in the aid: with ε=3 %\varepsilon = 3\ \%, the error each count leaves equals the rate at which the warehouse drifts in a month, and the ABC equilibrium rises from 4.7 % to 7.5 %.

After counting: reconcile

Not every discrepancy is a loss. The twin separates:

  • What can be explained: it was in the next location, it was another lot, it was entered in boxes. It’s reclassified and nothing is adjusted.
  • What can’t be explained: it’s adjusted, with sign-off that moves up a level with the amount, up to requiring a formal report.
  • Controlled drugs: any discrepancy is fully cleared up with a formal report and the responsible pharmacist.

That way counting stops being a yearly chore and becomes a control that runs all year.

What comes next

The medicine is at the unit and the system knows how much there is. One leg remains: getting it into the patient’s hands. The next post compares the pharmacy window with lockers and home delivery.