Skip to content

add Prevent duplicate dose intake in take_dose service #3

Description

@MosheRW

First of all thank you, this is a great idea and i am sure lots of people would benefit from this!!!

Issue: Prevent duplicate dose intake in take_dose service

Problem
The take_dose service currently allows taking the same dose multiple times, even if that dose has already been marked as taken. This can lead to incorrect medication tracking and inflated dose counts.

Expected Behavior

  • A dose should only be taken once within its valid time window.

  • If a dose is already marked as taken, calling take_dose again for the same dose should:

    • Be ignored, or
    • Return a clear error/response indicating the dose was already taken.

Current Behavior

  • Repeated calls to take_dose for the same dose result in the dose being recorded multiple times.

Proposed Solution

  • Add a guard in take_dose to check whether the dose is already marked as taken before proceeding.

  • This can be implemented by:

    • Checking a taken_at / is_taken field, or
    • Enforcing uniqueness at the database level (e.g., one taken record per dose per schedule window).
  • Ensure the service responds deterministically (success vs. already-taken state).

Acceptance Criteria

  • Calling take_dose on an already-taken dose does not change state.
  • No duplicate dose records are created.
  • Clear feedback is returned/logged when a duplicate attempt is made.
  • Existing valid flows (first-time dose intake) continue to work unchanged.

Impact
High. This affects data correctness and user safety in medication tracking.

Notes
Consider edge cases such as:

  • Time-window–based doses (e.g., morning/evening).
  • Concurrent calls (race conditions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions