Implement prescription edit and archive - #138
Conversation
mudabs
left a comment
There was a problem hiding this comment.
Request changes
Thanks Olivia for expanding the prescription module with edit, archive, and creation support. The endpoint and frontend service are now wired correctly, and the existing frontend test suite, lint checks, production build, and backend compilation are passing.
Before approving this PR, please address the following:
- Add backend tests for prescription lifecycle behavior
Please add tests covering:
- Creating a prescription for an authenticated user
- Requiring completed health consent
- Assigning the prescription to the authenticated user rather than accepting a client-provided user ID
- Retrieving only active prescriptions
- Updating only prescriptions owned by the current user
- Archiving only prescriptions owned by the current user
- Returning
404for missing, archived, or another user’s prescription - Confirming that archiving sets
archivedandarchived_atwithout deleting the record - Rejecting empty, whitespace-only, or null values for medication name, dosage, and frequency
- Accepting an optional
next_dosevalue
Because these endpoints handle personal medication information, ownership and authorization tests are particularly important.
- Add frontend tests for the prescription workflows
Please add tests for:
- Loading and displaying active prescriptions
- Showing the empty state when no active prescriptions exist
- Opening and submitting the add-prescription form
- Sending the expected payload to the create endpoint
- Refreshing the list after a successful create
- Opening and submitting the edit form
- Refreshing the list after a successful update
- Confirming an archive action
- Refreshing the list after archiving
- Canceling an archive action without making an API request
- Displaying errors when loading, creating, updating, or archiving fails
- Disabling the relevant controls while a request is in progress
The current general frontend suite passes, but it does not directly verify the new prescription functionality.
- Replace hard-coded user-facing strings with translations
The prescription page currently contains hard-coded text such as:
Loading prescriptions...No active prescriptions found.Add prescriptionMedication nameDosageFrequencyNext doseSave prescriptionSaving...Prescription added successfully.Prescription updated successfully.Prescription archived successfully.Failed to add prescription.- The archive confirmation text
Please add translation keys to the appropriate locale files and use t(...) consistently. Please also verify the layout with the supported languages, including Arabic RTL mode.
- Show a visible error when the initial prescription load fails
loadPrescriptions() currently catches the error and only logs it to the console. If the API request fails, the user sees an empty or incomplete page without knowing what happened.
Please add a visible error message with a retry action. The same existing error/toast conventions used elsewhere in the application should be used where appropriate.
- Add form validation and clear submission behavior
Please ensure that:
- Medication name, dosage, and frequency cannot be submitted as blank or whitespace-only values.
- The Save button is disabled while a request is running.
- The Add form cannot be submitted multiple times.
- The edit form cannot be submitted multiple times.
- The form displays the backend validation message when a request is rejected.
- A successful operation resets the appropriate form state.
Once these changes are added and the new tests pass, I would be comfortable approving the PR. The core direction is good; the remaining work is primarily verification, localization, and production-quality error handling.
mudabs
left a comment
There was a problem hiding this comment.
Approved
Thanks for addressing the requested changes.
The prescription lifecycle is now covered end to end:
- Users can create prescriptions through the authenticated API and frontend form.
- Users can edit active prescriptions.
- Users can archive prescriptions without deleting their database records.
- Prescription ownership and health-consent requirements are enforced.
- Backend validation rejects blank medication, dosage, and frequency values.
- Frontend tests cover loading, empty states, creation, editing, archiving, cancellation, validation, errors, retry behavior, and disabled submission states.
- New prescription UI text has been localized.
- The frontend test suite, lint checks, production build, and GitHub CI checks pass.
Approved for merge after the whitespace cleanup.
This PR adds the ability for users to edit and archive their prescriptions. Users can update prescription information, and changes are saved to the database. Users can also archive prescriptions they no longer use, which removes them from the active list while keeping the prescription history in the database.
Changes Made:
Closes #127