dosed.js 692 B

123456789101112131415161718192021222324252627
  1. function insulinDosed(opts) {
  2. var start = opts.start.getTime();
  3. var end = opts.end.getTime();
  4. var treatments = opts.treatments;
  5. var profile_data = opts.profile;
  6. var insulinDosed = 0;
  7. if (!treatments) {
  8. console.error("No treatments to process.");
  9. return {};
  10. }
  11. treatments.forEach(function(treatment) {
  12. //console.error(treatment);
  13. if(treatment.insulin && treatment.date > start && treatment.date <= end) {
  14. insulinDosed += treatment.insulin;
  15. }
  16. });
  17. //console.error(insulinDosed);
  18. return {
  19. insulin: Math.round( insulinDosed * 1000 ) / 1000
  20. };
  21. }
  22. exports = module.exports = insulinDosed;