|
| 1 | +# BLOOM Analytics Dashboard Integration |
| 2 | + |
| 3 | +This directory contains a loosely-coupled analytics solution for BLOOM LIMS and other Laboratory Information Systems (LIS). The integration uses **Metabase**, an open-source business intelligence tool, connected directly to the PostgreSQL database. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +``` |
| 8 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 9 | +│ BLOOM LIMS │────▶│ PostgreSQL │◀────│ Metabase │ |
| 10 | +│ (FastAPI) │ │ Database │ │ (Analytics) │ |
| 11 | +└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 12 | + │ |
| 13 | + ▼ |
| 14 | + ┌─────────────────┐ |
| 15 | + │ SQL Views │ |
| 16 | + │ (Analytics) │ |
| 17 | + └─────────────────┘ |
| 18 | +``` |
| 19 | + |
| 20 | +## Why Metabase? |
| 21 | + |
| 22 | +| Feature | Benefit for Labs | |
| 23 | +|---------|------------------| |
| 24 | +| Open Source (AGPL) | Free, no vendor lock-in | |
| 25 | +| PostgreSQL Native | Direct connection to BLOOM database | |
| 26 | +| Visual Query Builder | Non-technical users can create reports | |
| 27 | +| Embeddable | Dashboard embedding in BLOOM UI | |
| 28 | +| Alerting | Automated notifications for thresholds | |
| 29 | +| API | Programmatic access to dashboards | |
| 30 | + |
| 31 | +## Quick Start |
| 32 | + |
| 33 | +### Option 1: Docker (Recommended) |
| 34 | + |
| 35 | +```bash |
| 36 | +# Start Metabase with Docker |
| 37 | +cd analytics/metabase |
| 38 | +docker-compose up -d |
| 39 | + |
| 40 | +# Access Metabase at http://localhost:3000 |
| 41 | +``` |
| 42 | + |
| 43 | +### Option 2: Standalone JAR |
| 44 | + |
| 45 | +```bash |
| 46 | +# Download and run Metabase |
| 47 | +./analytics/metabase/run_metabase.sh |
| 48 | +``` |
| 49 | + |
| 50 | +### Option 3: Conda Environment |
| 51 | + |
| 52 | +```bash |
| 53 | +# If using conda, Metabase can run alongside BLOOM |
| 54 | +conda activate BLOOM |
| 55 | +./analytics/metabase/run_metabase.sh |
| 56 | +``` |
| 57 | + |
| 58 | +## Configuration |
| 59 | + |
| 60 | +### Environment Variables |
| 61 | + |
| 62 | +Add to your `.env` file: |
| 63 | + |
| 64 | +```bash |
| 65 | +# Metabase Configuration |
| 66 | +METABASE_PORT=3000 |
| 67 | +METABASE_DB_TYPE=postgres |
| 68 | +METABASE_DB_HOST=localhost |
| 69 | +METABASE_DB_PORT=5432 |
| 70 | +METABASE_DB_NAME=bloom_lims |
| 71 | +METABASE_DB_USER=bloom_user |
| 72 | +METABASE_DB_PASS=your_password |
| 73 | + |
| 74 | +# Optional: Embed dashboards in BLOOM |
| 75 | +METABASE_EMBED_SECRET=your-embed-secret-key |
| 76 | +``` |
| 77 | + |
| 78 | +## SQL Views for Analytics |
| 79 | + |
| 80 | +The `sql_views/` directory contains PostgreSQL views optimized for analytics: |
| 81 | + |
| 82 | +| View | Purpose | Key Metrics | |
| 83 | +|------|---------|-------------| |
| 84 | +| `v_sample_throughput` | Sample processing rates | Samples/day, TAT | |
| 85 | +| `v_workflow_bottlenecks` | Queue analysis | Wait times, backlogs | |
| 86 | +| `v_equipment_utilization` | Equipment usage | Utilization %, downtime | |
| 87 | +| `v_turnaround_times` | TAT analysis | Mean, median, percentiles | |
| 88 | +| `v_audit_activity` | User activity | Actions/user, peak times | |
| 89 | +| `v_object_counts` | Inventory | Counts by type/status | |
| 90 | + |
| 91 | +### Installing Views |
| 92 | + |
| 93 | +```bash |
| 94 | +# Run the analytics views installation script |
| 95 | +psql -d bloom_lims -f analytics/sql_views/install_views.sql |
| 96 | +``` |
| 97 | + |
| 98 | +## Sample Dashboards |
| 99 | + |
| 100 | +Pre-built dashboard configurations are in `dashboards/`: |
| 101 | + |
| 102 | +1. **Operations Overview** - Daily sample counts, active workflows |
| 103 | +2. **Turnaround Time Monitor** - TAT trends, SLA compliance |
| 104 | +3. **Equipment Dashboard** - Utilization, maintenance schedules |
| 105 | +4. **Quality Metrics** - Error rates, reprocessing trends |
| 106 | +5. **User Activity** - Audit logs, action summaries |
| 107 | + |
| 108 | +## Portability to Other LIS |
| 109 | + |
| 110 | +This analytics solution is designed to be portable: |
| 111 | + |
| 112 | +1. **Standardized Views**: SQL views use common LIS terminology |
| 113 | +2. **Configurable Mappings**: `config/lis_mappings.yaml` maps BLOOM fields to standard names |
| 114 | +3. **API Abstraction**: Dashboard definitions reference abstract metrics |
| 115 | +4. **Documentation**: Each view includes comments for adaptation |
| 116 | + |
| 117 | +### Adapting for Another LIS |
| 118 | + |
| 119 | +1. Copy `analytics/` directory to your LIS project |
| 120 | +2. Edit `config/lis_mappings.yaml` to map your schema |
| 121 | +3. Modify SQL views to match your database structure |
| 122 | +4. Import dashboard configurations into Metabase |
| 123 | + |
| 124 | +## Security Considerations |
| 125 | + |
| 126 | +- Metabase connects read-only to the database (recommended) |
| 127 | +- Use a dedicated database user with SELECT-only permissions |
| 128 | +- Enable HTTPS for production deployments |
| 129 | +- Configure Metabase authentication (LDAP, SSO, etc.) |
| 130 | + |
| 131 | +## Directory Structure |
| 132 | + |
| 133 | +``` |
| 134 | +analytics/ |
| 135 | +├── README.md # This file |
| 136 | +├── metabase/ |
| 137 | +│ ├── docker-compose.yml # Docker deployment |
| 138 | +│ ├── run_metabase.sh # Standalone runner |
| 139 | +│ └── metabase.db/ # Metabase config (gitignored) |
| 140 | +├── dashboards/ |
| 141 | +│ ├── operations_overview.json |
| 142 | +│ ├── turnaround_times.json |
| 143 | +│ └── equipment_utilization.json |
| 144 | +├── sql_views/ |
| 145 | +│ ├── install_views.sql # Main installation script |
| 146 | +│ ├── v_sample_throughput.sql |
| 147 | +│ ├── v_workflow_bottlenecks.sql |
| 148 | +│ └── ... |
| 149 | +└── config/ |
| 150 | + └── lis_mappings.yaml # LIS field mappings |
| 151 | +``` |
| 152 | + |
| 153 | +## Troubleshooting |
| 154 | + |
| 155 | +### Metabase can't connect to PostgreSQL |
| 156 | +- Ensure PostgreSQL is running: `pg_isready` |
| 157 | +- Check connection settings in Metabase admin |
| 158 | +- Verify firewall allows connection on port 5432 |
| 159 | + |
| 160 | +### Views not showing data |
| 161 | +- Run `SELECT * FROM v_sample_throughput LIMIT 5;` to test |
| 162 | +- Check that BLOOM has data in the database |
| 163 | +- Verify view permissions for Metabase user |
| 164 | + |
| 165 | +## License |
| 166 | + |
| 167 | +This analytics integration is released under the same MIT license as BLOOM LIMS. |
| 168 | + |
0 commit comments