Show original
Try the app
Enjoyed this article?
Use "Request tipping" to ask the author to set up tip receiving.
AI translation
睡眠日誌アプリ「sleep-diary-php」の紹介
Try the app
Enjoyed this article?
Use "Request tipping" to ask the author to set up tip receiving.
I'd like to introduce "sleep-diary-php," a web app that records daily sleep on a 24-hour timeline and can also be used as documentation for medical consultations.
I created it to support self-care for those struggling with sleep and to assist with medical consultations at healthcare facilities.
The production environment is https://sleep.223n.tech/で公開 and is currently operational.
A sleep diary is a record where you write down daily information such as bedtime and wake time, nighttime awakenings, and daytime sleepiness.
In the diagnosis and treatment of insomnia and hypersomnia, the sleep diary kept by the patient themselves becomes an important clue for diagnosis and treatment decisions.
While handwriting on paper is the common method, it comes with the following challenges:
This app aims to reduce the burden of handwriting while maintaining a format that can be shown to doctors.
The core of recording is a 24-hour timeline from noon to noon the next day, represented in 30-minute increments across 48 slots.
You can visually input a day's sleep simply by tapping and coloring in the time periods when you were sleeping.
The timeline consists of three columns:
States are mutually exclusive—only one per time period—while medication and meals can both be recorded in the same time period.
In addition to notes, you can also keep medication memos and private memos.
Private memos are for the user's eyes only and do not appear in PDFs shared with doctors.
On the list screen, you can view each day's sleep as side-by-side charts on a monthly basis.
Unrecorded days are displayed as blank rows, and tapping them allows you to immediately create a record for that day.
The detail screen displays aggregated information for each day, including total sleep time, number of mid-sleep awakenings, bedtime and wake time, and number of medication doses.
Furthermore, the transition graph overlays daily bars of sleep duration with a 7-day moving average, allowing you to track changes in trends.
Output options are also available for taking to medical facilities.
Since unrecorded days are also output as blank spaces in the printable documentation, it can also be used as a blank form for handwriting.
These generate PDFs on the server side for download, so they can be reliably saved even on iOS home screen apps where printing functions are difficult to use.
Recording only has meaning if you keep it up.
Sleep data is sensitive personal information related to health.
For this reason, I've put effort into authentication and privacy protection.
Data is strictly separated per user, and no one can view or edit other people's records.
New registration is limited to invitation-only via invitation links issued by administrators, preventing unauthorized registration.
From here, I'll introduce implementation details for developers.
Because there's no build process, the configuration is simple and works on shared hosting as-is.
lbuchs/webauthn libraryAll dates and times are handled in Japan Standard Time (JST), with "current target date" determined based on noon.
This is a design to correctly handle sleep periods that cross midnight as a single day.
The development environment is standardized with Docker and DevContainer, while production runs on Sakura's rental server (Standard plan).
Since Docker cannot be used on shared hosting in production, deployment is done by combining git archive and SSH.
These mechanisms allow safe development while confirming quality with each feature addition.
sleep-diary-php is an app aimed at supporting daily records for those struggling with sleep and helping communication with doctors.
I focused on reducing the burden of handwriting while maintaining a format useful for medical consultations.
If you're interested, please check out the following links:
The license is MIT License.
毎日の睡眠を24時間タイムラインで記録し、受診時の帳票としても使えるWebアプリ「sleep-diary-php」を紹介します。
睡眠に悩む方のセルフケアと、医療機関での受診補助を目的に作りました。
本番環境はhttps://sleep.223n.tech/で公開・稼働中です。
睡眠日誌は、就寝・起床の時刻や夜間の目覚め、日中の眠気などを日々書きとめる記録です。
不眠症や過眠症の診療では、患者さん自身がつけた睡眠日誌が診断や治療方針の重要な手がかりになります。
紙の用紙に手書きする方法が一般的ですが、次のような悩みがつきまといます。
このアプリは、こうした手書きの負担を減らしつつ、医師に見せられる帳票の形を保つことを目指しています。
記録の中心は、正午から翌正午までを30分刻み48スロットで表した24時間タイムラインです。
眠っていた時間帯をタップして塗るだけで、1日の睡眠が視覚的に入力できます。
タイムラインは3列で構成します。
状態は相互排他で同じ時間帯に1つだけ、服薬と食事は同じ時間帯に両方を記録できます。
備考のほかに、服薬メモと非公開メモも持てます。
非公開メモは本人だけが見るためのもので、医師へ渡すPDFには載りません。
一覧画面では、月単位で各日の睡眠を横並びのチャートとして見渡せます。
未記録の日は空白行として表示し、タップするとその日の記録をすぐに作成できます。
詳細画面では、1日ごとに合計睡眠時間・中途覚醒回数・就寝と起床の時刻・服薬回数などの集計を表示します。
さらに推移グラフでは、睡眠時間の日次バーと7日移動平均を重ねて、傾向の変化を追えます。
医療機関へ持っていくための出力も用意しています。
印刷帳票は未記録の日も空欄で出力するため、手書き用の白紙帳票としても使えます。
これらはサーバー側でPDFを生成してダウンロードできるので、印刷機能が使いにくいiOSのホーム画面アプリでも確実に保存できます。
記録は続けてこそ意味があります。
睡眠のデータは、健康に関わる繊細な個人情報です。
そのため、認証とプライバシーの保護に力を入れています。
データはユーザーごとに厳密に分離し、他人の記録は参照も編集もできません。
新規登録は管理者が発行した招待リンク経由に限る招待制で、誰でも勝手に登録できない仕組みです。
ここからは、開発者向けに実装のこだわりを紹介します。
ビルド工程を持たないぶん構成はシンプルで、共有ホスティングでもそのまま動きます。
lbuchs/webauthnライブラリを用いて実装しています日付と時刻はすべて日本時間(JST)で扱い、「現在の対象日」は正午を基準に判定します。
深夜をまたぐ睡眠区間を正しく1日として扱うための設計です。
開発環境はDockerとDevContainerでそろえ、本番はさくらのレンタルサーバー(スタンダード)で運用します。
本番は共有ホスティングでDockerを使えないため、git archiveとSSHを組み合わせてデプロイします。
これらの仕組みにより、機能追加のたびに品質を確認しながら安全に開発を進められます。
sleep-diary-phpは、睡眠に悩む方の毎日の記録を支え、医師とのコミュニケーションを助けることを目指したアプリです。
手書きの負担を減らしながら、診療で役立つ帳票の形を保つ点にこだわりました。
興味を持たれた方は、ぜひ次のリンクをご覧ください。
ライセンスはMIT Licenseです。