Ultrasound Analysis API
Ultrasound Analysis API
The Ultrasound Analysis API allows users to record and manage sonographic data throughout the first trimester. This data is used by the system to calculate medical-grade insights, track fetal development, and assess pregnancy risks.
Data Schema
All ultrasound entry objects follow this structure:
| Field | Type | Description |
| :--- | :--- | :--- |
| date | string | The date of the scan in YYYY-MM-DD format. |
| gestationalAge | string | Clinical gestational age (e.g., "7w 2d"). |
| gs_size | number | Gestational Sac size in millimeters (mm). |
| ys_size | number | Yolk Sac size in millimeters (mm). |
| crl_size | number | Crown-Rump Length in millimeters (mm). |
| heart_rate | number | Fetal heart rate in beats per minute (bpm). |
| numberOfSacs | number | Number of gestational sacs identified (Default: 1). |
| sacData | object | JSONB field for storing specific measurements for multiple sacs. |
| notes | string | Optional clinical notes or observations. |
Endpoints
All endpoints require authentication via session cookies.
1. Retrieve All Entries
GET /api/ultrasound-entries
Returns an array of all ultrasound records for the authenticated user.
Response (200 OK):
[
{
"id": 12,
"date": "2024-03-15",
"gestationalAge": "8w 0d",
"gs_size": 28,
"ys_size": 5,
"crl_size": 16,
"heart_rate": 155,
"numberOfSacs": 1,
"notes": "Healthy cardiac activity observed."
}
]
2. Create New Entry
POST /api/ultrasound-entries
Submits a new scan record.
Request Body:
{
"date": "2024-03-15",
"gestationalAge": "8w 0d",
"gs_size": 28,
"ys_size": 5,
"crl_size": 16,
"heart_rate": 155,
"notes": "Routine first trimester scan."
}
3. Update Entry
PUT /api/ultrasound-entries/:id
Updates an existing ultrasound record by ID.
4. Delete Entry
DELETE /api/ultrasound-entries/:id
Permanently removes a record from the database.
Implementation Example
To record a new ultrasound scan from the frontend:
async function saveUltrasoundData(scanData) {
try {
const response = await fetch('/api/ultrasound-entries', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
date: "2024-03-20",
gs_size: 32,
crl_size: 20,
heart_rate: 162,
gestationalAge: "8w 4d",
notes: "Scan performed at City General"
}),
});
if (!response.ok) throw new Error('Failed to save record');
const result = await response.json();
console.log('Record saved:', result.id);
} catch (err) {
console.error('Error:', err.message);
}
}
Advanced: Multiple Sac Support
For pregnancies with multiple sacs, the sacData field should be used to store an array of measurement objects corresponding to each sac. The numberOfSacs field should be updated accordingly to ensure accurate risk analysis.