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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Release

### Internal

- Bump Sentry to v8.22.0
- Bump AndroidX Lifecycle to v2.9.4
- Bump AndroidX Test Runner to v1.7.0
Expand Down Expand Up @@ -37,10 +38,12 @@
- Add Suspected option to hypertension and diabetes questions
- Handle Screening feature visibility based on feature flag `Screening`
- Add `hypertensionDiagnosedAt` and `diabetesDiagnosedAt` in `MedicalHistory` table
- Hide schedule appointment sheet for suspected patients

## 2025.09.09

### Internal

- Bump AGP to v8.13.0
- Bump Lint to v31.13.0
- Bump dagger to v2.57.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.room.RawQuery
import androidx.sqlite.db.SimpleSQLiteQuery
import io.reactivex.Flowable
import kotlinx.parcelize.Parcelize
import org.simple.clinic.medicalhistory.Answer.Suspected
import org.simple.clinic.medicalhistory.Answer.Unanswered
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithDiabetes
import org.simple.clinic.medicalhistory.MedicalHistoryQuestion.DiagnosedWithHypertension
Expand Down Expand Up @@ -92,6 +93,9 @@ data class MedicalHistory(
val diagnosisRecorded: Boolean
get() = hypertensionRecorded && diabetesRecorded

val suspected: Boolean
get() = diagnosedWithHypertension == Suspected && diagnosedWithDiabetes == Suspected

fun answered(question: MedicalHistoryQuestion, answer: Answer): MedicalHistory {
return when (question) {
DiagnosedWithHypertension -> copy(diagnosedWithHypertension = answer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ class PatientSummaryUpdate(
prescribedDrugs: List<PrescribedDrug>,
diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions,
): Next<PatientSummaryModel, PatientSummaryEffect> {
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated && !hasAppointmentChangedSinceScreenCreated
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated &&
!hasAppointmentChangedSinceScreenCreated &&
medicalHistory.suspected.not()

val hasAtLeastOneMeasurementRecorded = countOfRecordedBloodPressures + countOfRecordedBloodSugars > 0
val shouldShowDiagnosisError = hasAtLeastOneMeasurementRecorded && when {
model.isDiabetesManagementEnabled -> medicalHistory.diagnosisRecorded.not()
Expand All @@ -589,8 +592,10 @@ class PatientSummaryUpdate(
medicalHistory = medicalHistory,
hasShownMeasurementsWarningDialog = model.hasShownMeasurementsWarningDialog
)

val canShowHTNDiagnosisWarning = medicalHistory.diagnosedWithHypertension != Yes &&
prescribedDrugs.any { prescription -> diagnosisWarningPrescriptions.htnPrescriptions.contains(prescription.name.lowercase()) }

val canShowDiabetesDiagnosisWarning = medicalHistory.diagnosedWithDiabetes != Yes &&
prescribedDrugs.any { prescription -> diagnosisWarningPrescriptions.diabetesPrescriptions.contains(prescription.name.lowercase()) }

Expand All @@ -616,21 +621,29 @@ class PatientSummaryUpdate(
prescribedDrugs: List<PrescribedDrug>,
diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions,
): Next<PatientSummaryModel, PatientSummaryEffect> {
val openIntention = model.openIntention
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated && !hasAppointmentChangedSinceScreenCreated
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated
&& !hasAppointmentChangedSinceScreenCreated
&& medicalHistory.suspected.not()

val hasAtLeastOneMeasurementRecorded = countOfRecordedBloodPressures + countOfRecordedBloodSugars > 0
val shouldShowDiagnosisError = hasAtLeastOneMeasurementRecorded && when {
model.isDiabetesManagementEnabled -> medicalHistory.diagnosisRecorded.not()
else -> medicalHistory.hypertensionRecorded.not()
}

val openIntention = model.openIntention
val shouldGoToPreviousScreen = openIntention is ViewExistingPatient
val shouldGoToHomeScreen = openIntention is LinkIdWithPatient || openIntention is ViewNewPatient || openIntention is ViewExistingPatientWithTeleconsultLog
val shouldGoToHomeScreen = openIntention is LinkIdWithPatient ||
openIntention is ViewNewPatient ||
openIntention is ViewExistingPatientWithTeleconsultLog

val measurementWarningEffect = validateMeasurements(
isDiabetesManagementEnabled = model.isDiabetesManagementEnabled,
countOfRecordedBloodSugars = countOfRecordedBloodSugars,
countOfRecordedBloodPressures = countOfRecordedBloodPressures,
medicalHistory = medicalHistory,
hasShownMeasurementsWarningDialog = model.hasShownMeasurementsWarningDialog)

val canShowHTNDiagnosisWarning = medicalHistory.diagnosedWithHypertension != Yes &&
prescribedDrugs.any { prescription -> diagnosisWarningPrescriptions.htnPrescriptions.contains(prescription.name.lowercase()) }
val canShowDiabetesDiagnosisWarning = medicalHistory.diagnosedWithDiabetes != Yes &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.simple.clinic.cvdrisk.StatinInfo
import org.simple.clinic.drugs.DiagnosisWarningPrescriptions
import org.simple.clinic.facility.FacilityConfig
import org.simple.clinic.medicalhistory.Answer.No
import org.simple.clinic.medicalhistory.Answer.Suspected
import org.simple.clinic.medicalhistory.Answer.Unanswered
import org.simple.clinic.medicalhistory.Answer.Yes
import org.simple.clinic.patient.Answer
Expand Down Expand Up @@ -2820,6 +2821,60 @@ class PatientSummaryUpdateTest {
))
}

@Test
fun `when there are patient is suspected, clicking on back should not show the schedule appointment sheet`() {
val model = defaultModel.currentFacilityLoaded(facilityWithDiabetesManagementEnabled)

updateSpec
.given(model)
.whenEvent(DataForBackClickLoaded(
hasPatientMeasurementDataChangedSinceScreenCreated = true,
hasAppointmentChangeSinceScreenCreated = false,
countOfRecordedBloodPressures = 1,
countOfRecordedBloodSugars = 1,
medicalHistory = TestData.medicalHistory(
uuid = UUID.fromString("94056dc9-85e9-472e-8674-1657bbab56bb"),
patientUuid = patientUuid,
diagnosedWithHypertension = Suspected,
hasDiabetes = Suspected
),
canShowPatientReassignmentWarning = false,
prescribedDrugs = emptyList(),
diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions.empty()
))
.then(assertThatNext(
hasNoModel(),
hasEffects(GoBackToPreviousScreen)
))
}

@Test
fun `when there are patient is suspected, clicking on done should not show the schedule appointment sheet`() {
val model = defaultModel.currentFacilityLoaded(facilityWithDiabetesManagementEnabled)

updateSpec
.given(model)
.whenEvent(DataForDoneClickLoaded(
hasPatientMeasurementDataChangedSinceScreenCreated = true,
hasAppointmentChangeSinceScreenCreated = false,
countOfRecordedBloodPressures = 1,
countOfRecordedBloodSugars = 0,
medicalHistory = TestData.medicalHistory(
uuid = UUID.fromString("7aeb58c1-19f8-43f8-952c-8fb069b9268b"),
patientUuid = patientUuid,
diagnosedWithHypertension = Suspected,
hasDiabetes = Suspected
),
canShowPatientReassignmentWarning = false,
prescribedDrugs = emptyList(),
diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions.empty()
))
.then(assertThatNext(
hasNoModel(),
hasEffects(GoToHomeScreen)
))
}

private fun PatientSummaryModel.forExistingPatient(): PatientSummaryModel {
return copy(openIntention = ViewExistingPatient)
}
Expand Down