Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
- Add effect to fetch complete medical records
- Bump sqlcipher to v4.13.0
- Bump dagger to v2.59.1
- Bump Mockito Kotlin to v6.2.3
- Bump Sentry to v8.32.0
- Bump Sentry Android to v6.0.0
- Bump KSP to v2.3.5
- Bump AndroidX Camera to v1.5.3
- Bump AndroidX Camera View to v1.5.3
- Bump AndroidX Work to v2.11.1
- Bump AndroidX Activity to v1.12.4
- Bump Compose BOM to v2026.02.00
- Bump Kotlin to v2.3.10
- Bump AGP to v9.0.1
- Bump Lint to v32.0.1

### Changes

- Add `Sync Medical Records` button on setting page behind feature flag

## 2026.02.02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SettingsScreenTest {

private val defaultSettingsModel = SettingsModel.default(
isChangeLanguageFeatureEnabled = true,
showDiagnosisButton = true
)

@Test
Expand All @@ -30,7 +31,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand Down Expand Up @@ -58,7 +60,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -78,7 +81,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -97,7 +101,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -115,7 +120,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -133,7 +139,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -150,7 +157,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -168,7 +176,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -186,7 +195,8 @@ class SettingsScreenTest {
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -198,14 +208,16 @@ class SettingsScreenTest {
fun whenChangeLanguageFeatureIsNotEnabledThenDoNotShowChangeLanguageSetting() {
val model = SettingsModel.default(
isChangeLanguageFeatureEnabled = false,
showDiagnosisButton = true
)
composeRule.setContent {
SettingsScreen(
model = model,
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -217,14 +229,16 @@ class SettingsScreenTest {
fun whenChangeLanguageFeatureIsEnabledThenShowChangeLanguageSetting() {
val model = SettingsModel.default(
isChangeLanguageFeatureEnabled = true,
showDiagnosisButton = true,
)
composeRule.setContent {
SettingsScreen(
model = model,
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand All @@ -236,14 +250,16 @@ class SettingsScreenTest {
fun logoutButtonShouldBeVisible() {
val model = SettingsModel.default(
isChangeLanguageFeatureEnabled = true,
showDiagnosisButton = true
)
composeRule.setContent {
SettingsScreen(
model = model,
navigationIconClick = { /*no-op*/ },
changeLanguageButtonClick = { /*no-op*/ },
updateButtonClick = { /*no-op*/ },
logoutButtonClick = { /*no-op*/ }
logoutButtonClick = { /*no-op*/ },
syncMedicalRecordClick = { /*no-op*/ }
)
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/simple/clinic/feature/Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ enum class Feature(
PatientStatinNudge(false, "patient_statin_nudge_v0"),
NonLabBasedStatinNudge(false, "non_lab_based_statin_nudge"),
LabBasedStatinNudge(false, "lab_based_statin_nudge"),
Screening(false, "screening_feature_v0")
Screening(false, "screening_feature_v0"),
ShowDiagnosisButton(false, "show_diagnosis_button"),
}
40 changes: 22 additions & 18 deletions app/src/main/java/org/simple/clinic/patient/PatientRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -743,26 +743,30 @@ class PatientRepository @Inject constructor(

fun fetchCompleteMedicalRecord(): List<CompleteMedicalRecord> {
val patientProfiles = database.patientDao().allPatientProfiles()
return patientProfiles.map { patientProfile ->
val patientUuid = patientProfile.patientUuid
val medicalHistory = database.medicalHistoryDao().historyForPatientImmediate(patientUuid)
val appointments = database.appointmentDao().getAllAppointmentsForPatient(patientUuid)
val bloodPressures = database.bloodPressureDao().allBloodPressuresRecordedSinceImmediate(
patientUuid,
Instant.EPOCH
)
val bloodSugars = database.bloodSugarDao().allBloodSugarsImmediate(patientUuid)
return patientProfiles.mapNotNull { patientProfile ->
try {
val patientUuid = patientProfile.patientUuid
val medicalHistory = database.medicalHistoryDao().historyForPatientImmediate(patientUuid)
val appointments = database.appointmentDao().getAllAppointmentsForPatient(patientUuid)
val bloodPressures = database.bloodPressureDao().allBloodPressuresRecordedSinceImmediate(
patientUuid,
Instant.EPOCH
)
val bloodSugars = database.bloodSugarDao().allBloodSugarsImmediate(patientUuid)

val prescribedDrugs = database.prescriptionDao().forPatientImmediate(patientUuid)
val prescribedDrugs = database.prescriptionDao().forPatientImmediate(patientUuid)

CompleteMedicalRecord(
patient = patientProfile,
medicalHistory = medicalHistory,
appointments = appointments,
bloodPressures = bloodPressures,
bloodSugars = bloodSugars,
prescribedDrugs = prescribedDrugs
)
CompleteMedicalRecord(
patient = patientProfile,
medicalHistory = medicalHistory,
appointments = appointments,
bloodPressures = bloodPressures,
bloodSugars = bloodSugars,
prescribedDrugs = prescribedDrugs
)
} catch (_: Exception) {
null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.simple.clinic.patient.medicalRecords

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import org.simple.clinic.patient.CompleteMedicalRecord
import org.simple.clinic.patient.onlinelookup.api.CompleteMedicalRecordPayload

@JsonClass(generateAdapter = true)
data class CompleteMedicalRecordsPushRequest(

@Json(name = "patients")
val patients: List<CompleteMedicalRecordPayload>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.simple.clinic.patient.medicalRecords

import org.simple.clinic.patient.CompleteMedicalRecord
import org.simple.clinic.patient.onlinelookup.api.CompleteMedicalRecordPayload
import org.simple.clinic.patient.onlinelookup.api.RecordRetention
import org.simple.clinic.patient.onlinelookup.api.RetentionType
import org.simple.clinic.patient.onlinelookup.api.SecondsDuration
import org.simple.clinic.patient.sync.PatientSyncApi
import org.simple.clinic.util.UtcClock
import java.time.Duration
import java.time.Instant
import javax.inject.Inject

class PushMedicalRecordsOnline @Inject constructor(
private val patientSyncApi: PatientSyncApi,
private val clock: UtcClock,
) {
fun pushAllMedicalRecordsOnServer(
medicalRecords: List<CompleteMedicalRecord>
): Result {

if (medicalRecords.isEmpty()) {
return Result.NothingToPush
}

val request = CompleteMedicalRecordsPushRequest(
patients = medicalRecords.map { mapToPayload(it) }
)

return try {
val response = patientSyncApi
.pushAllPatientsData(request)
.execute()

return when (response.code()) {
200 -> Result.Success
else -> Result.ServerError(
code = response.code(),
message = response.errorBody()?.string()
)
}

} catch (e: Exception) {
Result.NetworkError(e)
}
}


fun mapToPayload(
completeMedicalRecord: CompleteMedicalRecord
): CompleteMedicalRecordPayload {

val patientProfile = completeMedicalRecord.patient
val patient = patientProfile.patient

return CompleteMedicalRecordPayload(
id = patient.uuid,
fullName = patient.fullName,
gender = patient.gender,
dateOfBirth = patient.ageDetails.dateOfBirth,
age = patient.ageDetails.ageValue,
ageUpdatedAt = patient.ageDetails.ageUpdatedAt,
status = patient.status,
createdAt = patient.createdAt,
updatedAt = patient.updatedAt,
deletedAt = patient.deletedAt,

address = patientProfile.address.toPayload(),

phoneNumbers = patientProfile.phoneNumbers
.map { it.toPayload() },

businessIds = patientProfile.businessIds
.map { it.toPayload() },

recordedAt = patient.recordedAt,

reminderConsent = patient.reminderConsent,

deletedReason = patient.deletedReason,

registeredFacilityId = patient.registeredFacilityId,

assignedFacilityId = patient.assignedFacilityId,

appointments = completeMedicalRecord.appointments
.map { it.toPayload() },

bloodPressures = completeMedicalRecord.bloodPressures
.map { it.toPayload() },

bloodSugars = completeMedicalRecord.bloodSugars
.map { it.toPayload() },

medicalHistory = completeMedicalRecord.medicalHistory
?.toPayload(),

prescribedDrugs = completeMedicalRecord.prescribedDrugs
.map { it.toPayload() },

retention = patient.retainUntil?.let { retainUntil ->
val duration = Duration.between(
Instant.now(clock),
retainUntil
).coerceAtLeast(Duration.ZERO)

RecordRetention(
type = RetentionType.Temporary,
retainFor = SecondsDuration(duration)
)
} ?: RecordRetention(
type = RetentionType.Permanent,
retainFor = null
)
)
}

sealed class Result {
data object Success : Result()
data object NothingToPush : Result()
data class ServerError(
val code: Int,
val message: String?
) : Result()

data class NetworkError(val throwable: Throwable) : Result()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.simple.clinic.patient.sync

import org.simple.clinic.di.network.Timeout
import org.simple.clinic.patient.medicalRecords.CompleteMedicalRecordsPushRequest
import org.simple.clinic.patient.onlinelookup.api.OnlineLookupResponsePayload
import org.simple.clinic.patient.onlinelookup.api.PatientOnlineLookupRequest
import org.simple.clinic.sync.DataPushResponse
Expand Down Expand Up @@ -31,4 +32,9 @@ interface PatientSyncApi {
fun lookup(
@Body body: PatientOnlineLookupRequest
): Call<OnlineLookupResponsePayload>

@POST("v4/legacy_data_dumps")
fun pushAllPatientsData(
@Body body: CompleteMedicalRecordsPushRequest
): Call<DataPushResponse>
}
Loading
Loading