Health API reference
Health sleep
FastAPI router for health sleep endpoints.
create_health_sleep
create_health_sleep(request, health_sleep, token_user_id, db, response)
Create health sleep data for a user.
A date that already has a record is answered with a 409; change it with PATCH /{id}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_sleep
|
HealthSleepCreate
|
The health sleep data to create, including the date and sleep duration. |
required |
token_user_id
|
UUID
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
Session
|
Database session dependency for database operations. |
required |
response
|
Response
|
The response, whose |
required |
Returns:
| Type | Description |
|---|---|
HealthSleepRead
|
health_sleep_schema.HealthSleepRead: The created health sleep data. |
Source code in backend/app/modules/health/health_sleep/router.py
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 | |
delete_health_sleep
delete_health_sleep(request, health_sleep_id, token_user_id, if_match, db)
Delete a health sleep record for the authenticated user.
This endpoint removes a specific health sleep entry from the database for the user identified by the access token. The user must have 'health:write' scope permission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_sleep_id
|
UUID
|
The unique identifier of the health sleep record to delete. |
required |
token_user_id
|
UUID
|
The user ID extracted from the access token. |
required |
if_match
|
IfMatch
|
The |
required |
db
|
Session
|
Database session dependency for executing the delete operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return a value. |
Raises:
| Type | Description |
|---|---|
PreconditionFailedError
|
If the record changed since the client read it. |
NotFoundError
|
If the user has no such record. |
Source code in backend/app/modules/health/health_sleep/router.py
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 | |
edit_health_sleep
edit_health_sleep(request, health_sleep_id, health_sleep, token_user_id, db, response, if_match)
Edit health sleep data for a user.
This endpoint updates existing health sleep records in the database for the authenticated user. Requires 'health:write' scope for authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_sleep_id
|
UuidId
|
ID of the record to change. |
required |
health_sleep
|
HealthSleepUpdate
|
The health sleep data to be updated, containing the new values for the health sleep record. |
required |
token_user_id
|
UUID
|
The user ID extracted from the JWT access token, used to identify the user making the request. |
required |
db
|
Session
|
Database session dependency for performing database operations. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthSleepRead
|
health_sleep_schema.HealthSleepRead: The updated health sleep record with the new values as stored in the database. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no such record. |
PreconditionFailedError
|
If the record changed since the client read it. |
Source code in backend/app/modules/health/health_sleep/router.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 | |
read_health_sleep_all_pagination
read_health_sleep_all_pagination(token_user_id, db, page, date_range, interval=None, has_resting_heart_rate=None)
Retrieve health sleep records for the authenticated user.
One page of records, newest first, optionally limited to an interval and to nights with or without a
resting heart rate; the total counts the same records. A record carries has_sleep_stages, not its
stages, which are on GET /health/sleep/{health_sleep_id}. Access is restricted to users with the
'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
page
|
ListPage
|
The requested page and page size. |
required |
interval
|
Annotated[Interval | None, Query(description='Look back from today over this interval; ignored when `start_date` or `end_date` is given')]
|
Optional interval looking back from today; ignored when a date range is given. |
None
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates, which replace the interval. |
required |
has_resting_heart_rate
|
Annotated[bool | None, Query(description='Keep only nights with (`true`) or without (`false`) a resting heart rate')]
|
Optional filter on whether a night records a resting heart rate. |
None
|
Returns:
| Type | Description |
|---|---|
Page[HealthSleepListItem]
|
The page of records with the total matching the interval and the filter. |
Source code in backend/app/modules/health/health_sleep/router.py
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 | |
read_health_sleep_by_id
read_health_sleep_by_id(health_sleep_id, token_user_id, db, response)
Retrieve one of the authenticated user's sleep records; its ETag is the version for If-Match.
Source code in backend/app/modules/health/health_sleep/router.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
read_health_sleep_chart
read_health_sleep_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's total sleep seconds over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small however long the history. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_sleep/router.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 95 96 97 98 99 100 101 | |
read_health_sleep_resting_heart_rate_chart
read_health_sleep_resting_heart_rate_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's resting heart rate over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small however long the history. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_sleep/router.py
104 105 106 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 | |
Pydantic request and response shapes for health sleep records.
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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
HealthSleepBase
Bases: HealthSleepCore
The sleep fields with the sleep stages, the base of every schema that carries them.
Attributes:
| Name | Type | Description |
|---|---|---|
sleep_stages |
list[HealthSleepStage] | None
|
List of sleep stages. |
Source code in backend/app/modules/health/health_sleep/schema.py
321 322 323 324 325 326 327 328 | |
HealthSleepCore
Bases: BaseModel
Pydantic model representing the sleep fields every sleep schema shares, without the sleep stages.
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_percent |
StrictInt | None
|
Average SpO2 oxygen saturation percentage (70-100%). |
lowest_spo2_percent |
StrictInt | None
|
Lowest SpO2 reading during sleep (70-100%). |
highest_spo2_percent |
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. |
sleep_stages |
list[SleepStage] | None
|
List of sleep stages. |
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
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 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 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 | |
validate_sleep_times
validate_sleep_times()
Validate sleep start < end, reading a time without an offset as UTC.
Source code in backend/app/modules/health/health_sleep/schema.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
HealthSleepCreate
Bases: HealthSleepWrite
Schema for creating a health sleep record.
The date is optional; service fills it in when the client sends none.
Source code in backend/app/modules/health/health_sleep/schema.py
372 373 374 375 376 377 378 | |
HealthSleepIdentity
Bases: HealthSleepCore
The stored identity and provenance every sleep read carries, with the sleep fields but not the stages.
Attributes:
| Name | Type | Description |
|---|---|---|
garminconnect_sleep_id |
StrictStr | None
|
Garmin Connect sleep record ID. |
source |
Source | None
|
Source of the sleep data. |
user_id |
UUID
|
Foreign key reference to the user. |
id |
UUID
|
Unique identifier for the sleep record to update or retrieve. |
version |
StrictInt
|
Optimistic-concurrency counter, also sent as the ETag. |
Source code in backend/app/modules/health/health_sleep/schema.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
HealthSleepImport
Bases: HealthSleepWrite
Sleep record written by the server itself: a provider sync or a profile import.
Unlike :class:HealthSleepCreate it carries the provenance, which a client never sets. Every
server-side writer of source takes Health<Kind>Import (create) or Health<Kind>ImportUpdate.
Attributes:
| Name | Type | Description |
|---|---|---|
garminconnect_sleep_id |
StrictStr | None
|
Garmin Connect sleep record ID. |
source |
Source
|
The source the record came from; |
Source code in backend/app/modules/health/health_sleep/schema.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
HealthSleepImportUpdate
Bases: NotClearable, HealthSleepWrite
Fields a provider sync or a profile import changes on a sleep record, provenance included.
Attributes:
| Name | Type | Description |
|---|---|---|
garminconnect_sleep_id |
StrictStr | None
|
Garmin Connect sleep record ID. |
source |
Source | None
|
The source the record came from. |
Source code in backend/app/modules/health/health_sleep/schema.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
HealthSleepListItem
Bases: HealthSleepIdentity
A sleep record as the list returns it: no stages, only whether the record has any.
The stages are on GET /health/sleep/{health_sleep_id}.
Attributes:
| Name | Type | Description |
|---|---|---|
has_sleep_stages |
bool
|
Whether the record has at least one sleep stage. Read from a stored row's
|
Source code in backend/app/modules/health/health_sleep/schema.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
HealthSleepRead
Bases: HealthSleepIdentity, HealthSleepBase
Read schema for a health sleep record, with its sleep stages.
Source code in backend/app/modules/health/health_sleep/schema.py
402 403 | |
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 |
StoredSleepStageType | 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
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 | |
serialize_time
serialize_time(value)
Dump a stage time as ISO 8601 text in every mode, as the JSON column that stores the stages requires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime | None
|
The time, or |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The time as the API writes it in JSON, or |
Source code in backend/app/modules/health/health_sleep/schema.py
135 136 137 138 139 140 141 142 143 144 145 | |
HealthSleepStageImport
Bases: HealthSleepStageWrite
A sleep stage the server writes: a provider sync or a profile import, which may hand over the stored number.
Source code in backend/app/modules/health/health_sleep/schema.py
346 347 348 349 350 351 | |
HealthSleepStageWrite
Bases: HealthSleepStage
A sleep stage a client writes.
Its times carry a UTC offset and are bounded, which a stored stage read back need not be.
Source code in backend/app/modules/health/health_sleep/schema.py
331 332 333 334 335 336 337 338 339 340 341 342 343 | |
HealthSleepUpdate
Bases: NotClearable, HealthSleepWrite
Schema for the fields a PATCH changes on a sleep record.
The record is named by the path, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_sleep/schema.py
434 435 436 437 438 439 440 441 442 443 | |
HealthSleepWrite
Bases: HealthSleepCore
Sleep fields a client writes: the date and times are bounded, which a stored row read back need not be.
Source code in backend/app/modules/health/health_sleep/schema.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
SleepStageType
Bases: StoredStrEnum
The stages of a sleep session; stored is the Garmin activity level kept in the sleep stages.
Attributes:
| Name | Type | Description |
|---|---|---|
DEEP |
Deep sleep, characterized by slow brain waves and muscle relaxation. |
|
LIGHT |
Light sleep, the transition between wakefulness and deep sleep. |
|
REM |
Rapid Eye Movement sleep, associated with vivid dreams and mental activity. |
|
AWAKE |
Awake, the stage when the person is conscious and not sleeping. |
Source code in backend/app/modules/health/health_sleep/schema.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
Source
Bases: Enum
Enum representing the source of sleep health data.
Attributes:
| Name | Type | Description |
|---|---|---|
MANUAL |
Sleep data entered manually. |
|
GARMIN |
Sleep data sourced from Garmin devices or services. |
Source code in backend/app/modules/health/health_sleep/schema.py
44 45 46 47 48 49 50 51 52 53 | |
Health steps
FastAPI router for health steps endpoints.
create_health_steps
create_health_steps(request, health_steps, token_user_id, db, response)
Create health steps data for a user.
A date that already has a record is answered with a 409; change it with PATCH /{id}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_steps
|
HealthSteps
|
The health steps data to create, including the date and step count. |
required |
token_user_id
|
UUID
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
Session
|
Database session dependency for database operations. |
required |
response
|
Response
|
The response, whose |
required |
Returns:
| Type | Description |
|---|---|
HealthStepsRead
|
health_steps_schema.HealthSteps: The created health steps data. |
Source code in backend/app/modules/health/health_steps/router.py
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 | |
delete_health_steps
delete_health_steps(request, health_steps_id, token_user_id, if_match, db)
Delete a health steps record for the authenticated user.
This endpoint removes a specific health steps entry from the database for the user identified by the access token. The user must have 'health:write' scope permission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_steps_id
|
UUID
|
The unique identifier of the health steps record to delete. |
required |
token_user_id
|
UUID
|
The user ID extracted from the access token. |
required |
if_match
|
IfMatch
|
The |
required |
db
|
Session
|
Database session dependency for executing the delete operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return a value. |
Raises:
| Type | Description |
|---|---|
PreconditionFailedError
|
If the record changed since the client read it. |
NotFoundError
|
If the user has no such record. |
Source code in backend/app/modules/health/health_steps/router.py
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 | |
edit_health_steps
edit_health_steps(request, health_steps_id, health_steps, token_user_id, db, response, if_match)
Edit health steps data for a user.
This endpoint updates existing health steps records in the database for the authenticated user. Requires 'health:write' scope for authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_steps_id
|
UuidId
|
ID of the record to change. |
required |
health_steps
|
HealthSteps
|
The health steps data to be updated, containing the new values for the health steps record. |
required |
token_user_id
|
UUID
|
The user ID extracted from the JWT access token, used to identify the user making the request. |
required |
db
|
Session
|
Database session dependency for performing database operations. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthStepsRead
|
health_steps_schema.HealthSteps: The updated health steps record with the new values as stored in the database. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no such record. |
PreconditionFailedError
|
If the record changed since the client read it. |
Source code in backend/app/modules/health/health_steps/router.py
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 | |
read_health_steps_all_pagination
read_health_steps_all_pagination(token_user_id, db, page, date_range, interval=None)
Retrieve paginated health steps records for the authenticated user.
One page of records, newest first, optionally limited to an interval. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
page
|
ListPage
|
The requested page and page size. |
required |
interval
|
Annotated[Interval | None, Query(description='Look back from today over this interval; ignored when `start_date` or `end_date` is given')]
|
Optional interval looking back from today; ignored when a date range is given. |
None
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates, which replace the interval. |
required |
Returns:
| Type | Description |
|---|---|
Page[HealthStepsRead]
|
The page of records with the total matching the interval. |
Source code in backend/app/modules/health/health_steps/router.py
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 | |
read_health_steps_by_id
read_health_steps_by_id(health_steps_id, token_user_id, db, response)
Retrieve one of the authenticated user's steps records; its ETag is the version for If-Match.
Source code in backend/app/modules/health/health_steps/router.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
read_health_steps_chart
read_health_steps_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's steps over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small however long the history. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_steps/router.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
Pydantic request and response shapes for health steps records.
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 and number of steps taken.
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. |
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
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 | |
HealthStepsCreate
Bases: HealthStepsWrite
Schema for creating a health steps record.
The date is optional; service fills it in when the client sends none.
Source code in backend/app/modules/health/health_steps/schema.py
63 64 65 66 67 68 69 | |
HealthStepsImport
Bases: HealthStepsCreate
Steps record written by the server itself: a provider sync or a profile import.
Unlike :class:HealthStepsCreate it carries the provenance, which a client never sets. Every
server-side writer of source takes Health<Kind>Import (create) or Health<Kind>ImportUpdate.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
The source the record came from; |
Source code in backend/app/modules/health/health_steps/schema.py
104 105 106 107 108 109 110 111 112 113 114 | |
HealthStepsImportUpdate
Bases: HealthStepsUpdate
Fields a provider sync or a profile import changes on a steps record, provenance included.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source | None
|
The source the record came from. |
Source code in backend/app/modules/health/health_steps/schema.py
117 118 119 120 121 122 123 124 125 126 | |
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 |
|---|---|---|
source |
Source | None
|
Source of the steps data (e.g., device, API, manual entry). Optional field. |
id |
UUID
|
Unique identifier for the steps record to update. Required field. |
user_id |
UUID
|
Foreign key reference to the user. Required field. |
Source code in backend/app/modules/health/health_steps/schema.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
HealthStepsUpdate
Bases: NotClearable, HealthStepsWrite
Schema for the fields a PATCH changes on a steps record.
The record is named by the path, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_steps/schema.py
92 93 94 95 96 97 98 99 100 101 | |
HealthStepsWrite
Bases: HealthStepsBase
Steps fields a client writes: the date is bounded, which a stored row read back need not be.
Source code in backend/app/modules/health/health_steps/schema.py
57 58 59 60 | |
Source
Bases: Enum
An enumeration representing supported sources for the application.
Members
MANUAL: Manually entered data GARMIN: Garmin health data source
Source code in backend/app/modules/health/health_steps/schema.py
18 19 20 21 22 23 24 25 26 27 | |
Health targets
FastAPI router for health targets endpoints.
read_health_targets_all
read_health_targets_all(token_user_id, db, response)
Retrieve all health targets for the authenticated user.
This endpoint fetches all health targets associated with the user identified by the access token. It requires the 'health-targets:read' scope for authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
UUID
|
The user ID extracted from the JWT access token, automatically injected by the authentication dependency. |
required |
db
|
Session
|
SQLAlchemy database session dependency for executing database queries. |
required |
response
|
Response
|
The response, which carries the targets' ETag. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargetsRead | None
|
health_targets_schema.HealthTargetsRead | None: The health targets object containing all targets for the user, or None if no targets are found. |
Source code in backend/app/modules/health/health_targets/router.py
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 44 45 | |
update_health_targets
update_health_targets(request, health_targets, token_user_id, db, response, if_match)
Update health targets for the authenticated user.
This endpoint allows users to modify their health-related targets such as weight goals, activity targets, or other health metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_targets
|
HealthTargetsUpdate
|
The health targets to update, containing the new values for the health metrics. |
required |
token_user_id
|
UUID
|
The authenticated user's ID extracted from the access token. |
required |
db
|
Session
|
Database session dependency for database operations. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthTargetsRead
|
health_targets_schema.HealthTargetsRead: The updated health targets object reflecting the changes made in the database. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no targets. |
PreconditionFailedError
|
If the targets changed since the client read them. |
Source code in backend/app/modules/health/health_targets/router.py
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 82 83 84 85 86 87 88 89 | |
Pydantic request and response shapes for health targets.
HealthTargetsBase
Bases: BaseModel
Base schema for health targets with shared fields.
Attributes:
| Name | Type | Description |
|---|---|---|
weight_kg |
StrictFloat | None
|
Target weight in kg. |
steps |
StrictInt | None
|
Target daily steps count. |
sleep_seconds |
StrictInt | None
|
Target sleep duration in seconds. |
fasting_seconds |
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
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 44 45 46 47 48 49 50 51 | |
HealthTargetsRead
Bases: HealthTargetsBase
Schema for reading health targets.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Unique identifier for the health target record. |
user_id |
UUID
|
Foreign key reference to the user. |
version |
StrictInt
|
Optimistic-concurrency counter, also sent as the ETag. |
Source code in backend/app/modules/health/health_targets/schema.py
54 55 56 57 58 59 60 61 62 63 64 65 66 | |
HealthTargetsUpdate
Bases: HealthTargetsBase
Schema for the fields a PATCH changes on a user's health targets.
The targets belong to the caller, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_targets/schema.py
69 70 71 72 73 74 | |
Health water
FastAPI router for health water intake endpoints.
This module defines the API endpoints for managing water intake records, including CRUD operations with pagination and filtering.
create_health_water
create_health_water(request, health_water, token_user_id, db, response)
Record a water intake for the user's day.
The intake is added to the day's total, so several intakes in one day are all counted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_water
|
HealthWaterCreate
|
Water intake data to create. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
db
|
DbSession
|
Database session dependency. |
required |
response
|
Response
|
The response, whose |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead
|
The day's HealthWaterRead record, with the intake added. |
Source code in backend/app/modules/health/health_water/router.py
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 | |
delete_health_water
delete_health_water(request, health_water_id, token_user_id, if_match, db)
Delete a water intake record for the authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_water_id
|
UuidId
|
ID of the water intake record. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
if_match
|
IfMatch
|
The |
required |
db
|
DbSession
|
Database session dependency. |
required |
Raises:
| Type | Description |
|---|---|
PreconditionFailedError
|
If the record changed since the client read it. |
NotFoundError
|
If the user has no such record. |
Source code in backend/app/modules/health/health_water/router.py
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 243 244 245 246 | |
edit_health_water
edit_health_water(request, health_water_id, health_water, token_user_id, db, response, if_match)
Edit an existing water intake record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_water_id
|
UuidId
|
ID of the record to change. |
required |
health_water
|
HealthWaterUpdate
|
Water intake data to update. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
db
|
DbSession
|
Database session dependency. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthWaterRead
|
Updated HealthWaterRead record. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no such record. |
PreconditionFailedError
|
If the record changed since the client read it. |
Source code in backend/app/modules/health/health_water/router.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 | |
read_health_water_all_pagination
read_health_water_all_pagination(token_user_id, db, page, date_range, interval=None)
Retrieve paginated water intake records for the user.
One page of records, newest first, optionally limited to an interval. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
page
|
ListPage
|
The requested page and page size. |
required |
interval
|
Annotated[Interval | None, Query(description='Look back from today over this interval; ignored when `start_date` or `end_date` is given')]
|
Optional interval looking back from today; ignored when a date range is given. |
None
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates, which replace the interval. |
required |
Returns:
| Type | Description |
|---|---|
Page[HealthWaterRead]
|
The page of records with the total matching the interval. |
Source code in backend/app/modules/health/health_water/router.py
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 | |
read_health_water_by_id
read_health_water_by_id(health_water_id, token_user_id, db, response)
Retrieve one of the authenticated user's water records; its ETag is the version for If-Match.
Source code in backend/app/modules/health/health_water/router.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
read_health_water_chart
read_health_water_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's water intake over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small however long the history. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_water/router.py
79 80 81 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 | |
Pydantic schemas for health water intake data.
This module defines the request/response schemas for water intake tracking, including validation rules and source enumeration.
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 |
date | None
|
Water consumed in milliliters. |
Source code in backend/app/modules/health/health_water/schema.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
HealthWaterCreate
Bases: HealthWaterWrite
Schema for creating a new water intake record.
The date is optional; service fills it in when the client sends none.
Source code in backend/app/modules/health/health_water/schema.py
70 71 72 73 74 75 76 | |
HealthWaterImport
Bases: HealthWaterCreate
Water record written by the server itself: a profile import.
Unlike :class:HealthWaterCreate it carries the provenance, which a client never sets. Every
server-side writer of source takes Health<Kind>Import (create) or Health<Kind>ImportUpdate.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
The source the record came from; |
Source code in backend/app/modules/health/health_water/schema.py
118 119 120 121 122 123 124 125 126 127 128 | |
HealthWaterImportUpdate
Bases: HealthWaterUpdate
Fields a profile import changes on a water record, provenance included.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source | None
|
The source the record came from. |
Source code in backend/app/modules/health/health_water/schema.py
131 132 133 134 135 136 137 138 139 140 | |
HealthWaterRead
Bases: HealthWaterBase
Schema for reading a water intake record.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
Source of the water intake data. |
id |
UUID
|
Unique identifier for the water intake record. |
user_id |
UUID
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_water/schema.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
HealthWaterUpdate
Bases: NotClearable, HealthWaterWrite
Schema for the fields a PATCH changes on a water record.
The record is named by the path, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_water/schema.py
106 107 108 109 110 111 112 113 114 115 | |
HealthWaterWrite
Bases: HealthWaterBase
Water fields a client writes: the date is bounded, which a stored row read back need not be.
Source code in backend/app/modules/health/health_water/schema.py
64 65 66 67 | |
Source
Bases: StrEnum
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
31 32 33 34 35 36 37 38 39 40 | |
Health weight
FastAPI router for health weight endpoints.
create_health_weight
create_health_weight(request, health_weight, token_user_id, db, response)
Create a health weight record for the authenticated user.
A date that already has a record is answered with a 409; change it with PATCH /{id}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_weight
|
HealthWeightCreate
|
The health weight data to create. Must include a date field. |
required |
token_user_id
|
UUID
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
Session
|
Database session dependency for performing database operations. |
required |
response
|
Response
|
The response, whose |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightRead
|
health_weight_schema.HealthWeightRead: The created health weight record. |
Source code in backend/app/modules/health/health_weight/router.py
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 | |
delete_health_weight
delete_health_weight(request, health_weight_id, token_user_id, if_match, db)
Delete a health weight entry for the authenticated user.
This endpoint allows users to delete their own health weight records. It requires the 'health:write' scope for authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_weight_id
|
UUID
|
The unique identifier of the health weight entry to delete. |
required |
token_user_id
|
UUID
|
The user ID extracted from the access token, used to ensure users can only delete their own weight entries. |
required |
if_match
|
IfMatch
|
The |
required |
db
|
Session
|
Database session dependency for performing database operations. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return any value upon successful deletion. |
Raises:
| Type | Description |
|---|---|
PreconditionFailedError
|
If the record changed since the client read it. |
NotFoundError
|
If the entry doesn't exist for the user. |
Source code in backend/app/modules/health/health_weight/router.py
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 | |
edit_health_weight
edit_health_weight(request, health_weight_id, health_weight, token_user_id, db, response, if_match)
Edit a health weight entry for the authenticated user.
This endpoint allows users with 'health:write' scope to update an existing health weight record in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_weight_id
|
UuidId
|
ID of the record to change. |
required |
health_weight
|
HealthWeight
|
The health weight data to be updated, containing the weight information and associated metadata. |
required |
token_user_id
|
UUID
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
Session
|
Database session dependency for executing database operations. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthWeightRead
|
The updated health weight record from the database. |
Raises:
| Type | Description |
|---|---|
PermissionDeniedError
|
If the record names another user. |
NotFoundError
|
If the entry doesn't exist. |
Source code in backend/app/modules/health/health_weight/router.py
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 | |
read_health_weight_all_pagination
read_health_weight_all_pagination(token_user_id, db, page, date_range, interval=None)
Retrieve paginated health weight records for the authenticated user.
One page of records, newest first, optionally limited to an interval. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
page
|
ListPage
|
The requested page and page size. |
required |
interval
|
Annotated[Interval | None, Query(description='Look back from today over this interval; ignored when `start_date` or `end_date` is given')]
|
Optional interval looking back from today; ignored when a date range is given. |
None
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates, which replace the interval. |
required |
Returns:
| Type | Description |
|---|---|
Page[HealthWeightRead]
|
The page of records with the total matching the interval. |
Source code in backend/app/modules/health/health_weight/router.py
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 | |
read_health_weight_by_id
read_health_weight_by_id(health_weight_id, token_user_id, db, response)
Retrieve one of the authenticated user's weight records; its ETag is the version for If-Match.
Source code in backend/app/modules/health/health_weight/router.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
read_health_weight_chart
read_health_weight_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's weight over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small however long the history. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_weight/router.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
Pydantic request and response shapes for health weight records.
WeightKg
module-attribute
WeightKg = Annotated[StrictFloat, Field(ge=0, le=500)]
Highest BMI a record may carry; a calculated value above it is unusable and not stored.
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_kg |
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_percent |
StrictFloat | None
|
Body fat percentage. Must be between 0 and 100. |
body_water_percent |
StrictFloat | None
|
Body water percentage. Must be between 0 and 100. |
bone_mass_kg |
StrictFloat | None
|
Bone mass in kilograms. Must be between 0 and 500. |
muscle_mass_kg |
StrictFloat | None
|
Muscle mass in kilograms. Must be between 0 and 500. |
physique_rating |
StrictInt | None
|
Physique rating score. Must be between 0 and the largest 32-bit integer. |
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. |
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
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 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
HealthWeightCreate
Bases: HealthWeightWrite
Schema for creating a health weight record.
The date is optional; service fills it in when the client sends none.
Source code in backend/app/modules/health/health_weight/schema.py
103 104 105 106 107 108 109 | |
HealthWeightImport
Bases: HealthWeightCreate
Weight record written by the server itself: a provider sync or a profile import.
Unlike :class:HealthWeightCreate it carries the provenance, which a client never sets. Every
server-side writer of source takes Health<Kind>Import (create) or Health<Kind>ImportUpdate.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
The source the record came from; |
Source code in backend/app/modules/health/health_weight/schema.py
144 145 146 147 148 149 150 151 152 153 154 | |
HealthWeightImportUpdate
Bases: HealthWeightUpdate
Fields a provider sync or a profile import changes on a weight record, provenance included.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source | None
|
The source the record came from. |
Source code in backend/app/modules/health/health_weight/schema.py
157 158 159 160 161 162 163 164 165 166 | |
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 |
|---|---|---|
source |
Source | None
|
The source or device from which the weight data was obtained. |
id |
UUID
|
Unique identifier for the weight record to update. |
user_id |
UUID
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_weight/schema.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
HealthWeightUpdate
Bases: NotClearable, HealthWeightWrite
Schema for the fields a PATCH changes on a weight record.
The record is named by the path, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_weight/schema.py
132 133 134 135 136 137 138 139 140 141 | |
HealthWeightWrite
Bases: HealthWeightBase
Weight fields a client writes: the date is bounded, which a stored row read back need not be.
Source code in backend/app/modules/health/health_weight/schema.py
97 98 99 100 | |
Source
Bases: Enum
Enumeration of data sources for health weight records.
Attributes:
| Name | Type | Description |
|---|---|---|
MANUAL |
Manually entered data. |
|
GARMIN |
Garmin fitness tracking platform as a data source. |
Source code in backend/app/modules/health/health_weight/schema.py
27 28 29 30 31 32 33 34 35 36 | |
Health poop
FastAPI router for health poop (bowel movement) endpoints.
This module defines the API endpoints for managing bowel movement records, including CRUD operations with pagination and filtering.
create_health_poop
create_health_poop(request, health_poop, token_user_id, db, response)
Create a new poop record for the user.
Unlike other health modules, multiple poop records can exist per day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_poop
|
HealthPoopCreate
|
Poop data to create. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
db
|
DbSession
|
Database session dependency. |
required |
response
|
Response
|
The response, whose |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead
|
Created HealthPoopRead record. |
Source code in backend/app/modules/health/health_poop/router.py
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 | |
delete_health_poop
delete_health_poop(request, health_poop_id, token_user_id, if_match, db)
Delete a poop record for the authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_poop_id
|
UuidId
|
ID of the poop record to delete. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
if_match
|
IfMatch
|
The |
required |
db
|
DbSession
|
Database session dependency. |
required |
Raises:
| Type | Description |
|---|---|
PreconditionFailedError
|
If the record changed since the client read it. |
NotFoundError
|
If the user has no such record. |
Source code in backend/app/modules/health/health_poop/router.py
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 258 259 260 261 262 263 | |
edit_health_poop
edit_health_poop(request, health_poop_id, health_poop, token_user_id, db, response, if_match)
Edit an existing poop record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
health_poop_id
|
UuidId
|
ID of the record to change. |
required |
health_poop
|
HealthPoopUpdate
|
Poop data to update. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
db
|
DbSession
|
Database session dependency. |
required |
response
|
Response
|
The response, which carries the new ETag. |
required |
if_match
|
IfMatch
|
The |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead
|
Updated HealthPoopRead record. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no such record. |
PreconditionFailedError
|
If the record changed since the client read it. |
Source code in backend/app/modules/health/health_poop/router.py
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 | |
read_health_poop_all_pagination
read_health_poop_all_pagination(token_user_id, db, page, date_range, interval=None)
Retrieve paginated poop records for the user.
One page of records, newest first, optionally limited to an interval. Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
page
|
ListPage
|
The requested page and page size. |
required |
interval
|
Annotated[Interval | None, Query(description='Look back from today over this interval; ignored when `start_date` or `end_date` is given')]
|
Optional interval looking back from today; ignored when a date range is given. |
None
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates, which replace the interval. |
required |
Returns:
| Type | Description |
|---|---|
Page[HealthPoopRead]
|
The page of records with the total matching the interval. |
Source code in backend/app/modules/health/health_poop/router.py
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 | |
read_health_poop_by_id
read_health_poop_by_id(health_poop_id, token_user_id, db, response)
Retrieve a specific poop record by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_poop_id
|
UuidId
|
ID of the poop record. |
required |
token_user_id
|
CurrentUserId
|
User ID from the access token. |
required |
db
|
DbSession
|
Database session dependency. |
required |
response
|
Response
|
The response, which carries the record's ETag. |
required |
Returns:
| Type | Description |
|---|---|
HealthPoopRead
|
HealthPoopRead for the specified record. |
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If the user has no such record. |
Source code in backend/app/modules/health/health_poop/router.py
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 | |
read_health_poop_chart
read_health_poop_chart(token_user_id, db, date_range, interval=health_constants.Interval.LAST_7_DAYS)
Chart the authenticated user's daily bowel-movement frequency over an interval.
One aggregated point per day, week or month depending on the interval, so the response stays small
however long the history. Declared before the /{health_poop_id} route so chart is not read as an id.
Access is restricted to users with the 'health:read' scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The ID of the authenticated user extracted from the access token. |
required |
db
|
DbSession
|
Database session for executing queries. |
required |
interval
|
Annotated[Interval, Query(description='Interval to chart, looking back from today; ignored when `start_date` or `end_date` is given')]
|
The window to chart, looking back from today; ignored when a date range is given. |
LAST_7_DAYS
|
date_range
|
DateRangeQuery
|
Optional inclusive start and end dates to chart instead of the interval. |
required |
Returns:
| Type | Description |
|---|---|
HealthChartSeries
|
The interval's bucket size and its points, oldest first. |
Source code in backend/app/modules/health/health_poop/router.py
79 80 81 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 | |
Pydantic schemas for health poop (bowel movement) data.
This module defines the request/response schemas for bowel movement tracking, including validation rules, Bristol Stool Scale types, and color enumerations.
BristolType
Bases: StoredStrEnum
Bristol Stool Scale classification types; stored is the scale number kept in the database.
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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
Color
Bases: Enum
Enumeration of common stool color descriptions.
Attributes:
| Name | Type | Description |
|---|---|---|
BROWN |
Normal brown color. |
|
DARK_BROWN |
Darker than normal brown. |
|
LIGHT_BROWN |
Lighter than normal brown. |
|
YELLOW |
Yellowish color. |
|
GREEN |
Greenish color. |
|
BLACK |
Black or very dark color. |
|
RED |
Red or reddish color. |
|
WHITE |
White or clay-colored. |
Source code in backend/app/modules/health/health_poop/schema.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
HealthPoopBase
Bases: BaseModel
Base model for health poop data.
Attributes:
| Name | Type | Description |
|---|---|---|
date_time |
Date and time of the bowel movement. |
|
bristol_type |
StoredBristolType | None
|
Bristol Stool Scale type. |
color |
Color | None
|
Stool color description. |
notes |
StrictStr | None
|
Optional notes about the bowel movement. |
Source code in backend/app/modules/health/health_poop/schema.py
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: HealthPoopWrite
Schema for creating a new poop record.
Requires date_time.
Source code in backend/app/modules/health/health_poop/schema.py
134 135 136 137 138 139 140 141 142 143 | |
HealthPoopImport
Bases: HealthPoopCreate
Poop record written by the server itself: a profile import, or a client's record with its assigned source.
Unlike :class:HealthPoopCreate it carries the provenance, which a client never sets. Every
server-side writer of source takes Health<Kind>Import (create) or Health<Kind>ImportUpdate. A record
without a source is a manual one.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
The source the record came from; |
Source code in backend/app/modules/health/health_poop/schema.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
HealthPoopRead
Bases: HealthPoopBase
Schema for reading a poop record.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
Source
|
Source of the data. |
id |
UUID
|
Unique identifier for the poop record. |
user_id |
UUID
|
Foreign key reference to the user. |
Source code in backend/app/modules/health/health_poop/schema.py
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 | |
HealthPoopUpdate
Bases: NotClearable, HealthPoopWrite
Schema for the fields a PATCH changes on a poop record.
The record is named by the path, so the body carries neither an id nor an owner; only the fields present are changed.
Source code in backend/app/modules/health/health_poop/schema.py
176 177 178 179 180 181 182 183 184 185 186 187 188 | |
HealthPoopWrite
Bases: HealthPoopBase
Poop fields a client writes: the time is bounded, which a stored row read back need not be.
Source code in backend/app/modules/health/health_poop/schema.py
125 126 127 128 129 130 131 | |
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
28 29 30 31 32 33 34 35 | |