The reports engine is registry-driven. About 70 report definitions across 12 domains feed the catalogue. The pivot engine supports drill-down from many KPIs to the underlying records, period-over-period comparison is live for table reports, and saved views let users park their preferred filter state. This article walks the engine architecture, what is live, what is on the roadmap, and the discipline that keeps reports trustworthy.
Where it lives#
- Reports → Catalogue: browse every available report at
/dashboard/reports/. - Reports → [report]: open a report with filters at
/dashboard/reports/<code>. - Dashboard: the owner overview at
/dashboard, plus domain dashboards at/dashboard/cx-marketing-insightand/dashboard/club/analytics. - Reports → Saved views: park filter state per user.
- Reports → Scheduled delivery: email or WhatsApp delivery (Coming soon).
The engine#
Registry-driven#
- Reports are defined as registered objects, not ad hoc queries.
- Definition declares: dimensions (group-by), measures (KPIs), filters, drill source.
- About 70 reports across finance, inventory, patients, sales, appointments, CRM, marketing, team, messaging, packages, clinical, dashboards.
- New reports add by declaring a new registry entry; the catalogue surfaces automatically.
Pivot engine#
- Hierarchical dimensions, for example branch then provider then service.
- Drill from a KPI cell to the underlying records when the definition registers a drill source.
- Schema-driven, so filters and groupings respect the definition.
- Export to CSV and Excel.
Snapshot vs live#
Reports run live by default. Each execution sets a 30-second Postgres statement timeout, runs the query, optionally writes the result to Redis with a TTL derived from the definition's refresh_interval_minutes, and returns. The next request with the same filters hits the cache.
A subset of reports is also precomputed. A Celery beat task runs every 30 minutes, walks every real-customer tenant (skips demo, canary, test), and warms the default-param cache key for any report flagged precompute=True. This is what people mean when they say "snapshot dashboards". The trade-off: a dashboard tile may be up to 30 minutes stale on first paint, then refreshes live as you change filters.
If you need a guaranteed-fresh number, change a filter (any change forces a new cache key) or wait for the next 30-minute cycle.
What is actually a dashboard today#
One thing to clear up before reading further: today the system has one top-nav dashboard at /dashboard (the owner overview), plus two domain dashboards: /dashboard/cx-marketing-insight and /dashboard/club/analytics. The names you see in the reports catalogue under "Dashboards" (Revenue, Bookings, Operations, Online Presence, Performance) are report definitions that open inside the reports module at /dashboard/reports/<code>. They are not separate top-nav surfaces yet.
Per-role dashboards (accountant, sales rep, provider, reception, marketer, inventory manager) are documented in per-role dashboards mapping as targets. None of them ship as standalone routes today.
Drill-down#
About half the report definitions register a drill source. When the definition has one, clicking a KPI tile or chart segment opens a drawer with the underlying records (invoices, sessions, leads, patients), inheriting the current date range, branch, and provider filters. From there each row opens the full record.
When a report has no drill source, the click does nothing. There is no error and no affordance to show this. If a tile does not drill, the data source has not registered drill yet. Treat it as a doc gap, not a broken feature.
Saved views#
Configure the report, choose Save view, and name it. Choose a personal view for your own work or a tenant-wide view to share the configuration with colleagues. A personal view can be your default for that report. Sharing a view does not grant access to a report or to records outside a colleague's permissions.
Sharing saved views#
The saved-views panel separates personal and tenant-wide views. Use the share-link action to send a colleague a link to a view. Editing and deletion follow the view's permissions; platform-provided locked views cannot be edited like your own views.
Scheduled delivery#
Recurring CSV and Excel delivery is available through a platform administrator. Ask support to configure the report, recipient users, rolling lookback window, and daily, weekly, or monthly cadence. Delivery runs at a tenant-local hour. Monthly schedules use days 1 to 28. There is no dedicated scheduling screen in the staff report interface yet.
The schedule keeps a snapshot of its report settings. Editing the original saved view does not change future scheduled exports; ask the administrator to update the schedule too. Recipients need an email address. Owner KPI digests can also be delivered through configured Telegram bindings; they are separate from full report attachments. WhatsApp delivery and arbitrary cron schedules are not available through report schedules.
Period-over-period comparison#
Live for table reports today. Every numeric cell carries an absolute delta, a percentage, and an up, down, or flat indicator against the prior matching window. The matcher uses the row key first, the row label as fallback. Rows that have no prior match render without a delta rather than as a false zero.
Dashboard-mode comparison (the KPI tile with a delta chip) is not wired yet. The data model has a placeholder on KpiResult but no current dashboard data source populates it.
Cross-branch roll-up (Coming soon)#
- Owner can view tenant-wide aggregated metrics with one click.
- Per-branch side-by-side compare with normalised per-FTE or per-chair KPIs.
- Drill into a single branch from any aggregated view.
- Today the branch-scope service supports passing multiple branch IDs at the API level. The FE just does not render the side-by-side view yet. Run the report twice with different branch filters until cross-branch ships.
Cohort and retention analytics (Coming soon)#
- Patient cohorts by first-visit month.
- Retention curve at M1, M3, M6, M12 (percent returning).
- Cohort revenue: lifetime value per acquisition vintage.
- Critical for marketing channel ROI: which sources bring patients that stay.
RFM segmentation (Coming soon)#
- Recency, frequency, monetary segments computed nightly.
- Segments visible on patient profile and as filters in reports.
- Drive campaign targeting (high-monetary recent customers, dormant low-recency).
External BI tool integration (Coming soon)#
- PowerBI, Looker, Tableau via API or scheduled CSV export.
- For sophisticated tenants who build their own data warehouse.
- Per-tenant read-only API key for BI consumption.
- Raw event stream available for tenants on integration tier.
Report categories (live registry)#
- Finance: payments summary, payment-method trend, outstanding invoices, revenue quality, tax summary, discount leakage, average collection days, COGS, gross margin. Trial balance, P&L, balance sheet, cash flow live in the Accounting module, not in reports.
- Sales: revenue, item performance, service profitability, AOV by branch, sales by time period.
- Patients: registrations, demographics, churn, first-visit source.
- Appointments: bookings, no-shows, utilisation, wait time.
- Inventory: stock value, consumption, expiry, write-off.
- CRM: pipeline, funnel, conversion.
- Marketing: source ROI, campaign performance, channel mix.
- Team: staff performance, staff revenue ranking, appointments per staff.
- Messaging: delivery, response, AI handover.
- Packages: sales, consumption, expiry, deferred revenue.
- Clinical: encounter counts, problem prevalence, outcome measures.
- Dashboards: aggregated KPI report definitions (open via the reports detail view).
Performance considerations#
The cache key is built from branch_ids, date_from, date_to, grouping, row groupings, column groupings, metrics, filters, comparison mode, page, page size, and ordering, then hashed with SHA-256. Any one of those is enough to invalidate.
- Precomputed reports warm their default-param cache every 30 minutes.
- Heavy reports cached server-side after first run with TTL = refresh_interval_minutes.
- Drill-down from KPI to records may be slower. Consider filter narrowing first.
- Export to Excel for very large result sets. Do not run interactively.
When the cache is in your way#
If a report shows a number you know is wrong because you just posted an invoice, the cache is almost always the cause. Three ways to break the key:
- Change any filter, even by one. Branch, date range, status, payment method. Filter changes change the SHA, the cache misses, the report re-runs live.
- Move the end date by one day. Same effect, different key.
- Wait. Cache TTL is the report's refresh_interval_minutes. Precomputed reports re-warm every 30 minutes.
Slow report timeout#
Every report execution sets a 30-second Postgres statement timeout. If your filter combination produces a heavy aggregate that runs past 30 seconds, Postgres cancels and the API returns a friendly "report timed out" message, not a 500. Two recoveries:
- Narrow the date range. A month at a time instead of a year.
- Drop one group-by. Each dimension expands the result set. Removing the deepest one often clears the timeout.
If a specific report consistently times out for a real reporting need, add it to the precompute list so the heavy query runs out-of-band on the beat schedule.
Precomputed vs live#
A report is precomputed when its definition flags precompute=True. Today this is the path the high-volume finance and dashboards reports take. The beat fan-out runs every 30 minutes, walks every real-customer tenant, and warms the default-param cache key, so the first paint after login is instant. Custom filter combinations still run live with their own cache key.
Reports without the flag run live on every request. The first run pays the full query cost. Subsequent runs with the same filters hit the cache until TTL.
Heavy export, what happens after you click Export#
Clicking Export on a large report creates a ReportRequest row, queues a Celery task on the heavy queue, and returns immediately with a status link. The worker has 5 minutes soft and 7 minutes hard timeout, with 6 exports per worker per minute as a rate limit. When the file lands, the system emails the requester a download link.
If the worker exhausts its timeout, the request is marked failed and you get an email saying so. Shrink the filter range and re-run. Do not raise the timeout silently. Past outages were caused by exports running unbounded.
Reports permissions#
Each report definition declares the Django permission codenames it requires. The catalogue endpoint filters to the subset the current user can see. The execute endpoint re-checks on every run. There is no per-report toggle UI under Settings. Permissions are managed at the role level via access_config.json and sync to RoleFeatureAccess. To grant a role a new report, add the permission to the role. Do not edit DB tables directly.
Branch scope is layered on top. A user without superuser sees only their accessible branches. A report executed with no branch filter returns the union of accessible branches, never the full tenant.
Permission scoping, "I see the tile but the drill is empty"#
Two things can hide rows from you:
- Report permission denies access to the report entirely. You do not see it in the catalogue.
- Branch scope filters rows to your accessible branches. The tile aggregate may still show a tenant-wide number from a precomputed cache, but the drill underneath only renders the records your branches own. This is the most common "the number does not match the list" cause.
If two managers see different totals for the same report, check whether they have different accessible_branches in their user profile.
Coming soon (consolidated)#
- Self-service scheduling and WhatsApp report delivery.
- Dashboard-mode period-over-period comparison (table mode already live).
- Cross-branch roll-up with per-FTE normalisation.
- Cohort and retention analytics.
- RFM segmentation.
- External BI tool integration (PowerBI, Looker, Tableau).
- Custom report builder (drag-drop dimensions and measures).
- NPS / patient satisfaction reporting.
- Predictive (churn risk, revenue forecast).
- Mobile owner widget for daily digest.
Common mistakes#
- Reading precomputed dashboard tiles as real-time: up to 30 minutes of drift. Fine for trend, not for live operations.
- Drill without filter narrowing: load 50,000 records, browser strains.
- Acting on a single-day anomaly: noise vs signal. Wait 2-3 weeks for trend.
- Building parallel reports outside the registry: drift from canonical KPIs.
- Owner relies on accountant emailed snapshots: same data manually, time wasted.
How the engine connects#
- Every module: emits the data that reports consume.
- Audit log: numbers traceable to records.
- Saved views: personal or tenant-wide report configurations.
- Automations: scheduled delivery as automated action.
- Notifications: dashboard alerts to owner.
- Export: CSV/Excel for external tools.
- API: BI tool read-only access (Coming soon).
