diff --git a/app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt b/app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt index 95fbb75077e..8205a769da1 100644 --- a/app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt +++ b/app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt @@ -96,7 +96,7 @@ class PatientSummaryUpdate( is HypertensionNotNowClicked -> hypertensionNotNowClicked(event.continueToDiabetesDiagnosisWarning) is StatinPrescriptionCheckInfoLoaded -> statinPrescriptionCheckInfoLoaded(event, model) is CVDRiskLoaded -> cvdRiskLoaded(event, model) - is CVDRiskCalculated -> cvdRiskCalculated(event, model) + is CVDRiskCalculated -> dispatch(LoadStatinInfo(model.patientUuid)) is StatinInfoLoaded -> statinInfoLoaded(event, model) } } @@ -129,30 +129,18 @@ class PatientSummaryUpdate( ): Next { val cvdRisk = event.risk return if (cvdRisk != null) { - //load statin - noChange() - + dispatch(LoadStatinInfo(model.patientUuid)) } else { - noChange() - //calculate cvd risk + dispatch(CalculateCVDRisk(model.patientSummaryProfile!!.patient)) } } - private fun cvdRiskCalculated( - event: CVDRiskCalculated, - model: PatientSummaryModel - ): Next { - val cvdRisk = event.risk - //load statin nudge info - return noChange() - } - private fun statinInfoLoaded( event: StatinInfoLoaded, model: PatientSummaryModel ): Next { val statinInfo = event.statinInfo - //load statin nudge info + //update model with statin info return noChange() } diff --git a/app/src/test/java/org/simple/clinic/summary/PatientSummaryUpdateTest.kt b/app/src/test/java/org/simple/clinic/summary/PatientSummaryUpdateTest.kt index 4982100e37f..19b6dc5b3ee 100644 --- a/app/src/test/java/org/simple/clinic/summary/PatientSummaryUpdateTest.kt +++ b/app/src/test/java/org/simple/clinic/summary/PatientSummaryUpdateTest.kt @@ -2134,6 +2134,44 @@ class PatientSummaryUpdateTest { )) } + @Test + fun `when cvd risk is loaded and risk score is not null, then load statin info`() { + updateSpec + .given(defaultModel) + .whenEvent(CVDRiskLoaded( + risk = "27" + )) + .then(assertThatNext( + hasEffects(LoadStatinInfo(patientUuid)) + )) + } + + @Test + fun `when cvd risk is loaded and risk score is null, then calculate cvd risk`() { + val model = defaultModel + .patientSummaryProfileLoaded(patientSummaryProfile) + updateSpec + .given(model) + .whenEvent(CVDRiskLoaded( + risk = null + )) + .then(assertThatNext( + hasEffects(CalculateCVDRisk(model.patientSummaryProfile!!.patient)) + )) + } + + @Test + fun `when cvd risk is calculated, then load statin info`() { + updateSpec + .given(defaultModel) + .whenEvent(CVDRiskCalculated( + risk = null + )) + .then(assertThatNext( + hasEffects(LoadStatinInfo(patientUuid)) + )) + } + private fun PatientSummaryModel.forExistingPatient(): PatientSummaryModel { return copy(openIntention = ViewExistingPatient) }