Skip to content

Feat/patient sync eligibility#15

Merged
solemabrothers merged 6 commits into
METS-Programme:mainfrom
jabahum:feat/patient-sync-eligibility
Aug 19, 2025
Merged

Feat/patient sync eligibility#15
solemabrothers merged 6 commits into
METS-Programme:mainfrom
jabahum:feat/patient-sync-eligibility

Conversation

@jabahum

@jabahum jabahum commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

jabahum added 5 commits July 22, 2025 10:28
This commit introduces a mechanism to mark patients as eligible for synchronization and updates the sync worker to only process eligible patients.

Key changes:

- **`PatientEntity.kt`:**
    - Added new fields: `isEligibleForSync` (Boolean), `isVoided` (Boolean), and `lastModified` (Long).

- **`PatientDao.kt`:**
    - Added `updateEligibilityForSync` function to update a patient's eligibility status and last modified timestamp.
    - Added `getEligibleUnsyncedPatients` function to retrieve only unsynced, non-voided, and eligible patients.

- **`PatientRepository.kt` & `PatientRepositoryImpl.kt`:**
    - Added `markPatientEligible` function to expose the DAO's eligibility update functionality.

- **`PatientsUseCase.kt`:**
    - Added `markPatientEligible` suspend function to call the repository method.

- **`SyncRepository.kt` & `SyncRepositoryImpl.kt`:**
    - Added `getEligibleUnsyncedPatients` function to fetch eligible patients for syncing.

- **`SyncUseCase.kt`:**
    - Added `getEligibleUnsyncedPatients` function to use the repository's new method.

- **`PatientsSyncWorker.kt`:**
    - Changed `syncUseCase.getUnsyncedPatients()` to `syncUseCase.getEligibleUnsyncedPatients()` to only sync eligible patients.
    - Updated `ensureNotificationChannelExists` to use `Build.VERSION_CODES.TIRAMISU` for API level check.

- **`WorklistEvent.kt`:**
    - Added `OnMarkPatientEligible` and `OnSyncPatientNow` events.

- **`WorklistViewModel.kt`:**
    - Added `markPatientEligibleForSync` and `syncPatientNow` placeholder functions to handle the new events.
This commit introduces "Eligible" and "Sync Now" options to the `PatientDetailsScreen` overflow menu.

- **`PatientDetailsScreen.kt`:**
    - Added a `MoreVert` icon button to the `TopAppBar`.
    - Implemented a `DropdownMenu` with "Eligible" and "Sync Now" options.
    - Clicking "Eligible" triggers `WorklistEvent.OnMarkPatientEligible`.
    - Clicking "Sync Now" triggers `WorklistEvent.OnSyncPatientNow`.
- **`WorklistEvent.kt`:**
    - Modified `OnMarkPatientEligible` and `OnSyncPatientNow` to accept nullable `patientId`.
- **`WorklistViewModel.kt`:**
    - Implemented `markPatientEligibleForSync` to mark the selected patient as eligible using `patientsUseCase.markPatientEligible`.
    - Implemented `syncPatientNow` to enable auto-sync via `preferenceManager`.
- **`SyncRepository.kt`:**
    - Removed the `markPatientEligible` suspend function as this is now handled by `patientsUseCase`.
- **`RecordVitalScreen.kt`:**
    - Removed the unused `ActionButtons` composable.
- **`RegisterPatientViewModel.kt`:**
    - Set `isLoading` to `false` after loading the questionnaire JSON to reflect the actual loading state.
- **`EncountersSyncWorker.kt`:**
    - Updated the notification channel existence check from `Build.VERSION_CODES.O` to `Build.VERSION_CODES.TIRAMISU` for more accurate API level targeting.
This commit introduces a `SyncNotificationHelper` class to centralize the creation and management of notifications for the sync workers. This helper is injected into `PatientsSyncWorker` and `EncountersSyncWorker` to handle notification display.

Key changes:

- **`SyncNotificationHelper.kt` (New in `core.data.notifications`):**
    - This new class encapsulates the logic for creating notification channels (if needed) and building `Notification` objects.
    - `createNotification()`: A method to construct a `NotificationCompat.Builder` with common settings (channel ID, title, content, small icon, ongoing, category, priority) and optional progress.
    - `notify()`: A method to issue a notification using the `NotificationManager`.
    - It uses constants from `NotificationConstants` for channel ID, name, description, and notification IDs.

- **`CoreModule.kt`:**
    - Added a Hilt provider for `SyncNotificationHelper` as a singleton.

- **`PatientsSyncWorker.kt` & `EncountersSyncWorker.kt`:**
    - Injected `SyncNotificationHelper`.
    - Removed local `notificationManager` properties, `ensureNotificationChannelExists()`, and `createForegroundNotification()` methods.
    - All notification creation and display logic now uses the injected `notificationHelper`.
    - Notification updates for starting, progress, error, retry, and success states are now delegated to `notificationHelper.createNotification()` and `notificationHelper.notify()`.
    - The content of the notifications remains largely the same, providing detailed feedback on the sync process.

This refactoring simplifies the worker classes by abstracting away notification details, promoting better code organization and reusability of notification logic.
…sScreen

This commit introduces a `SyncNotificationHelper` class in the `core` module to encapsulate notification creation and management logic, specifically for synchronization tasks.

Key changes:

- **`SyncNotificationHelper.kt` (New in `core.data.notifications`):**
    - Provides `ensureNotificationChannelExists()` to create a notification channel if it doesn't exist (for Android Tiramisu+).
    - Provides `createNotification()` to build a progress-style notification with title, content, and optional progress bar.
    - Provides `notify()` to display a notification.
    - Uses a low importance channel with sound and vibration disabled.

- **`PatientDetailsScreen.kt`:**
    - Simplified `LaunchedEffect` for loading vitals:
        - The effect for loading vitals (`viewModel.getVitalsByVisit`) is now keyed only by `state.mostRecentVisit`.
        - A separate `LaunchedEffect` keyed by `state.isLoading` is used to update the local `isLoading` variable.
    - This separation ensures that vitals are reloaded only when the `mostRecentVisit` changes, not when `isLoading` changes.

- **`PatientExtensions.kt`:**
    - Minor code style adjustments in `toFhirPatient()` for `HumanName`, `gender`, and `telecom` setup.
    - Simplified `birthDate` parsing with `runCatching` and default `null` on failure.

- **`PatientEntity.kt`:**
    - Minor code formatting adjustment.
… builds

This commit updates the Proguard rules in `app/proguard-rules.pro` to include specific keep rules for various libraries and app components, including Compose, Hilt, WorkManager, Room, Moshi, Retrofit, Coil, Android FHIR, Google Play Startup, DataStore, and Security Crypto. It also adds rules to keep ViewModels, Activities, Fragments, Kotlin metadata/annotations, and enums.

Additionally, the `app/build.gradle.kts` file has been modified to:
- Enable ABI splits for `armeabi-v7a`, `arm64-v8a`, `x86`, and `x86_64`.
- Enable `isMinifyEnabled = true` and `isShrinkResources = true` for release builds to optimize the app size.
@jabahum
jabahum requested review from Mwanje and solemabrothers July 23, 2025 08:06
This commit introduces several changes across the application:

- **Build Configuration (`app/build.gradle.kts`):**
    - Enabled ABI splits for `armeabi-v7a`, `arm64-v8a`, `x86`, and `x86_64`.
    - Set `isUniversalApk = false`.
    - Configured debug builds with `isMinifyEnabled = false` and `isDebuggable = true`.

- **Worklist Module (`worklist/src/main/java/.../WorklistViewModel.kt`):**
    - Modified `syncPatientNow()` to use `syncManager.syncNow()` with `PatientsSyncWorker` and `EncountersSyncWorker` instead of manipulating preference manager for auto-sync.
    - Added `project(":sync")` dependency to `worklist/build.gradle.kts`.
    - Added Hilt WorkManager and WorkManager KTX dependencies to `worklist/build.gradle.kts`.

- **Settings Module (`settings/src/main/java/.../SettingsViewModel.kt`):**
    - In `updateSyncInterval()`, when auto-sync is enabled, it now cancels existing periodic sync and re-schedules `PatientsSyncWorker` and `EncountersSyncWorker` with the new interval.
    - Added `project(":sync")` dependency to `settings/build.gradle.kts`.
    - Added Hilt WorkManager and WorkManager KTX dependencies to `settings/build.gradle.kts`.
@jabahum
jabahum marked this pull request as ready for review July 23, 2025 10:02
@solemabrothers
solemabrothers merged commit ae8fba2 into METS-Programme:main Aug 19, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants