Skip to content

Latest commit

 

History

History
143 lines (109 loc) · 7.83 KB

README.md

File metadata and controls

143 lines (109 loc) · 7.83 KB

Sleep Diary Report

As part of the Sleep Diary Project, this repository provides a report for use by sleep doctors. At the present time, this includes:

  • Summary data - statistics and graphs describing sleep
  • Short-term sleep chart - a Moldofsky/MacFarlane-like Sleep Disorder Patient Chart
  • Long-term sleep chart - sleep events over the course of years

Here are some useful links:

This project aims to provide a resource for doctors to understand their patients' sleeping disorders. If there is something more we could do, please describe it in a new issue. Please include the relevant software version if possible.

Version History

The summary data includes the version identifier for the report, and for the software that generated it.

Software versions allow developers to detect the exact software version used to build a report. This includes changes that don't affect the report itself, like changes to copyright dates. They are based on the lists of source code commits available in the software library that builds the data (usually the Sleep Diary Core Library) and in the report itself.

Report versions indicate changes to the report that are visible to doctors and patients. A complete list is available in the version history.

Moldofsky/Macfarlane Sleep Disorder Patient Charts

The Sleep Disorder Patient Chart, pioneered by Harvey Moldofsky and James G. Macfarlane in the early 1990's, has come to be widely used by sleep doctors around the world. It asks patients to record the following activities:

  • A - each alcoholic drink
  • C - each caffeinated drink (includes coffee, tea, chocolate, cola)
  • P - every time you take a sleeping pill, tranqulisier, or other medication to aid sleep
  • M - meals
  • S - snacks
  • X - exercise
  • T - use of toilet during sleep-time
  • N - noise that disturbs your sleep
  • W - time of wake-up alarm (if any)
  • - each time you got into bed
  • - each time you got out of bed
  • | - the time you began and the time you ended your sleep
  • | - the time you began and the time you ended any naps, either in a chair or in bed

Programs that generate sleep diaries are encouraged to let users log all of the above, so the data can be converted to a Sleep Disorder Patient Chart.

Although not currently required, programs are encouraged to let users log primary sleeps (usually about 8 hours at night), secondary sleeps (usually an hour or two during the afternoon) and tertiary sleeps (usually ten minutes at any time of day). Future versions of this program may use that information to examine quality of sleep.

Sleep Disorder Patient Charts are paper documents designed to be filled out by patients each morning. The exact layout differs slightly between organisations, but they all closely resemble this report's short-term sleep chart.

Using this project

Download sleepdiary-report.min.js and optionally sleepdiary-report.min.js.map into your project, then call sleepdiary_report() in your code. Here is a minimal example:

var report = sleepdiary_report({
  pdf: my_pdf,
  timezone: "Pacific/Apia",
  build_id: "...",
  recent: {
      activities     : [ ... ],
      schedule       : { ... },
      summary_days   : { ... },
      summary_asleep : { ... },
      sleeps_per_day : { ... },
      meds_per_day   : { ... },
  },
  long_term: {
      activities     : [ ... ],
      schedule       : { ... },
      summary_days   : { ... },
      summary_asleep : { ... },
      sleeps_per_day : { ... },
      meds_per_day   : { ... },
  }
});

var uri = report.pdf.output('datauristring', { filename: report.filename });

Reports are generally build with jsPDF, using data generated by the Sleep Diary Core Library. As such, a more common example looks like:

var diary = some_diary.to("Standard"),
    timezone = new Intl.DateTimeFormat().resolvedOptions().timeZone,
    activities = diary.daily_activities(
        timezone,
        undefined,
        undefined,
        1000*60*60,
    ),
    recent_activities = activities.slice(Math.max(activities.length-14,0)),
    cutoff = recent_activities[0].start,
    report = sleepdiary_report({
        pdf: new jspdf.jsPDF(),
        timezone: timezone,
        build_id: diary.build_id(),
        recent: {
            schedule       : diary.summarise_schedule(                             r => r.start>=cutoff, undefined, timezone ),
            summary_days   : diary.summarise_days    (                             r => r.start>=cutoff ),
            summary_asleep : diary.summarise_records ( r => r.status=="asleep"     &&   r.start>=cutoff ),
            sleeps_per_day : diary.total_per_day     ( r => r.status=="asleep"   , r => r.start>=cutoff ),
            meds_per_day   : diary.total_per_day     ( r => r.status=="sleep aid", r => r.start>=cutoff ),
        },
        long_term: {
            activities     : activities,
            schedule       : diary.summarise_schedule( undefined, undefined, timezone ),
            summary_days   : diary.summarise_days    (),
            summary_asleep : diary.summarise_records ( r => r.status == "asleep" ),
            sleeps_per_day : diary.total_per_day     ( r => r.status == "asleep" ),
            meds_per_day   : diary.total_per_day     ( r => r.status == "sleep aid" ),
        },
    });

var uri = report.pdf.output('datauristring', { filename: report.filename });

When constructing the data used by the report, make sure to use 24-hour days starting at 6pm local time, and to generate one-hour segments.

Get Involved

I found a bug, how should I tell you?

Create a new bug report and we'll get right on it.

I'd like to request a new feature, what should I say?

Please create a new feature request. We'll try to sort out your problem.

I'd like to change the code, how do I get started?

Take a look at our getting started guide. Or if you'd like to talk to someone first, open a discussion and describe what you're planning.

License

Sleep Diary Report, Copyright © 2021 Sleepdiary Developers

Sleep Diary Report comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. For details, see the license statement.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.3.1/jspdf.umd.min.js"></script> <script src="../core/sleepdiary-core.min.js"></script> <script src="sleepdiary-report.min.js"></script> <script src="index.js"></script>