Medical Risk Algorithms
The HCG AI engine utilizes clinical growth curves and statistical modeling to assess pregnancy progression. By comparing HCG titers and ultrasound measurements against expected gestational age, the system generates standardized Z-scores and categorizes findings into specific risk tiers.
Core Calculation Logic
The risk assessment is triggered upon the creation or update of HCG or Ultrasound entries. The algorithm evaluates the following primary data points:
1. HCG Trend Analysis
- Doubling Time: Calculated between successive HCG entries to ensure titers are increasing at a rate consistent with a viable intrauterine pregnancy (IUP).
- Gestational Age Correlation: Compares HCG values against the estimated gestational age (derived from LMP or ovulation date).
2. Ultrasound Biometrics
The system calculates Z-scores for four critical measurements:
- GS (Gestational Sac Size): Evaluated in millimeters.
- YS (Yolk Sac Size): Evaluated for presence and size (typically 3–6mm).
- CRL (Crown-Rump Length): The primary indicator of fetal age.
- FHR (Fetal Heart Rate): Measured in beats per minute (BPM).
Risk Level Definitions
Analysis results are stored in the analysis_results table and categorized into one of three risk levels:
| Risk Level | Clinical Context | | :--- | :--- | | LOW | Measurements are within ±1 Standard Deviation (SD) of the mean for the calculated gestational age. Doubling times are normal. | | MEDIUM | Measurements fall between 1–2 SD from the mean, or there is a discrepancy between HCG levels and ultrasound findings (e.g., HCG > 2000 mIU/mL without a visible sac). | | HIGH | Significant deviations (>2 SD), declining HCG levels, or absence of expected structures (e.g., CRL > 7mm with no heartbeat). |
Data Structure & API Usage
The Analysis Object
When querying the API for analysis, the system returns a structured analysisResult object linked to a specific entry.
Type Definition (JSON):
{
id: number;
entryType: 'hcg' | 'ultrasound';
entryId: number;
diagnosis: string; // Human-readable summary
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH';
zScores: {
hcg_z?: number;
crl_z?: number;
gs_z?: number;
};
recommendations: string[]; // Array of suggested clinical follow-ups
createdAt: string;
}
Retrieving Risk Data
To access the calculated risk for a specific user, you can query the analysis results associated with their entries.
# Example: Fetching analysis for a specific user session
GET /api/hcg-entries
Example Response Integration:
// Example of how the risk level is handled in the UI
const displayRiskAssessment = (analysis) => {
const { riskLevel, diagnosis, zScores } = analysis;
if (riskLevel === 'HIGH') {
notifyProvider(diagnosis); // Clinical alert logic
}
console.log(`Current HCG Z-Score: ${zScores.hcg_z}`);
};
Input Requirements for Accuracy
For the risk algorithm to function correctly, the following "Advanced Details" are highly recommended during data entry:
- LMP (Last Menstrual Period): Used as the baseline for gestational age.
- Cycle Length: Adjusts the expected ovulation date for non-standard (28-day) cycles.
- Ovulation Date: If known (via tracking or IVF), this overrides LMP for higher precision in Z-score calculation.
AI Interpretation
While the algorithmic risk level is based on hard clinical thresholds, the AI Chatbot (via OpenAI) utilizes the analysisResults and notes fields to provide conversational context to the user, explaining what a specific Z-score or doubling time means in layman's terms.