Provides population-level symptom analytics for the clinician dashboard. Protected by Firebase Authentication.
- BigQuery Dataset & Table must exist (see Step 1 below)
- Firebase project configured (you already have this)
- gcloud CLI authenticated (you already have this)
Go to BigQuery Console and run this SQL:
-- Create the dataset (run this first, or create via UI)
-- Dataset ID: oncydra_analytics
-- Create and seed the table
CREATE OR REPLACE TABLE `oncydra.oncydra_analytics.symptom_trends`
(
report_month DATE,
symptom_name STRING,
avg_severity FLOAT64,
patient_count INT64
);
INSERT INTO `oncydra.oncydra_analytics.symptom_trends` (report_month, symptom_name, avg_severity, patient_count)
VALUES
-- September 2024 - Baseline (high symptoms)
('2024-09-01', 'Nausea', 6.8, 312),
('2024-09-01', 'Fatigue', 7.5, 445),
('2024-09-01', 'Pain', 5.2, 289),
('2024-09-01', 'Appetite Loss', 6.1, 356),
-- October 2024 - Starting to use Oncydra
('2024-10-01', 'Nausea', 5.9, 378),
('2024-10-01', 'Fatigue', 7.1, 462),
('2024-10-01', 'Pain', 4.8, 301),
('2024-10-01', 'Appetite Loss', 5.5, 389),
-- November 2024 - Improvements visible
('2024-11-01', 'Nausea', 4.5, 421),
('2024-11-01', 'Fatigue', 6.2, 478),
('2024-11-01', 'Pain', 4.1, 334),
('2024-11-01', 'Appetite Loss', 4.8, 412),
-- December 2024 - Strong results
('2024-12-01', 'Nausea', 3.2, 456),
('2024-12-01', 'Fatigue', 5.1, 489),
('2024-12-01', 'Pain', 3.5, 367),
('2024-12-01', 'Appetite Loss', 3.9, 434);The Story: This data shows symptom severity DECREASING over 4 months as patients use Oncydra for daily voice check-ins. Nausea drops from 6.8 to 3.2 (53% improvement!).
cd backend/analytics-function
gcloud functions deploy analytics-function \
--gen2 \
--runtime=python311 \
--region=europe-west1 \
--source=. \
--entry-point=analytics \
--trigger-http \
--allow-unauthenticated \
--project=oncydraNote: --allow-unauthenticated lets the HTTP request through, but our code still verifies the Firebase token. This is the standard pattern.
After deploy, you'll see something like:
https://europe-west1-oncydra.cloudfunctions.net/analytics-function
Save this URL - you'll need it for the frontend.
# This should return 401 Unauthorized (no token)
curl https://europe-west1-oncydra.cloudfunctions.net/analytics-function
# To test with a real token, use the frontend or get a token from Firebase consoleReturns symptom trends data (default)
Response:
{
"success": true,
"query_type": "trends",
"data": [
{
"report_month": "2024-09-01",
"symptom_name": "Nausea",
"avg_severity": 6.8,
"patient_count": 312
},
...
]
}Returns summary statistics
Response:
{
"success": true,
"query_type": "summary",
"data": {
"symptom_types": 4,
"total_patient_reports": 6323,
"overall_avg_severity": 5.26,
"max_patients_single_symptom": 489
}
}// In ClinicianDashboard.tsx or a separate hook
const fetchAnalytics = async () => {
const user = auth.currentUser;
if (!user) return;
const token = await user.getIdToken();
const response = await fetch(
'https://europe-west1-oncydra.cloudfunctions.net/analytics-function',
{
headers: {
'Authorization': `Bearer ${token}`
}
}
);
const data = await response.json();
return data;
};401 Unauthorized
- Check that the user is logged in
- Check that the token is being passed in the Authorization header
BigQuery errors
- Make sure the dataset
oncydra_analyticsexists - Make sure the table
symptom_trendshas data - Check Cloud Function logs:
gcloud functions logs read analytics-function --region=europe-west1
CORS errors
- The function includes CORS headers, but if issues persist, check browser console for details