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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Bump Coroutines to v1.11.0
- Bump Gradle to v9.5.1

### Changes

- Update Titration nudge threshold for diabetic patients in SriLanka from `140/90` to `130/80`

## 2026.05.11

### Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ class BloodPressureRepositoryAndroidTest {
val newestBpForPatient3 = TestData.bloodPressureMeasurement(
uuid = UUID.fromString("3d948d3b-6d8f-4608-bde0-d8750fef75d4"),
patientUuid = patient3Uuid,
systolic = 150,
diastolic = 90,
systolic = 135,
diastolic = 85,
createdAt = Instant.parse("2000-01-01T00:03:00Z"),
recordedAt = Instant.parse("2000-01-01T00:03:00Z"),
updatedAt = Instant.parse("2000-01-01T00:03:00Z"),
Expand All @@ -475,9 +475,9 @@ class BloodPressureRepositoryAndroidTest {
))

// when
val isNewestBpEntryHighForPatient1 = repository.isNewestBpEntryHigh(patient1Uuid).blockingFirst()
val isNewestBpEntryHighForPatient2 = repository.isNewestBpEntryHigh(patient2Uuid).blockingFirst()
val isNewestBpEntryHighForPatient3 = repository.isNewestBpEntryHigh(patient3Uuid).blockingFirst()
val isNewestBpEntryHighForPatient1 = repository.isNewestBpEntryHigh(patient1Uuid, isDiabeticPatient = false, isSriLankaEnabled = false).blockingFirst()
val isNewestBpEntryHighForPatient2 = repository.isNewestBpEntryHigh(patient2Uuid, isDiabeticPatient = true, isSriLankaEnabled = false).blockingFirst()
val isNewestBpEntryHighForPatient3 = repository.isNewestBpEntryHigh(patient3Uuid, isDiabeticPatient = true, isSriLankaEnabled = true).blockingFirst()

// then
assertThat(isNewestBpEntryHighForPatient1).isTrue()
Expand Down
35 changes: 20 additions & 15 deletions app/src/main/java/org/simple/clinic/bp/BloodPressureMeasurement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,25 @@ data class BloodPressureMeasurement(
fun purgeBloodPressureMeasurementWhenPatientIsNull(): Int

@Query("""
SELECT
CASE
WHEN (COUNT(BP.uuid) >= 1) THEN 1
ELSE 0
END
FROM BloodPressureMeasurement BP
WHERE
BP.patientUuid = :patientUuid AND
date(BP.recordedAt) == :currentDate AND
(BP.systolic >= 140 OR BP.diastolic >= 90) AND
BP.deletedAt IS NULL
ORDER BY BP.recordedAt DESC
LIMIT 1
""")
fun isNewestBpEntryHigh(patientUuid: UUID, currentDate: LocalDate): Observable<Boolean>
SELECT
CASE
WHEN (COUNT(BP.uuid) >= 1) THEN 1
ELSE 0
END
FROM BloodPressureMeasurement BP
WHERE
BP.patientUuid = :patientUuid AND
date(BP.recordedAt) == :currentDate AND
(BP.systolic >= :systolicThreshold OR BP.diastolic >= :diastolicThreshold) AND
BP.deletedAt IS NULL
ORDER BY BP.recordedAt DESC
LIMIT 1
""")
fun isNewestBpEntryHigh(
patientUuid: UUID,
currentDate: LocalDate,
systolicThreshold: Int,
diastolicThreshold: Int
): Observable<Boolean>
}
}
20 changes: 18 additions & 2 deletions app/src/main/java/org/simple/clinic/bp/BloodPressureRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,25 @@ class BloodPressureRepository @Inject constructor(
)
}

fun isNewestBpEntryHigh(patientUuid: UUID): Observable<Boolean> {
fun isNewestBpEntryHigh(
patientUuid: UUID,
isDiabeticPatient: Boolean,
isSriLankaEnabled: Boolean
): Observable<Boolean> {

val currentDate = LocalDate.now(utcClock)

return dao.isNewestBpEntryHigh(patientUuid = patientUuid, currentDate = currentDate)
val systolicThreshold =
if (isSriLankaEnabled && isDiabeticPatient) 130 else 140

val diastolicThreshold =
if (isSriLankaEnabled && isDiabeticPatient) 80 else 90

return dao.isNewestBpEntryHigh(
patientUuid = patientUuid,
currentDate = currentDate,
systolicThreshold = systolicThreshold,
diastolicThreshold = diastolicThreshold
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,38 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
effects
.observeOn(schedulersProvider.io())
.switchMap {

val patientUuid = it.patientUuid
bloodPressureRepository.isNewestBpEntryHigh(patientUuid).map { Pair(patientUuid, it) }

val hasDiabetes =
medicalHistoryRepository.historyForPatientOrDefaultImmediate(
defaultHistoryUuid = uuidGenerator.v4(),
patientUuid = patientUuid
).diagnosedWithDiabetes == MedicalHistoryAnswer.Yes

val isSriLanka =
country.isoCountryCode == Country.SRI_LANKA

bloodPressureRepository.isNewestBpEntryHigh(
patientUuid = patientUuid,
isDiabeticPatient = hasDiabetes,
isSriLankaEnabled = isSriLanka
).map { isNewestBpEntryHigh ->
Pair(patientUuid, isNewestBpEntryHigh)
}
}
.switchMap { (patientUuid, isNewestBpEntryHigh) ->
prescriptionRepository.hasPrescriptionForPatientChangedToday(patientUuid).map { Pair(isNewestBpEntryHigh, it) }
prescriptionRepository
.hasPrescriptionForPatientChangedToday(patientUuid)
.map { hasPrescriptionsChangedToday ->
Pair(isNewestBpEntryHigh, hasPrescriptionsChangedToday)
}
}
.map { (isNewestBpEntryHigh, hasPrescriptionsChangedToday) ->
ClinicalDecisionSupportInfoLoaded(isNewestBpEntryHigh, hasPrescriptionsChangedToday)
ClinicalDecisionSupportInfoLoaded(
isNewestBpEntryHigh,
hasPrescriptionsChangedToday
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,14 @@ class PatientSummaryEffectHandlerTest {
// given
val patientUuid = UUID.fromString("44daeb85-de4c-4807-8b31-6a88bf597cc7")

whenever(bloodPressureRepository.isNewestBpEntryHigh(patientUuid)).doReturn(Observable.just(true))
val medicalHistory = TestData.medicalHistory()

whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(
defaultHistoryUuid = uuidGenerator.v4(),
patientUuid = patientUuid
)) doReturn medicalHistory

whenever(bloodPressureRepository.isNewestBpEntryHigh(patientUuid, medicalHistory.diagnosedWithDiabetes == Yes, false)).doReturn(Observable.just(true))
whenever(prescriptionRepository.hasPrescriptionForPatientChangedToday(patientUuid)).doReturn(Observable.just(true))

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import org.simple.clinic.cvdrisk.calculator.NonLabBasedCVDRiskCalculator
import org.simple.clinic.drugs.DiagnosisWarningPrescriptions
import org.simple.clinic.drugs.PrescriptionRepository
import org.simple.clinic.facility.FacilityRepository
import org.simple.clinic.feature.Feature
import org.simple.clinic.feature.Features
import org.simple.clinic.medicalhistory.Answer
import org.simple.clinic.medicalhistory.MedicalHistoryRepository
import org.simple.clinic.overdue.Appointment.Status.Cancelled
import org.simple.clinic.overdue.AppointmentCancelReason
Expand All @@ -35,11 +34,9 @@ import org.simple.clinic.patient.PatientRepository
import org.simple.clinic.patient.businessid.Identifier
import org.simple.clinic.patient.businessid.Identifier.IdentifierType.BpPassport
import org.simple.clinic.patientattribute.PatientAttributeRepository
import org.simple.clinic.remoteconfig.DefaultValueConfigReader
import org.simple.clinic.summary.OpenIntention.LinkIdWithPatient
import org.simple.clinic.summary.OpenIntention.ViewExistingPatient
import org.simple.clinic.summary.OpenIntention.ViewNewPatient
import org.simple.clinic.util.NoOpRemoteConfigService
import org.simple.clinic.util.RxErrorsRule
import org.simple.clinic.util.TestUserClock
import org.simple.clinic.util.TestUtcClock
Expand Down Expand Up @@ -104,16 +101,17 @@ class PatientSummaryScreenLogicTest {
.atZone(userClock.zone)
.toInstant()

whenever(bpRepository.isNewestBpEntryHigh(patientUuid)) doReturn Observable.just(true)
val medicalHistory = TestData.medicalHistory(uuid = medicalHistoryUuid)
whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(
defaultHistoryUuid = uuidGenerator.v4(),
patientUuid = patientUuid
)) doReturn medicalHistory
whenever(bpRepository.isNewestBpEntryHigh(patientUuid, isDiabeticPatient = medicalHistory.diagnosedWithDiabetes == Answer.Yes, isSriLankaEnabled = false)) doReturn Observable.just(true)
whenever(patientRepository.patientProfile(patientUuid)) doReturn Observable.just(Optional.of(patientProfile))
whenever(patientRepository.latestPhoneNumberForPatient(patientUuid)) doReturn Optional.empty()
whenever(appointmentRepository.lastCreatedAppointmentForPatient(patientUuid)) doReturn Optional.empty()
whenever(bpRepository.hasBPRecordedToday(patientUuid, today)) doReturn Observable.just(true)
whenever(facilityRepository.facility(assignedFacilityUuid)) doReturn Optional.of(TestData.facility())
whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(
defaultHistoryUuid = uuidGenerator.v4(),
patientUuid = patientUuid
)) doReturn TestData.medicalHistory(uuid = medicalHistoryUuid)
whenever(prescriptionRepository.newestPrescriptionsForPatientImmediate(patientUuid)) doReturn emptyList()
}

Expand Down
Loading