Merge pull request 'Show estimated HbA1c in mmol/mol (IFCC) alongside % (#25)' (#27) from dev into main
This commit was merged in pull request #27.
This commit is contained in:
@@ -4,6 +4,7 @@ import streamlit as st
|
|||||||
from auth import require_auth
|
from auth import require_auth
|
||||||
from nightscout_client import NightscoutConfigError
|
from nightscout_client import NightscoutConfigError
|
||||||
from reporting import (
|
from reporting import (
|
||||||
|
gmi_mmol_per_mol,
|
||||||
gmi_percent,
|
gmi_percent,
|
||||||
percent_cv,
|
percent_cv,
|
||||||
sensor_active_percent,
|
sensor_active_percent,
|
||||||
@@ -43,6 +44,7 @@ active_pct = sensor_active_percent(glucose, start, end)
|
|||||||
|
|
||||||
mean_mmol = glucose["mmol"].mean()
|
mean_mmol = glucose["mmol"].mean()
|
||||||
gmi = gmi_percent(mean_mmol)
|
gmi = gmi_percent(mean_mmol)
|
||||||
|
gmi_mmol_mol = gmi_mmol_per_mol(gmi)
|
||||||
cv = percent_cv(glucose)
|
cv = percent_cv(glucose)
|
||||||
tir = tir_breakdown_5band(glucose)
|
tir = tir_breakdown_5band(glucose)
|
||||||
|
|
||||||
@@ -50,7 +52,11 @@ st.subheader("Kerncijfers")
|
|||||||
col1, col2, col3, col4 = st.columns(4)
|
col1, col2, col3, col4 = st.columns(4)
|
||||||
col1.metric("Sensordekking", f"{active_pct:.0f}%", help="Streefwaarde: ≥70%")
|
col1.metric("Sensordekking", f"{active_pct:.0f}%", help="Streefwaarde: ≥70%")
|
||||||
col2.metric("Gemiddelde glucose", f"{mean_mmol:.1f} mmol/L")
|
col2.metric("Gemiddelde glucose", f"{mean_mmol:.1f} mmol/L")
|
||||||
col3.metric("Geschat HbA1c (GMI)", f"{gmi:.1f}%", help="Bergenstal et al. 2018 — geen labwaarde")
|
col3.metric(
|
||||||
|
"Geschat HbA1c (GMI)",
|
||||||
|
f"{gmi:.1f}% ({gmi_mmol_mol:.0f} mmol/mol)",
|
||||||
|
help="Bergenstal et al. 2018 — geen labwaarde",
|
||||||
|
)
|
||||||
col4.metric("Variabiliteit (%CV)", f"{cv:.0f}%", help="Streefwaarde: ≤36%")
|
col4.metric("Variabiliteit (%CV)", f"{cv:.0f}%", help="Streefwaarde: ≤36%")
|
||||||
|
|
||||||
st.subheader("Tijd in bereik (5 klinische banden)")
|
st.subheader("Tijd in bereik (5 klinische banden)")
|
||||||
|
|||||||
+3
-1
@@ -28,6 +28,7 @@ from reporting import (
|
|||||||
agp_percentile_bands,
|
agp_percentile_bands,
|
||||||
completeness_warning,
|
completeness_warning,
|
||||||
detect_events,
|
detect_events,
|
||||||
|
gmi_mmol_per_mol,
|
||||||
gmi_percent,
|
gmi_percent,
|
||||||
percent_cv,
|
percent_cv,
|
||||||
sensor_active_percent,
|
sensor_active_percent,
|
||||||
@@ -178,7 +179,8 @@ def _add_summary_section(pdf: FPDF, glucose: pd.DataFrame, start, end) -> None:
|
|||||||
pdf.set_font("Helvetica", "", 11)
|
pdf.set_font("Helvetica", "", 11)
|
||||||
pdf.cell(0, 6, f"Sensordekking: {active_pct:.0f}%", **_LINE_KWARGS)
|
pdf.cell(0, 6, f"Sensordekking: {active_pct:.0f}%", **_LINE_KWARGS)
|
||||||
pdf.cell(0, 6, f"Gemiddelde glucose: {mean_mmol:.1f} mmol/L", **_LINE_KWARGS)
|
pdf.cell(0, 6, f"Gemiddelde glucose: {mean_mmol:.1f} mmol/L", **_LINE_KWARGS)
|
||||||
pdf.cell(0, 6, f"Geschat HbA1c (GMI): {gmi_percent(mean_mmol):.1f}%", **_LINE_KWARGS)
|
gmi = gmi_percent(mean_mmol)
|
||||||
|
pdf.cell(0, 6, f"Geschat HbA1c (GMI): {gmi:.1f}% ({gmi_mmol_per_mol(gmi):.0f} mmol/mol)", **_LINE_KWARGS)
|
||||||
pdf.cell(0, 6, f"Variabiliteit (%CV): {percent_cv(glucose):.0f}%", **_LINE_KWARGS)
|
pdf.cell(0, 6, f"Variabiliteit (%CV): {percent_cv(glucose):.0f}%", **_LINE_KWARGS)
|
||||||
pdf.ln(2)
|
pdf.ln(2)
|
||||||
pdf.cell(0, 6, f"Zeer laag (<3.0 mmol/L): {tir['very_low']:.0f}%", **_LINE_KWARGS)
|
pdf.cell(0, 6, f"Zeer laag (<3.0 mmol/L): {tir['very_low']:.0f}%", **_LINE_KWARGS)
|
||||||
|
|||||||
@@ -36,6 +36,17 @@ def gmi_percent(mean_mmol: float) -> float:
|
|||||||
return round(3.31 + 0.4311 * mean_mmol, 1)
|
return round(3.31 + 0.4311 * mean_mmol, 1)
|
||||||
|
|
||||||
|
|
||||||
|
def gmi_mmol_per_mol(gmi_pct: float) -> int:
|
||||||
|
"""Zet een GMI-percentage (DCCT/NGSP) om naar IFCC mmol/mol.
|
||||||
|
|
||||||
|
mmol/mol = 10.929 x (% - 2.15) — de standaard IFCC-omrekening
|
||||||
|
(Hoelzel et al. 2004, Clin Chem 50(1):166-174), gangbare eenheid in
|
||||||
|
Nederlandse labuitslagen naast het %-getal (gitea #25). Bijv. 6.5% =
|
||||||
|
48 mmol/mol, de bekende diagnostische drempel.
|
||||||
|
"""
|
||||||
|
return round(10.929 * (gmi_pct - 2.15))
|
||||||
|
|
||||||
|
|
||||||
GMI_TREND_COLUMNS = ["date", "gmi", "rolling_avg", "trend", "trend_lower", "trend_upper"]
|
GMI_TREND_COLUMNS = ["date", "gmi", "rolling_avg", "trend", "trend_lower", "trend_upper"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from reporting import (
|
|||||||
daily_gmi,
|
daily_gmi,
|
||||||
day_of_week_pattern,
|
day_of_week_pattern,
|
||||||
detect_events,
|
detect_events,
|
||||||
|
gmi_mmol_per_mol,
|
||||||
gmi_percent,
|
gmi_percent,
|
||||||
gmi_trend,
|
gmi_trend,
|
||||||
minutes_per_day,
|
minutes_per_day,
|
||||||
@@ -35,6 +36,12 @@ def test_gmi_percent_matches_bergenstal_formula():
|
|||||||
assert gmi_percent(7.0) == pytest.approx(6.3, abs=0.05)
|
assert gmi_percent(7.0) == pytest.approx(6.3, abs=0.05)
|
||||||
|
|
||||||
|
|
||||||
|
def test_gmi_mmol_per_mol_matches_known_ifcc_reference_values():
|
||||||
|
# 6.5% is de bekende diagnostische drempel = 48 mmol/mol (IFCC).
|
||||||
|
assert gmi_mmol_per_mol(6.5) == 48
|
||||||
|
assert gmi_mmol_per_mol(7.0) == 53
|
||||||
|
|
||||||
|
|
||||||
def test_daily_gmi_aggregates_per_calendar_day():
|
def test_daily_gmi_aggregates_per_calendar_day():
|
||||||
glucose = _series(
|
glucose = _series(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user