Skip to content

Commit

Permalink
Change patient attribute column types
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Jan 3, 2025
1 parent a96e493 commit 1905a61
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions app/schemas/org.simple.clinic.AppDatabase/117.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 117,
"identityHash": "c7c0a757d4b32165ae6b15e7a40eb523",
"identityHash": "44292de9d5773c28b1b893fd8c95dc9b",
"entities": [
{
"tableName": "Patient",
Expand Down Expand Up @@ -2164,7 +2164,7 @@
},
{
"tableName": "PatientAttribute",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `patientUuid` TEXT NOT NULL, `userUuid` TEXT NOT NULL, `syncStatus` TEXT NOT NULL, `height` TEXT NOT NULL, `weight` TEXT NOT NULL, `createdAt` TEXT NOT NULL, `updatedAt` TEXT NOT NULL, `deletedAt` TEXT, PRIMARY KEY(`uuid`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `patientUuid` TEXT NOT NULL, `userUuid` TEXT NOT NULL, `syncStatus` TEXT NOT NULL, `height` REAL NOT NULL, `weight` REAL NOT NULL, `createdAt` TEXT NOT NULL, `updatedAt` TEXT NOT NULL, `deletedAt` TEXT, PRIMARY KEY(`uuid`))",
"fields": [
{
"fieldPath": "uuid",
Expand All @@ -2191,15 +2191,15 @@
"notNull": true
},
{
"fieldPath": "reading.height",
"fieldPath": "bmiReading.height",
"columnName": "height",
"affinity": "TEXT",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "reading.weight",
"fieldPath": "bmiReading.weight",
"columnName": "weight",
"affinity": "TEXT",
"affinity": "REAL",
"notNull": true
},
{
Expand Down Expand Up @@ -2249,7 +2249,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c7c0a757d4b32165ae6b15e7a40eb523')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '44292de9d5773c28b1b893fd8c95dc9b')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ class PatientAttributeRepositoryAndroidTest {
@Test
fun saving_a_patient_attribute_should_work_correctly() {
//given
val bmiReading = BMIReading(height = "177", weight = "64")
val bmiReading = BMIReading(height = 177f, weight = 64f)
val patientAttribute = testData.patientAttribute(reading = bmiReading)

//when
repository.save(
reading = patientAttribute.reading,
bmiReading = patientAttribute.bmiReading,
patientUuid = patientAttribute.patientUuid,
loggedInUserUuid = patientAttribute.userUuid,
uuid = patientAttribute.uuid
)

//then
val savedPatientAttribute = repository.getPatientAttributeImmediate(patientAttribute.patientUuid)!!
assertThat(savedPatientAttribute.reading).isEqualTo(patientAttribute.reading)
assertThat(savedPatientAttribute.bmiReading).isEqualTo(patientAttribute.bmiReading)
assertThat(savedPatientAttribute.patientUuid).isEqualTo(patientAttribute.patientUuid)
assertThat(savedPatientAttribute.userUuid).isEqualTo(patientAttribute.userUuid)
assertThat(savedPatientAttribute.uuid).isEqualTo(patientAttribute.uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class PatientAttributeSyncIntegrationTest {
patientUuid = patientUuid,
userUuid = userUuid,
reading = BMIReading(
height = "177.0",
weight = "68.0"
height = 177f,
weight = 68f
),
syncStatus = SyncStatus.PENDING,
)
Expand Down Expand Up @@ -136,8 +136,8 @@ class PatientAttributeSyncIntegrationTest {
patientUuid = patientUuid,
userUuid = userUuid,
reading = BMIReading(
height = "177",
weight = "68"
height = 177f,
weight = 68f
),
syncStatus = SyncStatus.PENDING,
)
Expand All @@ -148,7 +148,7 @@ class PatientAttributeSyncIntegrationTest {
sync.push()
assertThat(repository.pendingSyncRecordCount().blockingFirst()).isEqualTo(0)

val modifiedRecord = records[1].withReading(BMIReading(height = "182", weight = "78"))
val modifiedRecord = records[1].withReading(BMIReading(height = 182f, weight = 78f))
repository.save(listOf(modifiedRecord))
assertThat(repository.pendingSyncRecordCount().blockingFirst()).isEqualTo(1)

Expand All @@ -169,9 +169,9 @@ class PatientAttributeSyncIntegrationTest {

private fun PatientAttribute.syncCompleted(): PatientAttribute = copy(syncStatus = SyncStatus.DONE)

private fun PatientAttribute.withReading(reading: BMIReading): PatientAttribute {
private fun PatientAttribute.withReading(bmiReading: BMIReading): PatientAttribute {
return copy(
reading = reading.copy(height = reading.height, weight = reading.weight),
bmiReading = bmiReading.copy(height = bmiReading.height, weight = bmiReading.weight),
syncStatus = SyncStatus.PENDING,
timestamps = timestamps.copy(updatedAt = timestamps.updatedAt.plusMillis(1))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class BMIReading(val height: String, val weight: String) : Parcelable
data class BMIReading(val height: Float, val weight: Float) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class PatientAttribute(
val userUuid: UUID,

@Embedded
val reading: BMIReading,
val bmiReading: BMIReading,

@Embedded
val timestamps: Timestamps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PatientAttributeRepository @Inject constructor(
private val utcClock: UtcClock
) : SynceableRepository<PatientAttribute, PatientAttributePayload> {
fun save(
reading: BMIReading,
bmiReading: BMIReading,
patientUuid: UUID,
loggedInUserUuid: UUID,
uuid: UUID,
Expand All @@ -26,7 +26,7 @@ class PatientAttributeRepository @Inject constructor(
uuid = uuid,
patientUuid = patientUuid,
userUuid = loggedInUserUuid,
reading = reading,
bmiReading = bmiReading,
timestamps = Timestamps.create(utcClock),
syncStatus = PENDING
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ data class PatientAttributePayload(
uuid = uuid,
patientUuid = patientUuid,
userUuid = userUuid,
reading = BMIReading(
height = height,
weight = weight
bmiReading = BMIReading(
height = height.toFloat(),
weight = weight.toFloat()
),
timestamps = Timestamps(
createdAt = createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class PatientAttributeSync @Inject constructor(
uuid = uuid,
patientUuid = patientUuid,
userUuid = userUuid,
height = reading.height,
weight = reading.weight,
height = bmiReading.height.toString(),
weight = bmiReading.weight.toString(),
createdAt = timestamps.createdAt,
updatedAt = timestamps.updatedAt,
deletedAt = timestamps.deletedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Migration_117 @Inject constructor() : Migration(116, 117) {
"uuid" TEXT NOT NULL,
"patientUuid" TEXT NOT NULL,
"userUuid" TEXT NOT NULL,
"height" TEXT NOT NULL,
"weight" TEXT NOT NULL,
"height" REAL NOT NULL,
"weight" REAL NOT NULL,
"createdAt" TEXT NOT NULL,
"updatedAt" TEXT NOT NULL,
"deletedAt" TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ object TestData {
uuid = uuid,
patientUuid = patientUuid,
userUuid = userUuid,
reading = reading,
bmiReading = reading,
timestamps = Timestamps(
createdAt, updatedAt, deletedAt
),
Expand Down

0 comments on commit 1905a61

Please sign in to comment.