same notes for boluses

This commit is contained in:
Sergey Zorchenko 2022-06-21 09:00:32 +03:00
parent 1e55890ff7
commit 126c90024b
6 changed files with 20 additions and 5 deletions

View file

@ -107,7 +107,8 @@ class DetailedBolusInfo {
Bolus(
timestamp = bolusTimestamp ?: timestamp,
amount = insulin,
type = bolusType.toDBbBolusType()
type = bolusType.toDBbBolusType(),
notes = notes,
)
else null

View file

@ -30,6 +30,7 @@ fun Bolus.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
.put("created_at", dateUtil.toISOString(timestamp))
.put("date", timestamp)
.put("type", type.name)
.put("notes", notes)
.put("isValid", isValid)
.put("isSMB", type == Bolus.Type.SMB).also {
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
@ -55,6 +56,7 @@ fun bolusFromJson(jsonObject: JSONObject): Bolus? {
val amount = JsonHelper.safeGetDoubleAllowNull(jsonObject, "insulin") ?: return null
val type = Bolus.Type.fromString(JsonHelper.safeGetString(jsonObject, "type"))
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
val notes = JsonHelper.safeGetStringAllowNull(jsonObject, "notes", null)
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null) ?: return null
val pumpId = JsonHelper.safeGetLongAllowNull(jsonObject, "pumpId", null)
val pumpType = InterfaceIDs.PumpType.fromString(JsonHelper.safeGetStringAllowNull(jsonObject, "pumpType", null))
@ -67,7 +69,8 @@ fun bolusFromJson(jsonObject: JSONObject): Bolus? {
timestamp = timestamp,
amount = amount,
type = type,
isValid = isValid
notes = notes,
isValid = isValid,
).also {
it.interfaceIDs.nightscoutId = id
it.interfaceIDs.pumpId = pumpId

View file

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 22,
"identityHash": "8e5c513355bfdf0d24e72eedc263f0c3",
"identityHash": "09121464fb795b3c37bb1c2c2c3ea481",
"entities": [
{
"tableName": "apsResults",
@ -193,7 +193,7 @@
},
{
"tableName": "boluses",
"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, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `isBasalInsulin` INTEGER NOT NULL, `nightscoutSystemId` TEXT, `nightscoutId` TEXT, `pumpType` TEXT, `pumpSerial` TEXT, `temporaryId` INTEGER, `pumpId` INTEGER, `startId` INTEGER, `endId` INTEGER, `insulinLabel` TEXT, `insulinEndTime` INTEGER, `peak` INTEGER, FOREIGN KEY(`referenceId`) REFERENCES `boluses`(`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, `amount` REAL NOT NULL, `type` TEXT NOT NULL, `notes` TEXT, `isBasalInsulin` INTEGER NOT NULL, `nightscoutSystemId` TEXT, `nightscoutId` TEXT, `pumpType` TEXT, `pumpSerial` TEXT, `temporaryId` INTEGER, `pumpId` INTEGER, `startId` INTEGER, `endId` INTEGER, `insulinLabel` TEXT, `insulinEndTime` INTEGER, `peak` INTEGER, FOREIGN KEY(`referenceId`) REFERENCES `boluses`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"fields": [
{
"fieldPath": "id",
@ -249,6 +249,12 @@
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "notes",
"columnName": "notes",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isBasalInsulin",
"columnName": "isBasalInsulin",
@ -3593,7 +3599,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, '8e5c513355bfdf0d24e72eedc263f0c3')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '09121464fb795b3c37bb1c2c2c3ea481')"
]
}
}

View file

@ -73,6 +73,7 @@ open class DatabaseModule {
private val migration21to22 = object : Migration(21,22) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE `carbs` ADD COLUMN `notes` TEXT")
database.execSQL("ALTER TABLE `boluses` ADD COLUMN `notes` TEXT")
}
}

View file

@ -44,6 +44,7 @@ data class Bolus(
override var utcOffset: Long = TimeZone.getDefault().getOffset(timestamp).toLong(),
var amount: Double,
var type: Type,
var notes: String? = null,
var isBasalInsulin: Boolean = false,
@Embedded
var insulinConfiguration: InsulinConfiguration? = null
@ -55,6 +56,7 @@ data class Bolus(
utcOffset == other.utcOffset &&
amount == other.amount &&
type == other.type &&
notes == notes &&
isBasalInsulin == other.isBasalInsulin
fun onlyNsIdAdded(previous: Bolus): Boolean =

View file

@ -15,6 +15,7 @@ class InsertOrUpdateBolusTransaction(
timestamp: Long,
amount: Double,
type: Bolus.Type,
notes: String? = null,
isBasalInsulin: Boolean = false,
insulinConfiguration: InsulinConfiguration? = null,
interfaceIDs_backing: InterfaceIDs? = null
@ -22,6 +23,7 @@ class InsertOrUpdateBolusTransaction(
timestamp = timestamp,
amount = amount,
type = type,
notes = notes,
isBasalInsulin = isBasalInsulin,
insulinConfiguration = insulinConfiguration,
interfaceIDs_backing = interfaceIDs_backing