Merge pull request #2022 from nightscout/notes

notes for carbs
This commit is contained in:
Milos Kozak 2022-09-19 15:54:59 +02:00 committed by GitHub
commit 3c2d4cc126
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 3666 additions and 18 deletions

View file

@ -270,6 +270,10 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider {
}
holder.binding.calculation.tag = ml
var notes = ml.carbs?.notes ?: ml.bolus?.notes ?: ""
holder.binding.notes.text = notes
holder.binding.notes.visibility = if (notes != "") View.VISIBLE else View.GONE
}
override fun getItemCount() = mealLinks.size

View file

@ -88,7 +88,7 @@ class NSClientAddUpdateWorker(
.also { result ->
result.inserted.forEach {
uel.log(
Action.BOLUS, Sources.NSClient,
Action.BOLUS, Sources.NSClient, it.notes,
ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit.Insulin(it.amount)
)
@ -124,7 +124,7 @@ class NSClientAddUpdateWorker(
.also { result ->
result.inserted.forEach {
uel.log(
Action.CARBS, Sources.NSClient,
Action.CARBS, Sources.NSClient, it.notes,
ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit.Gram(it.amount.toInt())
)
@ -140,7 +140,7 @@ class NSClientAddUpdateWorker(
}
result.updated.forEach {
uel.log(
Action.CARBS, Sources.NSClient,
Action.CARBS, Sources.NSClient, it.notes,
ValueWithUnit.Timestamp(it.timestamp),
ValueWithUnit.Gram(it.amount.toInt())
)

View file

@ -544,7 +544,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
// **** Various treatment buttons ****
binding.buttonsLayout.carbsButton.visibility =
((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) && profile != null
(/*(!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) &&*/ profile != null
&& sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility()
binding.buttonsLayout.treatmentButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null
&& sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility()

View file

@ -91,7 +91,7 @@ open class VirtualPumpPlugin @Inject constructor(
it.basalStep = 0.01
it.basalMinimumRate = 0.01
it.isRefillingCapable = true
it.storesCarbInfo = false
//it.storesCarbInfo = false
it.is30minBasalRatesCapable = true
}

View file

@ -232,10 +232,10 @@ class CommandQueueImplementation @Inject constructor(
var carbsRunnable = Runnable { }
val originalCarbs = detailedBolusInfo.carbs
if ((detailedBolusInfo.carbs > 0) &&
if ((detailedBolusInfo.carbs > 0) /*&&
(!activePlugin.activePump.pumpDescription.storesCarbInfo ||
detailedBolusInfo.carbsDuration != 0L ||
(detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp) > dateUtil.now())
(detailedBolusInfo.carbsTimestamp ?: detailedBolusInfo.timestamp) > dateUtil.now())*/
) {
carbsRunnable = Runnable {
aapsLogger.debug(LTag.PUMPQUEUE, "Going to store carbs")

View file

@ -271,6 +271,16 @@
</LinearLayout>
<TextView
android:id="@+id/notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="20dp"
android:paddingEnd="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="RtlSymmetry"
tools:text="Notes" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View file

@ -107,7 +107,8 @@ class DetailedBolusInfo {
Bolus(
timestamp = bolusTimestamp ?: timestamp,
amount = insulin,
type = bolusType.toDBbBolusType()
type = bolusType.toDBbBolusType(),
notes = notes,
)
else null
@ -116,7 +117,8 @@ class DetailedBolusInfo {
Carbs(
timestamp = carbsTimestamp ?: timestamp,
amount = carbs,
duration = carbsDuration
duration = carbsDuration,
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

@ -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

@ -33,7 +33,7 @@ class PumpDescription() {
var basalMaximumRate = 0.0
var isRefillingCapable = false
var isBatteryReplaceable = false
var storesCarbInfo = false
//var storesCarbInfo = false
var is30minBasalRatesCapable = false
var supportsTDDs = false
var needsManualTDDLoad = false
@ -41,7 +41,7 @@ class PumpDescription() {
var isPatchPump = false
var useHardwareLink = false
fun resetSettings() {
private fun resetSettings() {
isBolusCapable = true
bolusStep = 0.1
isExtendedBolusCapable = true
@ -65,7 +65,7 @@ class PumpDescription() {
is30minBasalRatesCapable = false
isRefillingCapable = true
isBatteryReplaceable = true
storesCarbInfo = false
//storesCarbInfo = false
supportsTDDs = false
needsManualTDDLoad = true
hasCustomUnreachableAlertCheck = false
@ -101,7 +101,7 @@ class PumpDescription() {
basalMinimumRate = pumpType.baseBasalMinValue
isRefillingCapable = pumpCapability.hasCapability(PumpCapability.Refill)
isBatteryReplaceable = pumpCapability.hasCapability(PumpCapability.ReplaceBattery)
storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo)
//storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo)
supportsTDDs = pumpCapability.hasCapability(PumpCapability.TDD)
needsManualTDDLoad = pumpCapability.hasCapability(PumpCapability.ManualTDDLoad)
is30minBasalRatesCapable = pumpCapability.hasCapability(PumpCapability.BasalRate30min)

View file

@ -8,7 +8,7 @@ enum class PumpCapability {
BasalProfileSet, // isSetBasalProfileCapable
Refill, // isRefillingCapable
ReplaceBattery, // isBatteryReplaceable
StoreCarbInfo, // storesCarbInfo
// StoreCarbInfo, // removed. incompatible with storing notes with carbs
TDD, // supportsTDDs
ManualTDDLoad, // needsManualTDDLoad
BasalRate30min, // is30minBasalRatesCapable
@ -18,7 +18,8 @@ enum class PumpCapability {
VirtualPumpCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery)),
ComboCapabilities(arrayOf(Bolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, TDD, ManualTDDLoad)),
DanaCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, TDD, ManualTDDLoad)),
DanaWithHistoryCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, StoreCarbInfo, TDD, ManualTDDLoad)),
//DanaWithHistoryCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, StoreCarbInfo, TDD, ManualTDDLoad)),
DanaWithHistoryCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, TDD, ManualTDDLoad)),
InsightCapabilities(arrayOf(Bolus, ExtendedBolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, TDD, BasalRate30min)),
MedtronicCapabilities(arrayOf(Bolus, TempBasal, BasalProfileSet, Refill, ReplaceBattery, TDD)),
OmnipodCapabilities(arrayOf(Bolus, TempBasal, BasalProfileSet, BasalRate30min)),

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@ import androidx.room.TypeConverters
import info.nightscout.androidaps.database.daos.*
import info.nightscout.androidaps.database.entities.*
const val DATABASE_VERSION = 21
const val DATABASE_VERSION = 22
@Database(version = DATABASE_VERSION,
entities = [APSResult::class, Bolus::class, BolusCalculatorResult::class, Carbs::class,

View file

@ -27,6 +27,7 @@ open class DatabaseModule {
// .addMigrations(migration7to8)
// .addMigrations(migration11to12)
.addMigrations(migration20to21)
.addMigrations(migration21to22)
.addCallback(object : Callback() {
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
@ -34,6 +35,7 @@ open class DatabaseModule {
}
})
.fallbackToDestructiveMigration()
.fallbackToDestructiveMigrationOnDowngrade()
.build()
@Qualifier
@ -69,4 +71,13 @@ 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")
// Custom indexes must be dropped on migration to pass room schema checking after upgrade
dropCustomIndexes(database)
}
}
}

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 == other.notes &&
isBasalInsulin == other.isBasalInsulin
fun onlyNsIdAdded(previous: Bolus): Boolean =

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

@ -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

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
))