Skip to main content

Healthcare — pharmacy cold chain

The problem. Vaccines, blood products and many medications are only safe within a narrow temperature band. A pharmacy or ward fridge that drifts out of range — a door left ajar, a failing compressor overnight — can spoil tens of thousands of euros of stock and, worse, leave a patient given a product that quietly lost its potency. Staff can't watch every fridge; they need an alarm the moment one strays, and a clean temperature record to prove the chain held.

What we solve here is protecting temperature-sensitive stock with live monitoring and an auditable record.

Set up demo data

New workspace? Run this once (Python) to create a fridge's temperature series, create the subscription before we listen, and push it above the 2–8 °C band. Safe to re-run.

import datahub_sdk, numpy as np, pandas as pd

client = datahub_sdk.DataHubClient.from_env()

client.timeseries.create([datahub_sdk.TimeSeries(external_id="fridge_pharmacy_12_temp_c", name="Pharmacy fridge 12 temp", unit="deg_c", value_type="float")])
client.subscriptions.create([datahub_sdk.Subscription(
external_id="pharmacy_fridges", name="Pharmacy fridges", timeseries=["fridge_pharmacy_12_temp_c"])])
idx = pd.date_range(end=pd.Timestamp.now(tz="UTC"), periods=60, freq="1min")
t = np.full(60, 4.5); t[-10:] = 9.3 # rises above the 8 °C ceiling
client.timeseries.insert_from_lists(timestamps=idx, values=t, ts="fridge_pharmacy_12_temp_c")

1. Watch every fridge live

Each fridge streams its temperature; a subscription brings them into one feed. When one leaves its band, raise a cold_chain_excursion event so it's attended before stock is lost. See Consume live data.

import ai.intellistream.datahub.sdk.subscriptions.SubscriptionMessage;

try (var stream = client.subscriptions().listen(List.of("pharmacy_fridges"))
.stream((SubscriptionMessage msg) -> { // auto-acks after each message
if (outOfBand(msg.payload(), 2.0, 8.0)) { // °C — vaccine fridge band
EventModel excursion = new EventModel();
excursion.setExternalId("cold_chain_excursion_f12_" + System.currentTimeMillis());
excursion.setType("cold_chain_excursion");
excursion.setStatus("critical");
excursion.setMetadata(Map.of("fridge", "fridge_pharmacy_12", "temp_c", "9.3"));
excursion.setEventTime(ZonedDateTime.now());
client.events().create(List.of(excursion));
}
})) {
awaitShutdown(); // your app lifecycle; closing the stream ends delivery
}

2. Keep the compliance record

For an audit, retrieve a fridge's temperature history over any window to produce the time-stamped record showing the chain held. See Query & aggregate.

See the result

The warming fridge trips the loop while there's still time to act:

cold_chain_excursion_f12_… → critical (9.3 °C, above the 2–8 °C band)

See also