Skip to content

Commit fcb60a4

Browse files
Saket Narayanvinaysshenoy
authored andcommitted
Fix: entering an empty systolic or diastolic value crashes BP entry
Steps to reproduce: 1. Open a patient's summary 2. Tap on 'New BP' 3. Enter empty value for systolic 4. Hit IME-done in keyboard The same steps will also work for the diastolic field.
1 parent 67ea387 commit fcb60a4

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

app/src/main/java/org/simple/clinic/bp/entry/BloodPressureEntrySheet.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,14 @@ class BloodPressureEntrySheet : BottomSheetActivity() {
136136
errorTextView.text = getString(R.string.bloodpressureentry_error_diastolic_180)
137137
errorTextView.visibility = View.VISIBLE
138138
}
139+
140+
fun showSystolicEmptyError() {
141+
errorTextView.text = getString(R.string.bloodpressureentry_error_systolic_empty)
142+
errorTextView.visibility = View.VISIBLE
143+
}
144+
145+
fun showDiastolicEmptyError() {
146+
errorTextView.text = getString(R.string.bloodpressureentry_error_diastolic_empty)
147+
errorTextView.visibility = View.VISIBLE
148+
}
139149
}

app/src/main/java/org/simple/clinic/bp/entry/BloodPressureEntrySheetController.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import io.reactivex.rxkotlin.ofType
77
import io.reactivex.rxkotlin.withLatestFrom
88
import org.simple.clinic.ReportAnalyticsEvents
99
import org.simple.clinic.bp.BloodPressureRepository
10+
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_DIASTOLIC_EMPTY
1011
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_DIASTOLIC_TOO_HIGH
1112
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_DIASTOLIC_TOO_LOW
13+
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_SYSTOLIC_EMPTY
1214
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_SYSTOLIC_LESS_THAN_DIASTOLIC
1315
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_SYSTOLIC_TOO_HIGH
1416
import org.simple.clinic.bp.entry.BloodPressureEntrySheetController.Validation.ERROR_SYSTOLIC_TOO_LOW
@@ -84,7 +86,10 @@ class BloodPressureEntrySheetController @Inject constructor(
8486
ERROR_SYSTOLIC_TOO_LOW -> ui.showSystolicLowError()
8587
ERROR_DIASTOLIC_TOO_HIGH -> ui.showDiastolicHighError()
8688
ERROR_DIASTOLIC_TOO_LOW -> ui.showDiastolicLowError()
87-
SUCCESS -> { // Nothing to do here, SUCCESS handled below separately!
89+
ERROR_SYSTOLIC_EMPTY -> ui.showSystolicEmptyError()
90+
ERROR_DIASTOLIC_EMPTY -> ui.showDiastolicEmptyError()
91+
SUCCESS -> {
92+
// Nothing to do here, SUCCESS handled below separately!
8893
}
8994
}.exhaustive()
9095
}
@@ -104,8 +109,15 @@ class BloodPressureEntrySheetController @Inject constructor(
104109
}
105110

106111
private fun validateInput(systolic: String, diastolic: String): Validation {
107-
val systolicNumber = systolic.toInt()
108-
val diastolicNumber = diastolic.toInt()
112+
if (systolic.isBlank()) {
113+
return ERROR_SYSTOLIC_EMPTY
114+
}
115+
if (diastolic.isBlank()) {
116+
return ERROR_DIASTOLIC_EMPTY
117+
}
118+
119+
val systolicNumber = systolic.trim().toInt()
120+
val diastolicNumber = diastolic.trim().toInt()
109121

110122
return when {
111123
systolicNumber < 70 -> ERROR_SYSTOLIC_TOO_LOW
@@ -119,6 +131,8 @@ class BloodPressureEntrySheetController @Inject constructor(
119131

120132
enum class Validation {
121133
SUCCESS,
134+
ERROR_SYSTOLIC_EMPTY,
135+
ERROR_DIASTOLIC_EMPTY,
122136
ERROR_SYSTOLIC_TOO_HIGH,
123137
ERROR_SYSTOLIC_TOO_LOW,
124138
ERROR_DIASTOLIC_TOO_HIGH,

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
<string name="bloodpressureentry_error_systolic_300">Systolic cannot be more than 300</string>
103103
<string name="bloodpressureentry_error_diastolic_40">Diastolic cannot be less than 40</string>
104104
<string name="bloodpressureentry_error_diastolic_180">Diastolic cannot be more than 180</string>
105+
<string name="bloodpressureentry_error_systolic_empty">Enter systolic and diastolic pressures</string>
106+
<string name="bloodpressureentry_error_diastolic_empty">Enter systolic and diastolic pressures</string>
105107

106108
<!-- Patient summary -->
107109
<string name="patientsummary_contentdescription_up_button">Go back</string> <!-- TODO: The UP button will probably behave differently for different entry points. Update this CD accordingly. -->

app/src/test/java/org/simple/clinic/bp/entry/BloodPressureEntrySheetControllerTest.kt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,28 @@ class BloodPressureEntrySheetControllerTest {
110110
verify(sheet).showDiastolicHighError()
111111
}
112112

113+
@Test
114+
fun `when systolic is empty, show error`() {
115+
uiEvents.onNext(BloodPressureEntrySheetCreated(patientUuid))
116+
uiEvents.onNext(BloodPressureSystolicTextChanged(""))
117+
uiEvents.onNext(BloodPressureDiastolicTextChanged("190"))
118+
uiEvents.onNext(BloodPressureSaveClicked())
119+
120+
verify(bloodPressureRepository, never()).saveMeasurement(any(), any(), any())
121+
verify(sheet).showSystolicEmptyError()
122+
}
123+
124+
@Test
125+
fun `when diastolic is empty, show error`() {
126+
uiEvents.onNext(BloodPressureEntrySheetCreated(patientUuid))
127+
uiEvents.onNext(BloodPressureSystolicTextChanged("120"))
128+
uiEvents.onNext(BloodPressureDiastolicTextChanged(""))
129+
uiEvents.onNext(BloodPressureSaveClicked())
130+
131+
verify(bloodPressureRepository, never()).saveMeasurement(any(), any(), any())
132+
verify(sheet).showDiastolicEmptyError()
133+
}
134+
113135
@Test
114136
fun `when systolic or diastolic values change, hide the error message`() {
115137
uiEvents.onNext(BloodPressureEntrySheetCreated(patientUuid))
@@ -123,10 +145,17 @@ class BloodPressureEntrySheetControllerTest {
123145
}
124146

125147
@Test
126-
fun `when save is clicked but input is invalid then blood pressure measurement should not be saved`() {
148+
@Parameters(value = [
149+
",",
150+
"1,1"
151+
])
152+
fun `when save is clicked but input is invalid then blood pressure measurement should not be saved`(
153+
systolic: String,
154+
diastolic: String
155+
) {
127156
uiEvents.onNext(BloodPressureEntrySheetCreated(patientUuid))
128-
uiEvents.onNext(BloodPressureSystolicTextChanged("1"))
129-
uiEvents.onNext(BloodPressureDiastolicTextChanged("1"))
157+
uiEvents.onNext(BloodPressureSystolicTextChanged(systolic))
158+
uiEvents.onNext(BloodPressureDiastolicTextChanged(diastolic))
130159
uiEvents.onNext(BloodPressureSaveClicked())
131160

132161
verify(bloodPressureRepository, never()).saveMeasurement(any(), any(), any())

0 commit comments

Comments
 (0)