fix carbs entry notes field

This commit is contained in:
Sergey Zorchenko 2022-06-18 22:01:36 +03:00
parent f0a37d64f3
commit 1588df7ffe
5 changed files with 20 additions and 5 deletions

View file

@ -116,7 +116,8 @@ class DetailedBolusInfo {
Carbs(
timestamp = carbsTimestamp ?: timestamp,
amount = carbs,
duration = carbsDuration
duration = carbsDuration,
notes = notes,
)
else null

View file

@ -11,6 +11,7 @@ fun Carbs.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
JSONObject()
.put("eventType", if (amount < 12) TherapyEvent.Type.CARBS_CORRECTION.text else TherapyEvent.Type.MEAL_BOLUS.text)
.put("carbs", amount)
.put("notes", notes)
.put("created_at", dateUtil.toISOString(timestamp))
.put("isValid", isValid)
.put("date", timestamp).also {
@ -29,6 +30,7 @@ fun carbsFromNsIdForInvalidating(nsId: String): Carbs =
JSONObject()
.put("mills", 1)
.put("carbs", -1.0)
.put("notes", null)
.put("_id", nsId)
.put("isValid", false)
)!!
@ -37,6 +39,7 @@ fun carbsFromJson(jsonObject: JSONObject): Carbs? {
val timestamp = JsonHelper.safeGetLongAllowNull(jsonObject, "mills", null) ?: return null
val duration = JsonHelper.safeGetLong(jsonObject, "duration")
val amount = JsonHelper.safeGetDoubleAllowNull(jsonObject, "carbs") ?: return null
val notes = JsonHelper.safeGetStringAllowNull(jsonObject, "notes", null)
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
val pumpId = JsonHelper.safeGetLongAllowNull(jsonObject, "pumpId", null)
@ -50,6 +53,7 @@ fun carbsFromJson(jsonObject: JSONObject): Carbs? {
timestamp = timestamp,
duration = duration,
amount = amount,
notes = notes,
isValid = isValid
).also {
it.interfaceIDs.nightscoutId = id

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 21,
"identityHash": "e3558dc3bb3136c37dba4f90c97e8bdd",
"identityHash": "8e5c513355bfdf0d24e72eedc263f0c3",
"entities": [
{
"tableName": "apsResults",
@ -733,7 +733,7 @@
},
{
"tableName": "carbs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `version` INTEGER NOT NULL, `dateCreated` INTEGER NOT NULL, `isValid` INTEGER NOT NULL, `referenceId` INTEGER, `timestamp` INTEGER NOT NULL, `utcOffset` INTEGER NOT NULL, `duration` INTEGER NOT NULL, `amount` REAL NOT NULL, `nightscoutSystemId` TEXT, `nightscoutId` TEXT, `pumpType` TEXT, `pumpSerial` TEXT, `temporaryId` INTEGER, `pumpId` INTEGER, `startId` INTEGER, `endId` INTEGER, FOREIGN KEY(`referenceId`) REFERENCES `carbs`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `version` INTEGER NOT NULL, `dateCreated` INTEGER NOT NULL, `isValid` INTEGER NOT NULL, `referenceId` INTEGER, `timestamp` INTEGER NOT NULL, `utcOffset` INTEGER NOT NULL, `duration` INTEGER NOT NULL, `amount` REAL NOT NULL, `notes` TEXT, `nightscoutSystemId` TEXT, `nightscoutId` TEXT, `pumpType` TEXT, `pumpSerial` TEXT, `temporaryId` INTEGER, `pumpId` INTEGER, `startId` INTEGER, `endId` INTEGER, FOREIGN KEY(`referenceId`) REFERENCES `carbs`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"fields": [
{
"fieldPath": "id",
@ -789,6 +789,12 @@
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "notes",
"columnName": "notes",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "interfaceIDs_backing.nightscoutSystemId",
"columnName": "nightscoutSystemId",
@ -3587,7 +3593,7 @@
"views": [],
"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, 'e3558dc3bb3136c37dba4f90c97e8bdd')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8e5c513355bfdf0d24e72eedc263f0c3')"
]
}
}

View file

@ -35,7 +35,8 @@ data class Carbs(
override var timestamp: Long,
override var utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong(),
override var duration: Long, // in milliseconds
var amount: Double
var amount: Double,
var notes: String? = null
) : TraceableDBEntry, DBEntryWithTimeAndDuration {
private fun contentEqualsTo(other: Carbs): Boolean =
@ -43,6 +44,7 @@ data class Carbs(
timestamp == other.timestamp &&
utcOffset == other.utcOffset &&
amount == other.amount &&
notes == other.notes &&
duration == other.duration
fun onlyNsIdAdded(previous: Carbs): Boolean =

View file

@ -14,11 +14,13 @@ class InsertOrUpdateCarbsTransaction(
timestamp: Long,
amount: Double,
duration: Long,
notes: String,
interfaceIDs_backing: InterfaceIDs? = null
) : this(Carbs(
timestamp = timestamp,
amount = amount,
duration = duration,
notes = notes,
interfaceIDs_backing = interfaceIDs_backing
))