Skip to content

Commit

Permalink
Revert "Check diagnosis prescriptions when exiting prescriptions scre…
Browse files Browse the repository at this point in the history
…en (#4981)"

This reverts commit 46691cf.
  • Loading branch information
msasikanth committed Jun 17, 2024
1 parent 73e2156 commit 2b2dc76
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 482 deletions.
25 changes: 19 additions & 6 deletions app/src/debug/google-services.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.simple.clinic.drugs

import org.simple.clinic.summary.DiagnosisWarningResult
import java.util.UUID

sealed class EditMedicinesEffect
Expand All @@ -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()
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +26,6 @@ class EditMedicinesEffectHandler @AssistedInject constructor(
private val facility: Lazy<Facility>,
private val uuidGenerator: UuidGenerator,
private val appointmentsRepository: AppointmentRepository,
private val medicalHistoryRepository: MedicalHistoryRepository,
private val drugFrequencyToLabelMap: Map<DrugFrequency?, DrugFrequencyLabel>,
@Assisted private val viewEffectsConsumer: Consumer<EditMedicinesViewEffect>
) {
Expand All @@ -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<LoadDataOnExiting, EditMedicinesEvent> {
return ObservableTransformer { effects ->
effects
.observeOn(schedulersProvider.io())
.map {
val medicalHistory = medicalHistoryRepository.historyForPatientOrDefaultImmediate(
patientUuid = it.patientUuid,
defaultHistoryUuid = uuidGenerator.v4()
)

DataOnExitLoaded(medicalHistory)
}
}
}

private fun loadFrequencyChoiceItems(): ObservableTransformer<LoadDrugFrequencyChoiceItems, EditMedicinesEvent> {
return ObservableTransformer { effects ->
effects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -39,7 +38,3 @@ object PrescribedMedicinesRefilled : EditMedicinesEvent()
data class DrugFrequencyChoiceItemsLoaded(
val drugFrequencyToLabelMap: Map<DrugFrequency?, DrugFrequencyLabel>
) : EditMedicinesEvent()

data class DataOnExitLoaded(val medicalHistory: MedicalHistory) : EditMedicinesEvent()

data object BackClicked : EditMedicinesEvent()
14 changes: 3 additions & 11 deletions app/src/main/java/org/simple/clinic/drugs/EditMedicinesModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@ data class EditMedicinesModel(
val prescribedDrugs: List<PrescribedDrug>?,
val protocolDrugs: List<ProtocolDrugAndDosages>?,
val editMedicineButtonState: EditMedicineButtonState?,
val medicineFrequencyToLabelMap: Map<MedicineFrequency?, DrugFrequencyLabel>?,
val diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions,
val medicineFrequencyToLabelMap: Map<MedicineFrequency?, DrugFrequencyLabel>?
) : 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)
}
}

Expand Down
42 changes: 2 additions & 40 deletions app/src/main/java/org/simple/clinic/drugs/EditMedicinesUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<PrescribedDrug>,
): Next<EditMedicinesModel, EditMedicinesEffect> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class EditMedicinesViewEffectHandler(
)
is ShowUpdateCustomPrescriptionSheet -> uiActions.showUpdateCustomPrescriptionSheet(viewEffect.prescribedDrug)
GoBackToPatientSummary -> uiActions.goBackToPatientSummary()
is GoBackToPatientSummaryWithWarningResult -> uiActions.goBackToPatientSummary(viewEffect.diagnosisWarningResult)
}
}
}
18 changes: 0 additions & 18 deletions app/src/main/java/org/simple/clinic/drugs/PrescriptionModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,18 +30,4 @@ class PrescriptionModule {
fun lastPullToken(rxSharedPrefs: RxSharedPreferences): Preference<Optional<String>> {
return rxSharedPrefs.getOptional("last_prescription_pull_token_v2", StringPreferenceConverter())
}

@Provides
@OptIn(ExperimentalStdlibApi::class)
fun diagnosisWarningPrescriptions(moshi: Moshi, configReader: ConfigReader): DiagnosisWarningPrescriptions {
val adapter = moshi.adapter<DiagnosisWarningPrescriptions>()
val json = configReader.string("diagnosis_warning_prescriptions_v0", "{}")

return try {
adapter.fromJson(json)!!
} catch (e: Throwable) {
CrashReporter.report(e)
DiagnosisWarningPrescriptions.empty()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -69,7 +63,7 @@ class EditMedicinesScreen :
EditMedicinesModel,
EditMedicinesEvent,
EditMedicinesEffect,
EditMedicinesViewEffect>(), EditMedicinesUi, EditMedicinesUiActions, HandlesBack {
EditMedicinesViewEffect>(), EditMedicinesUi, EditMedicinesUiActions {

@Inject
lateinit var router: Router
Expand All @@ -89,9 +83,6 @@ class EditMedicinesScreen :
@Inject
lateinit var features: Features

@Inject
lateinit var diagnosisWarningPrescriptions: DiagnosisWarningPrescriptions

private val toolbar
get() = binding.prescribeddrugsToolbar

Expand Down Expand Up @@ -130,12 +121,7 @@ class EditMedicinesScreen :
screenKey.patientUuid
}

private val additionalEvents = DeferredEventSource<EditMedicinesEvent>()

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)
Expand All @@ -152,8 +138,6 @@ class EditMedicinesScreen :
.compose(ReportAnalyticsEvents())
.cast<EditMedicinesEvent>()

override fun additionalEventSources() = listOf(additionalEvents)

override fun createUpdate() = EditMedicinesUpdate(LocalDate.now(userClock), userClock.zone)

override fun createInit() = EditMedicinesInit()
Expand All @@ -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())

Expand All @@ -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 }
Expand Down Expand Up @@ -231,10 +210,6 @@ class EditMedicinesScreen :
router.pop()
}

override fun goBackToPatientSummary(diagnosisWarningResult: DiagnosisWarningResult) {
router.popWithResult(Succeeded(diagnosisWarningResult))
}

override fun showDosageSelectionSheet(
drugName: String,
patientUuid: UUID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.simple.clinic.drugs.selection

import org.simple.clinic.drugs.PrescribedDrug
import org.simple.clinic.summary.DiagnosisWarningResult
import java.util.UUID

interface EditMedicinesUiActions {
fun showNewPrescriptionEntrySheet(patientUuid: UUID)
fun showDosageSelectionSheet(drugName: String, patientUuid: UUID, prescribedDrugUuid: UUID?)
fun showUpdateCustomPrescriptionSheet(prescribedDrug: PrescribedDrug)
fun goBackToPatientSummary()
fun goBackToPatientSummary(diagnosisWarningResult: DiagnosisWarningResult)
}
Loading

0 comments on commit 2b2dc76

Please sign in to comment.