-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
708 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,121 @@ | ||
import logger from './utils'; | ||
import bolus from './bolus'; | ||
import basal from './basal'; | ||
import cortisone from './cortisone'; | ||
import alcohol from './alcohol'; | ||
import carbs from './carbs'; | ||
import liverRun from './liver'; | ||
import sgv from './sgv'; | ||
import pump from './pump'; | ||
import { MainParams, SimulationResult } from './Types'; | ||
import moment = require('moment'); | ||
import { physicalIsf, physicalLiver } from './physical'; | ||
import { transformNoteTreatmentsDrug } from './drug'; | ||
/** | ||
* Simulation module for blood glucose data calculation. | ||
* @param params - Main parameters for running the simulation. | ||
* @returns Simulation result containing blood glucose data and other parameters. | ||
*/ | ||
const simulator = (params: MainParams): SimulationResult => { | ||
const { | ||
patient, | ||
entries, | ||
treatments, | ||
profiles, //PUMP SIMULATION | ||
pumpEnabled, | ||
activities, //7-DAYS | ||
user, | ||
} = params; | ||
logger.info(user.nsUrl + ' Run Init CGMSim NSUrl:%o', user.nsUrl); | ||
|
||
if (!treatments) { | ||
throw new Error('treatments is ' + treatments); | ||
} | ||
if (!profiles) { | ||
throw new Error('profiles is ' + profiles); | ||
} | ||
|
||
const isfConstant = patient.ISF; | ||
const age = patient.AGE; | ||
const gender = patient.GENDER; | ||
const tz = patient?.TZ || 'UTC'; | ||
|
||
let isfActivityDependent = isfConstant; | ||
let liverActivityFactor = 1; | ||
if (isfActivityDependent < 9) { | ||
throw new Error('Isf must be greater than or equal to 9'); | ||
} | ||
if (activities && activities.length > 0) { | ||
isfActivityDependent = isfConstant * physicalIsf(activities, age, gender); | ||
liverActivityFactor = physicalLiver(activities, age, gender); | ||
} | ||
|
||
const weight = patient.WEIGHT; | ||
const dia = patient.DIA; | ||
const peak = patient.TP; | ||
const carbsAbs = patient.CARBS_ABS_TIME; | ||
const cr = patient.CR; | ||
|
||
//Find basal boluses | ||
const drugs = transformNoteTreatmentsDrug(treatments); | ||
|
||
const activeDrugTreatments = drugs.filter(function (e) { | ||
return e.minutesAgo <= 45 * 60; // keep only the basals from the last 45 hours | ||
}); | ||
|
||
const bolusActivity = bolus(treatments, dia, peak); | ||
const basalBolusActivity = basal(activeDrugTreatments, weight); | ||
const cortisoneActivity = cortisone(activeDrugTreatments, weight); | ||
const alcoholActivity = alcohol(activeDrugTreatments, weight, gender); | ||
const basalPumpActivity = pumpEnabled | ||
? pump(treatments, profiles, dia, peak) | ||
: 0; | ||
const carbsActivity = carbs(treatments, carbsAbs, isfActivityDependent, cr); | ||
|
||
//activity calc carb | ||
const liverActivity = liverRun( | ||
isfConstant, | ||
cr, | ||
{ | ||
physical: liverActivityFactor, | ||
alcohol: alcoholActivity, | ||
}, | ||
weight, | ||
tz, | ||
); | ||
|
||
const now = moment(); | ||
const orderedEntries = entries | ||
.filter((e) => e.mills <= now.toDate().getTime()) | ||
.sort((a, b) => b.mills - a.mills); | ||
|
||
const newSgvValue = sgv( | ||
orderedEntries, | ||
{ | ||
basalActivity: basalBolusActivity + basalPumpActivity, | ||
liverActivity, | ||
carbsActivity, | ||
bolusActivity, | ||
cortisoneActivity, | ||
alcoholActivity, | ||
}, | ||
isfActivityDependent, | ||
); | ||
|
||
logger.info(user.nsUrl + 'this is the simulator result: %o', { | ||
...newSgvValue, | ||
physicalISF: isfActivityDependent / isfConstant, | ||
physicalLiver: liverActivityFactor, | ||
}); | ||
|
||
// const arrows = arrowsRun([newSgvValue, ...entries]); | ||
|
||
return { | ||
...newSgvValue, | ||
activityFactor: liverActivityFactor, | ||
isf: { dynamic: isfActivityDependent, constant: isfConstant }, | ||
}; | ||
}; | ||
|
||
export default simulator; | ||
import logger from './utils'; | ||
import bolus from './bolus'; | ||
import basal from './basal'; | ||
import cortisone from './cortisone'; | ||
import alcohol from './alcohol'; | ||
import carbs from './carbs'; | ||
import liverRun from './liver'; | ||
import sgv from './sgv'; | ||
import pump from './pump'; | ||
import { MainParams, SimulationResult } from './Types'; | ||
import moment = require('moment'); | ||
import { physicalIsf, physicalLiver } from './physical'; | ||
import { transformNoteTreatmentsDrug } from './drug'; | ||
/** | ||
* Simulation module for blood glucose data calculation. | ||
* @param params - Main parameters for running the simulation. | ||
* @returns Simulation result containing blood glucose data and other parameters. | ||
*/ | ||
const simulator = (params: MainParams): SimulationResult => { | ||
const { | ||
patient, | ||
entries, | ||
treatments, | ||
profiles, //PUMP SIMULATION | ||
pumpEnabled, | ||
activities, //7-DAYS | ||
user, | ||
} = params; | ||
logger.info(user.nsUrl + ' Run Init CGMSim NSUrl:%o', user.nsUrl); | ||
|
||
if (!treatments) { | ||
throw new Error('treatments is ' + treatments); | ||
} | ||
if (!profiles) { | ||
throw new Error('profiles is ' + profiles); | ||
} | ||
if (patient.ISF < 9) { | ||
throw new Error('Isf must be greater than or equal to 9'); | ||
} | ||
const isfMMolConstant = patient.ISF / 18; | ||
const age = patient.AGE; | ||
const gender = patient.GENDER; | ||
const tz = patient?.TZ || 'UTC'; | ||
Check warning on line 43 in src/CGMSIMsimulator.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
|
||
let isfActivityDependent = isfMMolConstant; | ||
let liverActivityFactor = 1; | ||
|
||
if (activities && activities.length > 0) { | ||
isfActivityDependent = | ||
isfMMolConstant * physicalIsf(activities, age, gender); | ||
liverActivityFactor = physicalLiver(activities, age, gender); | ||
} | ||
|
||
const weight = patient.WEIGHT; | ||
const dia = patient.DIA; | ||
const peak = patient.TP; | ||
const carbsAbs = patient.CARBS_ABS_TIME; | ||
const cr = patient.CR; | ||
|
||
//Find basal boluses | ||
const drugs = transformNoteTreatmentsDrug(treatments); | ||
|
||
const activeDrugTreatments = drugs.filter(function (e) { | ||
return e.minutesAgo <= 45 * 60; // keep only the basals from the last 45 hours | ||
}); | ||
|
||
const bolusActivity = bolus(treatments, dia, peak); | ||
const basalBolusActivity = basal(activeDrugTreatments, weight); | ||
const cortisoneActivity = cortisone(activeDrugTreatments, weight); | ||
const alcoholActivity = alcohol(activeDrugTreatments, weight, gender); | ||
const basalPumpActivity = pumpEnabled | ||
? pump(treatments, profiles, dia, peak) | ||
: 0; | ||
const carbsActivity = carbs(treatments, carbsAbs, isfActivityDependent, cr); | ||
|
||
//activity calc carb | ||
const liverActivity = liverRun( | ||
isfMMolConstant, | ||
cr, | ||
{ | ||
physical: liverActivityFactor, | ||
alcohol: alcoholActivity, | ||
}, | ||
weight, | ||
tz, | ||
); | ||
|
||
const now = moment(); | ||
const orderedEntries = entries | ||
.filter((e) => e.mills <= now.toDate().getTime()) | ||
.sort((a, b) => b.mills - a.mills); | ||
|
||
const newSgvValue = sgv( | ||
orderedEntries, | ||
{ | ||
basalActivity: basalBolusActivity + basalPumpActivity, | ||
liverActivity, | ||
carbsActivity, | ||
bolusActivity, | ||
cortisoneActivity, | ||
alcoholActivity, | ||
}, | ||
isfActivityDependent, | ||
); | ||
|
||
logger.info(user.nsUrl + 'this is the simulator result: %o', { | ||
...newSgvValue, | ||
physicalISF: isfActivityDependent / isfMMolConstant, | ||
physicalLiver: liverActivityFactor, | ||
}); | ||
|
||
// const arrows = arrowsRun([newSgvValue, ...entries]); | ||
|
||
return { | ||
...newSgvValue, | ||
activityFactor: liverActivityFactor, | ||
isf: { dynamic: isfActivityDependent, constant: isfMMolConstant }, | ||
}; | ||
}; | ||
|
||
export default simulator; |
Oops, something went wrong.
2360e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Report generated by 🧪jest coverage report action from 2360e74