Disease Outbreak Prevention
Rank the highest-risk facilities in a public health network by weighted degree centrality (connection volume and intensity) to prioritize resource deployment during outbreaks.
What this template is for
During a disease outbreak, public health officials must quickly decide where to deploy limited resources like vaccines, testing equipment, and emergency response teams. This template demonstrates how to use weighted degree centrality — a graph algorithm that combines connectivity with transmission risk metrics — to identify the most strategically important healthcare facilities.
By analyzing a network of hospitals, clinics, testing centers, and community organizations with weighted connections based on patient transfer volumes and contact intensity, this template helps you prioritize facilities that pose the greatest cumulative risk. These high-risk facilities act as critical hubs in the health network, making them ideal locations for maximum resource reach and rapid outbreak containment during an outbreak response.
Who this is for
- Intermediate users who want to learn weighted degree centrality with a real-world epidemiological use case
- Data scientists new to RelationalAI looking for a simple graph analytics example
- Public health analysts planning outbreak response strategies
- Healthcare network planners optimizing resource allocation
What you’ll build
- A risk-weighted facility ranking — every facility scored by weighted degree centrality (
transfer_volume x contact_intensitysummed over its edges) — produced by graph analysis. - Per-facility connectivity signals: incoming and outgoing connection counts (indegree and outdegree) alongside the centrality score.
- A prioritized shortlist of the highest-risk facilities to guide where limited outbreak-response resources go first.
- An optional interactive Streamlit view of the same ranking, with a network visualization and CSV export.
Built using graph analysis (a directed, weighted graph with Facility as the node concept and built-in weighted degree centrality).
What’s included
- Model: shared setup in
model_setup.py— theFacilityconcept, theFacilityConnectionedge concept (withtransfer_volume,contact_intensity, and a derivedrisk_weight), and the directed weightedGraphbuilt from them. - Runner:
disease_outbreak_prevention_network.py(command-line analysis with detailed output) andapp.py(optional Streamlit web app), both driven by the same shared model. - Runbook:
runbook.md— a paste-testable walkthrough that reproduces the template step by step with the RAI skills; as important a reference as the script itself. - Sample data:
data/facilities.csvanddata/connections.csv. - Outputs: a ranked facility table, a top-priority breakdown, and network summary statistics printed to stdout; the Streamlit app adds an interactive network graph and CSV export.
Prerequisites
Access
- A Snowflake account that has the RAI Native App installed.
- A Snowflake user with permissions to access the RAI Native App.
Tools
- Python >= 3.10
- RelationalAI Python SDK (
relationalai == 1.11.0). - Optional:
streamlit,plotly,numpyfor the interactive app (installed via thevisualizationextra).
Quickstart
Follow these steps to run the template with the included sample data. You can customize the data and model as needed after you have it running end-to-end.
-
Download the ZIP file for this template and extract it:
Terminal window curl -O https://docs.relational.ai/templates/zips/v1/disease-outbreak-prevention.zipunzip disease-outbreak-prevention.zipcd disease-outbreak-prevention -
Create and activate a virtual environment
Terminal window python -m venv .venvsource .venv/bin/activatepython -m pip install -U pip -
Install dependencies
From this folder:
Terminal window python -m pip install . -
Configure Snowflake connection and RAI profile
Terminal window rai init -
Run the template
Option A: Command-line script
Terminal window python disease_outbreak_prevention_network.pyOption B: Interactive Streamlit app
Terminal window # Install additional dependencies for visualizationpython -m pip install .[visualization]# Launch the interactive appstreamlit run app.pyThe Streamlit app provides:
- Interactive network visualization with directional arrows
- Filterable facility rankings table
- Detailed priority facility analysis
- CSV export functionality
-
Expected output — a few lines confirm a successful run:
Top facilities by weighted degree centrality (transmission risk):1. Central Hospital 2602. Public Health Dept 2603. Regional Testing Lab 2184. Emergency Response Hub 188The full ranked table, top-priority breakdown, and network summary print above and below this; see
runbook.mdfor the complete walkthrough.
Template structure
disease-outbreak-prevention/ disease_outbreak_prevention_network.py # main CLI analysis script app.py # optional Streamlit web app model_setup.py # shared model + graph setup (used by both) data/ facilities.csv # 10 facilities (id, name, type, region) connections.csv # 15 directed connections with risk metrics README.md # this file runbook.md # step-by-step analyst walkthrough pyproject.toml # dependenciesStart here: run python disease_outbreak_prevention_network.py for the full ranking end to end, or follow runbook.md to rebuild it step by step.
Sample data
The bundled data is small and illustrative — a 10-facility regional health network, sized to teach the weighted-centrality flow, not to match a specific jurisdiction’s network.
data/facilities.csv(10 rows) — one row per facility, withid,name,type(hospital, clinic, testing center, government, emergency services), andregion.data/connections.csv(15 rows) — one row per directed connection, withfrom_facility_id,to_facility_id,transfer_volume, andcontact_intensity. The model derives each connection’srisk_weightastransfer_volume x contact_intensity. Every id must reference a valid facility infacilities.csv.
Model overview
The model is a directed, weighted graph with one node concept and one edge concept.
- Key entities:
Facility— a healthcare facility, testing center, or community organization (the graph’s node);FacilityConnection— a directed transfer link between two facilities, weighted by transmission risk (the graph’s edge). - Primary identifiers:
Facility.id(integer);FacilityConnectionis identified by its(from_facility, to_facility)pair. - Important invariants:
transfer_volumeandcontact_intensityare non-negative;risk_weightis derived, not loaded (transfer_volume x contact_intensity); every connection endpoint references an existingFacility.
For the full concept and property definitions, see model_setup.py; runbook.md builds them step by step with the RAI skills.
How it works
Both runners share one model builder, then compute weighted centrality on the resulting graph and rank facilities:
CSV files → model_setup.create_model() → weighted centrality + degree metrics → rank facilities → display / export-
Shared model setup.
model_setup.create_model()builds everything both runners need in one call: the RelationalAI model, theFacilitynode concept, theFacilityConnectionedge concept, the CSV loads, the derivedrisk_weight(transfer_volume x contact_intensity), and the directed, weighted graph that usesrisk_weightas its edge weight. -
Calculate graph metrics. The Graph API computes weighted degree centrality (summing risk-weighted edges, so the score reflects cumulative transmission risk rather than a raw connection count) alongside indegree and outdegree counts.
-
Query and rank. A single query pulls each facility’s identity, type, region, centrality score, and in/out connection counts, then sorts descending by centrality to produce the ranked shortlist.
-
Present results. The CLI script prints the ranked table, a top-priority breakdown, network summary statistics, and response recommendations. The optional Streamlit app renders the same ranking as an interactive network graph with a filterable table and CSV export.
See model_setup.py and disease_outbreak_prevention_network.py for the implementation and runbook.md for the skill-driven reproduction.
Customize this template
Focus on the first changes most users will make.
Use your own data
- Replace the CSV files in
data/with your own network, keeping the same column names (or update the loading logic inmodel_setup.py). - Make sure every facility referenced in
connections.csvis a valid id infacilities.csv. - For Snowflake-backed runs, swap the
pd.read_csv(...)calls inmodel_setup.pyformodel.data(snowflake_table)calls.
Tune parameters
- The risk formula is
risk_weight = transfer_volume x contact_intensity, defined inmodel_setup.py. Change how the two factors combine (for example, a weighted average) to reweight what “risk” means. - Switch the graph’s centrality metric if you want a different notion of importance (for example, betweenness or eigenvector centrality) in place of weighted degree.
Extend the model
- Add more risk factors to
FacilityConnection(for example, disease prevalence or facility bed capacity) and fold them intorisk_weight. - Add temporal aspects (for example, seasonal variation in transmission rates) as additional edge properties.
Scale up / productionize
- Replace the CSV bundle with CDC ingestion from your health-network systems; the graph shape is independent of the load pipeline.
- Pin
relationalai(this template targets1.11.0) and schedule the run as a pipeline step for reproducible re-runs.
Troubleshooting
Why does authentication/configuration fail?
- Run
rai initto create/updateraiconfig.yaml. - If you have multiple profiles, set
RAI_PROFILEor switch profiles in your config.
Why does the script fail to connect to the RAI Native App?
- Verify the Snowflake account/role/warehouse and
rai_app_nameare correct inraiconfig.yaml. - Ensure the RAI Native App is installed and you have access.
Why is the Streamlit app missing dependencies?
- Install the visualization extra:
python -m pip install .[visualization](addsstreamlit,plotly,numpy).
Learn more
Core concepts
- PyRel v1 query language —
where(...)/select(...)and result extraction. - Concepts and relationships — modeling entities and edges like
FacilityandFacilityConnection.
Reasoner reference
- Graph reasoner — node-concept and edge-concept patterns, degree centrality, and other graph algorithms.
CLI / SDK guides
- RelationalAI setup —
rai init, profiles, andraiconfig.yaml.
Support
- File issues at the RelationalAI templates repository.