Health API reference
Health sleep
Health sleep module for managing user sleep data.
This module provides CRUD operations and data models for user sleep tracking including sleep duration, stages, quality metrics, heart rate, SpO2, and sleep scoring.
Exports
- CRUD: get_health_sleep_number_by_user_id, get_health_sleep_by_user_id, get_health_sleep_by_date_and_user_id, create_health_sleep, edit_health_sleep, delete_health_sleep
- Schemas: HealthSleepBase, HealthSleepCreate, HealthSleepUpdate, HealthSleepRead, HealthSleepListResponse, HealthSleepStage
- Enums: Source, SleepStageType, HRVStatus, SleepScore
- Models: HealthSleep (ORM model)
HRVStatus
Bases: Enum
Enum representing the Heart Rate Variability (HRV) status classification.
Attributes:
| Name | Type | Description |
|---|---|---|
BALANCED |
Indicates healthy HRV levels with good cardiovascular autonomic balance. |
|
UNBALANCED |
Indicates HRV levels showing some autonomic imbalance or stress. |
|
LOW |
Indicates HRV levels that are lower than optimal, suggesting fatigue or overtraining. |
|
POOR |
Indicates critically low HRV levels, suggesting significant stress, illness, or recovery issues. |
Source code in backend/app/modules/health/health_sleep/schema.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
HealthSleepBase
Bases: BaseModel
Pydantic model representing the base schema for health sleep data.
This model defines the structure and validation rules for sleep-related health metrics, including sleep duration, quality scores, heart rate variability, oxygen saturation, respiration rates, and sleep stages.
Attributes:
| Name | Type | Description |
|---|---|---|
date |
date | None
|
Calendar date of the sleep session. |
sleep_start_time_gmt |
datetime | None
|
Start time of sleep in GMT. |
sleep_end_time_gmt |
datetime | None
|
End time of sleep in GMT. |
sleep_start_time_local |
datetime | None
|
Start time of sleep in local time. |
sleep_end_time_local |
datetime | None
|
End time of sleep in local time. |
total_sleep_seconds |
StrictInt | None
|
Total duration of sleep in seconds (>= 0). |
nap_time_seconds |
StrictInt | None
|
Duration of naps in seconds (>= 0). |
unmeasurable_sleep_seconds |
StrictInt | None
|
Unmeasurable sleep duration in seconds (>= 0). |
deep_sleep_seconds |
StrictInt | None
|
Duration of deep sleep in seconds (>= 0). |
light_sleep_seconds |
StrictInt | None
|
Duration of light sleep in seconds (>= 0). |
rem_sleep_seconds |
StrictInt | None
|
Duration of REM sleep in seconds (>= 0). |
awake_sleep_seconds |
StrictInt | None
|
Duration of awake time in seconds (>= 0). |
avg_heart_rate |
StrictInt | None
|
Average heart rate during sleep (20-220 bpm). |
min_heart_rate |
StrictInt | None
|
Minimum heart rate during sleep (20-220 bpm). |
max_heart_rate |
StrictInt | None
|
Maximum heart rate during sleep (20-220 bpm). |
avg_spo2 |
StrictInt | None
|
Average SpO2 oxygen saturation percentage (70-100%). |
lowest_spo2 |
StrictInt | None
|
Lowest SpO2 reading during sleep (70-100%). |
highest_spo2 |
StrictInt | None
|
Highest SpO2 reading during sleep (70-100%). |
avg_respiration |
StrictInt | None
|
Average respiration rate (>= 0). |
lowest_respiration |
StrictInt | None
|
Lowest respiration rate (>= 0). |
highest_respiration |
StrictInt | None
|
Highest respiration rate (>= 0). |
avg_stress_level |
StrictInt | None
|
Average stress level (0-100). |
awake_count |
StrictInt | None
|
Number of times awake during sleep (>= 0). |
restless_moments_count |
StrictInt | None
|
Number of restless moments during sleep (>= 0). |
sleep_score_overall |
StrictInt | None
|
Overall sleep score (0-100). |
sleep_score_duration |
SleepScore | None
|
Sleep duration score. |
sleep_score_quality |
SleepScore | None
|
Sleep quality score. |
garminconnect_sleep_id |
StrictStr | None
|
Garmin Connect sleep record ID. |
sleep_stages |
list[SleepStage] | None
|
List of sleep stages. |
source |
Source | None
|
Source of the sleep data. |
hrv_status |
HRVStatus | None
|
Heart rate variability status. |
resting_heart_rate |
StrictInt | None
|
Resting heart rate (20-220 bpm). |
avg_skin_temp_deviation |
StrictFloat | None
|
Average skin temperature deviation. |
awake_count_score |
SleepScore | None
|
Awake count score. |
rem_percentage_score |
SleepScore | None
|
REM percentage score. |
deep_percentage_score |
SleepScore | None
|
Deep sleep percentage score. |
light_percentage_score |
SleepScore | None
|
Light sleep percentage score. |
avg_sleep_stress |
StrictInt | None
|
Average sleep stress (0-100). |
sleep_stress_score |
SleepScore | None
|
Sleep stress score. |
Model Configuration
- Allows population from ORM attributes
- Forbids extra fields
- Validates on assignment
- Uses enum values in serialization
Validators
validate_sleep_times: Ensures sleep start time is before sleep end time for both GMT and local time zones.
Source code in backend/app/modules/health/health_sleep/schema.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
validate_sleep_times
validate_sleep_times()
Validate sleep start < end.
Source code in backend/app/modules/health/health_sleep/schema.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
HealthSleepCreate
Bases: HealthSleepBase
Validator for HealthSleepCreate model that automatically sets the date field.
This validator runs after model initialization to ensure that if no date is provided, it defaults to today's date.
Source code in backend/app/modules/health/health_sleep/schema.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
set_default_date
set_default_date()
Set date to today if not provided.
Clients should always send their own local date — the request carries no
timezone, so this fallback can only use the server's configured zone and
will file an entry logged near local midnight under the wrong day for an
athlete elsewhere. Resolved through settings.TZ explicitly rather
than date.today(), which silently depends on the container's clock.
Returns:
| Type | Description |
|---|---|
HealthSleepCreate
|
The validated model instance with date set. |
Source code in backend/app/modules/health/health_sleep/schema.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
HealthSleepListResponse
Bases: HealthListResponse
Response model for listing health sleep records.
Extends the base HealthListResponse to provide a typed response containing a list of sleep records. This model is used when returning multiple sleep entries from API endpoints.
Attributes:
| Name | Type | Description |
|---|---|---|
records |
list[HealthSleepRead]
|
A list of HealthSleepRead objects representing individual sleep records. |
Source code in backend/app/modules/health/health_sleep/schema.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
HealthSleepRead
Bases: HealthSleepBase
Read schema for health sleep records.
Extends the base health sleep schema with an identifier field for retrieving or referencing existing sleep records in the database.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
StrictInt
|
Foreign key reference to the user. |
id |
StrictInt
|
Unique identifier for the sleep record to update or retrieve. |
Source code in backend/app/modules/health/health_sleep/schema.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
HealthSleepStage
Bases: BaseModel
Represents a sleep stage with timing and duration information.
This model captures details about individual sleep stages within a sleep session, including the type of stage, when it occurred, and how long it lasted.
Attributes:
| Name | Type | Description |
|---|---|---|
stage_type |
SleepStageType | None
|
The classification of the sleep stage (e.g., light, deep, REM). |
start_time_gmt |
datetime | None
|
The beginning timestamp of the sleep stage in GMT timezone. |
end_time_gmt |
datetime | None
|
The ending timestamp of the sleep stage in GMT timezone. |
duration_seconds |
StrictInt | None
|
The length of the sleep stage in seconds. Must be non-negative. |
Source code in backend/app/modules/health/health_sleep/schema.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
HealthSleepUpdate
Bases: HealthSleepRead
Schema for updating health sleep records.
Inherits all fields from HealthSleepRead, allowing clients to update existing sleep data while maintaining consistency with the read schema.
Used in PUT/PATCH requests to modify sleep tracking information such as sleep duration, quality, and related health metrics.
Source code in backend/app/modules/health/health_sleep/schema.py
288 289 290 291 292 293 294 295 296 297 | |
SleepScore
Bases: Enum
Enumeration of sleep quality score levels.
Attributes:
| Name | Type | Description |
|---|---|---|
EXCELLENT |
str
|
Represents excellent sleep quality. |
GOOD |
str
|
Represents good sleep quality. |
FAIR |
str
|
Represents fair sleep quality. |
POOR |
str
|
Represents poor sleep quality. |
Source code in backend/app/modules/health/health_sleep/schema.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
SleepStageType
Bases: Enum
Enum representing different stages of sleep.
Attributes:
| Name | Type | Description |
|---|---|---|
DEEP |
int
|
Deep sleep stage, value 0. Characterized by slow brain waves and muscle relaxation. |
LIGHT |
int
|
Light sleep stage, value 1. Transitional sleep between wakefulness and deep sleep. |
REM |
int
|
Rapid Eye Movement sleep stage, value 2. Associated with vivid dreams and mental activity. |
AWAKE |
int
|
Awake state, value 3. The stage when the person is conscious and not sleeping. |
Source code in backend/app/modules/health/health_sleep/schema.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Source
Bases: Enum
Enum representing the source of sleep health data.
Attributes:
| Name | Type | Description |
|---|---|---|
GARMIN |
Sleep data sourced from Garmin devices or services. |
Source code in backend/app/modules/health/health_sleep/schema.py
20 21 22 23 24 25 26 27 28 | |
create_health_sleep
create_health_sleep(user_id, health_sleep, db)
Create a new health sleep record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID for the sleep record. |
required |
health_sleep
|
HealthSleepCreate
|
Health sleep data to create. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthSleepRead
|
Created health sleep record with assigned ID. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 if duplicate entry, 500 if database error. |
Source code in backend/app/modules/health/health_sleep/crud.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
delete_health_sleep
delete_health_sleep(user_id, health_sleep_id, db)
Delete a health sleep record for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the sleep record. |
required |
health_sleep_id
|
int
|
Sleep record ID to delete. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if not found, 500 if database error. |
Source code in backend/app/modules/health/health_sleep/crud.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
edit_health_sleep
edit_health_sleep(user_id, health_sleep, db)
Edit an existing health sleep record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID whose sleep record is being edited. |
required |
health_sleep
|
HealthSleepUpdate
|
Updated health sleep data. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthSleepRead
|
Updated HealthSleepRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if trying to edit other user record, 404 if not found, 500 if database error. |
Source code in backend/app/modules/health/health_sleep/crud.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_health_sleep_by_date_and_user_id
get_health_sleep_by_date_and_user_id(user_id, date, db)
Retrieve health sleep record for a user on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID. |
required |
date
|
str
|
Date string for the sleep record. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthSleepRead | None
|
HealthSleepRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_sleep/crud.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_health_sleep_by_user_id
get_health_sleep_by_user_id(user_id, db, page_number=None, num_records=None, interval=None)
Retrieve health sleep records for a specific user with optional pagination and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user whose health sleep records are to be retrieved. |
required |
db
|
Session
|
The database session used to execute the query. |
required |
page_number
|
int | None
|
The page number for pagination (1-indexed). If provided, num_records must also be provided. Defaults to None. |
None
|
num_records
|
int | None
|
The number of records per page. If provided, page_number must also be provided. Defaults to None. |
None
|
interval
|
Interval | None
|
The time interval to filter records. If provided, only records from the start of the interval to present are returned. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[HealthSleepRead]
|
list[health_sleep_schema.HealthSleepRead]: A list of health sleep records sorted by date in descending order, optionally paginated. |
Source code in backend/app/modules/health/health_sleep/crud.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
get_health_sleep_number_by_user_id
get_health_sleep_number_by_user_id(user_id, db, interval=None)
Retrieve total count of health sleep records for a user. If interval is provided, count only records starting from the calculated start date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to count records for. |
required |
db
|
Session
|
Database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of health sleep records. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_sleep/crud.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Health steps
Health steps module for managing user step count data.
This module provides CRUD operations and data models for user step tracking including daily step counts and data sources.
Exports
- CRUD: get_health_steps_number_by_user_id, get_health_steps_by_user_id, get_health_steps_by_date_and_user_id, create_health_steps, edit_health_steps, delete_health_steps
- Schemas: HealthStepsBase, HealthStepsCreate, HealthStepsUpdate, HealthStepsRead, HealthStepsListResponse
- Enums: Source
- Models: HealthSteps (ORM model)
HealthStepsBase
Bases: BaseModel
Base model for health steps data.
Represents the core attributes of a user's step count record, including the user reference, date of the record, number of steps taken, and the source of the data.
Attributes:
| Name | Type | Description |
|---|---|---|
date |
date | None
|
Calendar date of the steps record. Optional field. |
steps |
StrictInt | None
|
Number of steps taken. Must be a non-negative integer. Optional field. |
source |
Source | None
|
Source of the steps data (e.g., device, API, manual entry). Optional field. |
Configuration
- from_attributes: Allows model to be populated from ORM objects.
- extra: Forbids any extra fields not defined in the model.
- validate_assignment: Validates field values when assigned after model creation.
- use_enum_values: Uses enum values instead of enum objects in serialization.
Source code in backend/app/modules/health/health_steps/schema.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
HealthStepsCreate
Bases: HealthStepsBase
Validator for HealthStepsCreate model that automatically sets the date field.
This validator runs after model initialization to ensure that if no date is provided, it defaults to today's date.
Source code in backend/app/modules/health/health_steps/schema.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
set_default_date
set_default_date()
Set date to today if not provided.
Clients should always send their own local date — the request carries no
timezone, so this fallback can only use the server's configured zone and
will file an entry logged near local midnight under the wrong day for an
athlete elsewhere. Resolved through settings.TZ explicitly rather
than date.today(), which silently depends on the container's clock.
Returns:
| Type | Description |
|---|---|
HealthStepsCreate
|
The validated model instance with date set. |
Source code in backend/app/modules/health/health_steps/schema.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
HealthStepsListResponse
Bases: HealthListResponse
Response model for listing health steps records.
Extends the base HealthListResponse to provide a typed response containing a list of steps records. This model is used when returning multiple steps entries from API endpoints.
Attributes:
| Name | Type | Description |
|---|---|---|
records |
list[HealthStepsRead]
|
A list of HealthStepsRead objects representing individual steps records. |
Source code in backend/app/modules/health/health_steps/schema.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
HealthStepsRead
Bases: HealthStepsBase
Schema for reading health steps records.
Extends the base health steps schema with an identifier field for retrieving or referencing existing steps records in the database.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the steps record to update. Required field. |
user_id |
StrictInt
|
Foreign key reference to the user. Required field. |
Source code in backend/app/modules/health/health_steps/schema.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
HealthStepsUpdate
Bases: HealthStepsRead
Schema for updating health steps records.
Inherits from HealthStepsRead to maintain consistency with read operations while allowing modifications to health steps data. This schema is used for PUT/PATCH requests to update existing health steps entries.
Source code in backend/app/modules/health/health_steps/schema.py
96 97 98 99 100 101 102 103 | |
Source
Bases: Enum
An enumeration representing supported sources for the application.
Members
GARMIN: Garmin health data source
Source code in backend/app/modules/health/health_steps/schema.py
11 12 13 14 15 16 17 18 19 | |
create_health_steps
create_health_steps(user_id, health_steps, db)
Create a new health steps record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID for the record owner. |
required |
health_steps
|
HealthStepsCreate
|
Health steps data to create. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthStepsRead
|
Created health steps record. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If duplicate entry or database error. |
Source code in backend/app/modules/health/health_steps/crud.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
delete_health_steps
delete_health_steps(user_id, health_steps_id, db)
Delete a health steps record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_steps_id
|
int
|
Health steps record ID to delete. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If record not found or database error. |
Source code in backend/app/modules/health/health_steps/crud.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
edit_health_steps
edit_health_steps(user_id, health_steps, db)
Edit health steps record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_steps
|
HealthStepsUpdate
|
Health steps data to update. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthStepsRead
|
Updated HealthStepsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if trying to edit other user record, 404 if not found, 500 if database error. |
Source code in backend/app/modules/health/health_steps/crud.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
get_health_steps_by_date_and_user_id
get_health_steps_by_date_and_user_id(user_id, date, db)
Retrieve health steps record for a user on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID. |
required |
date
|
str
|
Date string for the steps record. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthStepsRead | None
|
HealthStepsRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_steps/crud.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
get_health_steps_by_user_id
get_health_steps_by_user_id(user_id, db, page_number=None, num_records=None, interval=None)
Retrieve health steps records for a specific user with optional pagination and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user whose health steps records are to be retrieved. |
required |
db
|
Session
|
The database session used to execute the query. |
required |
page_number
|
int | None
|
The page number for pagination (1-indexed). If provided, num_records must also be provided. Defaults to None. |
None
|
num_records
|
int | None
|
The number of records per page. If provided, page_number must also be provided. Defaults to None. |
None
|
interval
|
Interval | None
|
The time interval to filter records. If provided, only records from the start of the interval to present are returned. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[HealthStepsRead]
|
list[health_steps_schema.HealthStepsRead]: A list of health steps records sorted by date in descending order, optionally paginated. |
Source code in backend/app/modules/health/health_steps/crud.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
get_health_steps_number_by_user_id
get_health_steps_number_by_user_id(user_id, db, interval=None)
Retrieve total count of health steps records for a user. If interval is provided, count only records starting from the calculated start date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to count records for. |
required |
db
|
Session
|
Database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of health steps records. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_steps/crud.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Health targets
Health targets module for managing user health goals.
This module provides CRUD operations and data models for user health targets including weight, steps, and sleep goals.
Exports
- CRUD: get_health_targets_by_user_id, create_health_targets, edit_health_target
- Schemas: HealthTargetsBase, HealthTargetsUpdate, HealthTargetsRead
HealthTargetsBase
Bases: BaseModel
Base schema for health targets with shared fields.
Attributes:
| Name | Type | Description |
|---|---|---|
weight |
StrictFloat | None
|
Target weight in kg. |
steps |
StrictInt | None
|
Target daily steps count. |
sleep |
StrictInt | None
|
Target sleep duration in seconds. |
fasting |
StrictInt | None
|
Target fasting duration in seconds. |
water_ml |
StrictFloat | None
|
Target daily water intake in milliliters. |
poop_count |
StrictInt | None
|
Target daily bowel movement count. |
Source code in backend/app/modules/health/health_targets/schema.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
HealthTargetsRead
Bases: HealthTargetsBase
Schema for reading health targets.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the health target record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_targets/schema.py
46 47 48 49 50 51 52 53 54 55 56 | |
HealthTargetsUpdate
Bases: HealthTargetsRead
Schema for updating health targets.
Inherits all validation from HealthTargetsRead. All fields are optional for partial updates.
Source code in backend/app/modules/health/health_targets/schema.py
59 60 61 62 63 64 65 | |
create_health_targets
create_health_targets(user_id, db)
Create new health targets for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to create targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargetsRead
|
The created HealthTargetsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 error if targets already exist. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/health/health_targets/crud.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
edit_health_target
edit_health_target(health_target, user_id, db)
Update health targets for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_target
|
HealthTargetsUpdate
|
Schema with fields to update. |
required |
user_id
|
int
|
The ID of the user to update targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargetsRead
|
The updated HealthTargetsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if targets not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/modules/health/health_targets/crud.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
get_health_targets_by_user_id
get_health_targets_by_user_id(user_id, db)
Retrieve health targets for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to fetch targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargetsRead | None
|
The HealthTargetsRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/modules/health/health_targets/crud.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Health water
Health water intake module for managing user hydration data.
This module provides CRUD operations and data models for user water intake tracking including daily consumption amounts and data sources.
Exports
- CRUD: get_health_water_number_by_user_id, get_health_water_by_id_and_user_id, get_health_water_by_user_id, get_health_water_by_date_and_user_id, create_health_water, edit_health_water, delete_health_water
- Schemas: HealthWaterBase, HealthWaterCreate, HealthWaterUpdate, HealthWaterRead, HealthWaterListResponse
- Enums: Source
HealthWaterBase
Bases: BaseModel
Base model for health water intake data.
Attributes:
| Name | Type | Description |
|---|---|---|
date |
date | None
|
Calendar date of the water intake record. |
amount_ml |
StrictFloat | None
|
Water consumed in milliliters. |
source |
Source | None
|
Source of the water intake data. |
Source code in backend/app/modules/health/health_water/schema.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
HealthWaterCreate
Bases: HealthWaterBase
Schema for creating a new water intake record.
Automatically sets the date to today if not provided.
Source code in backend/app/modules/health/health_water/schema.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
set_default_date
set_default_date()
Set date to today if not provided.
Clients should always send their own local date — the request carries no
timezone, so this fallback can only use the server's configured zone and
will file an entry logged near local midnight under the wrong day for an
athlete elsewhere. Resolved through settings.TZ explicitly rather
than date.today(), which silently depends on the container's clock.
Returns:
| Type | Description |
|---|---|
HealthWaterCreate
|
The validated model instance with date set. |
Source code in backend/app/modules/health/health_water/schema.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
HealthWaterListResponse
Bases: HealthListResponse
Response model for listing health water intake records.
Attributes:
| Name | Type | Description |
|---|---|---|
records |
list[HealthWaterRead]
|
A list of HealthWaterRead objects representing individual water intake records. |
Source code in backend/app/modules/health/health_water/schema.py
125 126 127 128 129 130 131 132 133 134 135 136 137 | |
HealthWaterRead
Bases: HealthWaterBase
Schema for reading a water intake record.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the water intake record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_water/schema.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
HealthWaterUpdate
Bases: HealthWaterRead
Schema for updating a water intake record.
Inherits from HealthWaterRead for consistency with read operations while allowing modifications to water intake data.
Source code in backend/app/modules/health/health_water/schema.py
116 117 118 119 120 121 122 | |
Source
Bases: Enum
Enumeration of data sources for water intake records.
Attributes:
| Name | Type | Description |
|---|---|---|
MANUAL |
Manually entered water intake data. |
|
GARMIN |
Garmin fitness tracking platform as a data source. |
Source code in backend/app/modules/health/health_water/schema.py
25 26 27 28 29 30 31 32 33 34 35 | |
create_health_water
create_health_water(user_id, health_water, db)
Create a new water intake record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID for the record owner. |
required |
health_water
|
HealthWaterCreate
|
Water intake data to create. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead
|
Created water intake record. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If duplicate entry or database error. |
Source code in backend/app/modules/health/health_water/crud.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
delete_health_water
delete_health_water(user_id, health_water_id, db)
Delete a water intake record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_water_id
|
int
|
Water intake record ID to delete. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If record not found or database error. |
Source code in backend/app/modules/health/health_water/crud.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
edit_health_water
edit_health_water(user_id, health_water, db)
Edit water intake record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_water
|
HealthWaterUpdate
|
Water intake data to update. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead
|
Updated HealthWaterRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if editing another user's record, 404 if not found, 500 if database error. |
Source code in backend/app/modules/health/health_water/crud.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_health_water_by_date_and_user_id
get_health_water_by_date_and_user_id(user_id, date, db)
Retrieve water intake record for a user on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID. |
required |
date
|
str
|
Date string for the water intake record. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead | None
|
HealthWaterRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_water/crud.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
get_health_water_by_id_and_user_id
get_health_water_by_id_and_user_id(health_water_id, user_id, db)
Retrieve water intake record by ID and user ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_water_id
|
int
|
Water intake record ID to fetch. |
required |
user_id
|
int
|
User ID to fetch record for. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead | None
|
HealthWaterRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_water/crud.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_health_water_by_user_id
get_health_water_by_user_id(user_id, db, page_number=None, num_records=None, interval=None)
Retrieve water intake records for a user with optional pagination and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID whose records are to be retrieved. |
required |
db
|
Session
|
Database session used to execute the query. |
required |
page_number
|
int | None
|
Page number for pagination (1-indexed). |
None
|
num_records
|
int | None
|
Number of records per page. |
None
|
interval
|
Interval | None
|
Time interval to filter records. |
None
|
Returns:
| Type | Description |
|---|---|
list[HealthWaterRead]
|
List of HealthWaterRead schema records sorted by date descending. |
Source code in backend/app/modules/health/health_water/crud.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_health_water_number_by_user_id
get_health_water_number_by_user_id(user_id, db, interval=None)
Retrieve total count of water intake records for a user.
If interval is provided, count only records starting from the calculated start date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to count records for. |
required |
db
|
Session
|
Database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of health water intake records. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_water/crud.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Health weight
Health weight module for managing user weight and body composition.
This module provides CRUD operations and data models for user weight tracking including BMI, body composition metrics, and various health indicators.
Exports
- CRUD: get_all_health_weight, get_health_weight_number_by_user_id, get_all_health_weight_by_user_id, get_health_weight_by_user_id, get_health_weight_by_date_and_user_id, create_health_weight, edit_health_weight, delete_health_weight
- Schemas: HealthWeightBase, HealthWeightCreate, HealthWeightUpdate, HealthWeightRead, HealthWeightListResponse
- Enums: Source
- Utils: calculate_bmi, calculate_bmi_all_user_entries
HealthWeightBase
Bases: BaseModel
Pydantic model for health weight data.
This model defines the structure and validation rules for health weight information, including body composition metrics and related health indicators.
Attributes:
| Name | Type | Description |
|---|---|---|
date |
date | None
|
The date of the health weight measurement. |
weight |
StrictFloat | None
|
Weight in kilograms. Must be between 0 and 500. |
bmi |
StrictFloat | None
|
Body Mass Index value. Must be between 0 and 100. |
body_fat |
StrictFloat | None
|
Body fat percentage. Must be between 0 and 100. |
body_water |
StrictFloat | None
|
Body water percentage. Must be between 0 and 100. |
bone_mass |
StrictFloat | None
|
Bone mass in kilograms. Must be between 0 and 500. |
muscle_mass |
StrictFloat | None
|
Muscle mass in kilograms. Must be between 0 and 500. |
physique_rating |
StrictInt | None
|
Physique rating score. Must be greater than or equal to 0. |
visceral_fat |
StrictFloat | None
|
Visceral fat percentage. Must be between 0 and 100. |
metabolic_age |
StrictInt | None
|
Metabolic age in years. Must be between 0 and 120. |
source |
Source | None
|
The source or device from which the weight data was obtained. |
Model Configuration
- Populates from ORM attributes
- Forbids extra fields
- Validates assignments
- Uses enum values for serialization
Source code in backend/app/modules/health/health_weight/schema.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
HealthWeightCreate
Bases: HealthWeightBase
Validator for HealthWeightCreate model that automatically sets the date field.
This validator runs after model initialization to ensure that if no date is provided, it defaults to today's date.
Source code in backend/app/modules/health/health_weight/schema.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
set_default_date
set_default_date()
Set date to today if not provided.
Clients should always send their own local date — the request carries no
timezone, so this fallback can only use the server's configured zone and
will file an entry logged near local midnight under the wrong day for an
athlete elsewhere. Resolved through settings.TZ explicitly rather
than date.today(), which silently depends on the container's clock.
Returns:
| Type | Description |
|---|---|
HealthWeightCreate
|
The validated model instance with date set. |
Source code in backend/app/modules/health/health_weight/schema.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
HealthWeightListResponse
Bases: HealthListResponse
Response model for listing health weight records.
Extends the base HealthListResponse to provide a typed response containing a list of weight records. This model is used when returning multiple weight entries from API endpoints.
Attributes:
| Name | Type | Description |
|---|---|---|
records |
list[HealthWeightRead]
|
A list of HealthWeightRead objects representing individual weight records. |
Source code in backend/app/modules/health/health_weight/schema.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
HealthWeightRead
Bases: HealthWeightBase
Schema for reading a health weight record.
Extends HealthWeightBase with identifier fields required for retrieving and referencing weight records in the system.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the weight record to update. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_weight/schema.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
HealthWeightUpdate
Bases: HealthWeightRead
Schema for updating health weight records.
Inherits from HealthWeightRead to maintain consistency with read operations while allowing modifications to health weight data. This schema is used for PUT/PATCH requests to update existing health weight entries.
Source code in backend/app/modules/health/health_weight/schema.py
119 120 121 122 123 124 125 126 | |
Source
Bases: Enum
Enumeration of data sources for health weight records.
Attributes:
| Name | Type | Description |
|---|---|---|
GARMIN |
Garmin fitness tracking platform as a data source. |
Source code in backend/app/modules/health/health_weight/schema.py
18 19 20 21 22 23 24 25 26 | |
calculate_bmi
calculate_bmi(health_weight, user_id, db)
Calculate the Body Mass Index (BMI) for a health weight record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_weight
|
HealthWeightCreate | HealthWeightUpdate
|
Health weight record with weight value. |
required |
user_id
|
int
|
Unique identifier of the user. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightCreate | HealthWeightUpdate
|
Updated health weight record with calculated BMI. |
Source code in backend/app/modules/health/health_weight/utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
calculate_bmi_all_user_entries
calculate_bmi_all_user_entries(user_id, db)
Recalculate and persist BMI for all of a user's weight entries.
Fetches the user once and delegates to a single bulk update, avoiding a per-entry query and commit cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID whose entries should be processed. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in backend/app/modules/health/health_weight/utils.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
create_health_weight
create_health_weight(user_id, health_weight, db)
Create a new health weight entry for a user.
This function creates a new health weight record in the database. If the date is not provided, it defaults to the current date. If BMI is not provided, it is automatically calculated using the user's height and the provided weight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user for whom the health weight entry is being created. |
required |
health_weight
|
HealthWeightCreate
|
The health weight data to be created, containing fields such as weight, date, and optionally BMI. |
required |
db
|
Session
|
The database session used for database operations. |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightRead
|
health_weight_schema.HealthWeightRead: The created health weight schema instance. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
|
Note
- The function automatically sets the date to current timestamp if not provided.
- BMI is calculated automatically if not provided in the input.
- The database transaction is rolled back in case of any errors.
Source code in backend/app/modules/health/health_weight/crud.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
delete_health_weight
delete_health_weight(user_id, health_weight_id, db)
Delete a health weight record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the health weight record. |
required |
health_weight_id
|
int
|
Health weight record ID to delete. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If record not found or database error. |
Source code in backend/app/modules/health/health_weight/crud.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
edit_health_weight
edit_health_weight(user_id, health_weight, db)
Edit an existing health weight record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the health weight record. |
required |
health_weight
|
HealthWeightUpdate
|
Health weight data to update. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightRead
|
Updated health weight schema instance. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If record not found or database error. |
Source code in backend/app/modules/health/health_weight/crud.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
get_all_health_weight
get_all_health_weight(db)
Retrieve all health weight records from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
list[HealthWeightRead]
|
List of HealthWeightRead schemas ordered by date descending. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_weight/crud.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_all_health_weight_by_user_id
get_all_health_weight_by_user_id(user_id, db)
Retrieve all health weight records for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to fetch records for. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
list[HealthWeightRead]
|
List of HealthWeightRead schemas ordered by date descending. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_weight/crud.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get_health_weight_by_date_and_user_id
get_health_weight_by_date_and_user_id(user_id, date, db)
Retrieve health weight record for a user on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID. |
required |
date
|
str
|
Date string for the weight record. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightRead | None
|
HealthWeightRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_weight/crud.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
get_health_weight_by_user_id
get_health_weight_by_user_id(user_id, db, page_number=None, num_records=None, interval=None)
Retrieve health weight records for a specific user with optional pagination and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user whose health weight records are to be retrieved. |
required |
db
|
Session
|
The database session used to execute the query. |
required |
page_number
|
int | None
|
The page number for pagination (1-indexed). If provided, num_records must also be provided. Defaults to None. |
None
|
num_records
|
int | None
|
The number of records per page. If provided, page_number must also be provided. Defaults to None. |
None
|
interval
|
Interval | None
|
The time interval to filter records. If provided, only records from the start of the interval to present are returned. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[HealthWeightRead]
|
list[health_weight_models.HealthWeight]: A list of health weight records sorted by date in descending order, optionally paginated. |
Source code in backend/app/modules/health/health_weight/crud.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
get_health_weight_number_by_user_id
get_health_weight_number_by_user_id(user_id, db, interval=None)
Retrieve total count of health weight records for a user. If interval is provided, count only records starting from the calculated start date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to count records for. |
required |
db
|
Session
|
Database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of health weight records. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_weight/crud.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
Health poop
Health poop module for managing user bowel movement data.
This module provides CRUD operations and data models for user bowel movement tracking including daily records, Bristol stool scale type, and optional notes.
Exports
- CRUD: get_health_poop_number_by_user_id, get_health_poop_by_id_and_user_id, get_health_poop_by_user_id, get_health_poop_by_date_and_user_id, create_health_poop, edit_health_poop, delete_health_poop
- Schemas: HealthPoopBase, HealthPoopCreate, HealthPoopUpdate, HealthPoopRead, HealthPoopListResponse
- Enums: Source, BristolType
- Models: HealthPoop (ORM model)
BristolType
Bases: Enum
Bristol Stool Scale classification types.
Attributes:
| Name | Type | Description |
|---|---|---|
TYPE_1 |
Separate hard lumps (severe constipation). |
|
TYPE_2 |
Lumpy and sausage-like (mild constipation). |
|
TYPE_3 |
Sausage shape with cracks (normal). |
|
TYPE_4 |
Smooth, soft sausage (normal, ideal). |
|
TYPE_5 |
Soft blobs with clear edges (lacking fiber). |
|
TYPE_6 |
Mushy with ragged edges (mild diarrhea). |
|
TYPE_7 |
Liquid, no solid pieces (severe diarrhea). |
Source code in backend/app/modules/health/health_poop/schema.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
HealthPoopBase
Bases: BaseModel
Base model for health poop data.
Attributes:
| Name | Type | Description |
|---|---|---|
date_time |
datetime | None
|
Date and time of the bowel movement. |
bristol_type |
BristolType | None
|
Bristol Stool Scale type (1-7). |
color |
Color | None
|
Stool color description. |
notes |
StrictStr | None
|
Optional notes about the bowel movement. |
source |
Source | None
|
Source of the data. |
Source code in backend/app/modules/health/health_poop/schema.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
HealthPoopCreate
Bases: HealthPoopBase
Schema for creating a new poop record.
Requires date_time and sets defaults for source.
Source code in backend/app/modules/health/health_poop/schema.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
set_defaults_and_validate
set_defaults_and_validate()
Validate required fields and set defaults.
Returns:
| Type | Description |
|---|---|
HealthPoopCreate
|
The validated model instance with defaults set. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If date_time is not provided. |
Source code in backend/app/modules/health/health_poop/schema.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
HealthPoopListResponse
Bases: HealthListResponse
Response model for listing health poop records.
Attributes:
| Name | Type | Description |
|---|---|---|
records |
list[HealthPoopRead]
|
A list of HealthPoopRead objects representing individual bowel movement records. |
Source code in backend/app/modules/health/health_poop/schema.py
180 181 182 183 184 185 186 187 188 189 190 191 192 | |
HealthPoopModel
Bases: Base
User bowel movement tracking data.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Mapped[int]
|
Primary key, auto-incremented unique identifier. |
user_id |
Mapped[int]
|
Foreign key referencing users.id. |
date_time |
Mapped[datetime]
|
Date and time of the bowel movement. |
bristol_type |
Mapped[int | None]
|
Bristol Stool Scale type (1-7). |
color |
Mapped[str | None]
|
Stool color description. |
notes |
Mapped[str | None]
|
Optional notes about the bowel movement. |
source |
Mapped[str | None]
|
Source of the data. |
user |
Mapped[str | None]
|
Relationship to the Users model. |
Table
health_poop
Relationships
- Many-to-One with Users model through user_id
Source code in backend/app/modules/health/health_poop/models.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
HealthPoopRead
Bases: HealthPoopBase
Schema for reading a poop record.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the poop record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_poop/schema.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
HealthPoopUpdate
Bases: HealthPoopRead
Schema for updating a poop record.
Inherits from HealthPoopRead for consistency with read operations while allowing modifications to poop data.
Source code in backend/app/modules/health/health_poop/schema.py
171 172 173 174 175 176 177 | |
Source
Bases: Enum
Enumeration of data sources for poop records.
Attributes:
| Name | Type | Description |
|---|---|---|
MANUAL |
Manually entered data. |
Source code in backend/app/modules/health/health_poop/schema.py
24 25 26 27 28 29 30 31 32 | |
create_health_poop
create_health_poop(user_id, health_poop, db)
Create a new poop record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID for the record owner. |
required |
health_poop
|
HealthPoopCreate
|
Poop data to create. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead
|
Created poop record. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database integrity error. |
Source code in backend/app/modules/health/health_poop/crud.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
delete_health_poop
delete_health_poop(user_id, health_poop_id, db)
Delete a poop record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_poop_id
|
int
|
Poop record ID to delete. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If record not found or database error. |
Source code in backend/app/modules/health/health_poop/crud.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
edit_health_poop
edit_health_poop(user_id, health_poop, db)
Edit poop record for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID who owns the record. |
required |
health_poop
|
HealthPoopUpdate
|
Poop data to update. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead
|
Updated HealthPoopRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
403 if editing another user's record, 404 if not found, 500 if database error. |
Source code in backend/app/modules/health/health_poop/crud.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
get_health_poop_by_date_and_user_id
get_health_poop_by_date_and_user_id(user_id, date, db)
Retrieve poop records for a user on a specific date.
Unlike other health modules, poop can have multiple entries per day, so this returns a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID. |
required |
date
|
str
|
Date string for the poop records. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
list[HealthPoopRead]
|
List of HealthPoopRead schemas for the given date. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_poop/crud.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get_health_poop_by_id_and_user_id
get_health_poop_by_id_and_user_id(health_poop_id, user_id, db)
Retrieve poop record by ID and user ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_poop_id
|
int
|
Poop record ID to fetch. |
required |
user_id
|
int
|
User ID to fetch record for. |
required |
db
|
Session
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead | None
|
HealthPoopRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_poop/crud.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_health_poop_by_user_id
get_health_poop_by_user_id(user_id, db, page_number=None, num_records=None, interval=None)
Retrieve poop records for a user with optional pagination and filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID whose records are to be retrieved. |
required |
db
|
Session
|
Database session used to execute the query. |
required |
page_number
|
int | None
|
Page number for pagination (1-indexed). |
None
|
num_records
|
int | None
|
Number of records per page. |
None
|
interval
|
Interval | None
|
Time interval to filter records. |
None
|
Returns:
| Type | Description |
|---|---|
list[HealthPoopRead]
|
List of HealthPoopRead records sorted by date_time descending. |
Source code in backend/app/modules/health/health_poop/crud.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
get_health_poop_number_by_user_id
get_health_poop_number_by_user_id(user_id, db, interval=None)
Retrieve total count of poop records for a user.
If interval is provided, count only records starting from the calculated start date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
User ID to count records for. |
required |
db
|
Session
|
Database session. |
required |
interval
|
Interval | None
|
Optional filter by goal interval. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Total number of health poop records. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If database error occurs. |
Source code in backend/app/modules/health/health_poop/crud.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |