
Can hospital, regional and national emergency forecasts agree? In Portugal, yes.
In Portugal's emergency departments, a hospital's forecast should fit inside its region, and every region should fit inside the country. Yet many demand models treat each level as separate, leaving planners with numbers that look precise but do not reconcile. The question is whether one system can predict patient visits 28 days ahead while keeping hospital, regional and national totals in line.
Quick takeaways
The hidden cost of forecasts that do not add up
An emergency department can look busy in one forecast and quiet in another, depending on which level is being watched. A hospital may predict a heavy week while its regional total says the opposite. That mismatch changes how many nurses are scheduled, how beds are held open, and whether supplies reach the right place at the right time.
Most older forecasting systems treat each site as an isolated series. One model watches Lisbon, another watches Porto, another watches the country. Each can be accurate in its own lane, yet the numbers may not line up when stacked together. If hospital forecasts do not sum to regional totals, planners are left with answers that disagree. The same problem appears when regions fail to add up to the country.
The cost is hidden because no single screen shows all three levels at once. A manager can see a plausible hospital number and a plausible national number without noticing that they cannot both be true for the same week. In one set of tests, standard transformer forecasts had prediction side aggregation errors near 14.6 percent, 20.8 percent, and 18.4 percent across the three hierarchy steps. Those are not tiny rounding slips. They mean that lower level plans can point in a different direction from higher level plans.
A single model that learns Portugal from the top down
Portugal’s emergency departments are tracked at three administrative scales, from hospital to nation. Each hospital belongs to one of five regional health administrations, and a national total sits above all of them. The new system, called HierSTT, makes one set of forecasts for all three scales. It does not train separate models and then patch them together. Instead, a national forecaster first learns the broad shape of demand across the country. That forecast is then used as context for regional predictions. Each hospital prediction also receives the relevant regional forecast before it is written down. The Portuguese data cover 81 hospitals grouped into the same five regional administrations. They run from January 1, 2021 to April 20, 2024. Ten newly opened hospitals were left out because their history was too short. For every prediction, the model looks back over 42 days of records. It then predicts patient visits for the next 28 days. At the top, a Temporal Fusion Transformer reads the past with memory cells. It also uses attention to compare different days inside that future stretch. Its input weights can change from day to day, so weather or mortality signals matter more when they are useful. Below that level, the model uses encoder blocks that mix time and space. One attention path follows a single hospital or region through its own history. Another path compares all locations at the same moment, so shared surges can be learned. When building a forecast, each local decoder starts with calendar facts it already knows. Month, weekday, holidays, and open status are part of those known inputs. The higher-level forecast for each future day is also added to the local query. Training adds a gentle penalty whenever lower forecasts fail to add up to higher ones. The chosen weight was 0.3, which gave the best tested balance. The penalty compares predicted totals, not observed totals, so it teaches internal agreement. Three checks are used: hospital sums should match regional totals, and all levels should reach the national total. This design lets a cold snap or public health event shape many local forecasts at once. A hospital in Lisbon can therefore borrow information from the national trend, not just its own past.
When consistency is built in, accuracy does not have to suffer
Consistency can be built into the training process, not patched in after predictions are made. Instead of correcting predictions later, HierSTT adds a training penalty when lower totals miss higher forecasts. This penalty is soft, so the model still learns to predict real visit counts accurately.
The weight of that penalty matters because it sets the balance between agreement and accuracy. With no coherence penalty, average error across levels was about 7.13 percent. Hospital forecasts were less accurate, with an error rate of 10.87 percent. At a coherence weight of 0.3, average error fell to about 7.06 percent. Hospital error dropped from 10.87 percent to 10.81 percent, while national error improved from 929.89 visits to 897.78 visits. Regional error rose only slightly, from 162.10 visits to 162.77 visits.
It also became more internally consistent, with hospital-to-region aggregation error falling from 2.34 percent to 2.03 percent. Hospital-to-national error fell from about 3.28 percent to 2.83 percent, and region-to-national error fell from 3.49 percent to 3.11 percent. Pushing the weight much higher makes forecasts less accurate while only modestly improving consistency. At a near-maximum weight of 0.99, average error rose to about 7.46 percent. Hospital error increased from 22.16 visits per forecast to 24.15 visits. Regional error jumped from 162.10 visits to 186.68 visits, and national error was worse than at the best weight.
At an even higher weight, hospital error reached 11.86 percent and regional error reached 5.66 percent. Prediction-side aggregation error did fall below 1 percent, but the accuracy cost was steep. The model does not simply force totals to match because direct supervision remains active. The accuracy loss covers 87 series, while the coherence penalty covers only seven aggregation constraints. Even at a very high weight, national error stayed near its best value, about 5.47 percent versus 5.44 percent.
One forecast voice across hospital, region and nation
The central finding is simple in shape and hard to achieve in practice. One model can predict emergency department visits for 81 hospitals, five regions, and the whole country while keeping those forecasts aligned with one another. That alignment is not a cosmetic fix applied after the numbers are produced. It is learned during training, so the model learns that a hospital forecast belongs inside a regional total, and a regional total belongs inside a national picture. The payoff is practical: planners can use local staffing estimates without discovering later that they contradict the capacity plan above them.
The broader lesson reaches beyond Portuguese emergency rooms. Many systems are built in layers, from clinics to districts, factories to supply chains, power plants to grids, stores to regions. When each layer is forecast separately, the totals drift apart. That pattern suggests a single hierarchical model can reduce that drift without giving up much accuracy at any one level. It also shows why forcing forecasts to agree after the fact often helps less than teaching them to agree from the start.
The opportunity is clear: better coordination, fewer surprises, and decisions made on numbers that fit together. The obstacles are equally real. Data arrive unevenly across levels, rare surges can be smoothed away, openings or closures can shift demand quickly, and a model built for one setting may need careful adaptation elsewhere. The hardest part will not be producing coherent totals; it will be keeping those totals useful when the system beneath them changes.
If forecasts can finally speak in one voice across every level of care, what else might become possible?
You may also like
Technology and computing
Cars can be tracked through surveillance cameras nobody gave access to
Health and medicine · Brain and mind
Can a routine prescription become a clue to possible Alzheimer's protection?
Technology and computing
Can a robot imagine what will happen before it moves? New models test futures in milliseconds
Technology and computing
Your Wi-Fi may already know where you are standing in the room
Keep reading
A depth camera can tell Bharatanatyam dances apart by reading poses and movement together
September 17, 2026
Can computer-made ultrasound scans teach AI to map the layers of human skin?
September 17, 2026
Hospital records alone may predict who returns within 30 days, without reading clinical notes
September 17, 2026



