From 6eb5c7316219bbdb4466e6ee2de9981a60da0dd3 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Tue, 3 Dec 2024 15:22:13 +0530 Subject: [PATCH] Sync `isSmoker` and `cholestral_value` to and from server --- .../MedicalHistoryRepositoryAndroidTest.kt | 9 ++++++++- .../clinic/medicalhistory/MedicalHistoryRepository.kt | 6 +++--- .../clinic/medicalhistory/OngoingMedicalHistoryEntry.kt | 3 ++- .../clinic/medicalhistory/sync/MedicalHistoryPayload.kt | 6 ++++++ .../clinic/medicalhistory/sync/MedicalHistorySync.kt | 2 ++ .../patient/onlinelookup/api/LookupPatientOnline.kt | 5 +++-- .../src/main/java/org/simple/sharedTestCode/TestData.kt | 4 ++++ 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/org/simple/clinic/medicalhistory/MedicalHistoryRepositoryAndroidTest.kt b/app/src/androidTest/java/org/simple/clinic/medicalhistory/MedicalHistoryRepositoryAndroidTest.kt index 165035309a4..86f90234e15 100644 --- a/app/src/androidTest/java/org/simple/clinic/medicalhistory/MedicalHistoryRepositoryAndroidTest.kt +++ b/app/src/androidTest/java/org/simple/clinic/medicalhistory/MedicalHistoryRepositoryAndroidTest.kt @@ -53,7 +53,9 @@ class MedicalHistoryRepositoryAndroidTest { hasHadHeartAttack = Yes, hasHadStroke = Yes, hasHadKidneyDisease = Yes, - hasDiabetes = No) + hasDiabetes = No, + isSmoker = No, + ) repository.save( uuid = UUID.fromString("d33a3dfc-3da9-43a9-a543-095232c55597"), @@ -67,6 +69,7 @@ class MedicalHistoryRepositoryAndroidTest { assertThat(savedHistory.hasHadStroke).isEqualTo(Yes) assertThat(savedHistory.hasHadKidneyDisease).isEqualTo(Yes) assertThat(savedHistory.diagnosedWithDiabetes).isEqualTo(No) + assertThat(savedHistory.isSmoker).isEqualTo(No) assertThat(savedHistory.syncStatus).isEqualTo(SyncStatus.PENDING) } @@ -119,6 +122,8 @@ class MedicalHistoryRepositoryAndroidTest { assertThat(emptyHistory.hasHadStroke).isEqualTo(Unanswered) assertThat(emptyHistory.hasHadKidneyDisease).isEqualTo(Unanswered) assertThat(emptyHistory.diagnosedWithDiabetes).isEqualTo(Unanswered) + assertThat(emptyHistory.isSmoker).isEqualTo(Unanswered) + assertThat(emptyHistory.cholesterolReading).isEqualTo(null) assertThat(emptyHistory.syncStatus).isEqualTo(SyncStatus.DONE) } @@ -178,6 +183,8 @@ class MedicalHistoryRepositoryAndroidTest { assertThat(emptyHistory.hasHadKidneyDisease).isEqualTo(Unanswered) assertThat(emptyHistory.diagnosedWithHypertension).isEqualTo(Unanswered) assertThat(emptyHistory.diagnosedWithDiabetes).isEqualTo(Unanswered) + assertThat(emptyHistory.isSmoker).isEqualTo(Unanswered) + assertThat(emptyHistory.cholesterolReading).isEqualTo(null) assertThat(emptyHistory.syncStatus).isEqualTo(SyncStatus.DONE) } } diff --git a/app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryRepository.kt b/app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryRepository.kt index 521f8d7f4a9..59e5a54bdc8 100644 --- a/app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryRepository.kt +++ b/app/src/main/java/org/simple/clinic/medicalhistory/MedicalHistoryRepository.kt @@ -97,7 +97,7 @@ class MedicalHistoryRepository @Inject constructor( hasHadStroke = historyEntry.hasHadStroke, hasHadKidneyDisease = historyEntry.hasHadKidneyDisease, diagnosedWithDiabetes = historyEntry.hasDiabetes, - isSmoker = Unanswered, + isSmoker = historyEntry.isSmoker, cholesterolReading = null, syncStatus = SyncStatus.PENDING, createdAt = Instant.now(utcClock), @@ -163,8 +163,8 @@ class MedicalHistoryRepository @Inject constructor( hasHadStroke = hasHadStroke, hasHadKidneyDisease = hasHadKidneyDisease, diagnosedWithDiabetes = hasDiabetes, - isSmoker = Unanswered, - cholesterolReading = null, + isSmoker = isSmoker, + cholesterolReading = CholesterolReading(cholesterolValue.toString()), syncStatus = syncStatus, createdAt = createdAt, updatedAt = updatedAt, diff --git a/app/src/main/java/org/simple/clinic/medicalhistory/OngoingMedicalHistoryEntry.kt b/app/src/main/java/org/simple/clinic/medicalhistory/OngoingMedicalHistoryEntry.kt index 570041eed42..44cd4bce6a5 100644 --- a/app/src/main/java/org/simple/clinic/medicalhistory/OngoingMedicalHistoryEntry.kt +++ b/app/src/main/java/org/simple/clinic/medicalhistory/OngoingMedicalHistoryEntry.kt @@ -19,7 +19,8 @@ data class OngoingMedicalHistoryEntry( val diagnosedWithHypertension: Answer = Unanswered, val isOnHypertensionTreatment: Answer = Unanswered, val isOnDiabetesTreatment: Answer = Unanswered, - val hasDiabetes: Answer = Unanswered + val hasDiabetes: Answer = Unanswered, + val isSmoker: Answer = Unanswered, ) : Parcelable { fun answerChanged(question: MedicalHistoryQuestion, answer: Answer): OngoingMedicalHistoryEntry { diff --git a/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistoryPayload.kt b/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistoryPayload.kt index 6e52f3b6e73..6d3406b6cba 100644 --- a/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistoryPayload.kt +++ b/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistoryPayload.kt @@ -43,6 +43,12 @@ data class MedicalHistoryPayload( @Json(name = "hypertension") val hasHypertension: Answer?, + @Json(name = "smoking") + val isSmoker: Answer, + + @Json(name = "cholesterol") + val cholesterolValue: Float?, + @Json(name = "created_at") val createdAt: Instant, diff --git a/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistorySync.kt b/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistorySync.kt index 07eb27638bf..d3f07b4d17c 100644 --- a/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistorySync.kt +++ b/app/src/main/java/org/simple/clinic/medicalhistory/sync/MedicalHistorySync.kt @@ -49,6 +49,8 @@ class MedicalHistorySync @Inject constructor( hasHadKidneyDisease = hasHadKidneyDisease, hasDiabetes = diagnosedWithDiabetes, hasHypertension = diagnosedWithHypertension, + isSmoker = isSmoker, + cholesterolValue = cholesterolReading?.value?.toFloatOrNull(), createdAt = createdAt, updatedAt = updatedAt, deletedAt = deletedAt) diff --git a/app/src/main/java/org/simple/clinic/patient/onlinelookup/api/LookupPatientOnline.kt b/app/src/main/java/org/simple/clinic/patient/onlinelookup/api/LookupPatientOnline.kt index c22954d0e06..aaa704f05e6 100644 --- a/app/src/main/java/org/simple/clinic/patient/onlinelookup/api/LookupPatientOnline.kt +++ b/app/src/main/java/org/simple/clinic/patient/onlinelookup/api/LookupPatientOnline.kt @@ -4,6 +4,7 @@ import org.simple.clinic.bloodsugar.BloodSugarMeasurement import org.simple.clinic.bp.BloodPressureMeasurement import org.simple.clinic.drugs.PrescribedDrug import org.simple.clinic.medicalhistory.Answer +import org.simple.clinic.medicalhistory.CholesterolReading import org.simple.clinic.medicalhistory.MedicalHistory import org.simple.clinic.overdue.Appointment import org.simple.clinic.patient.Answer.Unanswered @@ -137,8 +138,8 @@ class LookupPatientOnline @Inject constructor( hasHadStroke = response.medicalHistory.hasHadStroke, hasHadKidneyDisease = response.medicalHistory.hasHadKidneyDisease, diagnosedWithDiabetes = response.medicalHistory.hasDiabetes, - isSmoker = Answer.Unanswered, - cholesterolReading = null, + isSmoker = response.medicalHistory.isSmoker, + cholesterolReading = CholesterolReading(response.medicalHistory.cholesterolValue.toString()), syncStatus = SyncStatus.DONE, createdAt = response.medicalHistory.createdAt, updatedAt = response.medicalHistory.updatedAt, diff --git a/sharedTestCode/src/main/java/org/simple/sharedTestCode/TestData.kt b/sharedTestCode/src/main/java/org/simple/sharedTestCode/TestData.kt index 935376cdcbf..07a3b1f7c36 100644 --- a/sharedTestCode/src/main/java/org/simple/sharedTestCode/TestData.kt +++ b/sharedTestCode/src/main/java/org/simple/sharedTestCode/TestData.kt @@ -788,6 +788,8 @@ object TestData { isOnTreatmentForHypertension: Answer = randomMedicalHistoryAnswer(), isOnDiabetesTreatment: Answer = randomMedicalHistoryAnswer(), hasDiabetes: Answer = randomMedicalHistoryAnswer(), + isSmoker: Answer = randomMedicalHistoryAnswer(), + cholesterolReading: CholesterolReading? = null, createdAt: Instant = Instant.now(), updatedAt: Instant = Instant.now(), deletedAt: Instant? = null @@ -803,6 +805,8 @@ object TestData { hasHadKidneyDisease = hasHadKidneyDisease, hasDiabetes = hasDiabetes, hasHypertension = diagnosedWithHypertension, + isSmoker = isSmoker, + cholesterolValue = cholesterolReading?.value?.toFloatOrNull(), createdAt = createdAt, updatedAt = updatedAt, deletedAt = deletedAt)