Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / health / AGENTS.md

AGENTS.md10.1 KiBRenderedCodeRaw

AGENTS.md — health/ (':health')

Scoped supplement. Global rules in root AGENTS.md apply. Stay inside health/ + allowed shared modules. Do not root-scan.

Install: ./install health (dev by default).

  • Gradle: :health / dir: health/
  • Package roots present: ui, data, domain, platform, service, notifications, intents
  • Entry files: MainActivity.kt, Route.kt (sealed nav destinations incl. DialogPage dialog routes), Navigation.kt + ui/NavigationEntries.kt
  • Deps: :library:room
  • Metadata: metadata_data/health.md (present)
  • Rust: no / screenshotTest: yes

Overview

Purpose: Offline health-metric manager (Google Fit replacement) — activity/vitals/body/exercise/sleep/hydration/nutrition plus FHIR medical records, backed by Health Connect. No account, no cloud sync. Key features:

  • Per-metric dashboards with charts/history (GenericLineChart/GenericBarChart, hypnogram for sleep)
  • Medications carry their own dosage timing (dose times/repeat) and an optional planned end date (shown only while Taking), with exact reminders as a literal on/off toggle on the medication record (DoseScheduler, DoseSoundService, boot-rescheduled; reminders fire per the medication timing and stop after its planned end date — there is no separate reminder schedule/end date); vaccinations from bundled CVX, drugs from RxNorm; card attachments (PDF/photo)
  • Food logging against a bundled database + search API; AI insights via the on-device OpenAssistant model; file export

Architecture / data-flow: Dialogs that act on a record/metric are Route.…Dialog destinations (DialogPage() entries in ui/NavigationEntries.kt) pushed from clicks, with stateless content under ui/dialogs/; the ingredient search→quantity chain in RecipeEditorPage is the one local exception (see its DIALOG LOCAL EXCEPTION marker). Screenshot coverage lives in src/screenshotTest MetadataPreviews (stateless screens: Today/Nutrition/Body/metric detail/nutrition breakdown/recipe list+editor/sleep/exercise + date-time and simple dialog routes); VM-draft routes are exempted per-route in Route.kt. ui/ Today + record pages → platform/MedicalViewModel (+ per-area Medical*Ops) → data/HealthRepository over Room (Record, MedicalRecords; dosage timing/planned end/reminder toggle are columns on MedicationEntry) synced with Health Connect; domain/ holds pure FHIR (Observations, Medication, Immunization, Allergy/Condition) + DoseSchedule (next-dose arithmetic over a MedicationEntry); reminders flow DoseScheduler (armed per medication) → receivers → DoseReminderActivity + service/DoseSoundService. DB is v13, with the medication timing/end/toggle columns living on MedicationEntry (migration 12→13 in data/Record.kt preserves existing schedules onto that record). Entry points + reading order: MainActivity.kt → ui/TodayPage.kt → platform/MedicalViewModel.kt → data/HealthRepository.kt → domain/FhirRecords.kt → platform/DoseScheduler.kt. Gotchas:

  • Day views use half-open local-calendar ranges (HealthChartData.dayRange, DAO startTime in [start, end), bucketed by start): DST days are 23/25h, midnight point records belong to the new day, and intervals crossing midnight count on their start day. Day-tab line metrics average their hourly averages; bar metrics sum their hourly sums; basal metabolic rate (stored kcal/day) is an averaged line metric, while Today hydration converts stored litres to ml. Month/year tabs bucket bar metrics into weekly/monthly sums: their per-day average divides the period total by the calendar days in the month/year, and a history row's goal is the daily goal scaled by the days its bucket covers (line metrics keep averaging and comparing bucket averages directly).
  • util/ is NOT a closed package root — don't add more files there
  • Medical data is dual-homed (Room + Health Connect) — writes must update both or they diverge
  • Dose reminders need the boot path re-armed like clock alarms; sound runs through a foreground service

Key files

Root — entry

  • com/vayunmathur/health/MainActivity.kt
  • com/vayunmathur/health/Route.kt
  • com/vayunmathur/health/Navigation.kt

data/ — Room entities + repository

  • com/vayunmathur/health/data/HealthRepository.kt
  • com/vayunmathur/health/data/Record.kt — also owns DB_NAME (passwords-db) and healthDbConfigs shared by the backup agent
  • com/vayunmathur/health/data/HealthConverters.kt — Room type converters (Converters)
  • com/vayunmathur/health/data/Record.kt
  • com/vayunmathur/health/data/NutritionScaling.kt
  • com/vayunmathur/health/data/MedicalRecords.kt
  • com/vayunmathur/health/data/FoodModels.kt
  • com/vayunmathur/health/data/ReferenceCatalog.kt
  • com/vayunmathur/health/data/VaccineCatalog.kt

domain/ — pure FHIR + dose schedule (no Android)

  • com/vayunmathur/health/domain/FhirRecords.kt
  • com/vayunmathur/health/domain/FhirObservations.kt
  • com/vayunmathur/health/domain/FhirMedication.kt
  • com/vayunmathur/health/domain/FhirImmunization.kt
  • com/vayunmathur/health/domain/FhirAllergyCondition.kt
  • com/vayunmathur/health/domain/FhirJson.kt
  • com/vayunmathur/health/domain/DoseSchedule.kt
  • com/vayunmathur/health/domain/SocialHistoryQuestions.kt

platform/ — ViewModel, medical ops, reminders

  • com/vayunmathur/health/platform/MedicalViewModel.kt
  • com/vayunmathur/health/platform/MedicalClinicalOps.kt
  • com/vayunmathur/health/platform/MedicalImportOps.kt
  • com/vayunmathur/health/platform/MedicalMedicationOps.kt
  • com/vayunmathur/health/platform/MedicalProfileOps.kt
  • com/vayunmathur/health/platform/MedicalVaccinationOps.kt
  • com/vayunmathur/health/platform/PersonalHealthRecords.kt
  • com/vayunmathur/health/platform/AttachmentStore.kt
  • com/vayunmathur/health/platform/DoseScheduler.kt
  • com/vayunmathur/health/platform/DoseReceiver.kt
  • com/vayunmathur/health/platform/DoseActionReceiver.kt
  • com/vayunmathur/health/platform/DoseReminderActivity.kt
  • com/vayunmathur/health/platform/HealthBootReceiver.kt
  • com/vayunmathur/health/platform/AppBackupAgent.kt — platform backup: SqlCipherDbCodec re-keys passwords-db into the backup payload (raw encrypted file is excluded by res/xml/data_extraction_rules.xml on both channels) and carries files/medical_attachments/ as extra files; food index and sync bookkeeping are not backed up

intents/ — assistant IPC

  • com/vayunmathur/health/intents/GetMetricSummaryIntent.kt — OpenAssistant health_get_metric_summary: validated metric/range over a recent local-calendar window, SQL aggregates only (latest/average/min/max/total/count via HealthRepository aggregate queries); no raw records cross in the library.intents.health DTO

notifications/ + service/ — channels and dose sound

  • com/vayunmathur/health/notifications/DoseNotification.kt
  • com/vayunmathur/health/notifications/MedicationChannels.kt
  • com/vayunmathur/health/service/DoseSoundService.kt

util/ — food DB, sync worker, ViewModel

  • com/vayunmathur/health/util/HealthViewModel.kt
  • com/vayunmathur/health/util/HealthUiContract.kt
  • com/vayunmathur/health/util/HealthSyncWorker.kt
  • com/vayunmathur/health/util/HealthAPI.kt
  • com/vayunmathur/health/util/FoodDatabase.kt
  • com/vayunmathur/health/util/FoodSearchAPI.kt
  • com/vayunmathur/health/util/Utils.kt

ui/ + ui/components/ — Today, records, charts, logging

  • com/vayunmathur/health/ui/NavigationEntries.kt
  • com/vayunmathur/health/ui/BodyScreen.kt
  • com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.kt
  • com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.kt
  • com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.kt
  • com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.kt
  • com/vayunmathur/health/ui/TodayPage.kt
  • com/vayunmathur/health/ui/TodayHero.kt
  • com/vayunmathur/health/ui/RecordsPage.kt
  • com/vayunmathur/health/ui/BodyPage.kt
  • com/vayunmathur/health/ui/SleepDetailsPage.kt
  • com/vayunmathur/health/ui/ExerciseDetailsPage.kt
  • com/vayunmathur/health/ui/NutritionPage.kt
  • com/vayunmathur/health/ui/NutritionDetailsPage.kt
  • com/vayunmathur/health/ui/FoodLoggingDialogs.kt
  • com/vayunmathur/health/ui/FoodDatabaseCard.kt
  • com/vayunmathur/health/ui/IngredientSearchDialog.kt
  • com/vayunmathur/health/ui/IngredientQuantityDialog.kt
  • com/vayunmathur/health/ui/RecipeEditorPage.kt
  • com/vayunmathur/health/ui/RecipeManagementPage.kt
  • com/vayunmathur/health/ui/MedicationPage.kt
  • com/vayunmathur/health/ui/DoseReminderScreen.kt
  • com/vayunmathur/health/ui/VaccinationsPage.kt
  • com/vayunmathur/health/ui/AllergiesPage.kt
  • com/vayunmathur/health/ui/AddAllergyPage.kt
  • com/vayunmathur/health/ui/ConditionsPage.kt
  • com/vayunmathur/health/ui/AddConditionPage.kt
  • com/vayunmathur/health/ui/AddLabResultPage.kt
  • com/vayunmathur/health/ui/LabResultsPage.kt
  • com/vayunmathur/health/ui/AddMedicationPage.kt
  • com/vayunmathur/health/ui/AddVaccinationPage.kt
  • com/vayunmathur/health/ui/AboutYouPage.kt
  • com/vayunmathur/health/ui/CatalogPickerPage.kt
  • com/vayunmathur/health/ui/BodyLoggingDialog.kt
  • com/vayunmathur/health/ui/GenericLineChart.kt
  • com/vayunmathur/health/ui/GenericBarChart.kt
  • com/vayunmathur/health/ui/BarChartDetails.kt
  • com/vayunmathur/health/ui/BarChartDetailsScreen.kt
  • com/vayunmathur/health/ui/ChartAxes.kt
  • com/vayunmathur/health/ui/MetricChartHeader.kt
  • com/vayunmathur/health/ui/MetricDashboardData.kt
  • com/vayunmathur/health/ui/HealthColors.kt
  • com/vayunmathur/health/ui/HealthFormat.kt
  • com/vayunmathur/health/ui/HealthMetricConfig.kt
  • com/vayunmathur/health/ui/PermissionsRationaleActivity.kt
  • com/vayunmathur/health/ui/components/HealthComponents.kt
  • com/vayunmathur/health/ui/components/HealthHypnogram.kt
  • com/vayunmathur/health/ui/components/AttachmentChip.kt
  • com/vayunmathur/health/ui/components/MedicalStorageNotice.kt
  • com/vayunmathur/health/ui/components/PickerField.kt
  • com/vayunmathur/health/ui/components/DosageTimingSection.kt — dosage timing fields on the medication form
  • com/vayunmathur/health/ui/components/ReminderToggleSection.kt — the literal reminder on/off toggle (+ full-screen-intent warning)
  • com/vayunmathur/health/ui/components/SectionLabel.kt
  • com/vayunmathur/health/ui/components/AnswerPickerDialog.kt

Verify (this module only)

./gradlew :health:compileDevKotlin
./gradlew :health:lint
./gradlew :health:checkMetadata