Skip to content
yens5757Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

MedTrack Pro

A medication tracking Android app built with Kotlin and Jetpack Compose, following the MVVM architecture with Room as the persistence layer. Patients track their medications and symptoms, look up drug information, and receive AI-generated guidance. Clinicians get a separate dashboard with aggregate statistics and AI-powered population insights.


Screenshots

Screenshot_20260620_233044 Screenshot_20260620_233233
Medication tracking with daily reset Symptom logging with severity
Screenshot_20260620_233106 Screenshot_20260620_233201
MedCoach — drug lookup & AI tips Clinician dashboard

Features

Patient features

  • Account system — sign up as a new patient, or claim a pre-loaded account by verifying a phone number and setting a password. Sessions persist across app restarts.
  • Medication tracking — view scheduled medications, add new ones, and tick off doses. Taken state persists to the database and resets automatically each day.
  • Symptom logging — record symptoms with a category, severity (1–10), date/time, and notes. History is sorted newest-first.
  • MedCoach — Drug lookup — search any medication and pull live data (purpose, warnings, dosage) from the OpenFDA Drug Label API.
  • MedCoach — AI tips — generate personalised, encouraging medication tips via Google Gemini. Tips are saved and viewable as history.
  • Drug Interaction Checker — send the patient's full medication list to Gemini for analysis of drug-drug interactions and food/timing warnings.

Clinician features

  • Access-gated dashboard — entered via a secure access key.
  • Aggregate statistics — total patients, average medications per patient, most common symptom category, average symptom severity, all computed in SQL.
  • AI insights — send the aggregate stats to Gemini and receive observations about the patient population.

Architecture

The app follows MVVM (Model–View–ViewModel) with a single Repository mediating all data access.

┌─────────────────────────────────────────────────┐
│  View (Composables)                              │
│  HomeScreen, MedCoachScreen, etc.                │
│  - observes state via collectAsState             │
│  - sends user actions to the ViewModel           │
└───────────────────┬─────────────────────────────┘
                    │
┌───────────────────▼─────────────────────────────┐
│  ViewModel                                       │
│  PatientViewModel, MedicationViewModel, etc.     │
│  - holds UI state (StateFlow)                    │
│  - runs work in viewModelScope                   │
└───────────────────┬─────────────────────────────┘
                    │
┌───────────────────▼─────────────────────────────┐
│  Repository (MedTrackRepository)                 │
│  - single mediator for ALL data                  │
│  - wraps 4 DAOs + 2 network services             │
└──────┬────────────────────────────┬──────────────┘
       │                            │
┌──────▼─────────┐         ┌────────▼───────────────┐
│  Room (local)  │         │  Network (remote)      │
│  4 DAOs        │         │  OpenFDA + Gemini       │
│  4 Entities    │         │  via Retrofit           │
└────────────────┘         └─────────────────────────┘

Data flow: View → ViewModel → Repository → DAO → Room, with reactive updates flowing back up via Kotlin Flow / StateFlow. The View never touches a DAO or constructs the database directly.


Project structure

app/
├── MainActivity.kt              # Entry point, NavHost, session check
│
├── data/                        # Model + ViewModel layers
│   ├── Patient.kt               # Entity
│   ├── Medication.kt            # Entity (with isTaken + takenDate)
│   ├── Symptom.kt               # Entity
│   ├── MedCoachTip.kt           # Entity (AI tip history)
│   ├── PatientDao.kt            # DAO
│   ├── MedicationDao.kt         # DAO
│   ├── SymptomDao.kt            # DAO (with aggregate queries)
│   ├── MedCoachTipDao.kt        # DAO
│   ├── MedTrackDatabase.kt      # Room database singleton
│   ├── MedTrackRepository.kt    # Single data mediator
│   ├── DatabaseSeeder.kt        # First-launch CSV seeding
│   ├── PatientViewModel.kt
│   ├── MedicationViewModel.kt
│   ├── SymptomViewModel.kt
│   ├── MedCoachViewModel.kt     # Drug lookup + AI tips + interactions
│   ├── ClinicianViewModel.kt    # Dashboard stats + AI insights
│   ├── DrugUiState.kt           # Sealed UI state for drug lookup
│   ├── TipUiState.kt            # Sealed UI state for AI tips
│   └── InteractionUiState.kt    # Sealed UI state for interaction check
│
├── network/                     # Remote data layer
│   ├── DrugAPIService.kt        # Retrofit interface for OpenFDA
│   ├── DrugResponseModel.kt     # OpenFDA response models
│   ├── GeminiAPIService.kt      # Retrofit interface for Gemini
│   └── GeminiModels.kt          # Gemini request/response models
│
└── screens/                     # View layer (composables)
    ├── WelcomeScreen.kt
    ├── LoginScreen.kt           # Login + auto-detect claim mode
    ├── SignUpScreen.kt
    ├── HomeScreen.kt            # Medication list + taken toggles
    ├── AddMedicationScreen.kt
    ├── SymptomsScreen.kt
    ├── MedCoachScreen.kt        # Drug lookup + tips + interactions
    ├── SettingScreen.kt
    ├── ClinicianLoginScreen.kt
    ├── ClinicianDashboardScreen.kt
    └── BottomNavBar.kt

Data model

Four Room entities. Medication, Symptom, and MedCoachTip each have a foreign key to Patient with ON DELETE CASCADE, so deleting a patient removes all their related records.

Entity Primary key Key fields Notes
Patient patientId: String phoneNumber, name, password String ID, no auto-generate. Empty password = unclaimed.
Medication id: Int (auto) patientId (FK), name, dosage, frequency, scheduledTime, type, notes, isTaken, takenDate isTaken/takenDate drive the daily-reset feature.
Symptom id: Int (auto) patientId (FK), category, severity, notes, dateTime
MedCoachTip id: Int (auto) patientId (FK), tipText, timestamp Stores AI tip history.

The database is at version 2 (bumped when isTaken/takenDate were added) using fallbackToDestructiveMigration().


Tech stack

  • Language: Kotlin
  • UI: Jetpack Compose, Material 3
  • Architecture: MVVM + Repository pattern
  • Persistence: Room (SQLite) with KSP
  • Networking: Retrofit 2.9.0 + Gson converter
  • Async: Kotlin Coroutines + Flow / StateFlow
  • Navigation: Navigation Compose
  • External APIs:

Setup

Prerequisites

  • Android Studio (latest stable)
  • An emulator or device running API 35+ (Android 15)
  • A Google Gemini API key (get one here)

Steps

  1. Clone the repo and open it in Android Studio.

  2. Add your Gemini API key to local.properties in the project root:

    apiKey=YOUR_GEMINI_API_KEY_HERE

    The build reads this into BuildConfig.apiKey at compile time (configured in app/build.gradle.kts). The key is never hardcoded into source.

  3. Confirm the seed data is present at app/src/main/assets/:

    • patients.csv
    • medications.csv
    • symptoms.csv
  4. Let Gradle sync, then Run.

On first launch, the app seeds the database from the CSVs. It checks whether the patients table already has rows, so seeding only happens once even across reinstalls of the same database.


How it works

First-launch seeding

MainActivity.onCreate calls DatabaseSeeder.seedIfNeeded(). The seeder checks patientCount > 0 on the patients table — if the table already has data, it skips; otherwise it parses the three CSVs and inserts each row through the Repository. Checking the table directly (rather than a flag) avoids the failure mode where a flag is set but the data never landed.

Account claiming

Pre-loaded patients arrive with an empty password. On the Login screen, a LaunchedEffect keyed on the Patient ID field runs a Room lookup on every keystroke. If the ID exists with an empty password, the form morphs into "claim mode" (phone + new password + confirm). Otherwise it stays in normal login mode. One screen handles both flows.

Taken toggle with daily reset

Each Medication row stores isTaken and takenDate. The Home screen treats a medication as taken only if isTaken == true and takenDate == today. So yesterday's ticks automatically appear unticked today — no background job needed. The stale row is overwritten the next time the user ticks it.

AI features (Gemini)

Three features call Gemini through the same Retrofit plumbing:

  • AI tips pull the patient's medications and symptoms from Room and bake them into the prompt for personalisation, then save the result for history.
  • Drug interaction checker sends the medication list and asks for drug-drug interactions plus food/timing warnings.
  • Clinician insights send aggregate statistics and ask for population observations.

Each uses a sealed-interface UI state (Initial / Loading / Success / Error) so the UI renders a spinner, a result card, or an error message via an exhaustive when block.


Design decisions

A few choices worth noting:

  • DB-state seeding check over a stored flag — more robust; can't get stuck in a "flag set but no data" state.
  • Gemini via Retrofit REST instead of the official SDK — the SDK was deprecated and failing against current servers. Calling the REST endpoint via Retrofit gives one consistent networking approach across both OpenFDA and Gemini.
  • One UI-state pattern reused everywhere — every async feature (drug lookup, tips, interactions, insights) uses the same sealed-interface shape, keeping the UI code uniform and making new features cheap to add.
  • API key in local.properties, injected via BuildConfig — keeps secrets out of source control.

Known limitations

  • Form state uses remember rather than rememberSaveable, so in-progress form input is lost on screen rotation.
  • The database uses fallbackToDestructiveMigration() rather than hand-written migrations — fine for development, but would lose data on a schema change in production.
  • Drug lookup results are not cached, so the OpenFDA feature requires a network connection each time.
  • AI interaction results are not persisted (unlike tips), so there's no interaction-check history.

Roadmap

  • Persist interaction-check results for a full history view
  • Cache OpenFDA drug data locally for offline lookups
  • Migrate form state to rememberSaveable for rotation safety
  • Hand-written Room migrations to preserve data across schema changes
  • Push notifications for medication reminders

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages