From 2b2dc76c8022f9942411dc72bc26e06ecae6ff7c Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 17 Jun 2024 08:56:27 +0530 Subject: [PATCH] Revert "Check diagnosis prescriptions when exiting prescriptions screen (#4981)" This reverts commit 46691cf74a4c1be897bed65ffa1650d3144633bc. --- app/src/debug/google-services.json | 25 +- .../drugs/DiagnosisWarningPrescriptions.kt | 28 --- .../clinic/drugs/EditMedicinesEffect.kt | 7 +- .../drugs/EditMedicinesEffectHandler.kt | 18 -- .../simple/clinic/drugs/EditMedicinesEvent.kt | 5 - .../simple/clinic/drugs/EditMedicinesModel.kt | 14 +- .../clinic/drugs/EditMedicinesUpdate.kt | 42 +--- .../drugs/EditMedicinesViewEffectHandler.kt | 1 - .../simple/clinic/drugs/PrescriptionModule.kt | 18 -- .../drugs/selection/EditMedicinesScreen.kt | 31 +-- .../drugs/selection/EditMedicinesUiActions.kt | 2 - .../MedicalHistorySummaryEffectHandler.kt | 4 +- .../drugs/EditMedicineEffectHandlerTest.kt | 27 --- .../clinic/drugs/EditMedicineUpdateTest.kt | 228 +----------------- .../clinic/drugs/EditMedicinesInitTest.kt | 2 +- .../drugs/EditMedicinesUiRendererTest.kt | 2 +- .../selection/EditMedicinesScreenLogicTest.kt | 18 +- .../MedicalHistorySummaryEffectHandlerTest.kt | 53 ---- .../MedicalHistorySummaryLogicTest.kt | 19 +- 19 files changed, 62 insertions(+), 482 deletions(-) delete mode 100644 app/src/main/java/org/simple/clinic/drugs/DiagnosisWarningPrescriptions.kt delete mode 100644 app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandlerTest.kt diff --git a/app/src/debug/google-services.json b/app/src/debug/google-services.json index 47d2caaf51e..e7742003584 100644 --- a/app/src/debug/google-services.json +++ b/app/src/debug/google-services.json @@ -1,26 +1,39 @@ { "project_info": { - "project_number": "591122937412", - "project_id": "simple-qa-e7810", - "storage_bucket": "simple-qa-e7810.appspot.com" + "project_number": "235314010044", + "firebase_url": "https://simple-org.firebaseio.com", + "project_id": "simple-org", + "storage_bucket": "simple-org.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:591122937412:android:1ca1165b5676e92b236e11", + "mobilesdk_app_id": "1:235314010044:android:26e63edde5002dd6", "android_client_info": { "package_name": "org.simple.clinic.qa.debug" } }, - "oauth_client": [], + "oauth_client": [ + { + "client_id": "235314010044-5cs4deattnhsdcs4ooljphm0fla9vjvh.apps.googleusercontent.com", + "client_type": 3 + } + ], "api_key": [ { - "current_key": "AIzaSyDXuNaHquD_Bb6q5pZQCl_0v0NUdtH8Fgs" + "current_key": "AIzaSyDtpDbqQ-TXRED-gdOhbRbgQIOicyGAiaM" } ], "services": { + "analytics_service": { + "status": 1 + }, "appinvite_service": { + "status": 1, "other_platform_oauth_client": [] + }, + "ads_service": { + "status": 2 } } } diff --git a/app/src/main/java/org/simple/clinic/drugs/DiagnosisWarningPrescriptions.kt b/app/src/main/java/org/simple/clinic/drugs/DiagnosisWarningPrescriptions.kt deleted file mode 100644 index 74c356a0331..00000000000 --- a/app/src/main/java/org/simple/clinic/drugs/DiagnosisWarningPrescriptions.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.simple.clinic.drugs - -import android.os.Parcelable -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import kotlinx.parcelize.Parcelize - -@Parcelize -@JsonClass(generateAdapter = true) -data class DiagnosisWarningPrescriptions( - - @Json(name = "htn_prescriptions") - val htnPrescriptions: List, - - @Json(name = "diabetes_prescriptions") - val diabetesPrescriptions: List -) : Parcelable { - - companion object { - - fun empty(): DiagnosisWarningPrescriptions { - return DiagnosisWarningPrescriptions( - htnPrescriptions = emptyList(), - diabetesPrescriptions = emptyList() - ) - } - } -} diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffect.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffect.kt index d9fa30d40bb..27e2b934826 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffect.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffect.kt @@ -1,6 +1,5 @@ package org.simple.clinic.drugs -import org.simple.clinic.summary.DiagnosisWarningResult import java.util.UUID sealed class EditMedicinesEffect @@ -11,8 +10,6 @@ data class RefillMedicines(val patientUuid: UUID) : EditMedicinesEffect() object LoadDrugFrequencyChoiceItems : EditMedicinesEffect() -data class LoadDataOnExiting(val patientUuid: UUID) : EditMedicinesEffect() - sealed class EditMedicinesViewEffect : EditMedicinesEffect() data class ShowNewPrescriptionEntrySheet(val patientUuid: UUID) : EditMedicinesViewEffect() @@ -25,6 +22,4 @@ data class OpenDosagePickerSheet( data class ShowUpdateCustomPrescriptionSheet(val prescribedDrug: PrescribedDrug) : EditMedicinesViewEffect() -data object GoBackToPatientSummary : EditMedicinesViewEffect() - -data class GoBackToPatientSummaryWithWarningResult(val diagnosisWarningResult: DiagnosisWarningResult) : EditMedicinesViewEffect() +object GoBackToPatientSummary : EditMedicinesViewEffect() diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffectHandler.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffectHandler.kt index 2b99ae6fc46..ef759fff198 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffectHandler.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEffectHandler.kt @@ -12,7 +12,6 @@ import io.reactivex.rxkotlin.Observables import org.simple.clinic.drugs.search.DrugFrequency import org.simple.clinic.drugs.selection.custom.drugfrequency.country.DrugFrequencyLabel import org.simple.clinic.facility.Facility -import org.simple.clinic.medicalhistory.MedicalHistoryRepository import org.simple.clinic.overdue.AppointmentRepository import org.simple.clinic.patient.PatientUuid import org.simple.clinic.protocol.ProtocolRepository @@ -27,7 +26,6 @@ class EditMedicinesEffectHandler @AssistedInject constructor( private val facility: Lazy, private val uuidGenerator: UuidGenerator, private val appointmentsRepository: AppointmentRepository, - private val medicalHistoryRepository: MedicalHistoryRepository, private val drugFrequencyToLabelMap: Map, @Assisted private val viewEffectsConsumer: Consumer ) { @@ -44,25 +42,9 @@ class EditMedicinesEffectHandler @AssistedInject constructor( .addTransformer(RefillMedicines::class.java, refillMedicines()) .addTransformer(LoadDrugFrequencyChoiceItems::class.java, loadFrequencyChoiceItems()) .addConsumer(EditMedicinesViewEffect::class.java, viewEffectsConsumer::accept) - .addTransformer(LoadDataOnExiting::class.java, loadDataOnExiting()) .build() } - private fun loadDataOnExiting(): ObservableTransformer { - return ObservableTransformer { effects -> - effects - .observeOn(schedulersProvider.io()) - .map { - val medicalHistory = medicalHistoryRepository.historyForPatientOrDefaultImmediate( - patientUuid = it.patientUuid, - defaultHistoryUuid = uuidGenerator.v4() - ) - - DataOnExitLoaded(medicalHistory) - } - } - } - private fun loadFrequencyChoiceItems(): ObservableTransformer { return ObservableTransformer { effects -> effects diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEvent.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEvent.kt index 72c31d63a56..82ebbf79e33 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEvent.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesEvent.kt @@ -2,7 +2,6 @@ package org.simple.clinic.drugs import org.simple.clinic.drugs.search.DrugFrequency import org.simple.clinic.drugs.selection.custom.drugfrequency.country.DrugFrequencyLabel -import org.simple.clinic.medicalhistory.MedicalHistory import org.simple.clinic.protocol.ProtocolDrugAndDosages import org.simple.clinic.widgets.UiEvent @@ -39,7 +38,3 @@ object PrescribedMedicinesRefilled : EditMedicinesEvent() data class DrugFrequencyChoiceItemsLoaded( val drugFrequencyToLabelMap: Map ) : EditMedicinesEvent() - -data class DataOnExitLoaded(val medicalHistory: MedicalHistory) : EditMedicinesEvent() - -data object BackClicked : EditMedicinesEvent() diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesModel.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesModel.kt index 9f875fc39ce..0a6bc23a83b 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesModel.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesModel.kt @@ -13,20 +13,12 @@ data class EditMedicinesModel( val prescribedDrugs: List?, val protocolDrugs: List?, val editMedicineButtonState: EditMedicineButtonState?, - val medicineFrequencyToLabelMap: Map?, - val diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions, + val medicineFrequencyToLabelMap: Map? ) : Parcelable { companion object { - fun create(patientUuid: UUID, diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions): EditMedicinesModel { - return EditMedicinesModel( - patientUuid = patientUuid, - prescribedDrugs = null, - protocolDrugs = null, - editMedicineButtonState = null, - medicineFrequencyToLabelMap = null, - diagnosisWarningPrescriptions = diagnosisWarningPrescriptions - ) + fun create(patientUuid: UUID): EditMedicinesModel { + return EditMedicinesModel(patientUuid, null, null, null, null) } } diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesUpdate.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesUpdate.kt index b27ad8b6e8c..e5b494e8537 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesUpdate.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesUpdate.kt @@ -4,11 +4,8 @@ import com.spotify.mobius.Next import com.spotify.mobius.Update import org.simple.clinic.drugs.EditMedicineButtonState.REFILL_MEDICINE import org.simple.clinic.drugs.EditMedicineButtonState.SAVE_MEDICINE -import org.simple.clinic.medicalhistory.Answer -import org.simple.clinic.medicalhistory.MedicalHistory import org.simple.clinic.mobius.dispatch import org.simple.clinic.mobius.next -import org.simple.clinic.summary.DiagnosisWarningResult import org.simple.clinic.teleconsultlog.medicinefrequency.MedicineFrequency import org.simple.clinic.util.toLocalDateAtZone import java.time.LocalDate @@ -27,49 +24,14 @@ class EditMedicinesUpdate( AddNewPrescriptionClicked -> dispatch(ShowNewPrescriptionEntrySheet(model.patientUuid)) is ProtocolDrugClicked -> dispatch(OpenDosagePickerSheet(event.drugName, model.patientUuid, event.prescription?.uuid)) is CustomPrescriptionClicked -> dispatch(ShowUpdateCustomPrescriptionSheet(event.prescribedDrug)) - PrescribedDrugsDoneClicked -> dispatch(LoadDataOnExiting(model.patientUuid)) + PrescribedDrugsDoneClicked -> dispatch(GoBackToPatientSummary) PresribedDrugsRefillClicked -> dispatch(RefillMedicines(model.patientUuid)) is DrugsListFetched -> drugsListAndButtonStateFetched(event, model) - PrescribedMedicinesRefilled -> dispatch(LoadDataOnExiting(model.patientUuid)) + PrescribedMedicinesRefilled -> dispatch(GoBackToPatientSummary) is DrugFrequencyChoiceItemsLoaded -> drugFrequencyChoiceItemsLoaded(model, event) - is DataOnExitLoaded -> dataOnExitLoaded( - event.medicalHistory, - model.diagnosisWarningPrescriptions, - model.prescribedDrugs.orEmpty() - ) - BackClicked -> dispatch(LoadDataOnExiting(model.patientUuid)) } } - private fun dataOnExitLoaded( - medicalHistory: MedicalHistory, - diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions, - prescribedDrugs: List, - ): Next { - val canShowDiabetesDiagnosisWarning = medicalHistory.diagnosedWithDiabetes != Answer.Yes && - prescribedDrugs.any { prescription -> diagnosisWarningPrescriptions.diabetesPrescriptions.contains(prescription.name.lowercase()) } - val canShowHTNDiagnosisWarning = medicalHistory.diagnosedWithHypertension != Answer.Yes && - prescribedDrugs.any { prescription -> diagnosisWarningPrescriptions.htnPrescriptions.contains(prescription.name.lowercase()) } - - val effect = when { - canShowHTNDiagnosisWarning && canShowDiabetesDiagnosisWarning -> { - GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.BothDiagnosisWarning) - } - - canShowHTNDiagnosisWarning -> { - GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.HypertensionWarning) - } - - canShowDiabetesDiagnosisWarning -> { - GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.DiabetesWarning) - } - - else -> GoBackToPatientSummary - } - - return dispatch(effect) - } - private fun drugFrequencyChoiceItemsLoaded( model: EditMedicinesModel, event: DrugFrequencyChoiceItemsLoaded diff --git a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesViewEffectHandler.kt b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesViewEffectHandler.kt index b8dff71a7f0..d99eab17d17 100644 --- a/app/src/main/java/org/simple/clinic/drugs/EditMedicinesViewEffectHandler.kt +++ b/app/src/main/java/org/simple/clinic/drugs/EditMedicinesViewEffectHandler.kt @@ -16,7 +16,6 @@ class EditMedicinesViewEffectHandler( ) is ShowUpdateCustomPrescriptionSheet -> uiActions.showUpdateCustomPrescriptionSheet(viewEffect.prescribedDrug) GoBackToPatientSummary -> uiActions.goBackToPatientSummary() - is GoBackToPatientSummaryWithWarningResult -> uiActions.goBackToPatientSummary(viewEffect.diagnosisWarningResult) } } } diff --git a/app/src/main/java/org/simple/clinic/drugs/PrescriptionModule.kt b/app/src/main/java/org/simple/clinic/drugs/PrescriptionModule.kt index 8ecd0ef80d3..8c09f682bcf 100644 --- a/app/src/main/java/org/simple/clinic/drugs/PrescriptionModule.kt +++ b/app/src/main/java/org/simple/clinic/drugs/PrescriptionModule.kt @@ -2,14 +2,10 @@ package org.simple.clinic.drugs import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.RxSharedPreferences -import com.squareup.moshi.Moshi -import com.squareup.moshi.adapter import dagger.Module import dagger.Provides import org.simple.clinic.AppDatabase import org.simple.clinic.drugs.sync.PrescriptionSyncApi -import org.simple.clinic.platform.crash.CrashReporter -import org.simple.clinic.remoteconfig.ConfigReader import org.simple.clinic.util.preference.StringPreferenceConverter import org.simple.clinic.util.preference.getOptional import retrofit2.Retrofit @@ -34,18 +30,4 @@ class PrescriptionModule { fun lastPullToken(rxSharedPrefs: RxSharedPreferences): Preference> { return rxSharedPrefs.getOptional("last_prescription_pull_token_v2", StringPreferenceConverter()) } - - @Provides - @OptIn(ExperimentalStdlibApi::class) - fun diagnosisWarningPrescriptions(moshi: Moshi, configReader: ConfigReader): DiagnosisWarningPrescriptions { - val adapter = moshi.adapter() - val json = configReader.string("diagnosis_warning_prescriptions_v0", "{}") - - return try { - adapter.fromJson(json)!! - } catch (e: Throwable) { - CrashReporter.report(e) - DiagnosisWarningPrescriptions.empty() - } - } } diff --git a/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesScreen.kt b/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesScreen.kt index 0cf98b9177b..b775eaada9a 100644 --- a/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesScreen.kt +++ b/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesScreen.kt @@ -26,9 +26,7 @@ import org.simple.clinic.databinding.ListPrescribeddrugsProtocolDrugBinding import org.simple.clinic.databinding.ScreenPatientPrescribedDrugsEntryBinding import org.simple.clinic.di.injector import org.simple.clinic.drugs.AddNewPrescriptionClicked -import org.simple.clinic.drugs.BackClicked import org.simple.clinic.drugs.CustomPrescriptionClicked -import org.simple.clinic.drugs.DiagnosisWarningPrescriptions import org.simple.clinic.drugs.EditMedicinesEffect import org.simple.clinic.drugs.EditMedicinesEffectHandler import org.simple.clinic.drugs.EditMedicinesEvent @@ -47,12 +45,8 @@ import org.simple.clinic.drugs.selection.custom.CustomDrugEntrySheet import org.simple.clinic.drugs.selection.custom.OpenAs import org.simple.clinic.drugs.selection.dosage.DosagePickerSheet import org.simple.clinic.feature.Features -import org.simple.clinic.mobius.DeferredEventSource -import org.simple.clinic.navigation.v2.HandlesBack import org.simple.clinic.navigation.v2.Router -import org.simple.clinic.navigation.v2.Succeeded import org.simple.clinic.navigation.v2.fragments.BaseScreen -import org.simple.clinic.summary.DiagnosisWarningResult import org.simple.clinic.util.UserClock import org.simple.clinic.util.UtcClock import org.simple.clinic.util.unsafeLazy @@ -69,7 +63,7 @@ class EditMedicinesScreen : EditMedicinesModel, EditMedicinesEvent, EditMedicinesEffect, - EditMedicinesViewEffect>(), EditMedicinesUi, EditMedicinesUiActions, HandlesBack { + EditMedicinesViewEffect>(), EditMedicinesUi, EditMedicinesUiActions { @Inject lateinit var router: Router @@ -89,9 +83,6 @@ class EditMedicinesScreen : @Inject lateinit var features: Features - @Inject - lateinit var diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions - private val toolbar get() = binding.prescribeddrugsToolbar @@ -130,12 +121,7 @@ class EditMedicinesScreen : screenKey.patientUuid } - private val additionalEvents = DeferredEventSource() - - override fun defaultModel() = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = diagnosisWarningPrescriptions - ) + override fun defaultModel() = EditMedicinesModel.create(patientUuid = patientUuid) override fun bindView(layoutInflater: LayoutInflater, container: ViewGroup?) = ScreenPatientPrescribedDrugsEntryBinding.inflate(layoutInflater, container, false) @@ -152,8 +138,6 @@ class EditMedicinesScreen : .compose(ReportAnalyticsEvents()) .cast() - override fun additionalEventSources() = listOf(additionalEvents) - override fun createUpdate() = EditMedicinesUpdate(LocalDate.now(userClock), userClock.zone) override fun createInit() = EditMedicinesInit() @@ -169,7 +153,7 @@ class EditMedicinesScreen : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - toolbar.setNavigationOnClickListener { additionalEvents.notify(BackClicked) } + toolbar.setNavigationOnClickListener { router.pop() } recyclerView.setHasFixedSize(false) recyclerView.layoutManager = LinearLayoutManager(requireContext()) @@ -181,11 +165,6 @@ class EditMedicinesScreen : recyclerView.itemAnimator = fadeAnimator } - override fun onBackPressed(): Boolean { - additionalEvents.notify(BackClicked) - return true - } - private fun doneClicks() = doneButton.clicks().map { PrescribedDrugsDoneClicked } private fun refillMedicineClicks() = refillMedicineButton.clicks().map { PresribedDrugsRefillClicked } @@ -231,10 +210,6 @@ class EditMedicinesScreen : router.pop() } - override fun goBackToPatientSummary(diagnosisWarningResult: DiagnosisWarningResult) { - router.popWithResult(Succeeded(diagnosisWarningResult)) - } - override fun showDosageSelectionSheet( drugName: String, patientUuid: UUID, diff --git a/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesUiActions.kt b/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesUiActions.kt index c8c26ea7bd3..123956b07ec 100644 --- a/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesUiActions.kt +++ b/app/src/main/java/org/simple/clinic/drugs/selection/EditMedicinesUiActions.kt @@ -1,7 +1,6 @@ package org.simple.clinic.drugs.selection import org.simple.clinic.drugs.PrescribedDrug -import org.simple.clinic.summary.DiagnosisWarningResult import java.util.UUID interface EditMedicinesUiActions { @@ -9,5 +8,4 @@ interface EditMedicinesUiActions { fun showDosageSelectionSheet(drugName: String, patientUuid: UUID, prescribedDrugUuid: UUID?) fun showUpdateCustomPrescriptionSheet(prescribedDrug: PrescribedDrug) fun goBackToPatientSummary() - fun goBackToPatientSummary(diagnosisWarningResult: DiagnosisWarningResult) } diff --git a/app/src/main/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandler.kt b/app/src/main/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandler.kt index 5d5770bc1e5..3a878180f83 100644 --- a/app/src/main/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandler.kt +++ b/app/src/main/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandler.kt @@ -33,8 +33,8 @@ class MedicalHistorySummaryEffectHandler @Inject constructor( return ObservableTransformer { effects -> effects .observeOn(schedulers.io()) - .flatMap { - medicalHistoryRepository.historyForPatientOrDefault( + .map { + medicalHistoryRepository.historyForPatientOrDefaultImmediate( defaultHistoryUuid = uuidGenerator.v4(), patientUuid = it.patientUUID ) diff --git a/app/src/test/java/org/simple/clinic/drugs/EditMedicineEffectHandlerTest.kt b/app/src/test/java/org/simple/clinic/drugs/EditMedicineEffectHandlerTest.kt index b58e494341a..4af0953eb34 100644 --- a/app/src/test/java/org/simple/clinic/drugs/EditMedicineEffectHandlerTest.kt +++ b/app/src/test/java/org/simple/clinic/drugs/EditMedicineEffectHandlerTest.kt @@ -17,8 +17,6 @@ import org.simple.clinic.drugs.search.DrugFrequency.QDS import org.simple.clinic.drugs.search.DrugFrequency.TDS import org.simple.clinic.drugs.selection.EditMedicinesUiActions import org.simple.clinic.drugs.selection.custom.drugfrequency.country.DrugFrequencyLabel -import org.simple.clinic.medicalhistory.Answer -import org.simple.clinic.medicalhistory.MedicalHistoryRepository import org.simple.clinic.mobius.EffectHandlerTestCase import org.simple.clinic.overdue.AppointmentRepository import org.simple.clinic.patient.SyncStatus @@ -37,7 +35,6 @@ class EditMedicineEffectHandlerTest { private val facility = TestData.facility(uuid = UUID.fromString("94db5d90-d483-4755-892a-97fde5a870fe")) private val uuidGenerator = mock() private val appointmentRepository = mock() - private val medicalHistoryRepository = mock() private val drugFrequencyToLabelMap = mapOf( null to DrugFrequencyLabel(label = "None"), @@ -56,7 +53,6 @@ class EditMedicineEffectHandlerTest { facility = Lazy { facility }, uuidGenerator = uuidGenerator, appointmentsRepository = appointmentRepository, - medicalHistoryRepository = medicalHistoryRepository, drugFrequencyToLabelMap = drugFrequencyToLabelMap, viewEffectsConsumer = viewEffectsConsumer ) @@ -137,27 +133,4 @@ class EditMedicineEffectHandlerTest { testCase.assertOutgoingEvents(DrugFrequencyChoiceItemsLoaded(drugFrequencyToLabelMap)) verifyNoInteractions(uiActions) } - - @Test - fun `when load data on exiting effect is received, then load data`() { - // given - val patientUuid = UUID.fromString("16288d04-8b87-40bb-b5b4-bb77b8c47040") - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("95b5a878-4bfa-43ce-8908-08d2ab28d71c"), - patientUuid = patientUuid, - diagnosedWithHypertension = Answer.No, - hasDiabetes = Answer.Yes - ) - - whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate( - patientUuid = patientUuid, - defaultHistoryUuid = uuidGenerator.v4() - )) doReturn medicalHistory - - // when - testCase.dispatch(LoadDataOnExiting(patientUuid)) - - // then - testCase.assertOutgoingEvents(DataOnExitLoaded(medicalHistory)) - } } diff --git a/app/src/test/java/org/simple/clinic/drugs/EditMedicineUpdateTest.kt b/app/src/test/java/org/simple/clinic/drugs/EditMedicineUpdateTest.kt index b0700c19f97..4d21ebf2fdc 100644 --- a/app/src/test/java/org/simple/clinic/drugs/EditMedicineUpdateTest.kt +++ b/app/src/test/java/org/simple/clinic/drugs/EditMedicineUpdateTest.kt @@ -13,10 +13,8 @@ import org.simple.clinic.drugs.search.DrugFrequency.OD import org.simple.clinic.drugs.search.DrugFrequency.QDS import org.simple.clinic.drugs.search.DrugFrequency.TDS import org.simple.clinic.drugs.selection.custom.drugfrequency.country.DrugFrequencyLabel -import org.simple.clinic.medicalhistory.Answer import org.simple.clinic.protocol.ProtocolDrug import org.simple.clinic.protocol.ProtocolDrugAndDosages -import org.simple.clinic.summary.DiagnosisWarningResult import org.simple.clinic.teleconsultlog.medicinefrequency.MedicineFrequency import java.time.Instant import java.time.LocalDate @@ -30,7 +28,7 @@ class EditMedicineUpdateTest { @Test fun `when prescribed drugs refill done is clicked, then refill medicines`() { val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val prescribedDrugRecords = listOf( TestData.prescription(uuid = UUID.fromString("4aec376e-1a8f-11eb-adc1-0242ac120002"), name = "Amlodipine1"), TestData.prescription(uuid = UUID.fromString("537a119e-1a8f-11eb-adc1-0242ac120002"), name = "Amlodipine2"), @@ -50,7 +48,7 @@ class EditMedicineUpdateTest { @Test fun `when the prescription has been updated on the current date, then the save medicine button must be shown`() { - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.parse("2018-01-01"), ZoneOffset.UTC)) val prescribedDrugRecords = listOf( TestData.prescription(uuid = UUID.fromString("4aec376e-1a8f-11eb-adc1-0242ac120002"), name = "Amlodipine1", createdAt = Instant.parse("2018-01-01T00:00:00Z"), updatedAt = Instant.parse("2018-01-01T00:00:00Z")), @@ -76,7 +74,7 @@ class EditMedicineUpdateTest { @Test fun `when prescription is empty and it has not been updated on the current day, then the save medicine button must be shown`() { - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) val prescribedDrugRecords = listOf() @@ -96,7 +94,7 @@ class EditMedicineUpdateTest { @Test fun `when the prescription has not been updated on the current day, then the refill medicine button must be shown`() { - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) val prescribedDrugRecords = listOf( TestData.prescription(uuid = UUID.fromString("4aec376e-1a8f-11eb-adc1-0242ac120002"), name = "Amlodipine1", createdAt = Instant.parse("2012-12-12T00:00:00Z"), updatedAt = Instant.parse("2012-12-12T00:00:00Z")), @@ -122,7 +120,7 @@ class EditMedicineUpdateTest { @Test fun `when filled prescribed drugs are fetched and some of the drugs are deleted, then set edit medicine button state to save button`() { - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) val prescribedDrugRecords = listOf( TestData.prescription(uuid = UUID.fromString("4aec376e-1a8f-11eb-adc1-0242ac120002"), name = "Amlodipine1", createdAt = Instant.parse("2020-11-18T00:00:00Z"), updatedAt = Instant.parse("2020-11-18T00:00:00Z")), @@ -148,7 +146,7 @@ class EditMedicineUpdateTest { @Test fun `when drug frequency choice items are loaded, then update the model with a map of medicine frequency to frequency choice items`() { - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) val drugFrequencyToLabelMap = mapOf( null to DrugFrequencyLabel(label = "None"), @@ -174,218 +172,4 @@ class EditMedicineUpdateTest { hasNoEffects() )) } - - @Test - fun `when data on exit is loaded and patient is not diagnosed as diabetic and has prescriptions for diabetes, then go back to patient summary and display diabetes diagnosis warning`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions( - htnPrescriptions = emptyList(), - diabetesPrescriptions = listOf( - "metformin", - "gliclazide", - "prazosin", - "insulin" - ) - ) - ).prescribedDrugsFetched(listOf( - TestData.prescription( - uuid = UUID.fromString("7f762f22-e796-4aa4-94d1-f52ad0b16066"), - name = "metformin" - ), - TestData.prescription( - uuid = UUID.fromString("ae8fddc2-0e32-4f6a-8e7e-3b03dc50b25b"), - name = "chlorthalidone" - ) - )) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("f255513f-6d61-46fd-90c6-4e0f60d70d67"), - patientUuid = patientUuid, - diagnosedWithHypertension = Answer.Yes, - hasDiabetes = Answer.No - ) - - updateSpec - .given(model) - .whenEvent(DataOnExitLoaded(medicalHistory)) - .then(assertThatNext( - hasNoModel(), - hasEffects(GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.DiabetesWarning)) - )) - } - - @Test - fun `when data on exit is loaded and patient is not diagnosed as htn and has prescriptions for htn, then go back to patient summary and display htn warning`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions( - htnPrescriptions = listOf( - "lisinopril", - "telmisartan", - "nifedipine sr", - "nifedipine", - "losartan", - ), - diabetesPrescriptions = emptyList() - ) - ).prescribedDrugsFetched(listOf( - TestData.prescription( - uuid = UUID.fromString("7f762f22-e796-4aa4-94d1-f52ad0b16066"), - name = "telmisartan" - ), - )) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("f255513f-6d61-46fd-90c6-4e0f60d70d67"), - patientUuid = patientUuid, - diagnosedWithHypertension = Answer.No, - hasDiabetes = Answer.Yes - ) - - updateSpec - .given(model) - .whenEvent(DataOnExitLoaded(medicalHistory)) - .then(assertThatNext( - hasNoModel(), - hasEffects(GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.HypertensionWarning)) - )) - } - - @Test - fun `when data on exit is loaded and patient is not diagnosed as htn and diabetes and has prescriptions for htn and diabetes, then go back to patient summary and display htn and diabetes warning`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions( - htnPrescriptions = listOf( - "lisinopril", - "telmisartan", - "nifedipine sr", - "nifedipine", - "losartan", - ), - diabetesPrescriptions = listOf( - "metformin", - "gliclazide", - "prazosin", - "insulin" - ) - ) - ).prescribedDrugsFetched(listOf( - TestData.prescription( - uuid = UUID.fromString("7f762f22-e796-4aa4-94d1-f52ad0b16066"), - name = "telmisartan" - ), - TestData.prescription( - uuid = UUID.fromString("d1b9e0d2-9f0c-4b69-bc42-46b900e10e6a"), - name = "metformin" - ), - )) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("f255513f-6d61-46fd-90c6-4e0f60d70d67"), - patientUuid = patientUuid, - diagnosedWithHypertension = Answer.No, - hasDiabetes = Answer.No - ) - - updateSpec - .given(model) - .whenEvent(DataOnExitLoaded(medicalHistory)) - .then(assertThatNext( - hasNoModel(), - hasEffects(GoBackToPatientSummaryWithWarningResult(DiagnosisWarningResult.BothDiagnosisWarning)) - )) - } - - @Test - fun `when data on exit is loaded and patient is diagnosed as diabetic and has prescriptions for diabetes, then go back to patient summary screen without warning result`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions( - htnPrescriptions = emptyList(), - diabetesPrescriptions = listOf( - "metformin", - "gliclazide", - "prazosin", - "insulin" - ) - ) - ).prescribedDrugsFetched(listOf( - TestData.prescription( - uuid = UUID.fromString("7f762f22-e796-4aa4-94d1-f52ad0b16066"), - name = "metformin" - ), - TestData.prescription( - uuid = UUID.fromString("ae8fddc2-0e32-4f6a-8e7e-3b03dc50b25b"), - name = "chlorthalidone" - ) - )) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("f255513f-6d61-46fd-90c6-4e0f60d70d67"), - patientUuid = patientUuid, - diagnosedWithHypertension = Answer.Yes, - hasDiabetes = Answer.Yes - ) - - updateSpec - .given(model) - .whenEvent(DataOnExitLoaded(medicalHistory)) - .then(assertThatNext( - hasNoModel(), - hasEffects(GoBackToPatientSummary) - )) - } - - @Test - fun `when done is clicked, then load data on exiting`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions.empty() - ) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - - updateSpec - .given(model) - .whenEvent(PrescribedDrugsDoneClicked) - .then(assertThatNext( - hasNoModel(), - hasEffects(LoadDataOnExiting(patientUuid)) - )) - } - - @Test - fun `when prescribed drugs are refilled, then load data on exiting`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions.empty() - ) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - - updateSpec - .given(model) - .whenEvent(PrescribedMedicinesRefilled) - .then(assertThatNext( - hasNoModel(), - hasEffects(LoadDataOnExiting(patientUuid)) - )) - } - - @Test - fun `when back is clicked, then load data on exiting`() { - val model = EditMedicinesModel.create( - patientUuid = patientUuid, - diagnosisWarningPrescriptions = DiagnosisWarningPrescriptions.empty() - ) - val updateSpec = UpdateSpec(EditMedicinesUpdate(LocalDate.of(2020, 11, 18), ZoneOffset.UTC)) - - updateSpec - .given(model) - .whenEvent(BackClicked) - .then(assertThatNext( - hasNoModel(), - hasEffects(LoadDataOnExiting(patientUuid)) - )) - } } diff --git a/app/src/test/java/org/simple/clinic/drugs/EditMedicinesInitTest.kt b/app/src/test/java/org/simple/clinic/drugs/EditMedicinesInitTest.kt index 4a808bc166a..ff0a799c15d 100644 --- a/app/src/test/java/org/simple/clinic/drugs/EditMedicinesInitTest.kt +++ b/app/src/test/java/org/simple/clinic/drugs/EditMedicinesInitTest.kt @@ -11,7 +11,7 @@ class EditMedicinesInitTest { @Test fun `when sheet is created, then fetch prescribed and protocol drugs and load drug frequency choice items`() { val patientUuid = UUID.fromString("bcdd3e43-4404-49b5-90dc-f58d3a31e431") - val model = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + val model = EditMedicinesModel.create(patientUuid) val initSpec = InitSpec(EditMedicinesInit()) initSpec diff --git a/app/src/test/java/org/simple/clinic/drugs/EditMedicinesUiRendererTest.kt b/app/src/test/java/org/simple/clinic/drugs/EditMedicinesUiRendererTest.kt index e6f6d34baac..83c67e45731 100644 --- a/app/src/test/java/org/simple/clinic/drugs/EditMedicinesUiRendererTest.kt +++ b/app/src/test/java/org/simple/clinic/drugs/EditMedicinesUiRendererTest.kt @@ -25,7 +25,7 @@ class EditMedicinesUiRendererTest { private val uiRenderer = EditMedicinesUiRenderer(ui) private val patientUuid = UUID.fromString("00f6ad74-703a-4176-acaa-fc6b57b4fa3c") - private val defaultModel = EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()) + private val defaultModel = EditMedicinesModel.create(patientUuid) private val medicineFrequencyToLabelMap = mapOf( null to DrugFrequencyLabel(label = "None"), OD to DrugFrequencyLabel(label = "OD"), diff --git a/app/src/test/java/org/simple/clinic/drugs/selection/EditMedicinesScreenLogicTest.kt b/app/src/test/java/org/simple/clinic/drugs/selection/EditMedicinesScreenLogicTest.kt index d1d8dcf989b..7dfa3b6a2e4 100644 --- a/app/src/test/java/org/simple/clinic/drugs/selection/EditMedicinesScreenLogicTest.kt +++ b/app/src/test/java/org/simple/clinic/drugs/selection/EditMedicinesScreenLogicTest.kt @@ -17,7 +17,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.simple.clinic.drugs.AddNewPrescriptionClicked import org.simple.clinic.drugs.CustomPrescriptionClicked -import org.simple.clinic.drugs.DiagnosisWarningPrescriptions import org.simple.clinic.drugs.EditMedicinesEffect import org.simple.clinic.drugs.EditMedicinesEffectHandler import org.simple.clinic.drugs.EditMedicinesEvent @@ -97,14 +96,13 @@ class EditMedicinesScreenLogicTest { facility = Lazy { facility }, uuidGenerator = uuidGenerator, appointmentsRepository = appointmentRepository, - medicalHistoryRepository = mock(), drugFrequencyToLabelMap = drugFrequencyToLabelMap, viewEffectsConsumer = viewEffectsConsumer ) fixture = MobiusTestFixture( uiEvents.ofType(), - EditMedicinesModel.create(patientUuid, DiagnosisWarningPrescriptions.empty()).medicineFrequencyToLabelMapLoaded(medicineFrequencyToLabelMap), + EditMedicinesModel.create(patientUuid).medicineFrequencyToLabelMapLoaded(medicineFrequencyToLabelMap), EditMedicinesInit(), EditMedicinesUpdate(LocalDate.of(2020, 11, 12), ZoneOffset.UTC), effectHandler.build(), @@ -250,6 +248,20 @@ class EditMedicinesScreenLogicTest { verify(uiActions).showUpdateCustomPrescriptionSheet(prescribedDrug) } + @Test + fun `when done click event is received then go back to patient summary`() { + //given + whenever(protocolRepository.drugsForProtocolOrDefault(protocolUuid)).thenReturn(emptyList()) + whenever(prescriptionRepository.newestPrescriptionsForPatient(patientUuid)).thenReturn(Observable.empty()) + + //when + setupController() + uiEvents.onNext(PrescribedDrugsDoneClicked) + + //then + verify(uiActions).goBackToPatientSummary() + } + private fun setupController() { fixture.start() diff --git a/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandlerTest.kt b/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandlerTest.kt deleted file mode 100644 index 292df4675ac..00000000000 --- a/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryEffectHandlerTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package org.simple.clinic.summary.medicalhistory - -import io.reactivex.Observable -import org.junit.Test -import org.mockito.kotlin.doReturn -import org.mockito.kotlin.mock -import org.mockito.kotlin.whenever -import org.simple.clinic.medicalhistory.MedicalHistoryRepository -import org.simple.clinic.mobius.EffectHandlerTestCase -import org.simple.clinic.summary.prescribeddrugs.DrugSummaryEffectHandler -import org.simple.clinic.util.scheduler.TestSchedulersProvider -import org.simple.sharedTestCode.TestData -import org.simple.sharedTestCode.util.TestUtcClock -import org.simple.sharedTestCode.uuid.FakeUuidGenerator -import java.util.UUID - -class MedicalHistorySummaryEffectHandlerTest { - - private val facility = TestData.facility(uuid = UUID.fromString("94db5d90-d483-4755-892a-97fde5a870fe")) - private val medicalHistoryRepository = mock() - private val clock = TestUtcClock() - private val uuidGenerator = FakeUuidGenerator(uuid = UUID.fromString("e78ec5f7-6fe9-4812-a894-9e34e55c670e")) - private val effectHandler = MedicalHistorySummaryEffectHandler( - schedulers = TestSchedulersProvider.trampoline(), - medicalHistoryRepository = medicalHistoryRepository, - clock = clock, - currentFacility = { facility }, - uuidGenerator = uuidGenerator - ) - - private val testCase = EffectHandlerTestCase(effectHandler.build()) - - @Test - fun `when load medical history effect is received, then load medical history`() { - // given - val patientUuid = UUID.fromString("642ba684-25f3-4750-ba52-cd21ebf7cfca") - val medicalHistory = TestData.medicalHistory( - uuid = UUID.fromString("8568fd00-7de8-469e-a869-e92e54eb7f9b"), - patientUuid = patientUuid - ) - - whenever(medicalHistoryRepository.historyForPatientOrDefault( - patientUuid = patientUuid, - defaultHistoryUuid = uuidGenerator.v4() - )) doReturn Observable.just(medicalHistory) - - // when - testCase.dispatch(LoadMedicalHistory(patientUUID = patientUuid)) - - // then - testCase.assertOutgoingEvents(MedicalHistoryLoaded(medicalHistory)) - } -} diff --git a/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryLogicTest.kt b/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryLogicTest.kt index 15cd1568e70..e76ab2aaa77 100644 --- a/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryLogicTest.kt +++ b/app/src/test/java/org/simple/clinic/summary/medicalhistory/MedicalHistorySummaryLogicTest.kt @@ -6,7 +6,6 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoMoreInteractions import org.mockito.kotlin.whenever import dagger.Lazy -import io.reactivex.Observable import io.reactivex.rxkotlin.ofType import io.reactivex.subjects.PublishSubject import junitparams.JUnitParamsRunner @@ -90,7 +89,7 @@ class MedicalHistorySummaryLogicTest { @Test fun `patient's medical history should be populated`() { // given - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController() @@ -120,7 +119,7 @@ class MedicalHistorySummaryLogicTest { val updatedMedicalHistory = medicalHistory.answered(question, newAnswer) val now = Instant.now(clock) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController() @@ -133,7 +132,7 @@ class MedicalHistorySummaryLogicTest { @Test fun `when the current facility supports diabetes management, show the diagnosis view and hide the diabetes history question`() { // given - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled) @@ -148,7 +147,7 @@ class MedicalHistorySummaryLogicTest { @Test fun `when the current facility does not support diabetes management, hide the diagnosis view and show the diabetes history question`() { // given - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController() @@ -165,7 +164,7 @@ class MedicalHistorySummaryLogicTest { // given val updatedMedicalHistory = medicalHistory.answered(DiagnosedWithHypertension, Yes) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled) @@ -184,7 +183,7 @@ class MedicalHistorySummaryLogicTest { // given val updatedMedicalHistory = medicalHistory.answered(DiagnosedWithDiabetes, No) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled) @@ -203,7 +202,7 @@ class MedicalHistorySummaryLogicTest { // given val updatedMedicalHistory = medicalHistory.answered(HasHadAKidneyDisease, Yes) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled) @@ -222,7 +221,7 @@ class MedicalHistorySummaryLogicTest { // given val updatedMedicalHistory = medicalHistory.answered(HasHadAHeartAttack, No) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled) @@ -241,7 +240,7 @@ class MedicalHistorySummaryLogicTest { // given val updatedMedicalHistory = medicalHistory.answered(HasHadAStroke, Yes) - whenever(medicalHistoryRepository.historyForPatientOrDefault(medicalHistoryUuid, patientUuid)) doReturn Observable.just(medicalHistory) + whenever(medicalHistoryRepository.historyForPatientOrDefaultImmediate(medicalHistoryUuid, patientUuid)) doReturn medicalHistory // when setupController(facility = facilityWithDiabetesManagementEnabled)