Skip to content

Commit 84b7f37

Browse files
author
sagarwal
committed
Fix updated_at not updating when a business identifier is updated
1 parent 3838180 commit 84b7f37

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

app/src/main/java/org/simple/clinic/editpatient/EditPatientEffectHandler.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.simple.clinic.util.UtcClock
3333
import org.simple.clinic.util.filterAndUnwrapJust
3434
import org.simple.clinic.util.scheduler.SchedulersProvider
3535
import org.simple.clinic.uuid.UuidGenerator
36+
import java.time.Instant
3637
import java.time.LocalDate
3738
import java.time.format.DateTimeFormatter
3839
import java.util.UUID
@@ -267,7 +268,12 @@ class EditPatientEffectHandler @AssistedInject constructor(
267268
private fun updateAlternativeId(savePatientEffects: Observable<SavePatientEffect>): Observable<EditPatientEvent> {
268269
return savePatientEffects
269270
.filter(::isAlternativeIdModified)
270-
.map { it.saveAlternativeId?.updateIdentifierValue(it.ongoingEntry.alternativeId) }
271+
.map {
272+
it.saveAlternativeId?.updateIdentifierValue(
273+
newValue = it.ongoingEntry.alternativeId,
274+
updatedAt = Instant.now(utcClock)
275+
)
276+
}
271277
.flatMapCompletable { patientRepository.saveBusinessId(it) }
272278
.toObservable()
273279
}

app/src/main/java/org/simple/clinic/patient/businessid/BusinessId.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ data class BusinessId(
8484
)
8585
}
8686

87-
fun updateIdentifierValue(newValue: String): BusinessId =
88-
copy(identifier = identifier.copy(value = newValue))
87+
fun updateIdentifierValue(newValue: String, updatedAt: Instant): BusinessId =
88+
copy(
89+
identifier = identifier.copy(value = newValue),
90+
updatedAt = updatedAt
91+
)
8992

9093
sealed class MetaDataVersion : Parcelable {
9194

app/src/test/java/org/simple/clinic/editpatient/EditPatientEffectHandlerTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ class EditPatientEffectHandlerTest {
186186
// given
187187
val bangladeshNationalIdText = "1569273"
188188
val ongoingEntryWithBangladeshId = entry.updateAlternativeId(bangladeshNationalIdText)
189-
val updatedBangladeshNationalId = bangladeshNationalId.updateIdentifierValue(bangladeshNationalIdText)
189+
val now = Instant.now(utcClock)
190+
val updatedBangladeshNationalId =
191+
bangladeshNationalId.updateIdentifierValue(
192+
newValue = bangladeshNationalIdText,
193+
updatedAt = now
194+
)
190195

191196
whenever(patientRepository.updatePatient(patient)) doReturn Completable.complete()
192197
whenever(patientRepository.updateAddressForPatient(patient.uuid, patientAddress)) doReturn Completable.complete()

0 commit comments

Comments
 (0)