Overview
The medical tracking system captures:- Glucose levels (mg/dL)
- Blood pressure - systolic and diastolic (mmHg)
- Heart rate (beats per minute)
- Oxygen saturation (SpO₂ %)
- Body temperature (°C)
- Respiratory rate (breaths per minute)
- Weight (kg)
- Height (m)
- Age (years)
- Blood type (A+, A-, B+, B-, AB+, AB-, O+, O-)
All medical data routes require JWT authentication. Users can only submit and view their own data.
Data Input Flow
Medical Data Form
Frontend Component
Fromsrc/components/medinfo.jsx:57-119:
Input Validation Ranges
Glucose
Glucose
- Range: 0-999 mg/dL
- Type: number
- Required: Yes
- Normal Range: 70-100 mg/dL (fasting)
Oxygen Saturation (SpO₂)
Oxygen Saturation (SpO₂)
- Range: 0-100%
- Type: number
- Required: Yes
- Normal Range: 95-100%
Blood Pressure
Blood Pressure
- Systolic Range: 0-300 mmHg
- Diastolic Range: 0-200 mmHg
- Type: number
- Required: Yes (both values)
- Normal Range: Less than 120/80 mmHg
Heart Rate
Heart Rate
- Range: 0-300 bpm
- Type: number
- Required: Yes
- Normal Range: 60-100 bpm (adults at rest)
Temperature
Temperature
- Range: 0-50°C
- Type: number (0.1 step)
- Required: Yes
- Normal Range: 36.5-37.5°C
Respiratory Rate
Respiratory Rate
- Range: 0-150 breaths/min
- Type: number
- Required: Yes
- Normal Range: 12-20 breaths/min
Weight
Weight
- Range: 0-500 kg
- Type: number (0.1 step)
- Required: Yes
Height
Height
- Range: 0-3 meters
- Type: number (0.01 step)
- Required: Yes
Age
Age
- Range: 0-150 years
- Type: integer
- Required: Yes
Blood Type
Blood Type
- Options: A+, A-, B+, B-, AB+, AB-, O+, O-
- Type: enum/select
- Required: Yes
API Integration
Submitting Medical Data
- Request
- Response
- Error Response
Frontend Submit Handler
Fromsrc/components/medinfo.jsx:22-55:
Backend Implementation
Route Handler
Fromsrc/routes/medical.js:1-45:
Data Validation
Zod Schema
Fromsrc/validators/medical.js:1-18:
Key Validation Features
Flexible Number Parsing
The schema accepts both strings and numbers, automatically converting strings to numbers. This handles form data where inputs are strings:
Blood Type Enum
Blood type is strictly validated against the 8 valid blood types:
Error Details
Validation errors return detailed field-level feedback:
Database Storage
Medical Records Table
FrominitDb.js:17-34:
Key Database Features
Foreign Key Constraint
Foreign Key Constraint
user_id references the users table with CASCADE delete:Timestamp Tracking
Timestamp Tracking
Each record automatically stores creation time:This enables time-series analysis and tracking health trends over time.
Numeric Precision
Numeric Precision
Vitals use NUMERIC type for precise decimal storage:
Retrieving Medical Data
Get Latest Record
Fromsrc/routes/medical.js:49-79:
Frontend Data Fetching
Fromsrc/components/healthplan.jsx:22-45:
Real-time Updates
Event Emitter Pattern
Fromsrc/utils/medicalDataContext.js:
Usage
When data is saved, emit an event:This pattern ensures the health dashboard automatically updates when new medical data is submitted, without requiring manual page refresh.
Security Considerations
-
Authentication Required: All medical routes use the
authmiddleware -
Authorization Checks: Users can only submit/view their own data
-
Input Validation: Zod schema prevents invalid data
-
SQL Injection Prevention: Parameterized queries
Best Practices
Regular Tracking
Encourage users to input data regularly for trend analysis:
- Daily tracking of critical vitals (glucose for diabetics)
- Weekly general health checks
- Immediate logging after doctor visits
Data Accuracy
Ensure accurate measurements:
- Use calibrated medical devices
- Measure at consistent times
- Rest before taking vitals
- Follow device instructions
Privacy Protection
Medical data is highly sensitive:
- Never share authentication tokens
- Log out on shared devices
- Review access logs regularly
- Report suspicious activity
Related Documentation
- Authentication System - Learn how to authenticate users
- Health Dashboard - View and analyze tracked data