Skip to content

Commit

Permalink
Show patient reassignment sheet when done/back is clicked in `Patient…
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth authored May 7, 2024
1 parent ef4caf1 commit 762c1bb
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 67 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@
- Add `isPatientEligibleForReassignment` to `PatientSearchResult` database view and `OverdueAppointment` model
- Bump Compose Compiler to v1.5.13
- Bump Jackson Core to v2.17.1
- Add facility reassignment view to `RecentPatientsItem`, `OverduePatientItem` and `PatientSearchResultItem`
- Show patient reassignment sheet when done/back is clicked in `PatientSummary`

### Fixes

- Fix app crash on searching overdue patient with special characters
- Fix consent text getting cropped and hidden on patient registration screen

### Changes

- Add facility reassignment view to `RecentPatientsItem`, `OverduePatientItem` and `PatientSearchResultItem`

## 2024-01-08-8979

### Internal
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/simple/clinic/feature/Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ enum class Feature(
OverdueInstantSearch(false, "overdue_instant_search_v2"),
OverdueSelectAndDownload(false, "overdue_select_and_download_v2"),
PatientLineListDownload(false, "patient_line_list_download_v2"),
LogoutUser(false, "logout_user_v1")
LogoutUser(false, "logout_user_v1"),
PatientReassignment(false, "patient_reassignment_v0")
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/simple/clinic/summary/ClickAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.simple.clinic.summary

enum class ClickAction {
DONE,
BACK
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ data class MarkReminderAsShown(val patientUuid: UUID) : PatientSummaryEffect()

data class LoadDataForBackClick(
val patientUuid: UUID,
val screenCreatedTimestamp: Instant
val screenCreatedTimestamp: Instant,
val patientEligibleForReassignment: Boolean
) : PatientSummaryEffect()

data class LoadDataForDoneClick(
val patientUuid: UUID,
val screenCreatedTimestamp: Instant
val screenCreatedTimestamp: Instant,
val patientEligibleForReassignment: Boolean
) : PatientSummaryEffect()

data class TriggerSync(val sheetOpenedFrom: AppointmentSheetOpenedFrom) : PatientSummaryEffect()
Expand All @@ -39,6 +41,14 @@ object CheckIfCDSSPilotIsEnabled : PatientSummaryEffect()

data class LoadLatestScheduledAppointment(val patientUuid: UUID) : PatientSummaryEffect()

data class UpdatePatientReassignmentStatus(val patientUuid: UUID, val status: Boolean) : PatientSummaryEffect()

data class CheckPatientReassignmentStatus(
val patientUuid: UUID,
val clickAction: ClickAction,
val screenCreatedTimestamp: Instant,
) : PatientSummaryEffect()

sealed class PatientSummaryViewEffect : PatientSummaryEffect()

data class HandleEditClick(
Expand Down Expand Up @@ -87,3 +97,5 @@ object OpenSelectFacilitySheet : PatientSummaryViewEffect()
data class DispatchNewAssignedFacility(val facility: Facility) : PatientSummaryViewEffect()

object RefreshNextAppointment : PatientSummaryViewEffect()

data class ShowReassignPatientSheet(val patientUuid: UUID) : PatientSummaryViewEffect()
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,30 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
.addTransformer(LoadPatientRegistrationData::class.java, checkPatientRegistrationData())
.addTransformer(CheckIfCDSSPilotIsEnabled::class.java, checkIfCDSSPilotIsEnabled())
.addTransformer(LoadLatestScheduledAppointment::class.java, loadLatestScheduledAppointment())
.addConsumer(UpdatePatientReassignmentStatus::class.java, { updatePatientReassignmentState(it.patientUuid, it.status) }, schedulersProvider.io())
.addTransformer(CheckPatientReassignmentStatus::class.java, checkPatientReassignmentStatus())
.build()
}

private fun checkPatientReassignmentStatus(): ObservableTransformer<CheckPatientReassignmentStatus, PatientSummaryEvent> {
return ObservableTransformer { effects ->
effects
.observeOn(schedulersProvider.io())
.map {
val isPatientEligibleForReassignment = patientRepository.isPatientEligibleForReassignment(it.patientUuid)
PatientReassignmentStatusLoaded(
isPatientEligibleForReassignment = isPatientEligibleForReassignment,
clickAction = it.clickAction,
screenCreatedTimestamp = it.screenCreatedTimestamp
)
}
}
}

private fun updatePatientReassignmentState(patientUuid: UUID, status: Boolean) {
patientRepository.updatePatientReassignmentEligibilityStatus(patientUuid, status)
}

private fun loadLatestScheduledAppointment(): ObservableTransformer<LoadLatestScheduledAppointment, PatientSummaryEvent> {
return ObservableTransformer { effects ->
effects
Expand Down Expand Up @@ -256,7 +277,8 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
hasAppointmentChangeSinceScreenCreated = hasAppointmentChanged,
countOfRecordedBloodPressures = countOfRecordedBloodPressures,
countOfRecordedBloodSugars = countOfRecordedBloodSugars,
medicalHistory = medicalHistory
medicalHistory = medicalHistory,
isPatientEligibleForReassignment = loadDataForBackClick.patientEligibleForReassignment
)
}
}
Expand Down Expand Up @@ -290,7 +312,8 @@ class PatientSummaryEffectHandler @AssistedInject constructor(
hasAppointmentChangeSinceScreenCreated = hasAppointmentChanged,
countOfRecordedBloodPressures = countOfRecordedBloodPressures,
countOfRecordedBloodSugars = countOfRecordedBloodSugars,
medicalHistory = medicalHistory
medicalHistory = medicalHistory,
isPatientEligibleForReassignment = loadDataForDoneClick.patientEligibleForReassignment
)
}
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/org/simple/clinic/summary/PatientSummaryEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ data class DataForBackClickLoaded(
val hasAppointmentChangeSinceScreenCreated: Boolean,
val countOfRecordedBloodPressures: Int,
val countOfRecordedBloodSugars: Int,
val medicalHistory: MedicalHistory
val medicalHistory: MedicalHistory,
val isPatientEligibleForReassignment: Boolean
) : PatientSummaryEvent()

data class DataForDoneClickLoaded(
val hasPatientMeasurementDataChangedSinceScreenCreated: Boolean,
val hasAppointmentChangeSinceScreenCreated: Boolean,
val countOfRecordedBloodPressures: Int,
val countOfRecordedBloodSugars: Int,
val medicalHistory: MedicalHistory
val medicalHistory: MedicalHistory,
val isPatientEligibleForReassignment: Boolean
) : PatientSummaryEvent()

data class SyncTriggered(val sheetOpenedFrom: AppointmentSheetOpenedFrom) : PatientSummaryEvent()
Expand Down Expand Up @@ -108,3 +110,9 @@ data class ClinicalDecisionSupportInfoLoaded(val isNewestBpEntryHigh: Boolean, v
data class CDSSPilotStatusChecked(val isPilotEnabledForFacility: Boolean) : PatientSummaryEvent()

data class LatestScheduledAppointmentLoaded(val appointment: Appointment?) : PatientSummaryEvent()

data class PatientReassignmentStatusLoaded(
val isPatientEligibleForReassignment: Boolean,
val clickAction: ClickAction,
val screenCreatedTimestamp: Instant,
) : PatientSummaryEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ class PatientSummaryScreen :
}

override fun createUpdate(): Update<PatientSummaryModel, PatientSummaryEvent, PatientSummaryEffect> {
return PatientSummaryUpdate()
return PatientSummaryUpdate(
isPatientReassignmentFeatureEnabled = features.isEnabled(Feature.PatientReassignment)
)
}

override fun createInit(): Init<PatientSummaryModel, PatientSummaryEffect> {
Expand Down Expand Up @@ -749,6 +751,10 @@ class PatientSummaryScreen :
clinicalDecisionSupportAlertView.visibility = GONE
}

override fun showReassignPatientSheet(patientUuid: UUID) {
// TODO: Show patient reassignment sheet
}

interface Injector {
fun inject(target: PatientSummaryScreen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ interface PatientSummaryUiActions {
fun openSelectFacilitySheet()
fun dispatchNewAssignedFacility(facility: Facility)
fun refreshNextAppointment()
fun showReassignPatientSheet(patientUuid: UUID)
}
99 changes: 82 additions & 17 deletions app/src/main/java/org/simple/clinic/summary/PatientSummaryUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import org.simple.clinic.mobius.dispatch
import org.simple.clinic.summary.AppointmentSheetOpenedFrom.BACK_CLICK
import org.simple.clinic.summary.AppointmentSheetOpenedFrom.DONE_CLICK
import org.simple.clinic.summary.AppointmentSheetOpenedFrom.NEXT_APPOINTMENT_ACTION_CLICK
import org.simple.clinic.summary.ClickAction.BACK
import org.simple.clinic.summary.ClickAction.DONE
import org.simple.clinic.summary.OpenIntention.LinkIdWithPatient
import org.simple.clinic.summary.OpenIntention.ViewExistingPatient
import org.simple.clinic.summary.OpenIntention.ViewExistingPatientWithTeleconsultLog
import org.simple.clinic.summary.OpenIntention.ViewNewPatient
import java.time.Instant
import java.util.UUID

class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, PatientSummaryEffect> {
class PatientSummaryUpdate(
private val isPatientReassignmentFeatureEnabled: Boolean
) : Update<PatientSummaryModel, PatientSummaryEvent, PatientSummaryEffect> {

override fun update(
model: PatientSummaryModel,
Expand All @@ -38,7 +43,8 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
hasAppointmentChangedSinceScreenCreated = event.hasAppointmentChangeSinceScreenCreated,
countOfRecordedBloodPressures = event.countOfRecordedBloodPressures,
countOfRecordedBloodSugars = event.countOfRecordedBloodSugars,
medicalHistory = event.medicalHistory
medicalHistory = event.medicalHistory,
isPatientEligibleForReassignment = event.isPatientEligibleForReassignment
)

is DataForDoneClickLoaded -> dataForHandlingDoneClickLoaded(
Expand All @@ -47,7 +53,8 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
countOfRecordedBloodSugars = event.countOfRecordedBloodSugars,
medicalHistory = event.medicalHistory,
hasPatientMeasurementDataChangedSinceScreenCreated = event.hasPatientMeasurementDataChangedSinceScreenCreated,
hasAppointmentChangedSinceScreenCreated = event.hasAppointmentChangeSinceScreenCreated
hasAppointmentChangedSinceScreenCreated = event.hasAppointmentChangeSinceScreenCreated,
isPatientEligibleForReassignment = event.isPatientEligibleForReassignment
)

is SyncTriggered -> scheduleAppointmentSheetClosed(model, event.sheetOpenedFrom)
Expand All @@ -72,17 +79,53 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
is CDSSPilotStatusChecked -> cdssPilotStatusChecked(event, model)
is LatestScheduledAppointmentLoaded -> next(model.scheduledAppointmentLoaded(event.appointment))
is MeasurementWarningNotNowClicked -> measurementWarningNotNowClicked(model, event)
is PatientReassignmentStatusLoaded -> patientReassignmentStatusLoaded(model, event)
}
}

private fun patientReassignmentStatusLoaded(
model: PatientSummaryModel,
event: PatientReassignmentStatusLoaded
): Next<PatientSummaryModel, PatientSummaryEffect> {
val effect: PatientSummaryEffect = when (event.clickAction) {
DONE -> LoadDataForDoneClick(
patientUuid = model.patientUuid,
screenCreatedTimestamp = event.screenCreatedTimestamp,
patientEligibleForReassignment = event.isPatientEligibleForReassignment
)
BACK -> LoadDataForBackClick(
patientUuid = model.patientUuid,
screenCreatedTimestamp = event.screenCreatedTimestamp,
patientEligibleForReassignment = event.isPatientEligibleForReassignment
)
}

return dispatch(
UpdatePatientReassignmentStatus(
patientUuid = model.patientUuid,
status = event.isPatientEligibleForReassignment
),
effect
)
}

private fun measurementWarningNotNowClicked(
model: PatientSummaryModel,
event: MeasurementWarningNotNowClicked
): Next<PatientSummaryModel, PatientSummaryEffect> {
val effect = if (model.hasPatientDied)
GoBackToPreviousScreen
else
LoadDataForBackClick(event.patientUuid, event.screenCreatedTimestamp)
val effect = when {
model.hasPatientDied -> GoBackToPreviousScreen
!isPatientReassignmentFeatureEnabled -> LoadDataForBackClick(
patientUuid = model.patientUuid,
screenCreatedTimestamp = event.screenCreatedTimestamp,
patientEligibleForReassignment = false
)
else -> CheckPatientReassignmentStatus(
patientUuid = model.patientUuid,
clickAction = BACK,
screenCreatedTimestamp = event.screenCreatedTimestamp
)
}

return dispatch(effect)
}
Expand Down Expand Up @@ -123,19 +166,37 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
}

private fun doneClicked(model: PatientSummaryModel, event: PatientSummaryDoneClicked): Next<PatientSummaryModel, PatientSummaryEffect> {
val effect = if (model.hasPatientDied)
GoToHomeScreen
else
LoadDataForDoneClick(event.patientUuid, event.screenCreatedTimestamp)
val effect = when {
model.hasPatientDied -> GoToHomeScreen
!isPatientReassignmentFeatureEnabled -> LoadDataForDoneClick(
patientUuid = model.patientUuid,
screenCreatedTimestamp = event.screenCreatedTimestamp,
patientEligibleForReassignment = false
)
else -> CheckPatientReassignmentStatus(
patientUuid = model.patientUuid,
clickAction = DONE,
screenCreatedTimestamp = event.screenCreatedTimestamp
)
}

return dispatch(effect)
}

private fun backClicked(model: PatientSummaryModel, event: PatientSummaryBackClicked): Next<PatientSummaryModel, PatientSummaryEffect> {
val effect = if (model.hasPatientDied)
GoBackToPreviousScreen
else
LoadDataForBackClick(event.patientUuid, event.screenCreatedTimestamp)
val effect = when {
model.hasPatientDied -> GoBackToPreviousScreen
!isPatientReassignmentFeatureEnabled -> LoadDataForBackClick(
patientUuid = model.patientUuid,
screenCreatedTimestamp = event.screenCreatedTimestamp,
patientEligibleForReassignment = false
)
else -> CheckPatientReassignmentStatus(
patientUuid = model.patientUuid,
clickAction = BACK,
screenCreatedTimestamp = event.screenCreatedTimestamp
)
}

return dispatch(effect)
}
Expand Down Expand Up @@ -178,7 +239,8 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
countOfRecordedBloodSugars: Int,
medicalHistory: MedicalHistory,
hasPatientMeasurementDataChangedSinceScreenCreated: Boolean,
hasAppointmentChangedSinceScreenCreated: Boolean
hasAppointmentChangedSinceScreenCreated: Boolean,
isPatientEligibleForReassignment: Boolean,
): Next<PatientSummaryModel, PatientSummaryEffect> {
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated && !hasAppointmentChangedSinceScreenCreated
val hasAtLeastOneMeasurementRecorded = countOfRecordedBloodPressures + countOfRecordedBloodSugars > 0
Expand All @@ -194,6 +256,7 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
return when {
shouldShowDiagnosisError -> dispatch(ShowDiagnosisError)
measurementWarningEffect != null -> next(model.shownMeasurementsWarningDialog(), setOf(measurementWarningEffect))
isPatientEligibleForReassignment -> dispatch(ShowReassignPatientSheet(model.patientUuid))
canShowAppointmentSheet -> dispatch(ShowScheduleAppointmentSheet(model.patientUuid, DONE_CLICK, model.currentFacility!!))
else -> dispatch(GoToHomeScreen)
}
Expand All @@ -205,7 +268,8 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
hasAppointmentChangedSinceScreenCreated: Boolean,
countOfRecordedBloodPressures: Int,
countOfRecordedBloodSugars: Int,
medicalHistory: MedicalHistory
medicalHistory: MedicalHistory,
isPatientEligibleForReassignment: Boolean,
): Next<PatientSummaryModel, PatientSummaryEffect> {
val openIntention = model.openIntention
val canShowAppointmentSheet = hasPatientMeasurementDataChangedSinceScreenCreated && !hasAppointmentChangedSinceScreenCreated
Expand All @@ -223,6 +287,7 @@ class PatientSummaryUpdate : Update<PatientSummaryModel, PatientSummaryEvent, Pa
return when {
shouldShowDiagnosisError -> dispatch(ShowDiagnosisError)
measurementWarningEffect != null -> next(model.shownMeasurementsWarningDialog(), setOf(measurementWarningEffect))
isPatientEligibleForReassignment -> dispatch(ShowReassignPatientSheet(model.patientUuid))
canShowAppointmentSheet -> dispatch(ShowScheduleAppointmentSheet(model.patientUuid, BACK_CLICK, model.currentFacility!!))
shouldGoToPreviousScreen -> dispatch(GoBackToPreviousScreen)
shouldGoToHomeScreen -> dispatch(GoToHomeScreen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PatientSummaryViewEffectHandler(
is DispatchNewAssignedFacility -> uiActions.dispatchNewAssignedFacility(viewEffect.facility)
is ShowUpdatePhonePopup -> uiActions.showUpdatePhoneDialog(viewEffect.patientUuid)
RefreshNextAppointment -> uiActions.refreshNextAppointment()
is ShowReassignPatientSheet -> uiActions.showReassignPatientSheet(viewEffect.patientUuid)
}.exhaustive()
}
}
Loading

0 comments on commit 762c1bb

Please sign in to comment.