1+ /* eslint-disable no-unused-expressions */
12import getAGPFigures from '@tidepool/viz/dist/getAGPFigures.js' ;
23import vizDataUtil from '@tidepool/viz/dist/data.js' ;
34import { Blob } from 'buffer' ;
@@ -51,6 +52,22 @@ class Report {
5152 settings : 'settings' ,
5253 } ;
5354
55+ #commonStats = {
56+ averageGlucose : 'averageGlucose' ,
57+ averageDailyDose : 'averageDailyDose' ,
58+ bgExtents : 'bgExtents' ,
59+ carbs : 'carbs' ,
60+ coefficientOfVariation : 'coefficientOfVariation' ,
61+ glucoseManagementIndicator : 'glucoseManagementIndicator' ,
62+ readingsInRange : 'readingsInRange' ,
63+ sensorUsage : 'sensorUsage' ,
64+ standardDev : 'standardDev' ,
65+ timeInAuto : 'timeInAuto' ,
66+ timeInOverride : 'timeInOverride' ,
67+ timeInRange : 'timeInRange' ,
68+ totalInsulin : 'totalInsulin' ,
69+ } ;
70+
5471 #reports = [ this . #reportTypes. all ] ;
5572
5673 #reportDates;
@@ -156,24 +173,88 @@ class Report {
156173 } ;
157174 }
158175
159- buildReportQueries ( ) {
176+ getStatsByChartType ( chartType , data ) {
177+ const bgSource = _ . get ( data , 'metaData.bgSources.current' ) ;
178+ const cbgSelected = bgSource === 'cbg' ;
179+ const smbgSelected = bgSource === 'smbg' ;
180+ const isAutomatedBasalDevice = _ . get ( data , 'metaData.latestPumpUpload.isAutomatedBasalDevice' ) ;
181+ const isSettingsOverrideDevice = _ . get ( data , 'metaData.latestPumpUpload.isSettingsOverrideDevice' ) ;
182+
183+ const stats = [ ] ;
184+
185+ switch ( chartType ) {
186+ case 'basics' :
187+ cbgSelected && stats . push ( this . #commonStats. timeInRange ) ;
188+ smbgSelected && stats . push ( this . #commonStats. readingsInRange ) ;
189+ stats . push ( this . #commonStats. averageGlucose ) ;
190+ cbgSelected && stats . push ( this . #commonStats. sensorUsage ) ;
191+ stats . push ( this . #commonStats. totalInsulin ) ;
192+ isAutomatedBasalDevice && stats . push ( this . #commonStats. timeInAuto ) ;
193+ isSettingsOverrideDevice && stats . push ( this . #commonStats. timeInOverride ) ;
194+ stats . push ( this . #commonStats. carbs ) ;
195+ stats . push ( this . #commonStats. averageDailyDose ) ;
196+ cbgSelected && stats . push ( this . #commonStats. glucoseManagementIndicator ) ;
197+ stats . push ( this . #commonStats. standardDev ) ;
198+ stats . push ( this . #commonStats. coefficientOfVariation ) ;
199+ stats . push ( this . #commonStats. bgExtents ) ;
200+ break ;
201+
202+ case 'daily' :
203+ cbgSelected && stats . push ( this . #commonStats. timeInRange ) ;
204+ smbgSelected && stats . push ( this . #commonStats. readingsInRange ) ;
205+ stats . push ( this . #commonStats. averageGlucose ) ;
206+ stats . push ( this . #commonStats. totalInsulin ) ;
207+ isAutomatedBasalDevice && stats . push ( this . #commonStats. timeInAuto ) ;
208+ isSettingsOverrideDevice && stats . push ( this . #commonStats. timeInOverride ) ;
209+ stats . push ( this . #commonStats. carbs ) ;
210+ cbgSelected && stats . push ( this . #commonStats. standardDev ) ;
211+ cbgSelected && stats . push ( this . #commonStats. coefficientOfVariation ) ;
212+ break ;
213+
214+ case 'bgLog' :
215+ stats . push ( this . #commonStats. readingsInRange ) ;
216+ stats . push ( this . #commonStats. averageGlucose ) ;
217+ stats . push ( this . #commonStats. standardDev ) ;
218+ stats . push ( this . #commonStats. coefficientOfVariation ) ;
219+ break ;
220+
221+ case 'agp' :
222+ stats . push ( this . #commonStats. timeInRange ) ;
223+ stats . push ( this . #commonStats. averageGlucose ) ;
224+ stats . push ( this . #commonStats. sensorUsage ) ;
225+ stats . push ( this . #commonStats. glucoseManagementIndicator ) ;
226+ stats . push ( this . #commonStats. coefficientOfVariation ) ;
227+ break ;
228+
229+ case 'trends' :
230+ cbgSelected && stats . push ( this . #commonStats. timeInRange ) ;
231+ smbgSelected && stats . push ( this . #commonStats. readingsInRange ) ;
232+ stats . push ( this . #commonStats. averageGlucose ) ;
233+ cbgSelected && stats . push ( this . #commonStats. sensorUsage ) ;
234+ stats . push ( this . #commonStats. totalInsulin ) ;
235+ stats . push ( this . #commonStats. averageDailyDose ) ;
236+ isAutomatedBasalDevice && stats . push ( this . #commonStats. timeInAuto ) ;
237+ isSettingsOverrideDevice && stats . push ( this . #commonStats. timeInOverride ) ;
238+ cbgSelected && stats . push ( this . #commonStats. glucoseManagementIndicator ) ;
239+ stats . push ( this . #commonStats. standardDev ) ;
240+ stats . push ( this . #commonStats. coefficientOfVariation ) ;
241+ stats . push ( this . #commonStats. bgExtents ) ;
242+ break ;
243+
244+ default :
245+ break ;
246+ }
247+
248+ return stats ;
249+ }
250+
251+ buildReportQueries ( { data } ) {
160252 const dataQueries = {
161253 basics : {
162254 endpoints : [ ] ,
163255 aggregationsByDate : 'basals, boluses, fingersticks, siteChanges' ,
164256 bgSource : 'cbg' ,
165- stats : [
166- 'timeInRange' ,
167- 'averageGlucose' ,
168- 'sensorUsage' ,
169- 'totalInsulin' ,
170- 'carbs' ,
171- 'averageDailyDose' ,
172- 'glucoseManagementIndicator' ,
173- 'standardDev' ,
174- 'coefficientOfVariation' ,
175- 'bgExtents' ,
176- ] ,
257+ stats : this . getStatsByChartType ( 'basics' , data ) ,
177258 excludeDaysWithoutBolus : false ,
178259 bgPrefs : this . getBGPrefs ( ) ,
179260 metaData : 'latestPumpUpload, bgSources' ,
@@ -183,12 +264,7 @@ class Report {
183264 bgLog : {
184265 endpoints : [ ] ,
185266 aggregationsByDate : 'dataByDate' ,
186- stats : [
187- 'readingsInRange' ,
188- 'averageGlucose' ,
189- 'standardDev' ,
190- 'coefficientOfVariation' ,
191- ] ,
267+ stats : this . getStatsByChartType ( 'bgLog' , data ) ,
192268 types : {
193269 smbg : { } ,
194270 } ,
@@ -201,14 +277,7 @@ class Report {
201277 daily : {
202278 endpoints : [ ] ,
203279 aggregationsByDate : 'dataByDate, statsByDate' ,
204- stats : [
205- 'timeInRange' ,
206- 'averageGlucose' ,
207- 'totalInsulin' ,
208- 'carbs' ,
209- 'standardDev' ,
210- 'coefficientOfVariation' ,
211- ] ,
280+ stats : this . getStatsByChartType ( 'daily' , data ) ,
212281 types : {
213282 basal : { } ,
214283 bolus : { } ,
@@ -229,13 +298,7 @@ class Report {
229298 endpoints : [ ] ,
230299 aggregationsByDate : 'dataByDate, statsByDate' ,
231300 bgSource : 'cbg' ,
232- stats : [
233- 'timeInRange' ,
234- 'averageGlucose' ,
235- 'sensorUsage' ,
236- 'glucoseManagementIndicator' ,
237- 'coefficientOfVariation' ,
238- ] ,
301+ stats : this . getStatsByChartType ( 'agp' , data ) ,
239302 types : {
240303 cbg : { } ,
241304 } ,
@@ -497,7 +560,7 @@ class Report {
497560 getReportOptions ( data ) {
498561 const datesByReport = this . getDateRangeByReport ( { data } ) ;
499562
500- const reportQueries = this . buildReportQueries ( ) ;
563+ const reportQueries = this . buildReportQueries ( { data } ) ;
501564
502565 const printOptions = {
503566 agp : {
0 commit comments