Skip to content

Medication reminder#73

Open
Waho-Joe wants to merge 3 commits intomainfrom
medication-reminder
Open

Medication reminder#73
Waho-Joe wants to merge 3 commits intomainfrom
medication-reminder

Conversation

@Waho-Joe
Copy link
Collaborator

@Waho-Joe Waho-Joe commented Sep 20, 2025

Description

Implemented medication reminder scheduling and dispatch features.

  • Added support for one-time reminders (automatically deactivates after firing).
  • Added support for recurring reminders (daily/weekly with configurable times).
  • Integrated reminderScheduler (cron-based) to check due reminders every minute.
  • Integrated reminderDispatcher to persist notifications and deliver alerts via notificationService.
  • Ensured proper linkage with patient records and createdBy user (caretaker/nurse).
  • Unified computeNextRunAt logic across controller and scheduler to avoid inconsistencies.

Todos

  • Tested and working locally
  • Code follows the style guidelines of this project
  • I have performed a self-review of my code
  • Code changes documented
  • Requested review from >= 1 devs on the team

How to test

  1. Install dependencies
npm install luxon node-cron
  1. Authentication
    Assumption: We already have a nurse user, a patient, and a patient log seeded in the database.
    Obtain a JWT access token for the nurse via login or registration (e.g. /auth/login).

  2. Create a One-Time Reminder (POST /api/v1/reminders)

{
  "entryReportId": "<entryReportId>",
  "patientId": "<patientId>",
  "medicationName": "Ibuprofen",
  "dosage": "200mg",
  "instructions": "Take with water",
  "schedule": {
    "type": "one_time",
    "at": "2025-09-20T17:54:00+10:00",
    "timezone": "Australia/Melbourne"
  },
  "notifyChannels": ["in_app"]
}
  1. Create a Recurring Reminder from Log (POST /api/v1/reminders/from-log/:logId)
{
  "medicationName": "Amoxicillin",
  "dosage": "500mg",
  "instructions": "After meal",
  "schedule": {
    "type": "recurring",
    "timesOfDay": ["08:00","20:00"],
    "daysOfWeek": [0,1,2,3,4,5,6],
    "timezone": "Australia/Melbourne"
  },
  "notifyChannels": ["in_app"]
}
  1. List My Reminders (GET /api/v1/reminders/my)
    Send request with optional query: ?status=all
    Expected result:
  • HTTP 200
  • Response is an array of reminders created by the logged-in nurse.
  1. Get a Reminder by ID (GET /api/v1/reminders/:id)
    Use the _id from Step 3 or 4.
    Expected result:
  • HTTP 200
    Response contains full reminder details including lastTriggeredAt and nextRunAt.
  1. Update a Reminder (PATCH /api/v1/reminders/:id)
{
  "dosage": "400mg",
  "instructions": "With water, avoid empty stomach"
}
  1. Manually Trigger a Reminder (POST /api/v1/reminders/:id/trigger)
    Call the trigger endpoint for a reminder.
    Expected result:
  • HTTP 200
  • lastTriggeredAt is updated.
  • If one-time → active=false.
  • If recurring → nextRunAt is recalculated.
  1. Delete a Reminder (DELETE /api/v1/reminders/:id)
    Delete the reminder created in Step 3.
    Expected result:
  • HTTP 200 or 204
  • A subsequent GET /:id returns 404.

Screenshots and/or Gifs

image image image image

Associated MS Planner Tasks

Known Issues

  • All times in your system are stored in UTC (world time) by MongoDB, so when you see values like 2025-09-20T07:42:00Z, that’s actually 5:42 pm Melbourne time (UTC+10). Your scheduler already uses Luxon with the configured timezone to ensure reminders trigger at the correct local time, but when reading directly from the database it will always look like UTC unless you convert it back to your timezone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant