跳到正文
DEV Community· Harrie·· 2 小時前AI 評分48

建立 CareLog 共享照護記錄

Building a shared care record

AI 導讀

作者為家庭及可信任照護者打造 CareLog 共享照護記錄,讓照護交接可查看各項記錄及記錄者。每個 pull request 的 Vercel 預覽會執行 32 項涵蓋 14 個範疇的瀏覽器測試,另有 40 項 repository 測試及 7 項本地 Playwright 測試。測試揭示登出影響其他用戶、時區造成記錄時間偏移及補貨任務過早完成等問題,作者已修正相關缺陷。

正文

When several people look after the same person, each may know something the others do not. One knows whether lunch was eaten. Another has booked the next appointment. Someone else remembers a question that still needs an answer. Before taking over, a caregiver needs to read what happened and ask about anything nobody has recorded.

I built CareLog for TestSprite Hackathon Season 4 to make that handover easier. It gives families and trusted caregivers a shared record of care, with each entry attached to the person who recorded it. The next caregiver reviews the handoff. Tasks are only closed when someone records what was done.

I could get through the app myself without a problem. When TestSprite ran several tests at once, people were signed out halfway through. Other tests found incorrect times and tasks closed too early. Here is what caused those bugs and how I fixed them.

What a care entry tells you

CareLog can show that someone recorded a medication administration. It cannot confirm that the medication was actually given. Preventing a second normal completion of a scheduled item helps avoid duplicate records, but cannot prevent every real-world double administration. If a second administration actually occurred, the app allows it to be reported as an exception with an explanation.

If a scheduled time passes without an entry, someone may have forgotten to log it. It does not necessarily mean the care was missed. CareLog shows that no administration has been recorded, leaving the caregiver to check what happened.

Corrections preserve the original entry and the reason for the change. Reviewing a handoff records that a person has seen it; it does not complete its tasks. The next caregiver can then ask about missing information without being told that something happened when nobody has confirmed it.

How I tested it

Each pull request receives a Vercel preview. Once that preview is ready, the TestSprite GitHub App runs 32 browser tests covering 14 areas, including records, handoffs, invitations, emergency links, supplies and care load.

The repository also contains 40 tests for rules that need more direct checks: concurrent attempts to complete an item, access after membership removal, who can read private records, money calculations, timezone handling and password changes. Seven local Playwright tests check the interface on phone, tablet and desktop sizes.

I eventually made the TestSprite result a requirement for merging into main, including for administrators. I should have done that earlier. At first, a failed test did not stop a merge. I had to change that setting too.

Why signing out interrupted other people

Several early browser tests stopped halfway through with “Please sign in.” I initially thought the tests were unreliable. Then I checked what the sign-out endpoint did.

The tests ran in parallel using one account. The sign-out endpoint deleted every session belonging to that user. So when one test signed out, the others were signed out too. Each test could appear to work alone while the group failed.

Someone might use CareLog on both their phone and a household tablet. Signing out on the tablet should not unexpectedly end the phone session. A shared-login household could encounter the same defect, although caregivers should use separate accounts so you can see who wrote each entry.

The endpoint now deletes only the current session. A repository test checks that signing out of one session does not end another.

After that, I checked the cause of failures before blaming the tests. Several people can use an account on different devices, and my code had not handled that properly.

Why a recorded time moved by an hour

Another test entered a care shift from 14:00 to 15:00. Its history showed 15:00 to 16:00.

The form read the entered time in the browser’s timezone, while the history displayed it in the care circle’s timezone. When those zones differed, the apparent time changed. Testing from a different timezone exposed the mismatch.

A relative entering a shift from another country could encounter the same bug. Shift and appointment forms now interpret their values in the circle’s timezone. Repository tests cover zones on both sides of UTC and daylight-saving boundaries.

The test also exposed an invalid character in the shift history. I fixed that character as well.

Restocking closed a task too early

Two more tests found problems after saving.

Restocking a supply marked its refill task complete even when more supplies were needed. It now closes only when the remaining stock is above the configured low-stock threshold.

Logging a care shift updated the hours total, but the interface did not show the shift itself. There was no way to check the shift they had entered. I added a history showing individual shifts.

PR #4 moved from 26 passed, three failed and three blocked tests to 31 passed out of 32. One test still needed investigation.

What changed when failure could block a merge

After enabling the merge gate, I opened PR #5. Its initial run passed 28 of 32 tests and blocked the merge. Across that run and the next few attempts, I made five changes.

One report noticed the word “null” above the sign-in fields. My DOM helper skipped null children, but a direct call to replaceChildren converted a null argument into visible text. The defect was already present in production. Filtering absent children removed it.

Another report found that a note added from Today appeared to disappear after the save confirmation. It existed on the Timeline, but Today did not display it. The page now lists the day’s notes using the records API and its existing privacy rules.

The invitation tests found two more problems. Tokens contained characters that were easy to confuse, and inviting someone on the same device required an awkward sign-out-and-copy sequence. Links now avoid look-alike characters. The interface also provides a way to hand the invitation to another person on that device.

Finally, a caregiver viewing a handoff addressed to someone else saw no acknowledgement button and no explanation. Only the intended caregiver should acknowledge it, but the page needed to explain that. The page now explains who the handoff is for and who can acknowledge it.

After the fixes, PR #5 passed 32 of 32 tests and merged through the gate. There could still be bugs those tests do not cover.

The next pull requests

PRs #6 to #10 each passed all 32 TestSprite tests before merging. Some went red first.

The biggest change was speed. People told me the dashboard felt slow, so I counted database queries per page. Each record was loaded with two extra queries, one for its corrections and one for its author. A list of 41 notes took 84 queries, and a handoff took 127. On Vercel, each query is a separate trip to the database, so pages took seconds and got slower as a circle grew. Records now load in batches. In the measured examples, the notes list dropped from 84 queries to 6, and the handoff from 127 to 10. This removes the two extra queries per record; it is not a timing benchmark for every page or care circle.

The same pull request added a Settings page. People can change their name and password, and sign out of their other devices if they lose a phone. Changing the password signs out every other session.

PR #10 fixed navigation as well. Before that, two design passes tidied the interface: clean addresses such as /circles/12/people instead of #/c/12/people, a lighter sidebar with icons, readable dates, and form controls that match across the site.

The tests needed correction too

Some failures came from the test setup or its expectations.

Repeated runs left similarly named records in a shared circle. Tests could select an older item or fail to find a new shift in a limited history. Tests that change data now create a fresh care circle and use unique titles.

Two-person workflows needed more precise instructions. Asking an agent to act as another caregiver did not reliably produce a separate identity. Those tests now create a second account, join through an invitation and switch accounts explicitly.

Later, the same tests failed for a different reason. The agent named each new circle with the same date and time on every run, so the test account built up several circles called, for example, “Handoff 2026-10-23 10:23”. After switching accounts, the owner opened an older one and prepared the handoff there. The helper, who had only joined the new circle, correctly saw nothing. Those tests now note the circle’s number from the address and go straight back to it.

One test expected private check-in text on a shared page. The note was supposed to be private. I changed the test, not who could read the note. Another test missed a save confirmation because it disappeared too quickly. I gave people more time to read it and made it pause on hover.

I read the reports before deciding what to change. Sometimes the code was wrong. Sometimes the test asked the app to do something it should not do.

What I have not fixed yet

Preview deployments currently share the production database. Tests create separate care circles, but their records are still written to the production database. I need separate databases for previews.

Full-suite results varied from 27 to 32 passes while I repaired the app and tests. Two-person flows were particularly difficult. PR #5 passed all 32 tests after several rounds of fixes, and PRs #6 to #10 each reached 32 of 32 before merging.

The gate was also enabled late. Earlier PRs merged under a check that could report success despite failed tests. PR #5 was the first one blocked until all the tests passed.

Push notifications are not built yet. A note when someone hands over to you, or when a dose has no record, would help, but it needs permission prompts and per-person settings that I have not designed.

Signing in, saving a shift and restocking supplies all worked in my walkthrough. The bugs appeared when tests used different sessions, time zones, and stock levels.

來源:DEV Community · dev.to