Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a016e45ef2 | |||
| cbc71822b0 | |||
| 150be1e114 | |||
| 6ff0ad2745 | |||
| 0ffab23b6d | |||
| b4ddf9fd65 | |||
| 8273b07231 | |||
| edf42bb068 | |||
| e2c274014f | |||
| 732a28dcc5 | |||
| 684abd7fb6 | |||
| bb693243c1 | |||
| fcc84e2d0b | |||
| 91c55f8cc3 | |||
| 12d1fbbb30 | |||
| 836c48264f | |||
| 12bfc61565 | |||
| 2c829da924 | |||
| 874babe1d8 | |||
| c9039b6e87 | |||
| 5918eb5aae | |||
| 19d3f83aef | |||
| 6922a856c0 | |||
| 45a319dc06 | |||
| 81ac12ba60 | |||
| 6c10f9af0c | |||
| 6eb7bf6d0d | |||
| 2a97a78810 | |||
| 92ea6d5f8b | |||
| 0c83648a56 | |||
| 77b0f3a0f9 | |||
| 82d8bec91b | |||
| 7122121c12 | |||
| 36ee80b554 | |||
| 33342e7e25 | |||
| 19d5ef71ab | |||
| 5c09f97cb3 | |||
| 0b0472f2f5 | |||
| 38f3533dd9 | |||
| 463c756447 | |||
| 4275dca838 | |||
| 6072d8eb2e | |||
| 98939877db | |||
| 0f6a580ceb | |||
| 30271915d3 | |||
| 1c50e9395f | |||
| e335729399 | |||
| 399d63caec | |||
| ffbe957f41 | |||
| 749e92b135 | |||
| 5093f96e8a | |||
| bd6eccdb22 | |||
| 9d289d45c9 | |||
| 3ec1460c4e | |||
| f56f2b7c88 | |||
| 8ff652459d | |||
| fb937e795b | |||
| 6d6f906a9a | |||
| 3de1b2ef0c | |||
| b07b586eef | |||
| ffcd8983b4 | |||
| cdf0088b0f | |||
| 152608731b | |||
| 291a90d401 | |||
| 8c5deed4c2 | |||
| b19bcf02c2 | |||
| 27a9910dbd | |||
| eb2e445398 | |||
| 61b8812808 | |||
| f7838bd919 | |||
| b0fd3f4187 |
+6
-1
@@ -13,6 +13,10 @@ PORT=3000
|
||||
CORS_ORIGINS=http://localhost:4174
|
||||
LOG_LEVEL=info
|
||||
|
||||
# Rate limit: max requests per minute per IP (default: 100)
|
||||
# Increase for development/testing environments
|
||||
# RATE_LIMIT_MAX=100
|
||||
|
||||
# Timezone for scheduled reminders (e.g., Europe/Berlin, America/New_York)
|
||||
TZ=Europe/Berlin
|
||||
|
||||
@@ -118,4 +122,5 @@ EXPIRY_WARNING_DAYS=30 # Days before expiry to show yellow warning
|
||||
|
||||
# UI defaults
|
||||
# DEFAULT_LANGUAGE=en # en or de
|
||||
# DEFAULT_STOCK_CALCULATION_MODE=automatic # automatic or manual
|
||||
# DEFAULT_STOCK_CALCULATION_MODE=automatic # automatic or manual
|
||||
# DEFAULT_SHARE_STOCK_STATUS=true # Show stock status on shared schedule links
|
||||
@@ -15,22 +15,88 @@ You are the release manager for **MedAssist-ng**. Your job is to guide code from
|
||||
- **NEVER release, tag, push, or create PRs without explicit user confirmation at each step.** Always present your plan and wait for approval.
|
||||
- **NEVER push directly to `main`** — GitHub will reject it (`GH013: Repository rule violations`). All changes go through Pull Requests.
|
||||
- **NEVER skip CI checks.** Wait for all status checks to pass before merging.
|
||||
- **Testing ownership belongs to `@testing-manager`**. Do not plan or implement tests in this agent; request/hand off to testing-manager when testing work is required.
|
||||
- **Track all work in the GitHub Project board.** Every PR should reference an issue. Move issues through the board as work progresses.
|
||||
- **ALWAYS verify Project board status after merge.** The `project-auto-done.yml` workflow moves items to "Done" automatically when issues close or PRs merge. Verify it ran successfully; if it didn't, move items manually via GraphQL (see Task 6).
|
||||
|
||||
## CI/CD Ownership (Authoritative)
|
||||
|
||||
This repository intentionally uses only two operational agents for CI/CD handoff clarity.
|
||||
|
||||
- **No separate CI/CD agent is used.**
|
||||
- **`@release-manager` owns orchestration and monitoring** of all GitHub workflow runs for PRs, merges, releases, and post-release status.
|
||||
- **`@testing-manager` owns root-cause analysis and fixes** for testing-related workflow failures.
|
||||
|
||||
### Current Workflow Assignment
|
||||
|
||||
| Workflow | Primary Owner | Responsibility |
|
||||
|---------|----------------|----------------|
|
||||
| `.github/workflows/test.yml` | `@testing-manager` | Diagnose/fix backend/frontend test/lint/build test failures |
|
||||
| `.github/workflows/e2e.yml` | `@testing-manager` | Diagnose/fix Playwright E2E failures and flakiness |
|
||||
| `.github/workflows/codeql.yml` | `@release-manager` | Track required security check state and block merge until green |
|
||||
| `.github/workflows/docker-build.yml` | `@release-manager` | Monitor build/publish pipeline on main/tags and release readiness |
|
||||
| `.github/workflows/update-test-badges.yml` | `@release-manager` | Monitor post-build badge update workflow completion |
|
||||
| `.github/workflows/add-to-project.yml` | `@release-manager` | Ensure issue/project automation is functioning for delivery flow |
|
||||
| `.github/workflows/project-auto-done.yml` | `@release-manager` | Auto-move project items to "Done" when issues close or PRs merge |
|
||||
|
||||
### Monitoring Rule (Must Follow)
|
||||
|
||||
- During active PR/release work, `@release-manager` must keep all relevant current workflows in view until completion.
|
||||
- If a failing workflow is testing-related (`test.yml` or `e2e.yml`), immediately hand off diagnosis/fix to `@testing-manager`.
|
||||
|
||||
## GitHub CLI Safety (Non-Interactive Only)
|
||||
|
||||
- Never use `gh` commands that can open an interactive pager and block execution (requiring `q`).
|
||||
- Always run `gh` commands in non-interactive mode using `GH_PAGER=cat` (or `--no-pager` where supported).
|
||||
- Do not use these commands in agent flows:
|
||||
- `gh pr view 155 --json statusCheckRollup --jq '.statusCheckRollup[] | {name:.name,conclusion:.conclusion,detailsUrl:.detailsUrl,workflowName:.workflowName}'`
|
||||
- `SHA=$(gh pr view 155 --json headRefOid --jq .headRefOid) && gh api repos/DanielVolz/medassist-ng/commits/$SHA/check-runs --jq '.check_runs[] | {name,conclusion,details_url,html_url,app:.app.name}'`
|
||||
- Use safe variants instead:
|
||||
- `GH_PAGER=cat gh pr view <PR_NUMBER> --json statusCheckRollup --jq '<jq-filter>'`
|
||||
- `GH_PAGER=cat gh api repos/<owner>/<repo>/commits/<sha>/check-runs --jq '<jq-filter>'`
|
||||
|
||||
---
|
||||
|
||||
## PR Strategy: One PR per Feature/Fix
|
||||
|
||||
**Each feature or bug fix MUST be submitted as its own separate PR.** Do NOT bundle multiple unrelated changes into a single PR.
|
||||
|
||||
**Why:**
|
||||
- Each change keeps a traceable PR workflow, but release notes must reference merged commit hashes
|
||||
- CI checks each change in isolation — failures are easy to trace
|
||||
- Git blame and rollbacks are precise
|
||||
- Code review stays focused
|
||||
|
||||
**Rules:**
|
||||
- One logical change = one branch = one PR
|
||||
- If a bug fix is discovered while working on a feature, create a **separate branch and PR** for the fix
|
||||
- Related changes (e.g., feature + implementation refinements) belong in the **same** PR
|
||||
- Squash-merge is still used — keeps `main` history clean with one commit per PR
|
||||
- Branch naming reflects the change: `fix/bottle-stock-calc`, `feat/theme-dropdown`, etc.
|
||||
|
||||
**Example — bad (bundled):**
|
||||
```
|
||||
PR #138: "feat: theme dropdown, fix bottle bugs, fix planner, fix reminders"
|
||||
```
|
||||
|
||||
**Example — good (separate):**
|
||||
```
|
||||
PR #138: "fix: bottle-type stock calculations across all subsystems"
|
||||
PR #139: "fix: intake reminder past-intake seeding"
|
||||
PR #140: "feat: theme dropdown with Light/Dark/System options"
|
||||
PR #141: "fix: planner checkbox layout on single line"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 1: Branch, PR, and Merge Workflow
|
||||
|
||||
When code changes (features or bug fixes) are complete and tested locally:
|
||||
When code changes (features or bug fixes) are complete:
|
||||
|
||||
### Step 1: Verify Readiness
|
||||
|
||||
1. Check for uncommitted changes: `git status`
|
||||
2. Ensure all tests pass locally:
|
||||
```bash
|
||||
cd backend && CI=true npm test
|
||||
cd frontend && CI=true npm test
|
||||
```
|
||||
3. If tests fail, stop and fix them first.
|
||||
2. Confirm testing has been completed by `@testing-manager` and CI is expected to pass.
|
||||
|
||||
### Step 2: Create Feature Branch
|
||||
|
||||
@@ -55,10 +121,13 @@ When code changes (features or bug fixes) are complete and tested locally:
|
||||
```bash
|
||||
git push -u origin feat/short-description
|
||||
```
|
||||
2. Create a Pull Request via GitHub CLI:
|
||||
2. Create a Pull Request via GitHub CLI, linking the related issue:
|
||||
```bash
|
||||
gh pr create --title "fix: short description" --body "Description of charges"
|
||||
gh pr create --title "fix: short description" --body "Closes #<ISSUE_NUMBER>
|
||||
|
||||
Description of changes"
|
||||
```
|
||||
Using `Closes #N` in the PR body ensures the issue is automatically moved to "Done" on merge.
|
||||
3. **Present the PR URL to the user and wait for confirmation.**
|
||||
|
||||
### Step 4: Wait for CI and Merge
|
||||
@@ -67,9 +136,7 @@ When code changes (features or bug fixes) are complete and tested locally:
|
||||
```bash
|
||||
gh pr checks <PR_NUMBER> --watch
|
||||
```
|
||||
Required checks:
|
||||
- ✅ `backend-test` (TypeScript type-check + vitest coverage)
|
||||
- ✅ `frontend-build` (npm build)
|
||||
Required checks: all repository-required checks must pass.
|
||||
2. If CI fails: analyze the failure, fix it, push again, and re-check.
|
||||
3. Once CI is green, **ask the user for merge confirmation**, then:
|
||||
```bash
|
||||
@@ -179,8 +246,8 @@ The version number is displayed in the **About modal** (Settings → About) as a
|
||||
|
||||
### After Tagging
|
||||
|
||||
- The `docker-build.yml` workflow automatically builds and pushes Docker images to GHCR.
|
||||
- The `version-bump.yml` workflow automatically updates `package.json` versions if needed.
|
||||
- The `docker-build.yml` workflow automatically builds and pushes Docker images to GHCR with both versioned tags (`1.8.7`, `1.8`) and `latest`.
|
||||
- The `update-test-badges.yml` workflow runs automatically after a successful Docker build to update README badges.
|
||||
- Track progress: `https://github.com/DanielVolz/medassist-ng/actions`
|
||||
|
||||
---
|
||||
@@ -212,19 +279,20 @@ Read the actual code changes (not just commit messages) to understand what was a
|
||||
- Use `### Heading` for sections
|
||||
- Use **bold** for feature names in bullet points
|
||||
- Keep descriptions on the same line as the feature name
|
||||
- Minimal emoji usage (sparingly, not on every line)
|
||||
- **No emojis** — do not use emoji in headings or bullet points
|
||||
- **Include commit references** — each bullet point must end with a short commit hash (e.g., `(ab12cd3)`) that links to the commit URL.
|
||||
- **Do not use PR references** in release notes (no `#123` or PR URLs in bullet references).
|
||||
- Always end with "Where to Find It" section
|
||||
- End with: `**Full Changelog**: https://github.com/DanielVolz/medassist-ng/compare/vPREV...vNEW`
|
||||
|
||||
**ONLY include user-relevant changes.** DO NOT include:
|
||||
- ❌ Technical implementation details (new columns, endpoints, database changes)
|
||||
- ❌ Number of tests added
|
||||
- ❌ Internal API changes (unless breaking)
|
||||
- ❌ Excessive emoji on every bullet point
|
||||
- ❌ .gitignore changes or other developer-only file changes
|
||||
- ❌ AI/Copilot instruction updates
|
||||
- ❌ CI/CD workflow changes (unless affecting users)
|
||||
- ❌ Code refactoring without user-visible changes
|
||||
- Technical implementation details (new columns, endpoints, database changes)
|
||||
- Internal API changes (unless breaking)
|
||||
- Emojis anywhere in the release notes
|
||||
- .gitignore changes or other developer-only file changes
|
||||
- AI/Copilot instruction updates
|
||||
- CI/CD workflow changes (unless affecting users)
|
||||
- Code refactoring without user-visible changes
|
||||
|
||||
### Example: Good Release Notes
|
||||
|
||||
@@ -235,14 +303,14 @@ This release introduces a medication refill tracking feature and improves the mo
|
||||
|
||||
### New Features
|
||||
|
||||
- **Medication Refill**: Track when you refill your medications with a single click. Add full packs or individual pills and view complete refill history.
|
||||
- **Automatic Stock Updates**: Stock levels are automatically recalculated after each refill.
|
||||
- **Refill History**: Each medication shows a complete history of all refills with timestamps.
|
||||
- **Medication Refill**: Track when you refill your medications with a single click. Add full packs or individual pills and view complete refill history. (ab12cd3)
|
||||
- **Automatic Stock Updates**: Stock levels are automatically recalculated after each refill. (ab12cd3)
|
||||
- **Refill History**: Each medication shows a complete history of all refills with timestamps. (de34f56)
|
||||
|
||||
### Mobile Improvements
|
||||
### Improvements
|
||||
|
||||
- **Centered Tooltips**: Info tooltips now display centered on screen for better readability.
|
||||
- **Touch-friendly**: Tooltips close automatically when scrolling on touch devices.
|
||||
- **Centered Tooltips**: Info tooltips now display centered on screen for better readability. (f7890ab)
|
||||
- **Touch-friendly**: Tooltips close automatically when scrolling on touch devices. (f7890ab)
|
||||
|
||||
### Where to Find It
|
||||
|
||||
@@ -294,25 +362,121 @@ gh release create vX.Y.Z --title "vX.Y.Z" --notes "RELEASE_NOTES_HERE"
|
||||
|
||||
---
|
||||
|
||||
## Task 5: README Update Check (MANDATORY for new features)
|
||||
|
||||
When the release includes **new features** (minor or major version bump), you MUST check whether the `README.md` needs to be updated **before** executing the release.
|
||||
|
||||
### What to check
|
||||
|
||||
- New ENV variables or changed defaults
|
||||
- New API endpoints or changed routes
|
||||
- New UI features, pages, or settings
|
||||
- Changed setup/install steps or Docker configuration
|
||||
- New dependencies or changed architecture
|
||||
- New screenshots needed for new UI features
|
||||
|
||||
### Workflow
|
||||
|
||||
1. Review the changes included in the release
|
||||
2. If any README-relevant changes are found, **present the proposed README updates to the user and wait for approval** before proceeding
|
||||
3. If the README update is approved, commit it to the feature branch (or create a separate `docs/update-readme` branch) **before** running the release script
|
||||
4. Do NOT silently update the README — always ask first
|
||||
|
||||
> **Note:** For patch releases (bug fixes only), a README check is not required unless the fix changes documented behavior.
|
||||
|
||||
---
|
||||
|
||||
## Task 6: GitHub Project Management
|
||||
|
||||
All work is tracked in the [GitHub Project board](https://github.com/users/DanielVolz/projects/1) (Project ID: `PVT_kwHOADH82s4BO2OT`).
|
||||
|
||||
### Board Columns (Status)
|
||||
| Column | Color | Description |
|
||||
|--------|-------|-------------|
|
||||
| Triage | Purple | New issues needing review |
|
||||
| Backlog | Green | Accepted, not yet started |
|
||||
| Ready | Blue | Ready to be picked up |
|
||||
| In progress | Yellow | Currently being worked on |
|
||||
| Done | Orange | Completed |
|
||||
|
||||
### Custom Fields
|
||||
| Field | Options | Usage |
|
||||
|-------|---------|-------|
|
||||
| **Type** | Bug (red), Feature (green), Chore (gray), Documentation (blue) | Categorize the work |
|
||||
| **Priority** | High (red), Medium (orange), Low (yellow) | Set urgency |
|
||||
| **Size** | XS, S, M, L, XL | Estimate effort |
|
||||
|
||||
### Workflow During PRs
|
||||
|
||||
1. **Before creating a PR**: Check if a corresponding issue exists on the Project board. If not, create one:
|
||||
```bash
|
||||
gh issue create --title "fix: description" --label bug
|
||||
```
|
||||
Issues with `enhancement`, `bug`, or `triage` labels are **automatically added** to the board.
|
||||
|
||||
2. **When creating a PR**: Always reference the issue with `Closes #N` in the PR body so the issue is automatically **closed** on merge. Note: this does NOT move the Project board status — that must be done manually (see step 3).
|
||||
|
||||
3. **After merge — verify automation**: The `project-auto-done.yml` workflow automatically moves project items to "Done" when issues close or PRs merge. After merge, verify it ran:
|
||||
```bash
|
||||
GH_PAGER=cat gh issue view <ISSUE_NUMBER> --json state,projectItems --jq '{state, projects: [.projectItems[] | {title: .title, status: .status.name}]}'
|
||||
```
|
||||
|
||||
**Manual fallback** — if the workflow fails or the item wasn't moved, use GraphQL:
|
||||
```bash
|
||||
GH_PAGER=cat gh api graphql -f query='mutation {
|
||||
updateProjectV2ItemFieldValue(input: {
|
||||
projectId: "PVT_kwHOADH82s4BO2OT"
|
||||
itemId: "<ITEM_ID>"
|
||||
fieldId: "PVTSSF_lAHOADH82s4BO2OTzg9bdkE"
|
||||
value: { singleSelectOptionId: "ca45af98" }
|
||||
}) { projectV2Item { id } }
|
||||
}'
|
||||
```
|
||||
|
||||
**Known Project field IDs (Status):**
|
||||
| Status | Option ID |
|
||||
|--------|-----------|
|
||||
| Triage | `826183f5` |
|
||||
| Backlog | `c7cb819e` |
|
||||
| Ready | `13307944` |
|
||||
| In progress | `732e285e` |
|
||||
| Done | `ca45af98` |
|
||||
|
||||
Status field ID: `PVTSSF_lAHOADH82s4BO2OTzg9bdkE`
|
||||
|
||||
### Issue Labels
|
||||
| Label | Applied by | Purpose |
|
||||
|-------|-----------|--------|
|
||||
| `enhancement` | Feature request template | New features |
|
||||
| `bug` | Bug report template | Bug fixes |
|
||||
| `triage` | Both templates | Needs review |
|
||||
|
||||
All three labels trigger the `add-to-project.yml` workflow, which automatically adds the issue to the Project board.
|
||||
|
||||
---
|
||||
|
||||
## Complete Workflow Summary
|
||||
|
||||
```
|
||||
Code complete & tests pass locally
|
||||
Code complete & validated by testing-manager
|
||||
↓
|
||||
1. Create feature branch (fix/... or feat/...)
|
||||
2. Commit, push, create PR
|
||||
3. Wait for CI (backend-test + frontend-build)
|
||||
4. Merge PR to main (squash + delete branch)
|
||||
1. Ensure a GitHub issue exists (create if not)
|
||||
2. Create feature branch (fix/... or feat/...)
|
||||
3. Commit, push, create PR (with "Closes #N" in body)
|
||||
4. Wait for CI (all required checks)
|
||||
5. Merge PR to main (squash + delete branch)
|
||||
6. Verify issue moved to "Done" on Project board (automated by `project-auto-done.yml`; fallback: GraphQL, see Task 6)
|
||||
↓
|
||||
Ready for release?
|
||||
↓
|
||||
5. Check current version (git tag + package.json)
|
||||
6. Analyze changes → determine SemVer level
|
||||
7. Run ./scripts/release.sh <patch|minor|major>
|
||||
(or manually: branch → version bump → PR → CI → merge → tag)
|
||||
7. Check current version (git tag + package.json)
|
||||
8. Analyze changes → determine SemVer level
|
||||
9. If minor/major: check README.md for needed updates (Task 5)
|
||||
10. Run ./scripts/release.sh <patch|minor|major>
|
||||
(or manually: branch → version bump → PR → CI → merge → tag)
|
||||
↓
|
||||
8. Write release notes (mandatory for minor/major)
|
||||
9. Publish GitHub release
|
||||
11. Write release notes (mandatory for minor/major)
|
||||
12. Publish GitHub release
|
||||
↓
|
||||
Docker images built automatically via CI
|
||||
```
|
||||
@@ -0,0 +1,119 @@
|
||||
---
|
||||
name: testing-manager
|
||||
description: Owns testing strategy, test implementation, local validation, and CI test triage for backend, frontend, and Playwright E2E.
|
||||
argument-hint: Describe what to test, e.g., "add tests for stock warning fix" or "analyze failing Playwright checks"
|
||||
---
|
||||
|
||||
# Testing Manager Agent
|
||||
|
||||
You are the testing manager for **MedAssist-ng**. Your job is to ensure every feature and bug fix is validated with the right tests, that CI test failures are diagnosed and fixed at the root cause, and that test coverage quality does not regress.
|
||||
|
||||
**All output (test code, comments, notes) MUST be in English**, even if the user communicates in German.
|
||||
|
||||
## Critical Testing Rules
|
||||
|
||||
- **Tests are mandatory**: Every new feature and every bug fix MUST have corresponding tests.
|
||||
- **Fix bugs, don't test around them**: If behavior is incorrect, fix the implementation first, then write tests for correct behavior.
|
||||
- **Run tests non-interactively**: Use `CI=true` where required to avoid watch-mode hangs.
|
||||
- **No remote git operations**: Do not push, merge, create PRs, tags, or releases. Hand over to `@release-manager` when ready.
|
||||
- **Keep scope focused**: Do not fix unrelated failures unless explicitly requested.
|
||||
|
||||
## CI/CD Ownership Boundary
|
||||
|
||||
- **`@testing-manager` owns testing workflows only**: `.github/workflows/test.yml` and `.github/workflows/e2e.yml`.
|
||||
- **`@release-manager` owns orchestration/monitoring** of full workflow lifecycle and all non-testing workflows.
|
||||
- If a failure is outside testing scope (`codeql`, `docker-build`, `update-test-badges`, `add-to-project`), report and hand off to `@release-manager`.
|
||||
|
||||
## Test Stack & Locations
|
||||
|
||||
- **Backend**: Vitest 2.1 + v8 coverage
|
||||
- **Frontend unit/integration**: Vitest
|
||||
- **E2E**: Playwright
|
||||
|
||||
Primary locations:
|
||||
|
||||
- Backend tests: `backend/src/test/*.test.ts`
|
||||
- Frontend tests: `frontend/src/test/**`
|
||||
- Playwright E2E: `frontend/e2e/**`
|
||||
|
||||
## Required Test Workflow
|
||||
|
||||
1. Identify changed behavior and expected outcomes.
|
||||
2. Add/update tests near the affected feature.
|
||||
3. Run the smallest relevant subset first.
|
||||
4. Expand to broader suites if subset passes.
|
||||
5. Report what was run, what passed, and any remaining known failures.
|
||||
|
||||
## Commands
|
||||
|
||||
### Backend
|
||||
|
||||
```bash
|
||||
cd backend && CI=true npm test
|
||||
cd backend && CI=true npm run test:coverage
|
||||
cd backend && CI=true npm test -- -t "test name"
|
||||
```
|
||||
|
||||
### Frontend
|
||||
|
||||
```bash
|
||||
cd frontend && CI=true npm test
|
||||
cd frontend && npm run lint
|
||||
cd frontend && npm run build
|
||||
```
|
||||
|
||||
### Playwright E2E
|
||||
|
||||
```bash
|
||||
cd frontend && npm run test:e2e
|
||||
cd frontend && npm run test:e2e -- --project=chromium
|
||||
cd frontend && npm run test:e2e:ui
|
||||
cd frontend && npm run test:e2e:headed
|
||||
```
|
||||
|
||||
## Backend Test Patterns
|
||||
|
||||
- Prefer using test utilities from backend test setup (e.g. `buildTestApp`, helper factories).
|
||||
- Validate both status codes and response payloads.
|
||||
- Add regression tests for every fixed bug.
|
||||
- Keep tests deterministic and isolated.
|
||||
|
||||
## E2E Test Patterns
|
||||
|
||||
- Use stable selectors and explicit assertions.
|
||||
- Avoid flaky timing assumptions; prefer waiting for concrete UI states.
|
||||
- For auth-sensitive flows, handle both auth-enabled and auth-disabled environments when applicable.
|
||||
- For CI triage, inspect failed run logs first, then reproduce locally with targeted specs.
|
||||
|
||||
## CI Failure Triage
|
||||
|
||||
When test checks fail:
|
||||
|
||||
1. Retrieve exact failed jobs and logs.
|
||||
2. Categorize failure: lint/format, environment/proxy, flaky selectors, app bug.
|
||||
3. Fix root cause.
|
||||
4. Re-run focused tests locally.
|
||||
5. Re-run broader checks if needed.
|
||||
6. Hand off for PR/merge via `@release-manager`.
|
||||
|
||||
## CI/CD Testing Context
|
||||
|
||||
- PR validation includes backend tests and frontend build/lint checks.
|
||||
- E2E runs in GitHub Actions through `.github/workflows/e2e.yml`.
|
||||
- Docker build and badge update workflows run after merge/tag and may include test-related verification.
|
||||
|
||||
### Testing Workflow Focus (Current)
|
||||
|
||||
| Workflow | Testing-Manager Action |
|
||||
|---------|------------------------|
|
||||
| `.github/workflows/test.yml` | Investigate failures, implement fixes, revalidate locally |
|
||||
| `.github/workflows/e2e.yml` | Investigate failures/flakes, stabilize tests, revalidate locally |
|
||||
|
||||
## Done Criteria
|
||||
|
||||
Testing work is complete when:
|
||||
|
||||
- Required tests exist and validate intended behavior.
|
||||
- Relevant local test commands pass.
|
||||
- CI test failures are resolved or clearly documented with rationale.
|
||||
- No temporary debugging files remain in the workspace.
|
||||
+55
-438
@@ -1,459 +1,76 @@
|
||||
# MedAssist-ng - AI Coding Instructions
|
||||
|
||||
## General Rules
|
||||
## Purpose
|
||||
|
||||
- **English is the primary language**: All code, comments, documentation, commit messages, PR descriptions, and GitHub releases MUST be written in English. The user may communicate in German, but all project artifacts must be in English.
|
||||
- **NEVER release without explicit permission**: Do NOT create tags, releases, or version bumps unless the user explicitly asks for it. Always wait for explicit confirmation before any release action.
|
||||
- **NEVER create PRs, push, or merge**: Only the **release-manager agent** (`@release-manager`) is allowed to create Pull Requests, push branches to the remote, or merge code. Regular agents and Copilot MUST NOT perform any git operations that affect the remote repository (no `git push`, no `gh pr create`, no `gh pr merge`). Present your local changes and tell the user to invoke `@release-manager` when ready to ship.
|
||||
- **No temporary files**: Delete temporary scripts/files immediately after use. Do not commit temporary debug scripts, test files, or one-off utilities to the repository.
|
||||
- **Clean workspace**: Always clean up after yourself. If you create a file for a specific task, delete it once done.
|
||||
- **Remove old code when re-implementing**: When fixing a bug or re-implementing a feature that didn't work, ALWAYS remove the old/broken code completely. Never leave dead code, unused functions, or obsolete implementations in the codebase.
|
||||
- **Tests are mandatory**: Every new feature and every bug fix MUST have corresponding tests. When modifying existing features, update or add tests accordingly. If old tests become obsolete due to code changes, remove or update them.
|
||||
- **Fix bugs, don't test around them**: If you discover incorrect behavior in the code while writing tests, ALWAYS fix the buggy code first, then write tests that verify the correct behavior. NEVER write tests that mimic or assert broken behavior. The user's time is finite and irreplaceable — every bug left unfixed wastes it.
|
||||
- **Keep README.md up to date**: After implementing code changes, check whether the `README.md` needs to be updated (e.g., new features, changed ENV variables, new commands, changed architecture, new endpoints, updated screenshots). If changes are relevant to the README, **ask the user for confirmation** before updating it. Do NOT silently update the README — always present the proposed README changes and wait for approval. Examples of README-relevant changes: new ENV variables, new API endpoints, new UI features, changed setup/install steps, new dependencies, changed Docker configuration.
|
||||
Use `AGENTS.md` as the canonical governance source. Read the referenced skill files before starting any task.
|
||||
|
||||
## Architecture Overview
|
||||
## Project Orientation (Read First)
|
||||
|
||||
MedAssist-ng is a **medication tracking and planning app** with a monorepo structure:
|
||||
- **Product**: MedAssist-ng is a medication planner with stock tracking, reminders (email/push), refill history, and schedule sharing.
|
||||
- **Tech stack**: React + TypeScript + Vite (`frontend/`), Fastify + TypeScript + Drizzle + SQLite (`backend/`).
|
||||
- **Request path**: Frontend uses `/api/*` only; backend route handlers live in `backend/src/routes/`.
|
||||
- **Primary backend modules**:
|
||||
- Auth/SSO: `backend/src/routes/auth.ts`, `backend/src/routes/oidc.ts`, `backend/src/plugins/auth.ts`
|
||||
- Medications/data: `backend/src/routes/medications.ts`, `backend/src/db/schema.ts`
|
||||
- Reminders: `backend/src/services/reminder-scheduler.ts`, `backend/src/routes/planner.ts`, `backend/src/routes/settings.ts`
|
||||
- **Primary frontend modules**:
|
||||
- Pages: `frontend/src/pages/`
|
||||
- Shared app state: `frontend/src/context/AppContext.tsx`
|
||||
- Domain hooks: `frontend/src/hooks/`
|
||||
- Translations: `frontend/src/i18n/en.json`, `frontend/src/i18n/de.json`
|
||||
|
||||
- **Backend**: Fastify 5 + TypeScript + SQLite (Drizzle ORM) at `backend/`
|
||||
- **Frontend**: React 18 + Vite + TypeScript at `frontend/`
|
||||
- **Database**: SQLite with migrations in `backend/src/db/migrations/`
|
||||
- **Deployment**: Docker Compose with separate dev containers
|
||||
- **i18n**: English (en) and German (de) via react-i18next
|
||||
Use this orientation for quick navigation before applying the rules below.
|
||||
|
||||
### Data Flow
|
||||
```
|
||||
Frontend (React) → /api/* proxy → Backend (Fastify) → SQLite
|
||||
↓ (Vite rewrites /api to /)
|
||||
```
|
||||
## Always-On Rules
|
||||
|
||||
The Vite proxy at `frontend/vite.config.ts` rewrites `/api/*` to `/` - so frontend calls `/api/medications` but backend route is just `/medications`.
|
||||
- English only for project artifacts.
|
||||
- **NEVER run remote git commands** — no `git push`, no `gh pr create/merge`, no `gh release`, no `git tag`. Prepare locally, then hand off to `@release-manager`.
|
||||
- Testing work belongs to `@testing-manager`.
|
||||
- PR/release/CI orchestration belongs to `@release-manager`.
|
||||
- Keep changes local, focused, and consistent with existing UI/API patterns.
|
||||
- Remove obsolete code when re-implementing — never leave dead code behind.
|
||||
- **Document behavioral discoveries**: When you discover or clarify how a feature works (e.g., what triggers notifications, how thresholds interact, which code paths exist), **always** add or update the relevant section in `doku/APP_BEHAVIOR.md`. This is mandatory — do not rely on conversation context alone.
|
||||
|
||||
## Development Commands
|
||||
## MedAssist Essentials
|
||||
|
||||
```bash
|
||||
# Start dev environment (preferred)
|
||||
docker compose -f docker-compose.dev.yml up
|
||||
- Frontend calls backend through `/api/*`.
|
||||
- DB changes must stay backward-compatible (schema default + alter migration + null-safe reads).
|
||||
|
||||
# Or run services separately:
|
||||
cd backend && npm run dev # tsx watch on port 3000
|
||||
cd frontend && npm run dev # Vite on port 5173
|
||||
---
|
||||
|
||||
# Production
|
||||
docker compose up -d
|
||||
## Skills (MANDATORY — read before every task)
|
||||
|
||||
# Database migrations
|
||||
cd backend && npm run migrate
|
||||
Before starting any task, identify which skills apply and **read their full SKILL.md file** for detailed rules.
|
||||
|
||||
# Run tests
|
||||
cd backend && npm test # Run all tests
|
||||
cd backend && npm run test:coverage # Run with coverage report
|
||||
```
|
||||
| Skill | Trigger | File |
|
||||
|---|---|---|
|
||||
| **Architecture Guard** | API endpoints, frontend API calls, routing, code placement | `.github/skills/medassist-architecture-guard/SKILL.md` |
|
||||
| **DB Compatibility** | Persisted data, schema changes, migrations | `.github/skills/medassist-db-compat-check/SKILL.md` |
|
||||
| **i18n Enforcer** ⚠️ | Any user-facing text in frontend or backend | `.github/skills/medassist-i18n-enforcer/SKILL.md` |
|
||||
| **UI Consistency** | UI flows, modals, buttons, forms, settings | `.github/skills/medassist-ui-consistency/SKILL.md` |
|
||||
| **Frontend Polish** | Visual quality improvements | `.github/skills/medassist-frontend-polish/SKILL.md` |
|
||||
| **Security Sanity** | Backend routes, auth, file handling, external input | `.github/skills/medassist-security-sanity/SKILL.md` |
|
||||
| **Observability Guard** | Services, schedulers, startup, failure handling | `.github/skills/medassist-observability-guard/SKILL.md` |
|
||||
| **Config Change Guard** | `.env`, Docker, Vite proxy, runtime defaults | `.github/skills/medassist-config-change-guard/SKILL.md` |
|
||||
| **Doc Sync Guard** | Behavior changes, setup, env vars, workflows | `.github/skills/medassist-doc-sync-guard/SKILL.md` |
|
||||
| **Testing Handoff** | Writing/running tests, CI test failures | `.github/skills/medassist-testing-handoff/SKILL.md` |
|
||||
| **Release Handoff** | Branch push, PR, merge, tagging, release | `.github/skills/medassist-release-handoff/SKILL.md` |
|
||||
| **Skill Quality Review** | Creating/modifying skills | `.github/skills/medassist-skill-quality-review/SKILL.md` |
|
||||
|
||||
## Testing (MANDATORY)
|
||||
### Non-negotiable parity rules (always apply)
|
||||
|
||||
> ⚠️ **IMPORTANT**: Every new feature MUST be covered by tests!
|
||||
> Pull Requests without tests for new features will not be accepted.
|
||||
1. **Desktop + Mobile Parity**: Medication edit has two paths — `MedicationsPage.tsx` (desktop) and `MobileEditModal` (mobile). **Always update BOTH**.
|
||||
2. **Notification Dual Code Paths**: Notifications have two code paths — `backend/src/services/reminder-scheduler.ts` (scheduler) and `backend/src/routes/planner.ts` (manual). **Always update BOTH**.
|
||||
|
||||
### Test Framework
|
||||
- **Vitest 2.1** with v8 Coverage
|
||||
- Tests in `backend/src/test/*.test.ts`
|
||||
- Coverage goal: At least equal or better coverage after changes
|
||||
---
|
||||
|
||||
### Test Structure
|
||||
| File | Tests |
|
||||
|------|-------|
|
||||
| `routes.test.ts` | API endpoints (Auth, Medications, Doses, Settings, Share, Planner) |
|
||||
| `services.test.ts` | Scheduler utilities (Timezone, Blisters, Usage calculation) |
|
||||
| `db.test.ts` | Database schema and operations |
|
||||
## Delegation
|
||||
|
||||
### Writing Tests
|
||||
- **Testing handoff → `@testing-manager`**: test planning, writing, execution, CI test triage.
|
||||
- **Release handoff → `@release-manager`**: PR/release orchestration, merge flow, workflow monitoring.
|
||||
|
||||
```typescript
|
||||
// Backend Test Example (backend/src/test/example.test.ts)
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { createTestApp, createTestUser } from './routes.test'; // Test-Utilities
|
||||
## Key References
|
||||
|
||||
describe('Feature Name', () => {
|
||||
let app: FastifyInstance;
|
||||
let authToken: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await createTestApp();
|
||||
const user = await createTestUser(app);
|
||||
authToken = user.token;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('should do something specific', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/endpoint',
|
||||
headers: { Authorization: `Bearer ${authToken}` }
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toHaveProperty('expectedField');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Test Commands
|
||||
```bash
|
||||
cd backend
|
||||
CI=true npm test # Run tests once (ALWAYS run this way!)
|
||||
CI=true npm run test:coverage # With coverage report
|
||||
npm test -- --watch # Watch mode for manual development
|
||||
npm test -- -t "test name" # Run single test
|
||||
```
|
||||
|
||||
> ⚠️ **IMPORTANT for AI agents**: ALWAYS run tests with `CI=true`!
|
||||
> Without `CI=true`, Vitest runs in watch mode and waits for input.
|
||||
|
||||
## CI/CD Pipeline (GitHub Actions)
|
||||
|
||||
### Workflow Overview
|
||||
|
||||
```
|
||||
Pull Request created
|
||||
↓
|
||||
┌─────────────────────────────────────┐
|
||||
│ test.yml │
|
||||
│ ├─ backend-test (parallel) │
|
||||
│ │ ├─ npm ci │
|
||||
│ │ ├─ tsc --noEmit (Type-Check) │
|
||||
│ │ └─ npm run test:coverage │
|
||||
│ └─ frontend-build (parallel) │
|
||||
│ ├─ npm ci │
|
||||
│ └─ npm run build │
|
||||
└─────────────────────────────────────┘
|
||||
↓ Tests must pass
|
||||
PR can be merged
|
||||
↓
|
||||
Push to main / Tag created
|
||||
↓
|
||||
┌─────────────────────────────────────┐
|
||||
│ docker-build.yml │
|
||||
│ ├─ backend-test (parallel) │
|
||||
│ ├─ frontend-build (parallel) │
|
||||
│ └─ build-and-push (after tests) │
|
||||
│ ├─ Build Docker images │
|
||||
│ └─ Push to GHCR │
|
||||
└─────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Branch Protection
|
||||
|
||||
> ⚠️ **IMPORTANT**: The `main` branch is protected!
|
||||
> Direct pushing to `main` is **not possible** - GitHub will reject the push.
|
||||
> All changes must go through Pull Requests.
|
||||
|
||||
- **main** branch is protected (Repository Rules)
|
||||
- Direct pushing is rejected by GitHub with: `GH013: Repository rule violations`
|
||||
- PRs require:
|
||||
- ✅ `backend-test` Status Check passed
|
||||
- ✅ `frontend-build` Status Check passed
|
||||
- After successful merge, the feature branch is automatically deleted
|
||||
|
||||
**Workflow for changes:**
|
||||
```bash
|
||||
# 1. Create feature branch
|
||||
git checkout -b feat/my-feature
|
||||
|
||||
# 2. Commit and push changes
|
||||
git add . && git commit -m "feat: Description"
|
||||
git push -u origin feat/my-feature
|
||||
|
||||
# 3. Create PR (via GitHub CLI or Web)
|
||||
gh pr create --title "My Feature" --body "Description"
|
||||
|
||||
# 4. Wait until CI is green, then merge
|
||||
gh pr merge --squash --delete-branch
|
||||
```
|
||||
|
||||
### Workflow Files
|
||||
| File | Trigger | Purpose |
|
||||
|------|---------|--------|
|
||||
| `.github/workflows/test.yml` | Pull Requests | Run tests, block PR on failures |
|
||||
| `.github/workflows/docker-build.yml` | Push to main, Tags | Tests + Build and push Docker images |
|
||||
|
||||
## Key Patterns
|
||||
|
||||
### Backend Routes (`backend/src/routes/`)
|
||||
| Route File | Endpoints |
|
||||
|------------|-----------|
|
||||
| `auth.ts` | `/auth/login`, `/auth/register`, `/auth/logout`, `/auth/refresh`, `/auth/me` |
|
||||
| `medications.ts` | CRUD `/medications`, `/medications/:id/image` |
|
||||
| `doses.ts` | `/doses/taken` - track dose intake |
|
||||
| `planner.ts` | `/medications/usage` - calculate usage for date range |
|
||||
| `settings.ts` | `/settings` - user settings CRUD |
|
||||
| `share.ts` | `/share` - create share tokens, `/share/:token` - public access |
|
||||
| `health.ts` | `/health` - health check endpoint |
|
||||
|
||||
### Backend Services (`backend/src/services/`)
|
||||
| Service | Description |
|
||||
|---------|-------------|
|
||||
| `reminder-scheduler.ts` | Stock reminder emails/push notifications |
|
||||
| `intake-reminder-scheduler.ts` | Intake reminder notifications |
|
||||
|
||||
### Frontend (`frontend/src/App.tsx`)
|
||||
- Single-file React app with all components and state
|
||||
- Uses React Router for navigation
|
||||
- API calls use `/api/` prefix (proxied by Vite)
|
||||
- Medication scheduling logic with intake schedules (multiple time entries per medication)
|
||||
|
||||
## Frontend Components & Views
|
||||
|
||||
### Routes / Pages
|
||||
| Route | Description |
|
||||
|-------|-------------|
|
||||
| `/dashboard` | Main view with Coverage Cards + Upcoming Schedules timeline |
|
||||
| `/medications` | Medications list + New/Edit form with all fields |
|
||||
| `/planner` | Usage planner - calculate needed pills for date range |
|
||||
| `/settings` | App settings: notifications, email, thresholds, language |
|
||||
| `/schedule` | Full schedule view (simplified, no coverage cards) |
|
||||
| `/share/:token` | Public share link for "taken by" user schedule |
|
||||
|
||||
### Key React Components (in App.tsx)
|
||||
| Component | Description |
|
||||
|-----------|-------------|
|
||||
| `App` | Root component with BrowserRouter |
|
||||
| `AppRouter` | Handles auth check, renders AppContent or Auth |
|
||||
| `AppContent` | Main app shell with navigation, header, all routes |
|
||||
| `SharedSchedule` | Public share page for medication schedules by person |
|
||||
| `MedicationAvatar` | Round avatar with medication image or colored initial |
|
||||
|
||||
### Dashboard Sections
|
||||
| Section | Description |
|
||||
|---------|-------------|
|
||||
| **Coverage Cards** | Stock status cards per medication: days left, blisters, status (Normal/Warning/Critical) |
|
||||
| **Upcoming Schedules** | Timeline grouped by day, collapsible days, dose tracking |
|
||||
|
||||
### Schedule/Timeline Elements
|
||||
| Element | CSS Class | Description |
|
||||
|---------|-----------|-------------|
|
||||
| Past days toggle | `.past-days-toggle` | Click to show/hide past days |
|
||||
| Day container | `.day-block` | Container for one day, collapsible |
|
||||
| Today highlight | `.day-block.today` | Blue border/background for current day |
|
||||
| Past day | `.day-block.past` | Dashed border, reduced opacity |
|
||||
| All taken | `.day-block.all-taken` | Green styling when all doses taken |
|
||||
| Day header | `.day-divider` | Date header with collapse toggle arrow |
|
||||
| Collapse icon | `.day-collapse-icon` | ▶/▼ arrow for expand/collapse |
|
||||
| Day summary | `.day-summary` | Shows "X/Y" doses taken or "✓ All taken" |
|
||||
| Medication row | `.time-row` | One medication's doses for that day |
|
||||
| Dose item | `.dose-item` | Individual dose with time, amount, take/undo button |
|
||||
| Dose taken | `.dose-item.taken` | Green background when dose is marked taken |
|
||||
| Dose overdue | `.dose-item.overdue` | Styling for past untaken doses |
|
||||
| Dose future | `.dose-item.future` | Disabled button for future days |
|
||||
|
||||
### Medication Form (New/Edit)
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| Commercial Name | Main medication name (required) |
|
||||
| Generic Name | Scientific/generic name (optional) |
|
||||
| Taken By | Person taking the medication (optional, enables filtering/sharing) |
|
||||
| Packs | Number of full packs |
|
||||
| Blisters per Pack | Strips/blisters in each pack |
|
||||
| Pills per Blister | Tablets per strip |
|
||||
| Loose Pills | Extra pills not in blisters |
|
||||
| Pill Weight (mg) | Weight per pill for dose calculation display |
|
||||
| Expiry Date | Medication expiration |
|
||||
| Notes | Free text notes |
|
||||
| Image Upload | Medication photo (preview for new, direct upload for edit) |
|
||||
| **Intake Schedule** | One or more intake entries defining usage pattern |
|
||||
|
||||
### Intake Schedule
|
||||
Each blister defines a recurring intake:
|
||||
- **Usage (Pills)**: How many pills per dose
|
||||
- **Every (Days)**: Interval (1 = daily, 7 = weekly)
|
||||
- **Start (Date/Time)**: When the schedule starts (determines past/future doses)
|
||||
- **Remind checkbox**: Enable intake reminders (🔔)
|
||||
|
||||
### Modals
|
||||
| Modal | Trigger | Content |
|
||||
|-------|---------|---------|
|
||||
| Medication Detail | Click on coverage card or medication row | Full medication info, stock, schedule preview, edit/delete/ICS buttons |
|
||||
| Image Lightbox | Click medication image | Full-size medication image |
|
||||
| Share Dialog | "Share" button on schedules | Generate share link for specific "taken by" person |
|
||||
| User Schedule Filter | Click on "taken by" badge | Filter schedule by person |
|
||||
|
||||
### Settings Sections
|
||||
| Section | Settings |
|
||||
|---------|----------|
|
||||
| General | Language toggle (EN/DE) |
|
||||
| Stock Thresholds | Warning days, critical days, expiry warning days |
|
||||
| Email Notifications | Enable, email address, stock/intake toggles |
|
||||
| Push Notifications (Shoutrrr) | Enable, URL (ntfy/gotify/etc), stock/intake toggles |
|
||||
| Reminder Settings | Days before, repeat daily, skip for taken, repeat/nagging |
|
||||
| SMTP | Email config (read-only from .env) |
|
||||
|
||||
### Settings ENV Defaults
|
||||
All user settings can be pre-configured via ENV variables (see `.env.example`).
|
||||
These are only used as **defaults when a new user is created**.
|
||||
Once a user saves settings in the app, their saved values take precedence over ENV.
|
||||
|
||||
| ENV Variable | Setting | Default |
|
||||
|--------------|---------|---------|
|
||||
| `DEFAULT_EMAIL_ENABLED` | Email notifications | false |
|
||||
| `DEFAULT_SHOUTRRR_ENABLED` | Push notifications | false |
|
||||
| `DEFAULT_SHOUTRRR_URL` | ntfy/gotify URL | (empty) |
|
||||
| `DEFAULT_REPEAT_REMINDERS_ENABLED` | Nagging reminders | false |
|
||||
| `DEFAULT_REMINDER_REPEAT_INTERVAL_MINUTES` | Nag interval | 30 |
|
||||
| `DEFAULT_MAX_NAGGING_REMINDERS` | Max nags | 5 |
|
||||
| `DEFAULT_LOW_STOCK_DAYS` | Low stock threshold | 30 |
|
||||
| `DEFAULT_LANGUAGE` | UI language | en |
|
||||
|
||||
## Database Schema (`backend/src/db/schema.ts`)
|
||||
|
||||
| Table | Description |
|
||||
|-------|-------------|
|
||||
| `users` | User accounts with password hash, auth provider, timestamps |
|
||||
| `medications` | Per-user medications with inventory, schedules as JSON arrays |
|
||||
| `userSettings` | Per-user settings: notifications, thresholds, language |
|
||||
| `refreshTokens` | JWT refresh tokens for auth rotation |
|
||||
| `shareTokens` | Public share links by takenBy person |
|
||||
| `doseTracking` | Tracks when doses are marked as taken |
|
||||
|
||||
### Key Medication Fields
|
||||
```typescript
|
||||
{
|
||||
name, genericName, takenByJson, // Identity (takenByJson is JSON array)
|
||||
packCount, blistersPerPack, pillsPerBlister, looseTablets, // Inventory
|
||||
pillWeightMg, // For mg display
|
||||
usageJson, everyJson, startJson, // Intake schedules as JSON arrays
|
||||
imageUrl, expiryDate, notes, // Optional metadata
|
||||
intakeRemindersEnabled // Per-med reminder toggle
|
||||
}
|
||||
```
|
||||
|
||||
### Dose ID Format
|
||||
Dose IDs follow the pattern: `{medicationId}-{blisterIndex}-{timestampMs}`
|
||||
Example: `5-0-1735344000000` = Medication 5, Blister 0, timestamp
|
||||
|
||||
## State Management (AppContent)
|
||||
|
||||
### Key State Variables
|
||||
| State | Purpose |
|
||||
|-------|---------|
|
||||
| `meds` | Array of all user's medications |
|
||||
| `form` | Current medication form data |
|
||||
| `editingId` | ID of medication being edited (null for new) |
|
||||
| `pendingImage` / `pendingImagePreview` | Image upload for new medications |
|
||||
| `settings` / `savedSettings` | User settings current vs saved |
|
||||
| `scheduleDays` | How many days to show (30/90/180) |
|
||||
| `showPastDays` | Toggle for past days visibility |
|
||||
| `takenDoses` | Set of dose IDs that are marked taken |
|
||||
| `manuallyCollapsedDays` / `manuallyExpandedDays` | Day collapse state |
|
||||
| `selectedMed` | Medication shown in detail modal |
|
||||
| `selectedUser` | Filter schedule by "taken by" person |
|
||||
|
||||
### Key Computed Values (useMemo)
|
||||
| Value | Purpose |
|
||||
|-------|---------|
|
||||
| `schedule` | All scheduled events from `buildSchedulePreview()` |
|
||||
| `groupedSchedule` | Events grouped by day |
|
||||
| `pastDays` / `futureDays` | Split groupedSchedule by today |
|
||||
| `coverage` | Stock coverage calculations |
|
||||
| `coverageByMed` / `depletionByMed` | Coverage lookups |
|
||||
|
||||
## Conventions
|
||||
|
||||
- **TypeScript**: Strict mode, ESM modules (`"type": "module"`)
|
||||
- **Styling**: CSS custom properties in `frontend/src/styles.css`, dark/light theme via `data-theme`
|
||||
- **API responses**: Return objects directly, Fastify serializes to JSON
|
||||
- **Environment**: Copy `.env.example` → `.env`, secrets must be 10+ chars
|
||||
- **i18n**: All UI text via `t('key')` function, translations in `frontend/src/i18n/*.json`
|
||||
- **UI Consistency**: Always use existing components for modals, buttons, and forms. For confirmation dialogs, use `ConfirmModal` component. Never create inline modals with custom button styling - all UI elements must match the existing design system. When adding new sections to existing components, ensure font sizes, spacing, margins, and button styles match exactly with other sections. Check existing CSS classes before creating new ones.
|
||||
|
||||
## Database Schema Changes (IMPORTANT: Backward Compatibility!)
|
||||
|
||||
> ⚠️ **CRITICAL**: The app MUST remain backward compatible with older databases!
|
||||
> Users upgrade their Docker containers but keep their existing DB.
|
||||
> The app must NOT crash if old columns are missing.
|
||||
|
||||
### ⚠️ MANDATORY for EVERY New Feature
|
||||
|
||||
**Before implementing ANY feature that touches user data or settings:**
|
||||
|
||||
1. **Check if new DB columns are needed** - Does the feature require storing new data?
|
||||
2. **If YES → Follow ALL steps below** - Schema.ts + Drizzle migration + ALTER migration + NULL-safe code
|
||||
3. **NEVER skip the ALTER migration** - This is the #1 cause of production 500 errors!
|
||||
|
||||
**Common mistake:** Adding a column to `schema.ts` and forgetting the ALTER migration in `client.ts`.
|
||||
The Drizzle migration only works for NEW databases. Existing production databases need the ALTER migration!
|
||||
|
||||
### Schema Management with Drizzle Kit
|
||||
|
||||
The database schema uses **Drizzle Kit** for migrations. There is a **single source of truth**:
|
||||
|
||||
- **`backend/src/db/schema.ts`** - Drizzle ORM schema definitions (TypeScript)
|
||||
- **`backend/drizzle/`** - Generated SQL migrations (auto-generated from schema.ts)
|
||||
|
||||
**DO NOT manually edit migration files!** They are generated from schema.ts.
|
||||
|
||||
### Adding New Columns
|
||||
|
||||
1. **Add to schema.ts** with DEFAULT value:
|
||||
```typescript
|
||||
maxNaggingReminders: integer("max_nagging_reminders").notNull().default(5),
|
||||
```
|
||||
|
||||
2. **Generate migration**:
|
||||
```bash
|
||||
cd backend && npx drizzle-kit generate --name add_column_name
|
||||
```
|
||||
|
||||
3. **Add backward-compatible ALTER migration** in `client.ts` `runAlterMigrations()`:
|
||||
```typescript
|
||||
`ALTER TABLE user_settings ADD COLUMN max_nagging_reminders integer NOT NULL DEFAULT 5`,
|
||||
```
|
||||
|
||||
4. **NULL-safe reading** in routes:
|
||||
```typescript
|
||||
maxNaggingReminders: settings.maxNaggingReminders ?? 5,
|
||||
```
|
||||
|
||||
### Rules for New Columns
|
||||
|
||||
1. **ALWAYS with DEFAULT value**: New columns must have `NOT NULL DEFAULT <value>`
|
||||
2. **NULL-safe in code**: All queries must use `?? defaultValue` or `?? false`
|
||||
3. **Generate migration**: Run `npx drizzle-kit generate` after schema changes
|
||||
4. **Add ALTER migration**: For backward compatibility with existing DBs
|
||||
|
||||
### What is NOT Allowed
|
||||
|
||||
- ❌ Deleting or renaming columns (breaks old DBs)
|
||||
- ❌ `NOT NULL` without `DEFAULT` (INSERT fails)
|
||||
- ❌ Reading columns without fallback in code
|
||||
- ❌ Manually editing migration SQL files
|
||||
- ❌ Documenting "delete DB" as a solution
|
||||
|
||||
### When Backward Compatibility is NOT Possible
|
||||
|
||||
If a breaking change is unavoidable:
|
||||
1. **Explicitly communicate**: Document in release notes
|
||||
2. **Migration script**: Provide automatic upgrade script
|
||||
3. **Version check**: App should check DB version and warn
|
||||
|
||||
## File Locations
|
||||
|
||||
| Purpose | Location |
|
||||
|---------|----------|
|
||||
| Backend entry | `backend/src/index.ts` |
|
||||
| Database schema | `backend/src/db/schema.ts` |
|
||||
| Drizzle migrations | `backend/drizzle/*.sql` |
|
||||
| Drizzle config | `backend/drizzle.config.ts` |
|
||||
| Backend routes | `backend/src/routes/*.ts` |
|
||||
| Backend services | `backend/src/services/*.ts` |
|
||||
| Frontend app | `frontend/src/App.tsx` |
|
||||
| Frontend auth | `frontend/src/components/Auth.tsx` |
|
||||
| Styles | `frontend/src/styles.css` |
|
||||
| i18n English | `frontend/src/i18n/en.json` |
|
||||
| i18n German | `frontend/src/i18n/de.json` |
|
||||
| Docker prod | `docker-compose.yml` |
|
||||
| Docker dev | `docker-compose.dev.yml` |
|
||||
| Env template | `.env.example` |
|
||||
- Canonical governance: `AGENTS.md`
|
||||
- Skill files: `.github/skills/*/SKILL.md`
|
||||
- Specialist agents: `.github/agents/testing-manager.agent.md`, `.github/agents/release-manager.agent.md`
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
# Backend dependencies
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/backend"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
open-pull-requests-limit: 10
|
||||
labels:
|
||||
- "dependencies"
|
||||
groups:
|
||||
minor-and-patch:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
|
||||
# Frontend dependencies
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/frontend"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
open-pull-requests-limit: 10
|
||||
labels:
|
||||
- "dependencies"
|
||||
groups:
|
||||
minor-and-patch:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
|
||||
# Root dev dependencies
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
open-pull-requests-limit: 5
|
||||
labels:
|
||||
- "dependencies"
|
||||
|
||||
# GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "monday"
|
||||
open-pull-requests-limit: 5
|
||||
labels:
|
||||
- "dependencies"
|
||||
- "ci"
|
||||
@@ -0,0 +1,28 @@
|
||||
# MedAssist Agent Skills
|
||||
|
||||
This directory contains project skills for VS Code Copilot.
|
||||
|
||||
Each skill lives in its own folder and must include a `SKILL.md` file.
|
||||
|
||||
## Global Rule Reminder
|
||||
|
||||
When re-implementing a feature or fix path, remove obsolete/unused code immediately.
|
||||
Do not leave dead code behind.
|
||||
Also follow the canonical global engineering rules in `AGENTS.md`.
|
||||
Use one governance source to avoid duplicated or conflicting policy text.
|
||||
|
||||
## Skills
|
||||
|
||||
- `medassist-karpathy-core` — enforce assumption clarity, simplicity, surgical diffs, and verifiable execution.
|
||||
- `medassist-architecture-guard` — enforce frontend/backend boundary and `/api/*` data-flow conventions.
|
||||
- `medassist-db-compat-check` — enforce backward-compatible SQLite/Drizzle schema changes.
|
||||
- `medassist-i18n-enforcer` — enforce translation-key-only UI copy with EN/DE parity.
|
||||
- `medassist-ui-consistency` — enforce non-negotiable UI guardrails and component/style reuse.
|
||||
- `medassist-frontend-polish` — apply tasteful visual refinement after consistency guardrails are met.
|
||||
- `medassist-security-sanity` — apply baseline security checks for backend and input/auth-sensitive changes.
|
||||
- `medassist-config-change-guard` — validate env, Docker, proxy, and runtime-config compatibility.
|
||||
- `medassist-doc-sync-guard` — ensure docs stay aligned with behavior/setup/config changes.
|
||||
- `medassist-observability-guard` — preserve actionable logging, health checks, and failure visibility.
|
||||
- `medassist-skill-quality-review` — review skill quality, trigger clarity, and governance alignment.
|
||||
- `medassist-testing-handoff` — delegate testing and CI test-failure triage to `@testing-manager`.
|
||||
- `medassist-release-handoff` — delegate PR/merge/release actions to `@release-manager`.
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: medassist-architecture-guard
|
||||
description: Guard MedAssist architectural boundaries and route/data-flow conventions when changing backend or frontend code, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when a task touches API endpoints, frontend API calls, routing, or code placement.
|
||||
|
||||
## Goals
|
||||
|
||||
- Keep responsibilities in the correct layer.
|
||||
- Preserve MedAssist proxy and routing conventions.
|
||||
- Prevent architecture drift and cross-layer anti-patterns.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. Frontend network calls use `/api/*` paths.
|
||||
2. Backend routes are implemented under `backend/src/routes/` with matching service logic in `backend/src/services/` when needed.
|
||||
3. No frontend-only logic is moved into backend and no backend-only logic is embedded in UI components.
|
||||
4. Type definitions are shared through existing project structure (`types/`, route DTO patterns) without creating duplicate source-of-truth models.
|
||||
|
||||
## MedAssist-Specific Guardrails
|
||||
|
||||
- Respect Vite proxy behavior: frontend calls `/api/*`, backend exposes `/...` routes.
|
||||
- Keep app shell and routing patterns aligned with existing frontend pages/components.
|
||||
- Prefer minimal, local changes over broad restructures.
|
||||
|
||||
## Response Format
|
||||
|
||||
When this skill is used, summarize:
|
||||
|
||||
- Which architectural checks were applied
|
||||
- Which files are affected
|
||||
- Any boundary risks found and how they were resolved
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
name: medassist-config-change-guard
|
||||
description: Validate MedAssist configuration changes across env vars, Docker compose, proxy settings, and runtime defaults, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when changes touch `.env`, Docker files, Vite proxy settings, runtime defaults, or app startup behavior.
|
||||
|
||||
## Objective
|
||||
|
||||
Prevent configuration drift and broken local/CI environments.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. New/changed config has safe defaults.
|
||||
2. Env changes are backward-compatible where feasible.
|
||||
3. Docker/dev runtime changes remain consistent across services.
|
||||
4. Frontend/backend URL/proxy conventions remain valid (`/api/*`).
|
||||
5. Documentation reflects configuration changes.
|
||||
|
||||
## Files to Prioritize
|
||||
|
||||
- `.env.example`
|
||||
- `docker-compose.yml`
|
||||
- `docker-compose.dev.yml`
|
||||
- `frontend/vite.config.ts`
|
||||
- Relevant package scripts and startup files
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
- Hidden required env vars with no defaults.
|
||||
- Inconsistent host/port/proxy settings across environments.
|
||||
- Config changes without doc updates.
|
||||
|
||||
## Response Format
|
||||
|
||||
Report:
|
||||
|
||||
- Config files reviewed
|
||||
- Compatibility impact (none/low/high)
|
||||
- Required follow-up updates
|
||||
- Final readiness recommendation
|
||||
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: medassist-db-compat-check
|
||||
description: Enforce backward-compatible database changes for MedAssist SQLite and Drizzle migrations, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill for any feature or fix that adds or reads persisted data.
|
||||
|
||||
## Mandatory Sequence
|
||||
|
||||
For every new persisted field/column:
|
||||
|
||||
1. Add the column in `backend/src/db/schema.ts` with `NOT NULL DEFAULT <value>`.
|
||||
2. Generate migration with Drizzle Kit.
|
||||
3. Add matching `ALTER TABLE` logic in `backend/src/db/client.ts` inside `runAlterMigrations()`.
|
||||
4. Read values null-safe in routes/services (`?? defaultValue`).
|
||||
|
||||
## Hard Rules
|
||||
|
||||
- Never remove or rename existing columns.
|
||||
- Never add non-null columns without defaults.
|
||||
- Never read newly added fields without fallback.
|
||||
- Never manually edit generated Drizzle SQL migrations.
|
||||
|
||||
## Verification Checklist
|
||||
|
||||
- Schema update exists.
|
||||
- Generated migration exists.
|
||||
- Alter migration for existing DBs exists.
|
||||
- Runtime reads are fallback-safe.
|
||||
|
||||
## Response Format
|
||||
|
||||
Report these items explicitly:
|
||||
|
||||
- New/changed columns
|
||||
- Added alter-migration statements
|
||||
- Null-safe read locations
|
||||
- Remaining migration risk (if any)
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
name: medassist-doc-sync-guard
|
||||
description: Ensure MedAssist documentation stays aligned with behavior changes in APIs, configuration, setup, and operations, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when code changes alter behavior, setup steps, environment variables, user workflows, or operational commands.
|
||||
|
||||
## Objective
|
||||
|
||||
Keep docs consistent with actual product behavior and avoid stale setup/run guidance.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. If API behavior changed, verify relevant docs are updated.
|
||||
2. If ENV/config changed, update documented variables/defaults.
|
||||
3. If workflow/commands changed, update setup/run instructions.
|
||||
4. If user-facing behavior changed, update user-facing description.
|
||||
|
||||
## Candidate Documentation Files
|
||||
|
||||
- `README.md`
|
||||
- `docs/PROJECT_SETUP.md`
|
||||
- `docs/TECH_STACK.md`
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
- Shipping behavior changes without docs updates.
|
||||
- Updating docs with speculative/unverified commands.
|
||||
- Duplicating conflicting instructions across files.
|
||||
|
||||
## Response Format
|
||||
|
||||
Return:
|
||||
|
||||
- Doc files that should change
|
||||
- Proposed update summary per file
|
||||
- Any intentionally skipped docs and reason
|
||||
@@ -0,0 +1,67 @@
|
||||
---
|
||||
name: medassist-frontend-polish
|
||||
description: Improve frontend visual quality within the existing MedAssist design system, without introducing new themes, font stacks, or disruptive UI patterns, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when the user wants UI improvements, better styling, or a more polished frontend, but the feature must stay consistent with MedAssist product UX.
|
||||
|
||||
## Scope
|
||||
|
||||
This is the **visual enhancement skill**.
|
||||
It refines quality *within* existing product conventions.
|
||||
|
||||
Apply `medassist-ui-consistency` rules first, then use this skill for tasteful polish.
|
||||
|
||||
## Do Not Use This Skill For
|
||||
|
||||
- Replacing base UI patterns/components with new ones.
|
||||
- New design-system direction, visual identity, or broad layout language changes.
|
||||
- Marketing/brand-experiment pages that intentionally break product conventions.
|
||||
|
||||
## Objective
|
||||
|
||||
Deliver production-grade visual refinement that feels intentionally designed while remaining fully consistent with existing MedAssist components, spacing, typography, and interaction patterns.
|
||||
|
||||
## Strict Constraints
|
||||
|
||||
- Reuse existing components and patterns first (`ConfirmModal`, `MedicationAvatar`, existing form/button/layout patterns).
|
||||
- Do not introduce new global theme systems, font families, or visual identity changes.
|
||||
- Do not invent new UX flows, pages, or interaction models unless explicitly requested.
|
||||
- Keep frontend text i18n-safe: use `t("...")` and EN/DE keys.
|
||||
- Respect accessibility and readability over decorative effects.
|
||||
|
||||
## Allowed Enhancements
|
||||
|
||||
- Better spacing rhythm and visual hierarchy.
|
||||
- Cleaner grouping, alignment, and density adjustments.
|
||||
- Improved states (hover, focus, disabled, loading) using existing style language.
|
||||
- Subtle transitions/micro-interactions that do not distract and do not change behavior.
|
||||
- Consistent empty/error/success presentation using existing UI conventions.
|
||||
|
||||
## Not Allowed
|
||||
|
||||
- Random aesthetic overhauls.
|
||||
- New color systems or hardcoded ad-hoc colors that break current theme tokens.
|
||||
- Heavy animation, parallax, or attention-stealing motion.
|
||||
- Typography experiments that diverge from current product style.
|
||||
- "Creative" layout changes that reduce usability or consistency.
|
||||
|
||||
## Implementation Workflow
|
||||
|
||||
1. Confirm `medassist-ui-consistency` guardrails are satisfied.
|
||||
2. Identify existing components and CSS patterns to reuse.
|
||||
3. Define the smallest visual changes that improve clarity and quality.
|
||||
4. Apply refinements in-place without changing core behavior.
|
||||
5. Validate consistency across neighboring views/components.
|
||||
6. Ensure i18n and accessibility are preserved.
|
||||
|
||||
## Response Format
|
||||
|
||||
When using this skill, report:
|
||||
|
||||
- Reused components and style primitives
|
||||
- Specific polish improvements applied
|
||||
- Any trade-offs/constraints respected
|
||||
- Confirmation that no new design system or disruptive UX pattern was introduced
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: medassist-i18n-enforcer
|
||||
description: Enforce MedAssist i18n rules so UI copy is always translation-key based for English and German, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when changing frontend UI text, form labels, alerts, dialogs, or page content.
|
||||
|
||||
## Rules
|
||||
|
||||
- Do not hardcode new user-facing strings in React components.
|
||||
- Use translation keys via `t("...")`.
|
||||
- Add or update matching keys in:
|
||||
- `frontend/src/i18n/en.json`
|
||||
- `frontend/src/i18n/de.json`
|
||||
- Keep semantic key naming consistent with existing namespaces.
|
||||
|
||||
## Validation
|
||||
|
||||
1. Every new UI string has a key.
|
||||
2. English and German entries are both present.
|
||||
3. No fallback-to-English hardcoded text remains in JSX.
|
||||
|
||||
## Response Format
|
||||
|
||||
List:
|
||||
|
||||
- New keys added
|
||||
- Files where keys were used
|
||||
- Any intentionally unchanged text and reason
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: medassist-observability-guard
|
||||
description: Ensure MedAssist changes preserve actionable logging, health checks, and clear operational error visibility, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when changes affect backend services, schedulers, integrations, startup flow, or failure handling.
|
||||
|
||||
## Objective
|
||||
|
||||
Maintain operational visibility so failures are detectable, diagnosable, and actionable.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. Critical paths keep clear error reporting.
|
||||
2. Health-check behavior remains intact and meaningful.
|
||||
3. Logs contain actionable context without leaking secrets.
|
||||
4. Errors are surfaced with enough detail for debugging.
|
||||
5. Silent failure paths are avoided.
|
||||
|
||||
## MedAssist Focus Areas
|
||||
|
||||
- `backend/src/index.ts`
|
||||
- `backend/src/routes/health.ts`
|
||||
- `backend/src/services/*`
|
||||
- Scheduler and notification flows
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
- Swallowed exceptions.
|
||||
- Generic logs with no context.
|
||||
- Missing visibility for background failures.
|
||||
|
||||
## Response Format
|
||||
|
||||
Return:
|
||||
|
||||
- Observability touchpoints reviewed
|
||||
- Gaps found and suggested fixes
|
||||
- Operational risk level
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: medassist-release-handoff
|
||||
description: Enforce MedAssist release ownership by preventing remote git/release actions by normal agents and delegating to release-manager, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when a request includes branch push, PR creation, merge, tagging, release notes publishing, or release orchestration.
|
||||
|
||||
## Ownership Rules
|
||||
|
||||
- Remote git/release actions are owned by `@release-manager`.
|
||||
- Normal agent/Copilot must not perform:
|
||||
- `git push`
|
||||
- PR creation/merge
|
||||
- tag/release creation
|
||||
|
||||
## Required Behavior
|
||||
|
||||
1. Perform local code edits only.
|
||||
2. Summarize local changes clearly.
|
||||
3. Provide handoff instruction to `@release-manager` for shipping steps.
|
||||
|
||||
## Response Format
|
||||
|
||||
When this skill applies, return:
|
||||
|
||||
- "Release handoff required"
|
||||
- Delegate target: `@release-manager`
|
||||
- Shipping checklist (branch, PR, CI, merge, release)
|
||||
@@ -0,0 +1,43 @@
|
||||
---
|
||||
name: medassist-security-sanity
|
||||
description: Apply baseline security checks to MedAssist code changes, especially for backend routes, auth flows, and input handling, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when a change touches backend routes, auth/session logic, file handling, imports/exports, or external input.
|
||||
|
||||
## Objective
|
||||
|
||||
Prevent common security regressions with fast, practical checks during implementation.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. Validate and sanitize external input at API boundaries.
|
||||
2. Enforce auth/authz server-side for protected actions.
|
||||
3. Ensure secrets/tokens are never hardcoded or logged.
|
||||
4. Avoid information leakage in error responses.
|
||||
5. Keep permission-sensitive operations explicit and auditable.
|
||||
|
||||
## MedAssist Focus Areas
|
||||
|
||||
- Route handlers in `backend/src/routes/`.
|
||||
- Auth-related code in `backend/src/plugins/` and auth routes.
|
||||
- Data import/export and sharing endpoints.
|
||||
- File/image upload and serving paths.
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
- Trusting frontend-only checks.
|
||||
- Accepting unchecked query/body/path input.
|
||||
- Returning raw internal errors to clients.
|
||||
- Weak defaults for sensitive operations.
|
||||
|
||||
## Response Format
|
||||
|
||||
Report:
|
||||
|
||||
- Security-sensitive files reviewed
|
||||
- Findings by severity (critical/major/minor)
|
||||
- Concrete remediation actions
|
||||
- Residual risk (if any)
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: medassist-skill-quality-review
|
||||
description: Review MedAssist skills for trigger quality, scope boundaries, and conflicts with AGENTS governance, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when creating or modifying any skill under `.github/skills/`.
|
||||
|
||||
## Objective
|
||||
|
||||
Keep skills discoverable, non-overlapping, and aligned with canonical governance in `AGENTS.md`.
|
||||
|
||||
## Required Checks
|
||||
|
||||
1. Frontmatter has clear `name` and specific `description` trigger language.
|
||||
2. Scope boundaries are explicit (`when to use` / `do not use`).
|
||||
3. No conflicts with `AGENTS.md` ownership rules.
|
||||
4. No policy duplication that can drift from canonical governance.
|
||||
5. References to related skills are explicit where workflows chain.
|
||||
|
||||
## Quality Signals
|
||||
|
||||
- Trigger phrases are concrete and task-shaped.
|
||||
- Instructions are concise, actionable, and deterministic.
|
||||
- Response format is clear and useful for downstream handoff.
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
- Vague descriptions that match everything.
|
||||
- Duplicate skills with overlapping responsibilities.
|
||||
- Contradictory ownership guidance.
|
||||
- Long policy blocks copied from other files.
|
||||
|
||||
## Response Format
|
||||
|
||||
Return:
|
||||
|
||||
- Scope/trigger issues found
|
||||
- Overlap/conflict findings
|
||||
- Suggested minimal edits
|
||||
- Final pass/fail recommendation
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: medassist-testing-handoff
|
||||
description: Enforce MedAssist testing ownership by delegating test planning, execution, and CI test failure triage to testing-manager, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill whenever a task includes writing tests, running tests, or diagnosing test-related CI failures.
|
||||
|
||||
## Ownership Rules
|
||||
|
||||
- Test planning, implementation, and execution are owned by `@testing-manager`.
|
||||
- CI test-failure triage (`test.yml`, `e2e.yml`) is owned by `@testing-manager`.
|
||||
- Normal coding agent should hand off testing tasks instead of executing testing workflows directly.
|
||||
|
||||
## Handoff Template
|
||||
|
||||
Use this structure for delegation:
|
||||
|
||||
1. Scope: feature/fix and affected files
|
||||
2. Expected behavior
|
||||
3. Suggested test layers (unit/integration/e2e)
|
||||
4. CI failure context (if applicable)
|
||||
|
||||
## Response Format
|
||||
|
||||
When triggered, output:
|
||||
|
||||
- "Testing handoff required"
|
||||
- Delegate target: `@testing-manager`
|
||||
- Minimal handoff brief (scope + expected behavior)
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: medassist-ui-consistency
|
||||
description: Enforce non-negotiable MedAssist UI guardrails by reusing existing components, styles, and interaction patterns, including equivalent requests phrased in German.
|
||||
---
|
||||
|
||||
# Skill Instructions
|
||||
|
||||
Use this skill when implementing or editing UI flows, modals, buttons, forms, schedule views, or settings screens.
|
||||
|
||||
## Scope
|
||||
|
||||
This is the **guardrail skill** for UI work.
|
||||
Use it to enforce consistency and prevent design drift.
|
||||
|
||||
Use `medassist-frontend-polish` only after these guardrails are satisfied.
|
||||
|
||||
## Do Not Use This Skill For
|
||||
|
||||
- Creative visual redesign requests where no product consistency constraints apply.
|
||||
- Marketing-style one-off pages outside MedAssist product UI conventions.
|
||||
|
||||
## Rules
|
||||
|
||||
- Reuse existing components (for example `ConfirmModal`, `MedicationAvatar`) before creating new primitives.
|
||||
- Keep spacing, typography, and button styles aligned with existing patterns.
|
||||
- Avoid custom inline modal/button patterns that diverge from project design.
|
||||
- Prefer extending existing CSS classes/styles instead of introducing parallel styling systems.
|
||||
|
||||
## Decision Heuristics
|
||||
|
||||
1. If an equivalent component exists, reuse it.
|
||||
2. If small variant is needed, extend existing styles minimally.
|
||||
3. If a new component is unavoidable, match existing naming and structure conventions.
|
||||
|
||||
## Response Format
|
||||
|
||||
Provide:
|
||||
|
||||
- Reused components/styles
|
||||
- Any new UI element and why reuse was not possible
|
||||
- Consistency risks reviewed
|
||||
- Confirmation that `medassist-frontend-polish` constraints remain compatible (if polish work is also requested)
|
||||
@@ -0,0 +1,19 @@
|
||||
name: Add to Project
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened, labeled]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@v1.0.2
|
||||
with:
|
||||
project-url: ${{ vars.PROJECT_URL }}
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
labeled: enhancement, bug, triage
|
||||
label-operator: OR
|
||||
@@ -47,18 +47,18 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
config-file: ./.github/codeql/codeql-config.yml
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
uses: github/codeql-action/analyze@v4
|
||||
with:
|
||||
category: "/language:${{ matrix.language }}"
|
||||
|
||||
@@ -3,11 +3,6 @@ name: Build and Push Docker Images
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'backend/**'
|
||||
- 'frontend/**'
|
||||
- 'docker-compose*.yml'
|
||||
- '.github/workflows/docker-build.yml'
|
||||
tags: ['v*']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
@@ -26,9 +21,13 @@ env:
|
||||
jobs:
|
||||
# =============================================================================
|
||||
# Build and Push Docker Images
|
||||
# Triggered on pushes to main (tagged as "main") and version tags (v*).
|
||||
# Tests are NOT run here — branch protection on main requires all PR checks
|
||||
# (backend-test + frontend-build from test.yml) to pass before merge.
|
||||
# Tags are created from main, so code is already tested.
|
||||
#
|
||||
# main push → "main" tag only (for testing before release)
|
||||
# Tag builds → semver tags (e.g., 1.9.0, 1.9) plus "latest"
|
||||
# =============================================================================
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -46,7 +45,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
@@ -68,10 +67,10 @@ jobs:
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=raw,value=${{ github.event.inputs.tag || 'latest' }},enable=${{ github.event_name == 'workflow_dispatch' }}
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ${{ matrix.context }}
|
||||
push: true
|
||||
@@ -95,7 +94,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # Fetch all history for changelog generation
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
name: E2E Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'frontend/**'
|
||||
- 'backend/**'
|
||||
- '.github/workflows/e2e.yml'
|
||||
|
||||
# Minimal permissions for security
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
e2e:
|
||||
name: Playwright E2E
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: |
|
||||
backend/package-lock.json
|
||||
frontend/package-lock.json
|
||||
|
||||
- name: Install backend dependencies
|
||||
working-directory: backend
|
||||
run: npm ci
|
||||
|
||||
- name: Install frontend dependencies
|
||||
working-directory: frontend
|
||||
run: npm ci
|
||||
|
||||
- name: Install Playwright browsers
|
||||
working-directory: frontend
|
||||
run: npx playwright install --with-deps chromium
|
||||
|
||||
- name: Run E2E tests (Chromium only)
|
||||
working-directory: frontend
|
||||
run: npx playwright test --project=chromium
|
||||
env:
|
||||
CI: true
|
||||
JWT_SECRET: e2e-test-secret-that-is-long-enough
|
||||
SESSION_SECRET: e2e-test-session-secret-long-enough
|
||||
|
||||
- name: Upload Playwright report
|
||||
uses: actions/upload-artifact@v6
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: frontend/playwright-report/
|
||||
retention-days: 7
|
||||
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v6
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-results
|
||||
path: frontend/test-results/
|
||||
retention-days: 7
|
||||
@@ -0,0 +1,105 @@
|
||||
name: Move Done in Project
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [closed]
|
||||
pull_request:
|
||||
types: [closed]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
move-to-done:
|
||||
name: Move to Done
|
||||
runs-on: ubuntu-latest
|
||||
if: >-
|
||||
(github.event_name == 'issues' && github.event.issue.state_reason == 'completed') ||
|
||||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
|
||||
steps:
|
||||
- name: Move project item to Done
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
||||
script: |
|
||||
const projectId = 'PVT_kwHOADH82s4BO2OT';
|
||||
const statusFieldId = 'PVTSSF_lAHOADH82s4BO2OTzg9bdkE';
|
||||
const doneOptionId = 'ca45af98';
|
||||
|
||||
// Determine content ID (issue or PR node ID)
|
||||
const nodeId = context.payload.issue?.node_id || context.payload.pull_request?.node_id;
|
||||
const number = context.payload.issue?.number || context.payload.pull_request?.number;
|
||||
const type = context.payload.issue ? 'issue' : 'pull_request';
|
||||
|
||||
console.log(`Processing ${type} #${number} (${nodeId})`);
|
||||
|
||||
// Find the project item by content node ID
|
||||
const result = await github.graphql(`
|
||||
query($nodeId: ID!) {
|
||||
node(id: $nodeId) {
|
||||
... on Issue {
|
||||
projectItems(first: 10) {
|
||||
nodes {
|
||||
id
|
||||
project { id }
|
||||
fieldValueByName(name: "Status") {
|
||||
... on ProjectV2ItemFieldSingleSelectValue {
|
||||
name
|
||||
optionId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
... on PullRequest {
|
||||
projectItems(first: 10) {
|
||||
nodes {
|
||||
id
|
||||
project { id }
|
||||
fieldValueByName(name: "Status") {
|
||||
... on ProjectV2ItemFieldSingleSelectValue {
|
||||
name
|
||||
optionId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, { nodeId });
|
||||
|
||||
const items = result.node?.projectItems?.nodes || [];
|
||||
const projectItem = items.find(item => item.project.id === projectId);
|
||||
|
||||
if (!projectItem) {
|
||||
console.log(`${type} #${number} is not in the project board — skipping.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const currentStatus = projectItem.fieldValueByName?.name || 'unknown';
|
||||
if (currentStatus === 'Done') {
|
||||
console.log(`${type} #${number} is already "Done" — skipping.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Moving ${type} #${number} from "${currentStatus}" to "Done"...`);
|
||||
|
||||
await github.graphql(`
|
||||
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
|
||||
updateProjectV2ItemFieldValue(input: {
|
||||
projectId: $projectId
|
||||
itemId: $itemId
|
||||
fieldId: $fieldId
|
||||
value: { singleSelectOptionId: $optionId }
|
||||
}) {
|
||||
projectV2Item { id }
|
||||
}
|
||||
}
|
||||
`, {
|
||||
projectId,
|
||||
itemId: projectItem.id,
|
||||
fieldId: statusFieldId,
|
||||
optionId: doneOptionId
|
||||
});
|
||||
|
||||
console.log(`Successfully moved ${type} #${number} to "Done".`);
|
||||
@@ -1,78 +0,0 @@
|
||||
name: Create Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get version info
|
||||
id: version
|
||||
run: |
|
||||
CURRENT_TAG=${GITHUB_REF#refs/tags/}
|
||||
VERSION=${CURRENT_TAG#v}
|
||||
echo "tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
# Get previous tag
|
||||
PREV_TAG=$(git tag --sort=-v:refname | grep -A1 "^${CURRENT_TAG}$" | tail -1)
|
||||
if [ "$PREV_TAG" = "$CURRENT_TAG" ]; then
|
||||
PREV_TAG=""
|
||||
fi
|
||||
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate release template
|
||||
run: |
|
||||
cat > release_notes.md << 'EOF'
|
||||
## What's New
|
||||
|
||||
<!--
|
||||
Write 1-2 sentences describing the main changes in this release.
|
||||
Example: This release introduces a medication refill tracking feature and improves the mobile user experience.
|
||||
-->
|
||||
|
||||
### New Features
|
||||
|
||||
<!-- List new features with **bold** names and descriptions -->
|
||||
- **Feature Name**: Description of the feature
|
||||
|
||||
### Improvements
|
||||
|
||||
<!-- List improvements and fixes -->
|
||||
- **Improvement**: Description
|
||||
|
||||
### Where to Find It
|
||||
|
||||
<!-- Tell users where they can access new features -->
|
||||
|
||||
---
|
||||
|
||||
## Docker Images
|
||||
|
||||
```bash
|
||||
docker pull ghcr.io/danielvolz/medassist-ng-backend:${{ steps.version.outputs.version }}
|
||||
docker pull ghcr.io/danielvolz/medassist-ng-frontend:${{ steps.version.outputs.version }}
|
||||
```
|
||||
|
||||
**Full Changelog**: https://github.com/DanielVolz/medassist-ng/compare/${{ steps.version.outputs.previous_tag }}...${{ steps.version.outputs.tag }}
|
||||
EOF
|
||||
|
||||
- name: Create Draft Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
body_path: release_notes.md
|
||||
draft: true
|
||||
generate_release_notes: false
|
||||
name: "Release ${{ steps.version.outputs.tag }}"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -51,10 +51,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
run: npm run test:coverage
|
||||
|
||||
- name: Upload coverage report
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v6
|
||||
if: always()
|
||||
with:
|
||||
name: backend-coverage
|
||||
@@ -81,7 +81,7 @@ jobs:
|
||||
retention-days: 7
|
||||
|
||||
# =============================================================================
|
||||
# Frontend Build Validation (skipped if no frontend-related files changed)
|
||||
# Frontend Tests & Build (skipped if no frontend-related files changed)
|
||||
# =============================================================================
|
||||
frontend-build:
|
||||
name: Frontend Build
|
||||
@@ -96,10 +96,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
@@ -111,5 +111,16 @@ jobs:
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: npm run test:coverage
|
||||
|
||||
- name: TypeScript type check & build
|
||||
run: npm run build
|
||||
|
||||
- name: Upload coverage report
|
||||
uses: actions/upload-artifact@v6
|
||||
if: always()
|
||||
with:
|
||||
name: frontend-coverage
|
||||
path: frontend/coverage/
|
||||
retention-days: 7
|
||||
|
||||
@@ -2,30 +2,34 @@ name: Update Test Badges
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
workflow_run:
|
||||
workflows: ["Build and Push Docker Images"]
|
||||
types: [completed]
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'backend/src/**'
|
||||
- 'frontend/src/**'
|
||||
- 'backend/package.json'
|
||||
- 'frontend/package.json'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
# Prevent parallel badge workflows from racing each other
|
||||
concurrency:
|
||||
group: update-test-badges
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
update-badges:
|
||||
name: Update Test Count Badges
|
||||
runs-on: ubuntu-latest
|
||||
# Only run after successful docker builds, not failed ones
|
||||
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
token: ${{ secrets.BADGE_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
@@ -100,5 +104,8 @@ jobs:
|
||||
echo "No badge changes to commit"
|
||||
else
|
||||
git commit -m "chore: update test count badges [skip ci]"
|
||||
# Rebase on latest main to avoid push rejection when concurrent
|
||||
# badge workflows or other [skip ci] commits land between checkout and push
|
||||
git pull --rebase origin main
|
||||
git push
|
||||
fi
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
name: Version Bump on Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
version-bump:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get version from tag
|
||||
id: version
|
||||
run: |
|
||||
# Extract version from tag (e.g., v1.6.0 -> 1.6.0)
|
||||
VERSION="${GITHUB_REF_NAME#v}"
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "Extracted version: $VERSION"
|
||||
|
||||
- name: Update package.json versions
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
|
||||
# Update backend/package.json
|
||||
jq --arg v "$VERSION" '.version = $v' backend/package.json > backend/package.json.tmp
|
||||
mv backend/package.json.tmp backend/package.json
|
||||
|
||||
# Update frontend/package.json
|
||||
jq --arg v "$VERSION" '.version = $v' frontend/package.json > frontend/package.json.tmp
|
||||
mv frontend/package.json.tmp frontend/package.json
|
||||
|
||||
echo "Updated versions to $VERSION"
|
||||
cat backend/package.json | head -5
|
||||
cat frontend/package.json | head -5
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
git add backend/package.json frontend/package.json
|
||||
|
||||
# Only commit if there are changes
|
||||
if git diff --staged --quiet; then
|
||||
echo "No version changes needed"
|
||||
else
|
||||
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} [skip ci]"
|
||||
git push origin main
|
||||
fi
|
||||
+2
-1
@@ -80,4 +80,5 @@ Thumbs.db
|
||||
.roo/
|
||||
.roomodes
|
||||
AGENTS.md
|
||||
docs/TECH_STACK.md
|
||||
docs/TECH_STACK.md
|
||||
doku
|
||||
@@ -18,8 +18,8 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Backend_Tests-494%2F494-brightgreen?logo=vitest" alt="Backend Tests 454/454" />
|
||||
<img src="https://img.shields.io/badge/Frontend_Tests-639%2F639-brightgreen?logo=vitest" alt="Frontend Tests 611/611" />
|
||||
<img src="https://img.shields.io/badge/Backend_Tests-526%2F526-brightgreen?logo=vitest" alt="Backend Tests 454/454" />
|
||||
<img src="https://img.shields.io/badge/Frontend_Tests-719%2F719-brightgreen?logo=vitest" alt="Frontend Tests 611/611" />
|
||||
</p>
|
||||
|
||||
### 🤖 AI-Generated Code
|
||||
@@ -120,7 +120,7 @@ Share your medication schedule with others via a public link.
|
||||
</details>
|
||||
|
||||
### Smart Inventory
|
||||
- Track exact stock: packs, blisters, and loose pills
|
||||
- Track exact stock: packs, blisters, bottles, and loose pills
|
||||
- Display remaining days of supply
|
||||
- Automatic calculation based on intake schedule
|
||||
|
||||
@@ -141,6 +141,7 @@ Share your medication schedule with others via a public link.
|
||||
### Trip Planner
|
||||
- Calculate how many pills you need for a trip or date range
|
||||
- Plan ahead for vacations, business trips, or hospital stays
|
||||
- Send demand reports via email or push notification
|
||||
|
||||
### Multi-Person Support
|
||||
- Manage medications for multiple people
|
||||
@@ -212,7 +213,7 @@ Generate secrets with: `openssl rand -hex 32`
|
||||
| `OIDC_ISSUER_URL` | — | OIDC provider URL |
|
||||
| `OIDC_CLIENT_ID` | — | Client ID from OIDC provider |
|
||||
| `OIDC_CLIENT_SECRET` | — | Client secret from OIDC provider |
|
||||
| `OIDC_REDIRECT_URI` | — | Callback URL |
|
||||
| `OIDC_REDIRECT_URI` | — | Full callback URL (e.g., `https://your-domain.com/api/auth/oidc/callback`) |
|
||||
| `OIDC_SCOPES` | `openid profile email` | Scopes to request |
|
||||
| `OIDC_USERNAME_CLAIM` | `preferred_username` | Claim for username |
|
||||
| `OIDC_AUTO_CREATE_USERS` | `true` | Auto-create users on first SSO login |
|
||||
@@ -254,6 +255,14 @@ Configure push notifications in Settings → Push, or set defaults via environme
|
||||
| `DEFAULT_SHOUTRRR_STOCK_REMINDERS` | `true` | Send stock warnings via push |
|
||||
| `DEFAULT_SHOUTRRR_INTAKE_REMINDERS` | `true` | Send intake reminders via push |
|
||||
|
||||
### Default User Settings
|
||||
|
||||
These defaults are applied when a new user is created. Once a user saves settings in the app, their values take precedence.
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `DEFAULT_SHARE_STOCK_STATUS` | `true` | Show stock status (Normal/Low/Critical) on shared schedule links |
|
||||
|
||||
#### URL Examples
|
||||
|
||||
**ntfy** (free, self-hostable):
|
||||
|
||||
@@ -5,6 +5,6 @@ export default defineConfig({
|
||||
out: "./drizzle",
|
||||
dialect: "sqlite",
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL || "./data/medassist.db",
|
||||
url: process.env.DATABASE_URL || "./data/medassist-ng.db",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE `user_settings` ADD `last_stock_reminder_sent` text;--> statement-breakpoint
|
||||
ALTER TABLE `user_settings` ADD `last_stock_reminder_channel` text;--> statement-breakpoint
|
||||
ALTER TABLE `user_settings` ADD `last_stock_reminder_med_names` text;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `user_settings` ADD `share_stock_status` integer DEFAULT true NOT NULL;
|
||||
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE `medications` ADD `prescription_enabled` integer NOT NULL DEFAULT 0;
|
||||
ALTER TABLE `medications` ADD `prescription_authorized_refills` integer;
|
||||
ALTER TABLE `medications` ADD `prescription_remaining_refills` integer;
|
||||
ALTER TABLE `medications` ADD `prescription_low_refill_threshold` integer NOT NULL DEFAULT 1;
|
||||
ALTER TABLE `medications` ADD `prescription_expiry_date` text;
|
||||
|
||||
ALTER TABLE `user_settings` ADD `email_prescription_reminders` integer NOT NULL DEFAULT 1;
|
||||
ALTER TABLE `user_settings` ADD `shoutrrr_prescription_reminders` integer NOT NULL DEFAULT 1;
|
||||
@@ -0,0 +1,907 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "7cd75e33-b3d8-4930-a60b-2a0a9f644c6d",
|
||||
"prevId": "fb61e5fd-152d-4e61-8836-e2fd1d28e3f0",
|
||||
"tables": {
|
||||
"dose_tracking": {
|
||||
"name": "dose_tracking",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dose_id": {
|
||||
"name": "dose_id",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_at": {
|
||||
"name": "taken_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(strftime('%s','now'))"
|
||||
},
|
||||
"marked_by": {
|
||||
"name": "marked_by",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dismissed": {
|
||||
"name": "dismissed",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"dose_tracking_user_id_users_id_fk": {
|
||||
"name": "dose_tracking_user_id_users_id_fk",
|
||||
"tableFrom": "dose_tracking",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"medications": {
|
||||
"name": "medications",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"generic_name": {
|
||||
"name": "generic_name",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_by_json": {
|
||||
"name": "taken_by_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"package_type": {
|
||||
"name": "package_type",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'blister'"
|
||||
},
|
||||
"pack_count": {
|
||||
"name": "pack_count",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"blisters_per_pack": {
|
||||
"name": "blisters_per_pack",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"pills_per_blister": {
|
||||
"name": "pills_per_blister",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"total_pills": {
|
||||
"name": "total_pills",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"loose_tablets": {
|
||||
"name": "loose_tablets",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"stock_adjustment": {
|
||||
"name": "stock_adjustment",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"last_stock_correction_at": {
|
||||
"name": "last_stock_correction_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pill_weight_mg": {
|
||||
"name": "pill_weight_mg",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dose_unit": {
|
||||
"name": "dose_unit",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'mg'"
|
||||
},
|
||||
"usage_json": {
|
||||
"name": "usage_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"every_json": {
|
||||
"name": "every_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"start_json": {
|
||||
"name": "start_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"intakes_json": {
|
||||
"name": "intakes_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"image_url": {
|
||||
"name": "image_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expiry_date": {
|
||||
"name": "expiry_date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"notes": {
|
||||
"name": "notes",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"intake_reminders_enabled": {
|
||||
"name": "intake_reminders_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"dismissed_until": {
|
||||
"name": "dismissed_until",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"medications_user_id_users_id_fk": {
|
||||
"name": "medications_user_id_users_id_fk",
|
||||
"tableFrom": "medications",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"refill_history": {
|
||||
"name": "refill_history",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"medication_id": {
|
||||
"name": "medication_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"packs_added": {
|
||||
"name": "packs_added",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"loose_pills_added": {
|
||||
"name": "loose_pills_added",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"refill_date": {
|
||||
"name": "refill_date",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(strftime('%s','now'))"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"refill_history_medication_id_medications_id_fk": {
|
||||
"name": "refill_history_medication_id_medications_id_fk",
|
||||
"tableFrom": "refill_history",
|
||||
"tableTo": "medications",
|
||||
"columnsFrom": [
|
||||
"medication_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"refill_history_user_id_users_id_fk": {
|
||||
"name": "refill_history_user_id_users_id_fk",
|
||||
"tableFrom": "refill_history",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"refresh_tokens": {
|
||||
"name": "refresh_tokens",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token_id": {
|
||||
"name": "token_id",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"rotated_at": {
|
||||
"name": "rotated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"revoked": {
|
||||
"name": "revoked",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"refresh_tokens_token_id_unique": {
|
||||
"name": "refresh_tokens_token_id_unique",
|
||||
"columns": [
|
||||
"token_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"refresh_tokens_user_id_users_id_fk": {
|
||||
"name": "refresh_tokens_user_id_users_id_fk",
|
||||
"tableFrom": "refresh_tokens",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"share_tokens": {
|
||||
"name": "share_tokens",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token": {
|
||||
"name": "token",
|
||||
"type": "text(64)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_by": {
|
||||
"name": "taken_by",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"schedule_days": {
|
||||
"name": "schedule_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"share_tokens_token_unique": {
|
||||
"name": "share_tokens_token_unique",
|
||||
"columns": [
|
||||
"token"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"share_tokens_user_id_users_id_fk": {
|
||||
"name": "share_tokens_user_id_users_id_fk",
|
||||
"tableFrom": "share_tokens",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"user_settings": {
|
||||
"name": "user_settings",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email_enabled": {
|
||||
"name": "email_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"notification_email": {
|
||||
"name": "notification_email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email_stock_reminders": {
|
||||
"name": "email_stock_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"email_intake_reminders": {
|
||||
"name": "email_intake_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"shoutrrr_enabled": {
|
||||
"name": "shoutrrr_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"shoutrrr_url": {
|
||||
"name": "shoutrrr_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"shoutrrr_stock_reminders": {
|
||||
"name": "shoutrrr_stock_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"shoutrrr_intake_reminders": {
|
||||
"name": "shoutrrr_intake_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"reminder_days_before": {
|
||||
"name": "reminder_days_before",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 7
|
||||
},
|
||||
"repeat_daily_reminders": {
|
||||
"name": "repeat_daily_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"skip_reminders_for_taken_doses": {
|
||||
"name": "skip_reminders_for_taken_doses",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"repeat_reminders_enabled": {
|
||||
"name": "repeat_reminders_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"reminder_repeat_interval_minutes": {
|
||||
"name": "reminder_repeat_interval_minutes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"max_nagging_reminders": {
|
||||
"name": "max_nagging_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 5
|
||||
},
|
||||
"low_stock_days": {
|
||||
"name": "low_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"normal_stock_days": {
|
||||
"name": "normal_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 90
|
||||
},
|
||||
"high_stock_days": {
|
||||
"name": "high_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 180
|
||||
},
|
||||
"expiry_warning_days": {
|
||||
"name": "expiry_warning_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 90
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'en'"
|
||||
},
|
||||
"stock_calculation_mode": {
|
||||
"name": "stock_calculation_mode",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'automatic'"
|
||||
},
|
||||
"last_auto_email_sent": {
|
||||
"name": "last_auto_email_sent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_notification_type": {
|
||||
"name": "last_notification_type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_notification_channel": {
|
||||
"name": "last_notification_channel",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_reminder_med_name": {
|
||||
"name": "last_reminder_med_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_reminder_taken_by": {
|
||||
"name": "last_reminder_taken_by",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_sent": {
|
||||
"name": "last_stock_reminder_sent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_channel": {
|
||||
"name": "last_stock_reminder_channel",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_med_names": {
|
||||
"name": "last_stock_reminder_med_names",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"user_settings_user_id_unique": {
|
||||
"name": "user_settings_user_id_unique",
|
||||
"columns": [
|
||||
"user_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"user_settings_user_id_users_id_fk": {
|
||||
"name": "user_settings_user_id_users_id_fk",
|
||||
"tableFrom": "user_settings",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"password_hash": {
|
||||
"name": "password_hash",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"avatar_url": {
|
||||
"name": "avatar_url",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"auth_provider": {
|
||||
"name": "auth_provider",
|
||||
"type": "text(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'local'"
|
||||
},
|
||||
"oidc_subject": {
|
||||
"name": "oidc_subject",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_active": {
|
||||
"name": "is_active",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"last_login_at": {
|
||||
"name": "last_login_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"users_username_unique": {
|
||||
"name": "users_username_unique",
|
||||
"columns": [
|
||||
"username"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,915 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "b6f1ee4b-cc31-4060-a4d4-bcd4fdc5bd87",
|
||||
"prevId": "7cd75e33-b3d8-4930-a60b-2a0a9f644c6d",
|
||||
"tables": {
|
||||
"dose_tracking": {
|
||||
"name": "dose_tracking",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dose_id": {
|
||||
"name": "dose_id",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_at": {
|
||||
"name": "taken_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(strftime('%s','now'))"
|
||||
},
|
||||
"marked_by": {
|
||||
"name": "marked_by",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dismissed": {
|
||||
"name": "dismissed",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"dose_tracking_user_id_users_id_fk": {
|
||||
"name": "dose_tracking_user_id_users_id_fk",
|
||||
"tableFrom": "dose_tracking",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"medications": {
|
||||
"name": "medications",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"generic_name": {
|
||||
"name": "generic_name",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_by_json": {
|
||||
"name": "taken_by_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"package_type": {
|
||||
"name": "package_type",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'blister'"
|
||||
},
|
||||
"pack_count": {
|
||||
"name": "pack_count",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"blisters_per_pack": {
|
||||
"name": "blisters_per_pack",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"pills_per_blister": {
|
||||
"name": "pills_per_blister",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 1
|
||||
},
|
||||
"total_pills": {
|
||||
"name": "total_pills",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"loose_tablets": {
|
||||
"name": "loose_tablets",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"stock_adjustment": {
|
||||
"name": "stock_adjustment",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"last_stock_correction_at": {
|
||||
"name": "last_stock_correction_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pill_weight_mg": {
|
||||
"name": "pill_weight_mg",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"dose_unit": {
|
||||
"name": "dose_unit",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'mg'"
|
||||
},
|
||||
"usage_json": {
|
||||
"name": "usage_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"every_json": {
|
||||
"name": "every_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"start_json": {
|
||||
"name": "start_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"intakes_json": {
|
||||
"name": "intakes_json",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"image_url": {
|
||||
"name": "image_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expiry_date": {
|
||||
"name": "expiry_date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"notes": {
|
||||
"name": "notes",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"intake_reminders_enabled": {
|
||||
"name": "intake_reminders_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"dismissed_until": {
|
||||
"name": "dismissed_until",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"medications_user_id_users_id_fk": {
|
||||
"name": "medications_user_id_users_id_fk",
|
||||
"tableFrom": "medications",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"refill_history": {
|
||||
"name": "refill_history",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"medication_id": {
|
||||
"name": "medication_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"packs_added": {
|
||||
"name": "packs_added",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"loose_pills_added": {
|
||||
"name": "loose_pills_added",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"refill_date": {
|
||||
"name": "refill_date",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(strftime('%s','now'))"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"refill_history_medication_id_medications_id_fk": {
|
||||
"name": "refill_history_medication_id_medications_id_fk",
|
||||
"tableFrom": "refill_history",
|
||||
"tableTo": "medications",
|
||||
"columnsFrom": [
|
||||
"medication_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"refill_history_user_id_users_id_fk": {
|
||||
"name": "refill_history_user_id_users_id_fk",
|
||||
"tableFrom": "refill_history",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"refresh_tokens": {
|
||||
"name": "refresh_tokens",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token_id": {
|
||||
"name": "token_id",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"rotated_at": {
|
||||
"name": "rotated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"revoked": {
|
||||
"name": "revoked",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"refresh_tokens_token_id_unique": {
|
||||
"name": "refresh_tokens_token_id_unique",
|
||||
"columns": [
|
||||
"token_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"refresh_tokens_user_id_users_id_fk": {
|
||||
"name": "refresh_tokens_user_id_users_id_fk",
|
||||
"tableFrom": "refresh_tokens",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"share_tokens": {
|
||||
"name": "share_tokens",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"token": {
|
||||
"name": "token",
|
||||
"type": "text(64)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"taken_by": {
|
||||
"name": "taken_by",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"schedule_days": {
|
||||
"name": "schedule_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"share_tokens_token_unique": {
|
||||
"name": "share_tokens_token_unique",
|
||||
"columns": [
|
||||
"token"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"share_tokens_user_id_users_id_fk": {
|
||||
"name": "share_tokens_user_id_users_id_fk",
|
||||
"tableFrom": "share_tokens",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"user_settings": {
|
||||
"name": "user_settings",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email_enabled": {
|
||||
"name": "email_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"notification_email": {
|
||||
"name": "notification_email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email_stock_reminders": {
|
||||
"name": "email_stock_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"email_intake_reminders": {
|
||||
"name": "email_intake_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"shoutrrr_enabled": {
|
||||
"name": "shoutrrr_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"shoutrrr_url": {
|
||||
"name": "shoutrrr_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"shoutrrr_stock_reminders": {
|
||||
"name": "shoutrrr_stock_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"shoutrrr_intake_reminders": {
|
||||
"name": "shoutrrr_intake_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"reminder_days_before": {
|
||||
"name": "reminder_days_before",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 7
|
||||
},
|
||||
"repeat_daily_reminders": {
|
||||
"name": "repeat_daily_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"skip_reminders_for_taken_doses": {
|
||||
"name": "skip_reminders_for_taken_doses",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"repeat_reminders_enabled": {
|
||||
"name": "repeat_reminders_enabled",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"reminder_repeat_interval_minutes": {
|
||||
"name": "reminder_repeat_interval_minutes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"max_nagging_reminders": {
|
||||
"name": "max_nagging_reminders",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 5
|
||||
},
|
||||
"low_stock_days": {
|
||||
"name": "low_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 30
|
||||
},
|
||||
"normal_stock_days": {
|
||||
"name": "normal_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 90
|
||||
},
|
||||
"high_stock_days": {
|
||||
"name": "high_stock_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 180
|
||||
},
|
||||
"expiry_warning_days": {
|
||||
"name": "expiry_warning_days",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 90
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'en'"
|
||||
},
|
||||
"stock_calculation_mode": {
|
||||
"name": "stock_calculation_mode",
|
||||
"type": "text(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'automatic'"
|
||||
},
|
||||
"share_stock_status": {
|
||||
"name": "share_stock_status",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"last_auto_email_sent": {
|
||||
"name": "last_auto_email_sent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_notification_type": {
|
||||
"name": "last_notification_type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_notification_channel": {
|
||||
"name": "last_notification_channel",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_reminder_med_name": {
|
||||
"name": "last_reminder_med_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_reminder_taken_by": {
|
||||
"name": "last_reminder_taken_by",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_sent": {
|
||||
"name": "last_stock_reminder_sent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_channel": {
|
||||
"name": "last_stock_reminder_channel",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_stock_reminder_med_names": {
|
||||
"name": "last_stock_reminder_med_names",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"user_settings_user_id_unique": {
|
||||
"name": "user_settings_user_id_unique",
|
||||
"columns": [
|
||||
"user_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"user_settings_user_id_users_id_fk": {
|
||||
"name": "user_settings_user_id_users_id_fk",
|
||||
"tableFrom": "user_settings",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"password_hash": {
|
||||
"name": "password_hash",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"avatar_url": {
|
||||
"name": "avatar_url",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"auth_provider": {
|
||||
"name": "auth_provider",
|
||||
"type": "text(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'local'"
|
||||
},
|
||||
"oidc_subject": {
|
||||
"name": "oidc_subject",
|
||||
"type": "text(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_active": {
|
||||
"name": "is_active",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": true
|
||||
},
|
||||
"last_login_at": {
|
||||
"name": "last_login_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"users_username_unique": {
|
||||
"name": "users_username_unique",
|
||||
"columns": [
|
||||
"username"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,20 @@
|
||||
"when": 1769893708813,
|
||||
"tag": "0005_add_intakes_json",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "6",
|
||||
"when": 1770626907896,
|
||||
"tag": "0006_add_stock_reminder_tracking",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "6",
|
||||
"when": 1770659669121,
|
||||
"tag": "0007_add_share_stock_status",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+997
-1155
File diff suppressed because it is too large
Load Diff
+16
-16
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medassist-ng-backend",
|
||||
"version": "1.8.6",
|
||||
"version": "1.10.3",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
@@ -17,31 +17,31 @@
|
||||
"check": "npx biome check . && tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cookie": "^10.0.1",
|
||||
"@fastify/cors": "^10.0.1",
|
||||
"@fastify/cookie": "^11.0.2",
|
||||
"@fastify/cors": "^11.2.0",
|
||||
"@fastify/helmet": "^13.0.2",
|
||||
"@fastify/jwt": "^10.0.0",
|
||||
"@fastify/multipart": "^9.3.0",
|
||||
"@fastify/multipart": "^9.4.0",
|
||||
"@fastify/rate-limit": "^10.3.0",
|
||||
"@fastify/sensible": "^6.0.4",
|
||||
"@fastify/static": "^8.3.0",
|
||||
"@libsql/client": "^0.10.0",
|
||||
"argon2": "^0.40.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"@fastify/static": "^9.0.0",
|
||||
"@libsql/client": "^0.17.0",
|
||||
"argon2": "^0.44.0",
|
||||
"dotenv": "^17.3.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"fastify": "^5.7.3",
|
||||
"nodemailer": "^7.0.11",
|
||||
"openid-client": "^6.8.1",
|
||||
"fastify": "^5.7.4",
|
||||
"nodemailer": "^8.0.1",
|
||||
"openid-client": "^6.8.2",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.12",
|
||||
"@types/node": "^22.7.4",
|
||||
"@biomejs/biome": "^2.3.15",
|
||||
"@types/node": "^25.2.3",
|
||||
"@types/nodemailer": "^6.4.21",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"@vitest/coverage-v8": "^4.0.16",
|
||||
"drizzle-kit": "^0.31.8",
|
||||
"supertest": "^7.0.0",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"drizzle-kit": "^0.31.9",
|
||||
"supertest": "^7.2.2",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.5.4",
|
||||
"vitest": "^4.0.16"
|
||||
|
||||
+25
-25
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
|
||||
import { type Client, createClient } from "@libsql/client";
|
||||
import dotenv from "dotenv";
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
|
||||
import { log } from "../utils/logger.js";
|
||||
// Import utilities from db-utils (side-effect-free)
|
||||
import {
|
||||
ensureDataDirectory,
|
||||
@@ -40,34 +40,34 @@ dotenv.config({ path: envPath });
|
||||
// Use absolute path to ensure it works in Docker
|
||||
const { dataDir, dbPath, url } = getDbPaths();
|
||||
|
||||
console.log(`[DB] Data directory: ${dataDir}`);
|
||||
console.log(`[DB] Database path: ${dbPath}`);
|
||||
console.log(`[DB] Database URL: ${url}`);
|
||||
log.debug(`[DB] Data directory: ${dataDir}`);
|
||||
log.debug(`[DB] Database path: ${dbPath}`);
|
||||
log.debug(`[DB] Database URL: ${url}`);
|
||||
|
||||
// Ensure data directory exists and is writable
|
||||
const dirResult = ensureDataDirectory(dataDir);
|
||||
if (!dirResult.success) {
|
||||
console.error(`[DB] ERROR: Cannot access data directory: ${dirResult.error}`);
|
||||
console.error(`[DB] Please ensure the volume mount has correct permissions.`);
|
||||
console.error(`[DB] Try running on host: sudo chown -R 1000:1000 ${dataDir}`);
|
||||
log.error(`[DB] ERROR: Cannot access data directory: ${dirResult.error}`);
|
||||
log.error(`[DB] Please ensure the volume mount has correct permissions.`);
|
||||
log.error(`[DB] Try running on host: sudo chown -R 1000:1000 ${dataDir}`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`[DB] Data directory is writable`);
|
||||
log.debug(`[DB] Data directory is writable`);
|
||||
|
||||
// Log directory stats
|
||||
const stats = statSync(dataDir);
|
||||
console.log(`[DB] Directory permissions: ${stats.mode.toString(8)}`);
|
||||
console.log(`[DB] Directory UID: ${stats.uid}, GID: ${stats.gid}`);
|
||||
console.log(`[DB] Write test successful`);
|
||||
log.debug(`[DB] Directory permissions: ${stats.mode.toString(8)}`);
|
||||
log.debug(`[DB] Directory UID: ${stats.uid}, GID: ${stats.gid}`);
|
||||
log.debug(`[DB] Write test successful`);
|
||||
}
|
||||
|
||||
let client: Client;
|
||||
try {
|
||||
client = createClient({ url });
|
||||
console.log(`[DB] Database client created successfully`);
|
||||
log.debug(`[DB] Database client created successfully`);
|
||||
} catch (err: any) {
|
||||
console.error(`[DB] ERROR: Failed to create database client: ${err.message}`);
|
||||
console.error(`[DB] Database path: ${dbPath}`);
|
||||
log.error(`[DB] ERROR: Failed to create database client: ${err.message}`);
|
||||
log.error(`[DB] Database path: ${dbPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -76,46 +76,46 @@ export const db = drizzle(client);
|
||||
// Auto-run migrations (self-healing database)
|
||||
async function runMigrations() {
|
||||
// Run drizzle-kit generated migrations
|
||||
console.log(`[DB] Running drizzle migrations...`);
|
||||
log.info(`[DB] Running migrations...`);
|
||||
const migrateResult = await runDrizzleMigrations(db);
|
||||
if (!migrateResult.success) {
|
||||
console.error(`[DB] Migration error:`, migrateResult.error);
|
||||
log.error(`[DB] Migration error: ${migrateResult.error}`);
|
||||
} else if (migrateResult.warning) {
|
||||
console.log(`[DB] Migration warning:`, migrateResult.warning);
|
||||
log.warn(`[DB] Migration warning: ${migrateResult.warning}`);
|
||||
} else {
|
||||
console.log(`[DB] Drizzle migrations completed`);
|
||||
log.debug(`[DB] Drizzle migrations completed`);
|
||||
}
|
||||
|
||||
// Run ALTER TABLE migrations for backward compatibility
|
||||
const alterResult = await runAlterMigrations(client);
|
||||
if (alterResult.errors.length > 0) {
|
||||
alterResult.errors.forEach((err) => console.error(`[DB] ALTER migration error:`, err));
|
||||
alterResult.errors.forEach((err) => log.error(`[DB] ALTER migration error: ${err}`));
|
||||
}
|
||||
console.log(`[DB] Tables verified/created`);
|
||||
log.debug(`[DB] Tables verified/created`);
|
||||
|
||||
// Repair dose IDs with trailing hyphens (from frontend takenBy bug)
|
||||
const trailingResult = await repairTrailingHyphenDoseIds(client);
|
||||
if (trailingResult.repaired > 0) {
|
||||
console.log(`[DB] Repaired ${trailingResult.repaired} dose IDs with trailing hyphens`);
|
||||
log.info(`[DB] Repaired ${trailingResult.repaired} dose IDs with trailing hyphens`);
|
||||
}
|
||||
if (trailingResult.errors.length > 0) {
|
||||
trailingResult.errors.forEach((err) => console.error(`[DB] Trailing-hyphen repair error:`, err));
|
||||
trailingResult.errors.forEach((err) => log.error(`[DB] Trailing-hyphen repair error: ${err}`));
|
||||
}
|
||||
|
||||
// Repair orphaned dose tracking IDs from past schedule changes
|
||||
const repairResult = await repairOrphanedDoseIds(client);
|
||||
if (repairResult.repaired > 0) {
|
||||
console.log(`[DB] Repaired ${repairResult.repaired} orphaned dose tracking IDs`);
|
||||
log.info(`[DB] Repaired ${repairResult.repaired} orphaned dose tracking IDs`);
|
||||
}
|
||||
if (repairResult.errors.length > 0) {
|
||||
repairResult.errors.forEach((err) => console.error(`[DB] Dose repair error:`, err));
|
||||
repairResult.errors.forEach((err) => log.error(`[DB] Dose repair error: ${err}`));
|
||||
}
|
||||
|
||||
// If auth is disabled, ensure a default user exists (ID=1)
|
||||
const authEnabled = process.env.AUTH_ENABLED === "true";
|
||||
const created = await ensureDefaultUser(client, authEnabled);
|
||||
if (created) {
|
||||
console.log(`[DB] Created default user for auth-disabled mode`);
|
||||
log.info(`[DB] Created default user for auth-disabled mode`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,10 +88,10 @@ export async function runDrizzleMigrations(
|
||||
await migrate(database, { migrationsFolder });
|
||||
return { success: true };
|
||||
} catch (err: any) {
|
||||
// If the error is "duplicate column", it means the schema is already up-to-date
|
||||
// This happens when ALTER migrations in client.ts have already added the columns
|
||||
// We consider this a success with a warning, not a failure
|
||||
if (err.message?.includes("duplicate column")) {
|
||||
// If the error is about existing schema objects, the DB is already up-to-date
|
||||
// This happens when ALTER migrations in client.ts have already added the columns,
|
||||
// or when tables were created before drizzle migrations were introduced
|
||||
if (err.message?.includes("duplicate column") || err.message?.includes("already exists")) {
|
||||
return { success: true, warning: `Schema already up-to-date: ${err.message}` };
|
||||
}
|
||||
return { success: false, error: err.message };
|
||||
@@ -129,6 +129,25 @@ export async function runAlterMigrations(client: Client): Promise<{ success: boo
|
||||
`ALTER TABLE medications ADD COLUMN dose_unit text DEFAULT 'mg'`,
|
||||
// Added for intake-level takenBy: unified intakes structure
|
||||
`ALTER TABLE medications ADD COLUMN intakes_json text NOT NULL DEFAULT '[]'`,
|
||||
// Added for separate stock reminder tracking
|
||||
`ALTER TABLE user_settings ADD COLUMN last_stock_reminder_sent text`,
|
||||
`ALTER TABLE user_settings ADD COLUMN last_stock_reminder_channel text`,
|
||||
`ALTER TABLE user_settings ADD COLUMN last_stock_reminder_med_names text`,
|
||||
// Added for share stock visibility toggle
|
||||
`ALTER TABLE user_settings ADD COLUMN share_stock_status integer NOT NULL DEFAULT 1`,
|
||||
// Added for prescription refill tracking and reminders
|
||||
`ALTER TABLE medications ADD COLUMN prescription_enabled integer NOT NULL DEFAULT 0`,
|
||||
`ALTER TABLE medications ADD COLUMN prescription_authorized_refills integer`,
|
||||
`ALTER TABLE medications ADD COLUMN prescription_remaining_refills integer`,
|
||||
`ALTER TABLE medications ADD COLUMN prescription_low_refill_threshold integer NOT NULL DEFAULT 1`,
|
||||
`ALTER TABLE medications ADD COLUMN prescription_expiry_date text`,
|
||||
`ALTER TABLE user_settings ADD COLUMN email_prescription_reminders integer NOT NULL DEFAULT 1`,
|
||||
`ALTER TABLE user_settings ADD COLUMN shoutrrr_prescription_reminders integer NOT NULL DEFAULT 1`,
|
||||
`ALTER TABLE user_settings ADD COLUMN last_prescription_reminder_sent text`,
|
||||
`ALTER TABLE user_settings ADD COLUMN last_prescription_reminder_channel text`,
|
||||
`ALTER TABLE user_settings ADD COLUMN last_prescription_reminder_med_names text`,
|
||||
// Added for refill history prescription tracking
|
||||
`ALTER TABLE refill_history ADD COLUMN used_prescription integer NOT NULL DEFAULT 0`,
|
||||
];
|
||||
|
||||
for (const sql of alterMigrations) {
|
||||
@@ -166,6 +185,23 @@ export async function runAlterMigrations(client: Client): Promise<{ success: boo
|
||||
}
|
||||
}
|
||||
|
||||
// Create indexes that might be missing (silently fail if already exists)
|
||||
const createIndexMigrations = [
|
||||
// Added in v1.6.x - case-insensitive unique usernames
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS users_username_lower_unique ON users(lower(username))`,
|
||||
];
|
||||
|
||||
for (const sql of createIndexMigrations) {
|
||||
try {
|
||||
await client.execute(sql);
|
||||
} catch (e: any) {
|
||||
// Silently ignore "already exists" errors
|
||||
if (!e.message?.includes("already exists")) {
|
||||
errors.push(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { success: errors.length === 0, errors };
|
||||
}
|
||||
|
||||
|
||||
@@ -63,17 +63,17 @@ export function getStatementPreview(stmt: string, maxLength: number = 50): strin
|
||||
const url = "file:./data/medassist-ng.db";
|
||||
|
||||
async function main() {
|
||||
console.log("Starting database setup...");
|
||||
console.log("Database URL:", url);
|
||||
console.log("Migrations folder:", migrationsFolder);
|
||||
console.log("[DB] Starting database setup...");
|
||||
console.log("[DB] Database URL:", url);
|
||||
console.log("[DB] Migrations folder:", migrationsFolder);
|
||||
|
||||
const client = createClient({ url });
|
||||
const db = drizzle(client);
|
||||
|
||||
console.log("Running drizzle migrations...");
|
||||
console.log("[DB] Running drizzle migrations...");
|
||||
await migrate(db, { migrationsFolder });
|
||||
|
||||
console.log("Database setup complete!");
|
||||
console.log("[DB] Database setup complete!");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,11 @@ export const medications = sqliteTable("medications", {
|
||||
expiryDate: text("expiry_date"),
|
||||
notes: text("notes"),
|
||||
intakeRemindersEnabled: integer("intake_reminders_enabled", { mode: "boolean" }).notNull().default(false),
|
||||
prescriptionEnabled: integer("prescription_enabled", { mode: "boolean" }).notNull().default(false),
|
||||
prescriptionAuthorizedRefills: integer("prescription_authorized_refills"),
|
||||
prescriptionRemainingRefills: integer("prescription_remaining_refills"),
|
||||
prescriptionLowRefillThreshold: integer("prescription_low_refill_threshold").notNull().default(1),
|
||||
prescriptionExpiryDate: text("prescription_expiry_date"),
|
||||
dismissedUntil: text("dismissed_until"), // ISO date string (e.g. "2026-01-23") - all past doses until this date are dismissed
|
||||
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
});
|
||||
@@ -65,11 +70,15 @@ export const userSettings = sqliteTable("user_settings", {
|
||||
notificationEmail: text("notification_email"),
|
||||
emailStockReminders: integer("email_stock_reminders", { mode: "boolean" }).notNull().default(true),
|
||||
emailIntakeReminders: integer("email_intake_reminders", { mode: "boolean" }).notNull().default(true),
|
||||
emailPrescriptionReminders: integer("email_prescription_reminders", { mode: "boolean" }).notNull().default(true),
|
||||
// Push notifications (shoutrrr/ntfy)
|
||||
shoutrrrEnabled: integer("shoutrrr_enabled", { mode: "boolean" }).notNull().default(false),
|
||||
shoutrrrUrl: text("shoutrrr_url"),
|
||||
shoutrrrStockReminders: integer("shoutrrr_stock_reminders", { mode: "boolean" }).notNull().default(true),
|
||||
shoutrrrIntakeReminders: integer("shoutrrr_intake_reminders", { mode: "boolean" }).notNull().default(true),
|
||||
shoutrrrPrescriptionReminders: integer("shoutrrr_prescription_reminders", { mode: "boolean" })
|
||||
.notNull()
|
||||
.default(true),
|
||||
// Reminder settings
|
||||
reminderDaysBefore: integer("reminder_days_before").notNull().default(7),
|
||||
repeatDailyReminders: integer("repeat_daily_reminders", { mode: "boolean" }).notNull().default(false),
|
||||
@@ -86,12 +95,22 @@ export const userSettings = sqliteTable("user_settings", {
|
||||
language: text("language", { length: 10 }).notNull().default("en"),
|
||||
// Stock calculation mode: "automatic" (schedule-based) or "manual" (only marked doses)
|
||||
stockCalculationMode: text("stock_calculation_mode", { length: 20 }).notNull().default("automatic"),
|
||||
// Last notification tracking
|
||||
// Whether shared schedule links show stock status (Critical/Low/Normal) to intake users
|
||||
shareStockStatus: integer("share_stock_status", { mode: "boolean" }).notNull().default(true),
|
||||
// Last notification tracking (intake reminders)
|
||||
lastAutoEmailSent: text("last_auto_email_sent"),
|
||||
lastNotificationType: text("last_notification_type"),
|
||||
lastNotificationChannel: text("last_notification_channel"),
|
||||
lastReminderMedName: text("last_reminder_med_name"),
|
||||
lastReminderTakenBy: text("last_reminder_taken_by"),
|
||||
// Last stock reminder tracking (separate from intake)
|
||||
lastStockReminderSent: text("last_stock_reminder_sent"),
|
||||
lastStockReminderChannel: text("last_stock_reminder_channel"),
|
||||
lastStockReminderMedNames: text("last_stock_reminder_med_names"),
|
||||
// Last prescription reminder tracking (separate from stock/intake)
|
||||
lastPrescriptionReminderSent: text("last_prescription_reminder_sent"),
|
||||
lastPrescriptionReminderChannel: text("last_prescription_reminder_channel"),
|
||||
lastPrescriptionReminderMedNames: text("last_prescription_reminder_med_names"),
|
||||
// Timestamps
|
||||
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
});
|
||||
@@ -153,5 +172,6 @@ export const refillHistory = sqliteTable("refill_history", {
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
packsAdded: integer("packs_added").notNull().default(0),
|
||||
loosePillsAdded: integer("loose_pills_added").notNull().default(0),
|
||||
usedPrescription: integer("used_prescription", { mode: "boolean" }).notNull().default(false),
|
||||
refillDate: integer("refill_date", { mode: "timestamp" }).notNull().default(sql`(strftime('%s','now'))`),
|
||||
});
|
||||
|
||||
@@ -64,20 +64,29 @@ function getRegionFromTimezone(): string | undefined {
|
||||
}
|
||||
|
||||
type TranslationKeys = {
|
||||
// Stock reminder email
|
||||
// Stock reminder (shared across email + push)
|
||||
stockReminder: {
|
||||
subject: string;
|
||||
title: string;
|
||||
description: string;
|
||||
descriptionEmpty: string;
|
||||
descriptionMixed: string;
|
||||
alertSingle: string;
|
||||
alertMultiple: string;
|
||||
alertEmptySingle: string;
|
||||
alertEmptyMultiple: string;
|
||||
alertLowSingle: string;
|
||||
alertLowMultiple: string;
|
||||
alertLowStockSingle: string;
|
||||
alertLowStockMultiple: string;
|
||||
descriptionLow: string;
|
||||
tableHeaders: {
|
||||
medication: string;
|
||||
pills: string;
|
||||
days: string;
|
||||
runsOut: string;
|
||||
};
|
||||
footer: string;
|
||||
now: string;
|
||||
repeatDailyNote: string;
|
||||
};
|
||||
// Intake reminder email
|
||||
@@ -94,7 +103,6 @@ type TranslationKeys = {
|
||||
};
|
||||
pills: string;
|
||||
takenBy: string;
|
||||
footer: string;
|
||||
};
|
||||
// Push notifications
|
||||
push: {
|
||||
@@ -107,35 +115,103 @@ type TranslationKeys = {
|
||||
repeatDailyNote: string;
|
||||
empty: string;
|
||||
low: string;
|
||||
critical: string;
|
||||
lowStock: string;
|
||||
reorderNow: string;
|
||||
emptySection: string;
|
||||
lowSection: string;
|
||||
criticalSection: string;
|
||||
lowStockSection: string;
|
||||
};
|
||||
// Prescription reminder (shared across email + push)
|
||||
prescriptionReminder: {
|
||||
subjectSingle: string;
|
||||
subjectMultiple: string;
|
||||
pushTitleLow: string;
|
||||
pushTitleEmpty: string;
|
||||
pushEmpty: string;
|
||||
pushEmptySingle: string;
|
||||
pushLow: string;
|
||||
pushLowSingle: string;
|
||||
pushRenewNow: string;
|
||||
pushEmptySection: string;
|
||||
pushLowSection: string;
|
||||
pushRefillsLeft: string;
|
||||
title: string;
|
||||
titleEmpty: string;
|
||||
descriptionLow: string;
|
||||
descriptionEmpty: string;
|
||||
alertLowSingle: string;
|
||||
alertLowMultiple: string;
|
||||
alertEmptySingle: string;
|
||||
alertEmptyMultiple: string;
|
||||
line: string;
|
||||
lineEmpty: string;
|
||||
expiresSuffix: string;
|
||||
repeatDailyNote: string;
|
||||
tableHeaders: {
|
||||
medication: string;
|
||||
refillsLeft: string;
|
||||
reminderThreshold: string;
|
||||
prescriptionExpires: string;
|
||||
};
|
||||
};
|
||||
// Demand calculator email
|
||||
demandCalculator: {
|
||||
subject: string;
|
||||
title: string;
|
||||
description: string;
|
||||
summaryOutOfStock: string;
|
||||
summaryAllOk: string;
|
||||
tableHeaders: {
|
||||
medication: string;
|
||||
usage: string;
|
||||
needed: string;
|
||||
prescriptionRefills: string;
|
||||
available: string;
|
||||
status: string;
|
||||
};
|
||||
statusEnough: string;
|
||||
statusEmpty: string;
|
||||
prescriptionNotApplicable: string;
|
||||
};
|
||||
// Common
|
||||
common: {
|
||||
pill: string;
|
||||
pills: string;
|
||||
blister: string;
|
||||
blisters: string;
|
||||
day: string;
|
||||
days: string;
|
||||
soon: string;
|
||||
footer: string;
|
||||
};
|
||||
};
|
||||
|
||||
const translations: Record<Language, TranslationKeys> = {
|
||||
en: {
|
||||
stockReminder: {
|
||||
subject: "MedAssist-ng Auto-Reminder: {count} Medication{s} Running Low",
|
||||
title: "⚠️ MedAssist-ng - Automatic Reorder Reminder",
|
||||
description: "The following medications are running low and need to be reordered:",
|
||||
alertSingle: "⚠️ 1 medication running low!",
|
||||
alertMultiple: "⚠️ {count} medications running low!",
|
||||
subject: "MedAssist-ng: ⚠️ {count} Medication{s} Running Critically Low",
|
||||
title: "⚠️ MedAssist-ng: Automatic Reorder Reminder",
|
||||
description: "The following medications are running critically low and need to be reordered:",
|
||||
descriptionEmpty: "The following medications are empty and need to be reordered immediately:",
|
||||
descriptionMixed: "The following medications need to be reordered:",
|
||||
alertSingle: "⚠️ 1 medication running critically low!",
|
||||
alertMultiple: "⚠️ {count} medications running critically low!",
|
||||
alertEmptySingle: "🚨 1 medication empty - reorder immediately!",
|
||||
alertEmptyMultiple: "🚨 {count} medications empty - reorder immediately!",
|
||||
alertLowSingle: "⚠️ 1 medication running critically low",
|
||||
alertLowMultiple: "⚠️ {count} medications running critically low",
|
||||
alertLowStockSingle: "⚠️ 1 medication running low",
|
||||
alertLowStockMultiple: "⚠️ {count} medications running low",
|
||||
descriptionLow: "The following medications are running low and should be reordered soon:",
|
||||
tableHeaders: {
|
||||
medication: "Medication",
|
||||
pills: "Pills",
|
||||
days: "Days",
|
||||
runsOut: "Runs Out",
|
||||
},
|
||||
footer: "🤖 Automatic reminder from MedAssist-ng",
|
||||
now: "NOW",
|
||||
repeatDailyNote: "You are receiving this daily reminder because 'Repeat Daily' is enabled in settings.",
|
||||
},
|
||||
intakeReminder: {
|
||||
@@ -151,44 +227,109 @@ const translations: Record<Language, TranslationKeys> = {
|
||||
},
|
||||
pills: "pills",
|
||||
takenBy: "for {name}",
|
||||
footer: "🤖 Automatic reminder from MedAssist-ng",
|
||||
},
|
||||
push: {
|
||||
stockTitle: "MedAssist-ng: 1 Medication Running Low",
|
||||
stockTitleMultiple: "MedAssist-ng: {count} Medications Running Low",
|
||||
intakeTitle: "💊 Medication Reminder in {minutes} min",
|
||||
stockTitle: "MedAssist-ng: 1 Medication Running Critically Low",
|
||||
stockTitleMultiple: "MedAssist-ng: {count} Medications Running Critically Low",
|
||||
intakeTitle: "💊 Reminder: Medication intake in {minutes} min",
|
||||
pillsLeft: "{count} pills",
|
||||
daysLeft: "{count} days left",
|
||||
pillsAt: "{count} pills at {time}",
|
||||
repeatDailyNote: "(Daily reminder enabled)",
|
||||
empty: "Empty",
|
||||
low: "Low",
|
||||
low: "Critical",
|
||||
critical: "Critical",
|
||||
lowStock: "Low",
|
||||
reorderNow: "Reorder Now!",
|
||||
emptySection: "EMPTY (reorder immediately)",
|
||||
lowSection: "RUNNING LOW (reorder soon)",
|
||||
emptySection: "Empty (reorder immediately)",
|
||||
lowSection: "Running critically low",
|
||||
criticalSection: "Running critically low",
|
||||
lowStockSection: "Running low",
|
||||
},
|
||||
prescriptionReminder: {
|
||||
subjectSingle: "MedAssist-ng: 🚨 Prescription Refill Reminder",
|
||||
subjectMultiple: "MedAssist-ng: 🚨 {count} Prescriptions Need Renewal Soon",
|
||||
pushTitleLow: "💊 MedAssist-ng: {count} prescriptions are running low",
|
||||
pushTitleEmpty: "💊 MedAssist-ng: {count} prescriptions need renewal now",
|
||||
pushEmpty: "prescriptions out of refills",
|
||||
pushEmptySingle: "prescription out of refills",
|
||||
pushLow: "prescriptions low on refills",
|
||||
pushLowSingle: "prescription low on refills",
|
||||
pushRenewNow: "Renew Now!",
|
||||
pushEmptySection: "Prescriptions with no refills left",
|
||||
pushLowSection: "Prescriptions running low on refills",
|
||||
pushRefillsLeft: "{count} refill(s) remaining on this prescription",
|
||||
title: "⚠️ MedAssist-ng - Prescription Reminder",
|
||||
titleEmpty: "🚨 MedAssist-ng - Prescription Reminder",
|
||||
descriptionLow: "Some prescriptions are low on remaining refills.",
|
||||
descriptionEmpty: "Some prescriptions have no refills left. Contact your doctor for renewal.",
|
||||
alertLowSingle: "⚠️ 1 prescription is low on refills",
|
||||
alertLowMultiple: "⚠️ {count} prescriptions are low on refills",
|
||||
alertEmptySingle: "🚨 1 prescription needs renewal now",
|
||||
alertEmptyMultiple: "🚨 {count} prescriptions need renewal now",
|
||||
line: "{name}: {refills} refill(s) remaining on this prescription{expirySuffix}",
|
||||
lineEmpty: "{name}: no refills remaining on this prescription{expirySuffix}",
|
||||
expiresSuffix: ", expires {date}",
|
||||
repeatDailyNote: "You are receiving this daily reminder because 'Repeat Daily' is enabled in settings.",
|
||||
tableHeaders: {
|
||||
medication: "Medication",
|
||||
refillsLeft: "Prescription refills left",
|
||||
reminderThreshold: "Reminder threshold",
|
||||
prescriptionExpires: "Prescription expires",
|
||||
},
|
||||
},
|
||||
demandCalculator: {
|
||||
subject: "MedAssist-ng: Supply Overview ({from} - {until})",
|
||||
title: "MedAssist-ng: Demand Calculator",
|
||||
description: "Supply overview from {from} to {until}",
|
||||
summaryOutOfStock: "⚠️ {count} medication{s} will be out of stock during this period.",
|
||||
summaryAllOk: "✓ All medications have sufficient supply for this period.",
|
||||
tableHeaders: {
|
||||
medication: "Medication",
|
||||
usage: "Usage",
|
||||
needed: "Blisters needed",
|
||||
prescriptionRefills: "Prescription refills",
|
||||
available: "Available",
|
||||
status: "Status",
|
||||
},
|
||||
statusEnough: "✓ Enough",
|
||||
statusEmpty: "✗ Empty",
|
||||
prescriptionNotApplicable: "–",
|
||||
},
|
||||
common: {
|
||||
pill: "pill",
|
||||
pills: "pills",
|
||||
blister: "blister",
|
||||
blisters: "blisters",
|
||||
day: "day",
|
||||
days: "days",
|
||||
soon: "soon",
|
||||
footer: "🤖 Sent from MedAssist-ng",
|
||||
},
|
||||
},
|
||||
de: {
|
||||
stockReminder: {
|
||||
subject: "MedAssist-ng Auto-Erinnerung: {count} Medikament{e} wird knapp",
|
||||
title: "⚠️ MedAssist-ng - Automatische Nachbestell-Erinnerung",
|
||||
description: "Die folgenden Medikamente gehen zur Neige und sollten nachbestellt werden:",
|
||||
alertSingle: "⚠️ 1 Medikament wird knapp!",
|
||||
alertMultiple: "⚠️ {count} Medikamente werden knapp!",
|
||||
subject: "MedAssist-ng: ⚠️ {count} Medikament{e} kritisch niedrig",
|
||||
title: "⚠️ MedAssist-ng: Automatische Nachbestell-Erinnerung",
|
||||
description: "Die folgenden Medikamente sind kritisch niedrig und sollten nachbestellt werden:",
|
||||
descriptionEmpty: "Die folgenden Medikamente sind leer und müssen sofort nachbestellt werden:",
|
||||
descriptionMixed: "Die folgenden Medikamente müssen nachbestellt werden:",
|
||||
alertSingle: "⚠️ 1 Medikament kritisch niedrig!",
|
||||
alertMultiple: "⚠️ {count} Medikamente kritisch niedrig!",
|
||||
alertEmptySingle: "🚨 1 Medikament leer - sofort nachbestellen!",
|
||||
alertEmptyMultiple: "🚨 {count} Medikamente leer - sofort nachbestellen!",
|
||||
alertLowSingle: "⚠️ 1 Medikament kritisch niedrig",
|
||||
alertLowMultiple: "⚠️ {count} Medikamente kritisch niedrig",
|
||||
alertLowStockSingle: "⚠️ 1 Medikament niedrig",
|
||||
alertLowStockMultiple: "⚠️ {count} Medikamente niedrig",
|
||||
descriptionLow: "Die folgenden Medikamente werden knapp und sollten bald nachbestellt werden:",
|
||||
tableHeaders: {
|
||||
medication: "Medikament",
|
||||
pills: "Tabletten",
|
||||
days: "Tage",
|
||||
runsOut: "Aufgebraucht",
|
||||
},
|
||||
footer: "🤖 Automatische Erinnerung von MedAssist-ng",
|
||||
now: "JETZT",
|
||||
repeatDailyNote:
|
||||
"Sie erhalten diese tägliche Erinnerung, weil 'Täglich wiederholen' in den Einstellungen aktiviert ist.",
|
||||
},
|
||||
@@ -205,28 +346,86 @@ const translations: Record<Language, TranslationKeys> = {
|
||||
},
|
||||
pills: "Tabletten",
|
||||
takenBy: "für {name}",
|
||||
footer: "🤖 Automatische Erinnerung von MedAssist-ng",
|
||||
},
|
||||
push: {
|
||||
stockTitle: "MedAssist-ng: 1 Medikament wird knapp",
|
||||
stockTitleMultiple: "MedAssist-ng: {count} Medikamente werden knapp",
|
||||
intakeTitle: "💊 Einnahme-Erinnerung in {minutes} Min.",
|
||||
stockTitle: "MedAssist-ng: 1 Medikament kritisch niedrig",
|
||||
stockTitleMultiple: "MedAssist-ng: {count} Medikamente kritisch niedrig",
|
||||
intakeTitle: "💊 Erinnerung: Medikamenteneinnahme in {minutes} Min.",
|
||||
pillsLeft: "{count} Tabletten",
|
||||
daysLeft: "{count} Tage übrig",
|
||||
pillsAt: "{count} Tabletten um {time}",
|
||||
repeatDailyNote: "(Tägliche Erinnerung aktiviert)",
|
||||
empty: "Leer",
|
||||
low: "Knapp",
|
||||
low: "Kritisch",
|
||||
critical: "Kritisch",
|
||||
lowStock: "Niedrig",
|
||||
reorderNow: "Jetzt nachbestellen!",
|
||||
emptySection: "LEER (sofort nachbestellen)",
|
||||
lowSection: "WIRD KNAPP (bald nachbestellen)",
|
||||
emptySection: "Leer (sofort nachbestellen)",
|
||||
lowSection: "Kritisch niedrig",
|
||||
criticalSection: "Kritisch niedrig",
|
||||
lowStockSection: "Niedrig",
|
||||
},
|
||||
prescriptionReminder: {
|
||||
subjectSingle: "MedAssist-ng: 🚨 Rezept-Nachfüll-Erinnerung",
|
||||
subjectMultiple: "MedAssist-ng: 🚨 {count} Rezepte müssen bald erneuert werden",
|
||||
pushTitleLow: "💊 MedAssist-ng: {count} Rezept(e) haben nur noch wenige Nachfüllungen",
|
||||
pushTitleEmpty: "💊 MedAssist-ng: {count} Rezept(e) müssen jetzt erneuert werden",
|
||||
pushEmpty: "Rezepte ohne verbleibende Nachfüllung",
|
||||
pushEmptySingle: "Rezept ohne verbleibende Nachfüllung",
|
||||
pushLow: "Rezepte mit wenigen verbleibenden Nachfüllungen",
|
||||
pushLowSingle: "Rezept mit wenigen verbleibenden Nachfüllungen",
|
||||
pushRenewNow: "Jetzt erneuern!",
|
||||
pushEmptySection: "Rezepte ohne Nachfüllungen",
|
||||
pushLowSection: "Rezepte mit bald aufgebrauchten Nachfüllungen",
|
||||
pushRefillsLeft: "{count} Nachfüllung(en) für dieses Rezept übrig",
|
||||
title: "⚠️ MedAssist-ng - Rezept-Erinnerung",
|
||||
titleEmpty: "🚨 MedAssist-ng - Rezept-Erinnerung",
|
||||
descriptionLow: "Einige Rezepte haben nur noch wenige Nachfüllungen.",
|
||||
descriptionEmpty:
|
||||
"Einige Rezepte haben keine Nachfüllungen mehr. Bitte kontaktieren Sie Ihren Arzt für eine Erneuerung.",
|
||||
alertLowSingle: "⚠️ 1 Rezept ist bei den Nachfüllungen niedrig",
|
||||
alertLowMultiple: "⚠️ {count} Rezepte sind bei den Nachfüllungen niedrig",
|
||||
alertEmptySingle: "🚨 1 Rezept muss jetzt erneuert werden",
|
||||
alertEmptyMultiple: "🚨 {count} Rezepte müssen jetzt erneuert werden",
|
||||
line: "{name}: {refills} Nachfüllung(en) für dieses Rezept übrig{expirySuffix}",
|
||||
lineEmpty: "{name}: keine Nachfüllung mehr für dieses Rezept{expirySuffix}",
|
||||
expiresSuffix: ", läuft ab {date}",
|
||||
repeatDailyNote:
|
||||
"Sie erhalten diese tägliche Erinnerung, weil 'Täglich wiederholen' in den Einstellungen aktiviert ist.",
|
||||
tableHeaders: {
|
||||
medication: "Medikament",
|
||||
refillsLeft: "Rezept-Nachfüllungen übrig",
|
||||
reminderThreshold: "Erinnerungsschwelle",
|
||||
prescriptionExpires: "Rezeptablauf",
|
||||
},
|
||||
},
|
||||
demandCalculator: {
|
||||
subject: "MedAssist-ng: Bestandsübersicht ({from} - {until})",
|
||||
title: "MedAssist-ng: Bedarfsrechner",
|
||||
description: "Bestandsübersicht von {from} bis {until}",
|
||||
summaryOutOfStock: "⚠️ {count} Medikament{e} wird im Zeitraum nicht ausreichen.",
|
||||
summaryAllOk: "✓ Alle Medikamente reichen für diesen Zeitraum.",
|
||||
tableHeaders: {
|
||||
medication: "Medikament",
|
||||
usage: "Verbrauch",
|
||||
needed: "Blister benötigt",
|
||||
prescriptionRefills: "Rezept-Nachfüllungen",
|
||||
available: "Verfügbar",
|
||||
status: "Status",
|
||||
},
|
||||
statusEnough: "✓ Ausreichend",
|
||||
statusEmpty: "✗ Leer",
|
||||
prescriptionNotApplicable: "–",
|
||||
},
|
||||
common: {
|
||||
pill: "Tablette",
|
||||
pills: "Tabletten",
|
||||
blister: "Blister",
|
||||
blisters: "Blister",
|
||||
day: "Tag",
|
||||
days: "Tage",
|
||||
soon: "bald",
|
||||
footer: "🤖 Gesendet von MedAssist-ng",
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -264,3 +463,38 @@ export function getDateLocale(language: Language): string {
|
||||
return "en-US";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the app URL from the first CORS_ORIGINS entry.
|
||||
* Falls back to empty string if not set.
|
||||
*/
|
||||
export function getAppUrl(): string {
|
||||
const origins = process.env.CORS_ORIGINS || "";
|
||||
return origins.split(",")[0]?.trim() || "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unified footer as HTML with MedAssist-ng as a link to the instance.
|
||||
* @param variant - 'planner' uses the Medication Planner footer text
|
||||
*/
|
||||
export function getFooterHtml(language: Language): string {
|
||||
const tr = getTranslations(language);
|
||||
const appUrl = getAppUrl();
|
||||
const appName = appUrl
|
||||
? `<a href="${appUrl}" style="color: #6b7280; text-decoration: underline;">MedAssist-ng</a>`
|
||||
: "MedAssist-ng";
|
||||
return tr.common.footer.replace("MedAssist-ng", appName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unified footer as plain text.
|
||||
* @param variant - 'planner' uses the Medication Planner footer text
|
||||
*/
|
||||
export function getFooterPlain(language: Language): string {
|
||||
const tr = getTranslations(language);
|
||||
const appUrl = getAppUrl();
|
||||
if (appUrl) {
|
||||
return `${tr.common.footer} (${appUrl})`;
|
||||
}
|
||||
return tr.common.footer;
|
||||
}
|
||||
|
||||
@@ -126,9 +126,11 @@ export async function createApp(options?: {
|
||||
// Server initialization (runs on import)
|
||||
// =============================================================================
|
||||
|
||||
import { log } from "./utils/logger.js";
|
||||
|
||||
// Wait for database migrations before anything else
|
||||
await migrationsReady;
|
||||
console.log("[DB] Migrations complete, starting server...");
|
||||
log.info("[DB] Migrations complete, starting server...");
|
||||
|
||||
// Ensure images directory exists
|
||||
const imagesDir = ensureImagesDirectory();
|
||||
@@ -162,7 +164,7 @@ await app.register(sensible);
|
||||
await app.register(helmet);
|
||||
await app.register(cors, { origin: origins, credentials: true });
|
||||
await app.register(rateLimit, {
|
||||
max: 100,
|
||||
max: Number(process.env.RATE_LIMIT_MAX) || 100,
|
||||
timeWindow: "1 minute",
|
||||
});
|
||||
await app.register(cookie, { secret: env.COOKIE_SECRET ?? "dev-cookie-secret" });
|
||||
@@ -197,12 +199,14 @@ const start = async () => {
|
||||
// Start the automatic reminder scheduler
|
||||
startReminderScheduler({
|
||||
info: (msg) => app.log.info(msg),
|
||||
debug: (msg) => app.log.debug(msg),
|
||||
error: (msg) => app.log.error(msg),
|
||||
});
|
||||
|
||||
// Start the intake reminder scheduler (checks every minute)
|
||||
startIntakeReminderScheduler({
|
||||
info: (msg) => app.log.info(msg),
|
||||
debug: (msg) => app.log.debug(msg),
|
||||
error: (msg) => app.log.error(msg),
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -37,7 +37,6 @@ export async function getAnonymousUserId(): Promise<number> {
|
||||
`);
|
||||
|
||||
anonymousUserVerified = true;
|
||||
console.log(`Created anonymous user with fixed ID ${ANONYMOUS_USER_ID} for no-auth mode`);
|
||||
|
||||
return ANONYMOUS_USER_ID;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomBytes } from "node:crypto";
|
||||
import argon2 from "argon2";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
@@ -129,7 +129,7 @@ export async function authRoutes(app: FastifyInstance) {
|
||||
const { username, password } = parsed.data;
|
||||
|
||||
// Check if username already exists
|
||||
const [existingUser] = await db.select().from(users).where(eq(users.username, username));
|
||||
const [existingUser] = await db.select().from(users).where(sql`lower(${users.username}) = lower(${username})`);
|
||||
if (existingUser) {
|
||||
return reply.status(409).send({ error: "Username already taken", code: "USERNAME_EXISTS" });
|
||||
}
|
||||
@@ -190,7 +190,7 @@ export async function authRoutes(app: FastifyInstance) {
|
||||
const { username, password, rememberMe } = parsed.data;
|
||||
|
||||
// Find user by username
|
||||
const [user] = await db.select().from(users).where(eq(users.username, username));
|
||||
const [user] = await db.select().from(users).where(sql`lower(${users.username}) = lower(${username})`);
|
||||
|
||||
// Generic error to prevent user enumeration
|
||||
const invalidCredentialsError = () =>
|
||||
|
||||
@@ -37,6 +37,7 @@ const inventorySchema = z.object({
|
||||
pillsPerBlister: z.number().int().min(1).default(1),
|
||||
looseTablets: z.number().int().min(0).default(0),
|
||||
stockAdjustment: z.number().int().default(0), // Manual stock correction
|
||||
packageType: z.enum(["blister", "bottle"]).default("blister"),
|
||||
});
|
||||
|
||||
const medicationExportSchema = z.object({
|
||||
@@ -51,6 +52,11 @@ const medicationExportSchema = z.object({
|
||||
expiryDate: z.string().nullable().optional(),
|
||||
notes: z.string().nullable().optional(),
|
||||
intakeRemindersEnabled: z.boolean().default(false),
|
||||
prescriptionEnabled: z.boolean().default(false),
|
||||
prescriptionAuthorizedRefills: z.number().int().min(0).nullable().optional(),
|
||||
prescriptionRemainingRefills: z.number().int().min(0).nullable().optional(),
|
||||
prescriptionLowRefillThreshold: z.number().int().min(0).default(1),
|
||||
prescriptionExpiryDate: z.string().nullable().optional(),
|
||||
image: z.string().nullable().optional(), // base64 data URL or null
|
||||
lastStockCorrectionAt: z.string().nullable().optional(), // ISO datetime of last stock correction
|
||||
});
|
||||
@@ -79,11 +85,13 @@ const settingsExportSchema = z
|
||||
notificationEmail: z.string().nullable().optional(),
|
||||
emailStockReminders: z.boolean().default(true),
|
||||
emailIntakeReminders: z.boolean().default(true),
|
||||
emailPrescriptionReminders: z.boolean().default(true),
|
||||
// Push notifications
|
||||
shoutrrrEnabled: z.boolean().optional(),
|
||||
shoutrrrUrl: z.string().nullable().optional(),
|
||||
shoutrrrStockReminders: z.boolean().default(true),
|
||||
shoutrrrIntakeReminders: z.boolean().default(true),
|
||||
shoutrrrPrescriptionReminders: z.boolean().default(true),
|
||||
// Reminder settings
|
||||
reminderDaysBefore: z.number().int().default(7),
|
||||
repeatDailyReminders: z.boolean().default(false),
|
||||
@@ -276,6 +284,7 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
pillsPerBlister: med.pillsPerBlister ?? 1,
|
||||
looseTablets: med.looseTablets ?? 0,
|
||||
stockAdjustment: med.stockAdjustment ?? 0,
|
||||
packageType: med.packageType ?? "blister",
|
||||
},
|
||||
pillWeightMg: med.pillWeightMg,
|
||||
doseUnit: med.doseUnit ?? "mg",
|
||||
@@ -283,6 +292,11 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
expiryDate: med.expiryDate,
|
||||
notes: med.notes,
|
||||
intakeRemindersEnabled: med.intakeRemindersEnabled ?? false,
|
||||
prescriptionEnabled: med.prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: med.prescriptionAuthorizedRefills ?? null,
|
||||
prescriptionRemainingRefills: med.prescriptionRemainingRefills ?? null,
|
||||
prescriptionLowRefillThreshold: med.prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: med.prescriptionExpiryDate ?? null,
|
||||
image: includeImages ? imageToBase64(med.imageUrl) : null,
|
||||
lastStockCorrectionAt: lastStockCorrectionAtIso,
|
||||
};
|
||||
@@ -344,11 +358,13 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
notificationEmail: settings.notificationEmail,
|
||||
emailStockReminders: settings.emailStockReminders,
|
||||
emailIntakeReminders: settings.emailIntakeReminders,
|
||||
emailPrescriptionReminders: settings.emailPrescriptionReminders ?? true,
|
||||
// Only include sensitive data if requested
|
||||
shoutrrrEnabled: includeSensitive ? settings.shoutrrrEnabled : undefined,
|
||||
shoutrrrUrl: includeSensitive ? settings.shoutrrrUrl : undefined,
|
||||
shoutrrrStockReminders: settings.shoutrrrStockReminders,
|
||||
shoutrrrIntakeReminders: settings.shoutrrrIntakeReminders,
|
||||
shoutrrrPrescriptionReminders: settings.shoutrrrPrescriptionReminders ?? true,
|
||||
reminderDaysBefore: settings.reminderDaysBefore,
|
||||
repeatDailyReminders: settings.repeatDailyReminders,
|
||||
skipRemindersForTakenDoses: settings.skipRemindersForTakenDoses,
|
||||
@@ -490,6 +506,7 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
name: med.name,
|
||||
genericName: med.genericName || null,
|
||||
takenByJson,
|
||||
packageType: med.inventory.packageType ?? "blister",
|
||||
packCount: med.inventory.packCount,
|
||||
blistersPerPack: med.inventory.blistersPerPack,
|
||||
pillsPerBlister: med.inventory.pillsPerBlister,
|
||||
@@ -505,6 +522,11 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
expiryDate: med.expiryDate || null,
|
||||
notes: med.notes || null,
|
||||
intakeRemindersEnabled,
|
||||
prescriptionEnabled: med.prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: med.prescriptionEnabled ? (med.prescriptionAuthorizedRefills ?? null) : null,
|
||||
prescriptionRemainingRefills: med.prescriptionEnabled ? (med.prescriptionRemainingRefills ?? null) : null,
|
||||
prescriptionLowRefillThreshold: med.prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: med.prescriptionExpiryDate || null,
|
||||
imageUrl: null, // Will be set after image is saved
|
||||
})
|
||||
.returning();
|
||||
@@ -548,10 +570,12 @@ export async function exportRoutes(app: FastifyInstance) {
|
||||
notificationEmail: importData.settings.notificationEmail || null,
|
||||
emailStockReminders: importData.settings.emailStockReminders ?? true,
|
||||
emailIntakeReminders: importData.settings.emailIntakeReminders ?? true,
|
||||
emailPrescriptionReminders: importData.settings.emailPrescriptionReminders ?? true,
|
||||
shoutrrrEnabled: importData.settings.shoutrrrEnabled ?? false,
|
||||
shoutrrrUrl: importData.settings.shoutrrrUrl || null,
|
||||
shoutrrrStockReminders: importData.settings.shoutrrrStockReminders ?? true,
|
||||
shoutrrrIntakeReminders: importData.settings.shoutrrrIntakeReminders ?? true,
|
||||
shoutrrrPrescriptionReminders: importData.settings.shoutrrrPrescriptionReminders ?? true,
|
||||
reminderDaysBefore: importData.settings.reminderDaysBefore ?? 7,
|
||||
repeatDailyReminders: importData.settings.repeatDailyReminders ?? false,
|
||||
skipRemindersForTakenDoses: importData.settings.skipRemindersForTakenDoses ?? false,
|
||||
|
||||
@@ -48,12 +48,39 @@ const medicationSchema = z
|
||||
doseUnit: doseUnitSchema,
|
||||
expiryDate: z.string().nullable().optional(),
|
||||
notes: z.string().max(2000).nullable().optional(),
|
||||
prescriptionEnabled: z.boolean().default(false),
|
||||
prescriptionAuthorizedRefills: z.number().int().min(0).nullable().optional(),
|
||||
prescriptionRemainingRefills: z.number().int().min(0).nullable().optional(),
|
||||
prescriptionLowRefillThreshold: z.number().int().min(0).default(1),
|
||||
prescriptionExpiryDate: z.string().nullable().optional(),
|
||||
intakeRemindersEnabled: z.boolean().default(false), // Medication-level (deprecated, kept for backward compat)
|
||||
// Accept either new intakes format or legacy blisters format
|
||||
intakes: z.array(intakeSchema).min(1).max(12).optional(),
|
||||
blisters: z.array(blisterSchema).min(1).max(12).optional(), // Legacy format
|
||||
})
|
||||
.refine((data) => data.intakes || data.blisters, { message: "Either 'intakes' or 'blisters' must be provided" });
|
||||
.refine((data) => data.intakes || data.blisters, { message: "Either 'intakes' or 'blisters' must be provided" })
|
||||
.refine(
|
||||
(data) => {
|
||||
if (!data.prescriptionEnabled) return true;
|
||||
if (data.prescriptionAuthorizedRefills == null || data.prescriptionRemainingRefills == null) return false;
|
||||
return data.prescriptionRemainingRefills <= data.prescriptionAuthorizedRefills;
|
||||
},
|
||||
{
|
||||
message: "When prescription is enabled, remaining refills must be <= authorized refills",
|
||||
path: ["prescriptionRemainingRefills"],
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(data) => {
|
||||
if (!data.prescriptionEnabled) return true;
|
||||
if (data.prescriptionAuthorizedRefills == null) return false;
|
||||
return data.prescriptionLowRefillThreshold <= data.prescriptionAuthorizedRefills;
|
||||
},
|
||||
{
|
||||
message: "When prescription is enabled, low refill threshold must be <= authorized refills",
|
||||
path: ["prescriptionLowRefillThreshold"],
|
||||
}
|
||||
);
|
||||
|
||||
export async function medicationRoutes(app: FastifyInstance) {
|
||||
// All medication routes require auth
|
||||
@@ -109,6 +136,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
expiryDate: row.expiryDate,
|
||||
notes: row.notes,
|
||||
intakeRemindersEnabled: row.intakeRemindersEnabled ?? false,
|
||||
prescriptionEnabled: row.prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: row.prescriptionAuthorizedRefills ?? null,
|
||||
prescriptionRemainingRefills: row.prescriptionRemainingRefills ?? null,
|
||||
prescriptionLowRefillThreshold: row.prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: row.prescriptionExpiryDate ?? null,
|
||||
dismissedUntil: row.dismissedUntil ?? null,
|
||||
updatedAt: row.updatedAt,
|
||||
};
|
||||
@@ -134,6 +166,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
doseUnit,
|
||||
expiryDate,
|
||||
notes,
|
||||
prescriptionEnabled,
|
||||
prescriptionAuthorizedRefills,
|
||||
prescriptionRemainingRefills,
|
||||
prescriptionLowRefillThreshold,
|
||||
prescriptionExpiryDate,
|
||||
intakeRemindersEnabled,
|
||||
intakes: inputIntakes,
|
||||
blisters: inputBlisters,
|
||||
@@ -187,6 +224,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
doseUnit: doseUnit ?? "mg",
|
||||
expiryDate: expiryDate || null,
|
||||
notes: notes || null,
|
||||
prescriptionEnabled: prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: prescriptionEnabled ? (prescriptionAuthorizedRefills ?? null) : null,
|
||||
prescriptionRemainingRefills: prescriptionEnabled ? (prescriptionRemainingRefills ?? null) : null,
|
||||
prescriptionLowRefillThreshold: prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: prescriptionExpiryDate || null,
|
||||
intakeRemindersEnabled: intakeRemindersEnabled ?? false,
|
||||
intakesJson,
|
||||
usageJson,
|
||||
@@ -216,6 +258,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
expiryDate: inserted.expiryDate,
|
||||
notes: inserted.notes,
|
||||
intakeRemindersEnabled: inserted.intakeRemindersEnabled,
|
||||
prescriptionEnabled: inserted.prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: inserted.prescriptionAuthorizedRefills ?? null,
|
||||
prescriptionRemainingRefills: inserted.prescriptionRemainingRefills ?? null,
|
||||
prescriptionLowRefillThreshold: inserted.prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: inserted.prescriptionExpiryDate ?? null,
|
||||
updatedAt: inserted.updatedAt,
|
||||
};
|
||||
});
|
||||
@@ -249,6 +296,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
doseUnit,
|
||||
expiryDate,
|
||||
notes,
|
||||
prescriptionEnabled,
|
||||
prescriptionAuthorizedRefills,
|
||||
prescriptionRemainingRefills,
|
||||
prescriptionLowRefillThreshold,
|
||||
prescriptionExpiryDate,
|
||||
intakeRemindersEnabled,
|
||||
intakes: inputIntakes,
|
||||
blisters: inputBlisters,
|
||||
@@ -312,6 +364,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
doseUnit: doseUnit ?? "mg",
|
||||
expiryDate: expiryDate || null,
|
||||
notes: notes || null,
|
||||
prescriptionEnabled: prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: prescriptionEnabled ? (prescriptionAuthorizedRefills ?? null) : null,
|
||||
prescriptionRemainingRefills: prescriptionEnabled ? (prescriptionRemainingRefills ?? null) : null,
|
||||
prescriptionLowRefillThreshold: prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: prescriptionExpiryDate || null,
|
||||
intakeRemindersEnabled: intakeRemindersEnabled ?? false,
|
||||
intakesJson,
|
||||
usageJson,
|
||||
@@ -465,6 +522,11 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
expiryDate: result[0].expiryDate,
|
||||
notes: result[0].notes,
|
||||
intakeRemindersEnabled: result[0].intakeRemindersEnabled,
|
||||
prescriptionEnabled: result[0].prescriptionEnabled ?? false,
|
||||
prescriptionAuthorizedRefills: result[0].prescriptionAuthorizedRefills ?? null,
|
||||
prescriptionRemainingRefills: result[0].prescriptionRemainingRefills ?? null,
|
||||
prescriptionLowRefillThreshold: result[0].prescriptionLowRefillThreshold ?? 1,
|
||||
prescriptionExpiryDate: result[0].prescriptionExpiryDate ?? null,
|
||||
updatedAt: result[0].updatedAt,
|
||||
};
|
||||
});
|
||||
@@ -656,7 +718,13 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
const blistersPerPack = row.blistersPerPack ?? 1;
|
||||
const looseTablets = row.looseTablets ?? 0;
|
||||
const stockAdjustment = row.stockAdjustment ?? 0;
|
||||
const originalTotalPills = packCount * blistersPerPack * pillsPerBlister + looseTablets + stockAdjustment;
|
||||
const packageType = row.packageType ?? "blister";
|
||||
|
||||
// For bottle type, looseTablets IS the current stock (no blister math)
|
||||
const originalTotalPills =
|
||||
packageType === "bottle"
|
||||
? looseTablets + stockAdjustment
|
||||
: packCount * blistersPerPack * pillsPerBlister + looseTablets + stockAdjustment;
|
||||
|
||||
// Calculate consumption based on ACTUAL taken doses from dose_tracking
|
||||
// This ensures Planner shows the same "current stock" as the Dashboard/Modal
|
||||
@@ -725,9 +793,13 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
const currentStock = Math.max(0, originalTotalPills - consumedUntilNow);
|
||||
|
||||
// Calculate usage for the planning period
|
||||
// Always use the user-selected start date for the usage calculation.
|
||||
// Using max(now, start) would cause asymmetric counting when now falls
|
||||
// between morning and evening doses on the start day (e.g., morning dose
|
||||
// skipped but evening counted), leading to confusing off-by-one results.
|
||||
// The stock already reflects consumed doses, so no double-counting occurs.
|
||||
// When includeUntilStart is true, calculate from now to end (useful for trip planning)
|
||||
// When false, calculate from max(now, start) to end (default behavior)
|
||||
const effectivePlannerStart = includeUntilStart ? now : new Date(Math.max(now.getTime(), start.getTime()));
|
||||
const effectivePlannerStart = includeUntilStart ? now : start;
|
||||
const usageTotal = calculateUsageInRange(blisters, effectivePlannerStart, end);
|
||||
|
||||
const blistersNeeded = pillsPerBlister > 0 ? Math.ceil(usageTotal / pillsPerBlister) : 0;
|
||||
@@ -735,18 +807,27 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
// Calculate AVAILABLE = stock AFTER the planned period (currentStock - usageTotal)
|
||||
const availableAfterPeriod = Math.max(0, currentStock - usageTotal);
|
||||
|
||||
// Calculate stock breakdown for availableAfterPeriod
|
||||
// Consumption order: loose pills first, then from blisters
|
||||
const totalConsumedByEnd = originalTotalPills - availableAfterPeriod;
|
||||
const looseConsumedByEnd = Math.min(totalConsumedByEnd, looseTablets);
|
||||
const loosePillsRemaining = Math.max(0, looseTablets - looseConsumedByEnd);
|
||||
const blisterPillsConsumed = totalConsumedByEnd - looseConsumedByEnd;
|
||||
const originalBlisterPills = originalTotalPills - looseTablets;
|
||||
const blisterPillsRemaining = Math.max(0, originalBlisterPills - blisterPillsConsumed);
|
||||
let fullBlisters: number;
|
||||
let loosePills: number;
|
||||
|
||||
const fullBlisters = pillsPerBlister > 0 ? Math.floor(blisterPillsRemaining / pillsPerBlister) : 0;
|
||||
const openBlisterPills = pillsPerBlister > 0 ? blisterPillsRemaining % pillsPerBlister : 0;
|
||||
const loosePills = loosePillsRemaining + openBlisterPills; // Combine open blister + remaining loose
|
||||
if (packageType === "bottle") {
|
||||
// Bottle type: no blisters, everything is loose pills
|
||||
fullBlisters = 0;
|
||||
loosePills = availableAfterPeriod;
|
||||
} else {
|
||||
// Blister type: calculate stock breakdown
|
||||
// Consumption order: loose pills first, then from blisters
|
||||
const totalConsumedByEnd = originalTotalPills - availableAfterPeriod;
|
||||
const looseConsumedByEnd = Math.min(totalConsumedByEnd, looseTablets);
|
||||
const loosePillsRemaining = Math.max(0, looseTablets - looseConsumedByEnd);
|
||||
const blisterPillsConsumed = totalConsumedByEnd - looseConsumedByEnd;
|
||||
const originalBlisterPills = originalTotalPills - looseTablets;
|
||||
const blisterPillsRemaining = Math.max(0, originalBlisterPills - blisterPillsConsumed);
|
||||
|
||||
fullBlisters = pillsPerBlister > 0 ? Math.floor(blisterPillsRemaining / pillsPerBlister) : 0;
|
||||
const openBlisterPills = pillsPerBlister > 0 ? blisterPillsRemaining % pillsPerBlister : 0;
|
||||
loosePills = loosePillsRemaining + openBlisterPills; // Combine open blister + remaining loose
|
||||
}
|
||||
|
||||
const enough = currentStock >= usageTotal;
|
||||
return {
|
||||
@@ -759,6 +840,7 @@ export async function medicationRoutes(app: FastifyInstance) {
|
||||
fullBlisters,
|
||||
loosePills,
|
||||
enough,
|
||||
packageType,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -824,12 +906,28 @@ function calculateUsageInRange(
|
||||
end: Date
|
||||
) {
|
||||
let total = 0;
|
||||
const msPerDay = 86400000;
|
||||
blisters.forEach((blister) => {
|
||||
const blisterStart = parseLocalDateTime(blister.start);
|
||||
if (Number.isNaN(blisterStart.getTime())) return;
|
||||
// iterate occurrences from blisterStart up to end
|
||||
for (let dt = new Date(blisterStart); dt < end; dt.setDate(dt.getDate() + blister.every)) {
|
||||
if (dt >= start && dt < end) total += blister.usage;
|
||||
|
||||
const every = Math.max(1, blister.every);
|
||||
|
||||
// Skip ahead to the first occurrence at or after start to avoid
|
||||
// iterating through months/years of past doses
|
||||
const dt = new Date(blisterStart);
|
||||
if (dt < start) {
|
||||
const daysToSkip = Math.floor((start.getTime() - dt.getTime()) / (every * msPerDay));
|
||||
dt.setDate(dt.getDate() + daysToSkip * every);
|
||||
// Fine-tune: advance until we reach or pass start
|
||||
while (dt < start) {
|
||||
dt.setDate(dt.getDate() + every);
|
||||
}
|
||||
}
|
||||
|
||||
// Count occurrences in [start, end)
|
||||
for (; dt < end; dt.setDate(dt.getDate() + every)) {
|
||||
total += blister.usage;
|
||||
}
|
||||
});
|
||||
return Number(total.toFixed(2));
|
||||
|
||||
+15
-15
@@ -1,5 +1,5 @@
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import type { FastifyInstance, FastifyReply } from "fastify";
|
||||
import * as client from "openid-client";
|
||||
import { db } from "../db/client.js";
|
||||
@@ -144,17 +144,17 @@ export async function oidcRoutes(app: FastifyInstance) {
|
||||
|
||||
try {
|
||||
const config = await getOIDCConfig();
|
||||
const _redirectUri = env.OIDC_REDIRECT_URI!;
|
||||
const redirectUri = env.OIDC_REDIRECT_URI!;
|
||||
|
||||
// Exchange code for tokens
|
||||
const tokens = await client.authorizationCodeGrant(
|
||||
config,
|
||||
new URL(request.url, `http://${request.headers.host}`),
|
||||
{
|
||||
pkceCodeVerifier: storedVerifier.value,
|
||||
expectedState: state,
|
||||
}
|
||||
);
|
||||
// Build complete callback URL with query parameters for validation
|
||||
const callbackUrl = new URL(redirectUri);
|
||||
callbackUrl.search = new URLSearchParams(request.query as Record<string, string>).toString();
|
||||
|
||||
const tokens = await client.authorizationCodeGrant(config, callbackUrl, {
|
||||
pkceCodeVerifier: storedVerifier.value,
|
||||
expectedState: state,
|
||||
});
|
||||
|
||||
// Get user info
|
||||
const sub = tokens.claims()?.sub;
|
||||
@@ -201,7 +201,7 @@ export async function oidcRoutes(app: FastifyInstance) {
|
||||
});
|
||||
|
||||
// Set cookies (use app's centralized cookie options)
|
||||
console.log(
|
||||
request.log.debug(
|
||||
`[OIDC] Setting cookies for user ${user.username}, NODE_ENV=${env.NODE_ENV}, secure=${app.config.cookieOptions.secure}`
|
||||
);
|
||||
setAuthCookies(app, reply, accessToken, refreshToken);
|
||||
@@ -234,19 +234,19 @@ async function findOrCreateOIDCUser(
|
||||
}
|
||||
|
||||
// Check if username already exists (potential collision)
|
||||
const [existingByUsername] = await db.select().from(users).where(eq(users.username, username));
|
||||
const [existingByUsername] = await db.select().from(users).where(sql`lower(${users.username}) = lower(${username})`);
|
||||
|
||||
if (existingByUsername) {
|
||||
// Username collision! Check if it's a local user without OIDC linked
|
||||
if (existingByUsername.authProvider === "local" && !existingByUsername.oidcSubject) {
|
||||
// Local user exists without SSO - link this OIDC account to existing user
|
||||
await db.update(users).set({ oidcSubject: oidcSubject }).where(eq(users.id, existingByUsername.id));
|
||||
console.log(`[OIDC] Linked OIDC to existing local user: ${username}`);
|
||||
// Linked OIDC to existing local user
|
||||
return { id: existingByUsername.id, username: existingByUsername.username };
|
||||
} else if (existingByUsername.oidcSubject && existingByUsername.oidcSubject !== oidcSubject) {
|
||||
// User already has a DIFFERENT OIDC subject - create new user with suffix
|
||||
username = `${username}_sso`;
|
||||
console.log(`[OIDC] Username collision (different OIDC subject), using: ${username}`);
|
||||
// Username collision (different OIDC subject), use suffixed name
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ async function findOrCreateOIDCUser(
|
||||
})
|
||||
.returning({ id: users.id, username: users.username });
|
||||
|
||||
console.log(`[OIDC] Created new user: ${newUser.username} (ID: ${newUser.id})`);
|
||||
// New OIDC user created
|
||||
return newUser;
|
||||
}
|
||||
|
||||
|
||||
+533
-194
@@ -1,6 +1,16 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||
import nodemailer from "nodemailer";
|
||||
import { getDateLocale, getTranslations, type Language, t } from "../i18n/translations.js";
|
||||
import { db } from "../db/client.js";
|
||||
import { medications } from "../db/schema.js";
|
||||
import {
|
||||
getDateLocale,
|
||||
getFooterHtml,
|
||||
getFooterPlain,
|
||||
getTranslations,
|
||||
type Language,
|
||||
t,
|
||||
} from "../i18n/translations.js";
|
||||
import { getAnonymousUserId, requireAuth } from "../plugins/auth.js";
|
||||
import { env } from "../plugins/env.js";
|
||||
import { updateReminderSentTime, updateUserReminderSentTime } from "../services/reminder-scheduler.js";
|
||||
@@ -29,6 +39,7 @@ type PlannerRow = {
|
||||
fullBlisters: number;
|
||||
loosePills: number;
|
||||
enough: boolean;
|
||||
packageType?: string;
|
||||
};
|
||||
|
||||
type SendEmailBody = {
|
||||
@@ -44,6 +55,7 @@ type LowStockItem = {
|
||||
medsLeft: number;
|
||||
daysLeft: number | null;
|
||||
depletionDate: string | null;
|
||||
isCritical?: boolean;
|
||||
};
|
||||
|
||||
type ReminderEmailBody = {
|
||||
@@ -52,6 +64,19 @@ type ReminderEmailBody = {
|
||||
language?: Language; // Optional: passed from frontend for unauthenticated requests
|
||||
};
|
||||
|
||||
type PrescriptionReminderItem = {
|
||||
name: string;
|
||||
remainingRefills: number;
|
||||
threshold: number;
|
||||
expiryDate?: string | null;
|
||||
};
|
||||
|
||||
type PrescriptionReminderBody = {
|
||||
email: string;
|
||||
prescriptionLow: PrescriptionReminderItem[];
|
||||
language?: Language;
|
||||
};
|
||||
|
||||
export async function plannerRoutes(app: FastifyInstance) {
|
||||
// Add auth hook for all planner routes
|
||||
app.addHook("preHandler", requireAuth);
|
||||
@@ -68,32 +93,28 @@ export async function plannerRoutes(app: FastifyInstance) {
|
||||
return authUser.id;
|
||||
}
|
||||
|
||||
// Demand calculator notification (supports email and push)
|
||||
app.post<{ Body: SendEmailBody }>("/planner/send-email", async (request, reply) => {
|
||||
const { email, from, until, rows, language: bodyLanguage } = request.body;
|
||||
|
||||
if (!email || !rows || rows.length === 0) {
|
||||
return reply.status(400).send({ error: "Missing email or planner data" });
|
||||
if (!rows || rows.length === 0) {
|
||||
return reply.status(400).send({ error: "Missing planner data" });
|
||||
}
|
||||
|
||||
const smtpHost = process.env.SMTP_HOST;
|
||||
const smtpUser = process.env.SMTP_USER;
|
||||
const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence
|
||||
const smtpPort = parseInt(process.env.SMTP_PORT ?? "587", 10);
|
||||
const smtpSecure = process.env.SMTP_SECURE === "true";
|
||||
const smtpFrom = process.env.SMTP_FROM ?? smtpUser;
|
||||
|
||||
if (!smtpHost || !smtpUser) {
|
||||
return reply.status(400).send({ error: "SMTP not configured" });
|
||||
}
|
||||
// Load user settings for notification channels
|
||||
const userId = await getUserId(request);
|
||||
const userSettings = await loadUserSettings(userId);
|
||||
const notificationSettings = {
|
||||
emailEnabled: userSettings.emailEnabled,
|
||||
shoutrrrEnabled: userSettings.shoutrrrEnabled,
|
||||
shoutrrrUrl: userSettings.shoutrrrUrl || "",
|
||||
};
|
||||
|
||||
// Get locale from user settings or use the language passed in the body
|
||||
let language: Language = bodyLanguage || "en";
|
||||
const authUser = request.user as unknown as AuthUser | null;
|
||||
if (authUser?.id) {
|
||||
const userSettings = await loadUserSettings(authUser.id);
|
||||
language = userSettings.language;
|
||||
}
|
||||
const language: Language = (userSettings.language as Language) || bodyLanguage || "en";
|
||||
const locale = getDateLocale(language);
|
||||
const tr = getTranslations(language);
|
||||
const dc = tr.demandCalculator;
|
||||
|
||||
// Format dates for display - escape to prevent XSS even though toLocaleDateString should be safe
|
||||
const fromDate = escapeHtml(
|
||||
@@ -111,47 +132,121 @@ export async function plannerRoutes(app: FastifyInstance) {
|
||||
})
|
||||
);
|
||||
|
||||
// Build HTML table with horizontal scroll for mobile
|
||||
// Escape/coerce all user-provided values to prevent XSS
|
||||
const tableRows = rows
|
||||
.map((row) => {
|
||||
const safeName = escapeHtml(row.medicationName);
|
||||
const safeTotalPills = Number(row.totalPills) || 0;
|
||||
const safePlannerUsage = Number(row.plannerUsage) || 0;
|
||||
const safeBlistersNeeded = Number(row.blistersNeeded) || 0;
|
||||
const safeBlisterSize = Number(row.blisterSize) || 0;
|
||||
const safeFullBlisters = Number(row.fullBlisters) || 0;
|
||||
const safeLoosePills = Number(row.loosePills) || 0;
|
||||
return `
|
||||
<tr>
|
||||
const outOfStockCount = rows.filter((r) => !r.enough).length;
|
||||
const summaryText = outOfStockCount > 0 ? t(dc.summaryOutOfStock, { count: outOfStockCount }) : dc.summaryAllOk;
|
||||
|
||||
// Load prescription data for medications referenced in planner rows
|
||||
const medIds = rows.map((r) => r.medicationId).filter(Boolean);
|
||||
const allMeds =
|
||||
medIds.length > 0
|
||||
? await db
|
||||
.select({
|
||||
id: medications.id,
|
||||
prescriptionEnabled: medications.prescriptionEnabled,
|
||||
prescriptionRemainingRefills: medications.prescriptionRemainingRefills,
|
||||
})
|
||||
.from(medications)
|
||||
.where(eq(medications.userId, userId))
|
||||
: [];
|
||||
const prescriptionMap = new Map(allMeds.map((m) => [m.id, m]));
|
||||
|
||||
// Build plain text (shared between email and push)
|
||||
const plainText = `${dc.title}
|
||||
${t(dc.description, { from: fromDate, until: untilDate })}
|
||||
|
||||
${summaryText}
|
||||
|
||||
${rows
|
||||
.map((r) => {
|
||||
const isBottle = r.packageType === "bottle";
|
||||
const usage = `${r.plannerUsage} ${tr.common.pills}`;
|
||||
const needed = isBottle ? "–" : `${r.blistersNeeded} × ${r.blisterSize}`;
|
||||
const medPrescription = prescriptionMap.get(r.medicationId);
|
||||
const rxRefills = medPrescription?.prescriptionEnabled
|
||||
? String(medPrescription.prescriptionRemainingRefills ?? 0)
|
||||
: dc.prescriptionNotApplicable;
|
||||
const loosePills = Math.round((Number(r.loosePills) || 0) * 10) / 10;
|
||||
const available = isBottle
|
||||
? `${loosePills} ${tr.common.pills}`
|
||||
: `${r.fullBlisters} ${tr.common.blisters}${loosePills > 0 ? ` + ${loosePills} ${tr.common.pills}` : ""}`;
|
||||
const status = r.enough ? dc.statusEnough : dc.statusEmpty;
|
||||
return `${r.medicationName}: ${usage}, ${needed}, ${dc.tableHeaders.prescriptionRefills}: ${rxRefills}, ${available} - ${status}`;
|
||||
})
|
||||
.join("\n")}
|
||||
|
||||
---
|
||||
${getFooterPlain(language)}`;
|
||||
|
||||
const results: { email?: boolean; push?: boolean; errors: string[] } = { errors: [] };
|
||||
|
||||
// Send email if enabled
|
||||
if (notificationSettings.emailEnabled && email) {
|
||||
const smtpHost = process.env.SMTP_HOST;
|
||||
const smtpUser = process.env.SMTP_USER;
|
||||
const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence
|
||||
const smtpPort = parseInt(process.env.SMTP_PORT ?? "587", 10);
|
||||
const smtpSecure = process.env.SMTP_SECURE === "true";
|
||||
const smtpFrom = process.env.SMTP_FROM ?? smtpUser;
|
||||
|
||||
if (smtpHost && smtpUser) {
|
||||
// Build HTML table with horizontal scroll for mobile
|
||||
// Escape/coerce all user-provided values to prevent XSS
|
||||
const tableRows = rows
|
||||
.map((row) => {
|
||||
const safeName = escapeHtml(row.medicationName);
|
||||
const safePlannerUsage = Number(row.plannerUsage) || 0;
|
||||
const safeBlistersNeeded = Number(row.blistersNeeded) || 0;
|
||||
const safeBlisterSize = Number(row.blisterSize) || 0;
|
||||
const safeFullBlisters = Number(row.fullBlisters) || 0;
|
||||
const safeLoosePills = Math.round((Number(row.loosePills) || 0) * 10) / 10;
|
||||
const isBottle = row.packageType === "bottle";
|
||||
|
||||
// "Blisters needed" column: dash for bottles
|
||||
const neededCell = isBottle ? "–" : `${safeBlistersNeeded} × ${safeBlisterSize}`;
|
||||
|
||||
// "Prescription refills" column
|
||||
const medPrescription = prescriptionMap.get(row.medicationId);
|
||||
const rxCell = medPrescription?.prescriptionEnabled
|
||||
? String(medPrescription.prescriptionRemainingRefills ?? 0)
|
||||
: dc.prescriptionNotApplicable;
|
||||
|
||||
// "Available" column: match frontend format
|
||||
let availableCell: string;
|
||||
if (isBottle) {
|
||||
availableCell = `${safeLoosePills} ${tr.common.pills}`;
|
||||
} else {
|
||||
availableCell = `${safeFullBlisters} ${tr.common.blisters}`;
|
||||
if (safeLoosePills > 0) {
|
||||
availableCell += ` + ${safeLoosePills} ${tr.common.pills}`;
|
||||
}
|
||||
}
|
||||
|
||||
const rowBg = row.enough ? "" : " background: #fef2f2;";
|
||||
|
||||
return `
|
||||
<tr style="${rowBg}">
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${safeName}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;"><strong>${safeTotalPills}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;"><strong>${safePlannerUsage}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeBlistersNeeded} × ${safeBlisterSize}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeFullBlisters}${safeLoosePills > 0 ? ` (+${safeLoosePills})` : ""}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;"><strong>${safePlannerUsage}</strong> ${tr.common.pills}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${neededCell}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${rxCell}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${availableCell}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">
|
||||
<span style="display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; ${
|
||||
row.enough ? "background: #d1fae5; color: #065f46;" : "background: #fee2e2; color: #991b1b;"
|
||||
}">
|
||||
${row.enough ? "✓ OK" : "✗ Out of Stock"}
|
||||
${row.enough ? dc.statusEnough : dc.statusEmpty}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
})
|
||||
.join("");
|
||||
})
|
||||
.join("");
|
||||
|
||||
const outOfStockCount = rows.filter((r) => !r.enough).length;
|
||||
const summaryText =
|
||||
outOfStockCount > 0
|
||||
? `⚠️ ${outOfStockCount} medication${outOfStockCount > 1 ? "s" : ""} will be out of stock during this period.`
|
||||
: "✓ All medications have sufficient supply for this period.";
|
||||
|
||||
const html = `
|
||||
const html = `
|
||||
<div style="font-family: system-ui, -apple-system, sans-serif; max-width: 100%; margin: 0 auto; padding: 12px; background: #f9fafb;">
|
||||
<div style="background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">MedAssist-ng - Demand Calculator</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">Supply overview from <strong>${fromDate}</strong> to <strong>${untilDate}</strong></p>
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${dc.title}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${t(dc.description, { from: `<strong>${fromDate}</strong>`, until: `<strong>${untilDate}</strong>` })}</p>
|
||||
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; ${
|
||||
outOfStockCount > 0
|
||||
@@ -167,12 +262,12 @@ export async function plannerRoutes(app: FastifyInstance) {
|
||||
<table style="width: 100%; border-collapse: collapse; background: white; min-width: 550px;">
|
||||
<thead>
|
||||
<tr style="background: #f3f4f6;">
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Medication</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Stock</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Usage</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Needed</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Available</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">Status</th>
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.medication}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.usage}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.needed}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.prescriptionRefills}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.available}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.05em; white-space: nowrap;">${dc.tableHeaders.status}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -182,44 +277,76 @@ export async function plannerRoutes(app: FastifyInstance) {
|
||||
</div>
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">Sent from MedAssist-ng Medication Planner</p>
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">${getFooterHtml(language)}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const plainText = `MedAssist-ng - Demand Calculator
|
||||
Supply overview from ${fromDate} to ${untilDate}
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
auth: {
|
||||
user: smtpUser,
|
||||
pass: smtpPass ?? "",
|
||||
},
|
||||
});
|
||||
|
||||
${summaryText}
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: email,
|
||||
subject: t(dc.subject, { from: fromDate, until: untilDate }),
|
||||
text: plainText,
|
||||
html,
|
||||
});
|
||||
|
||||
${rows.map((r) => `${r.medicationName}: ${r.totalPills} pills in stock, ${r.plannerUsage} pills needed, ${r.fullBlisters} blisters available${r.loosePills > 0 ? ` (+${r.loosePills} loose)` : ""} (${r.blistersNeeded} needed) - ${r.enough ? "Enough" : "OUT OF STOCK"}`).join("\n")}
|
||||
results.email = true;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
results.errors.push(`Email: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
Sent from MedAssist-ng Medication Planner`;
|
||||
// Send push notification if enabled
|
||||
if (notificationSettings.shoutrrrEnabled && notificationSettings.shoutrrrUrl) {
|
||||
const pushTitle = t(dc.subject, { from: fromDate, until: untilDate });
|
||||
const pushMessage = `${summaryText}\n\n${rows
|
||||
.map((r) => {
|
||||
const usage = `${r.plannerUsage} ${tr.common.pills}`;
|
||||
const status = r.enough ? dc.statusEnough : dc.statusEmpty;
|
||||
return `${r.enough ? "✓" : "✗"} ${r.medicationName}: ${usage} - ${status}`;
|
||||
})
|
||||
.join("\n")}\n\n---\n${getFooterPlain(language)}`;
|
||||
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
auth: {
|
||||
user: smtpUser,
|
||||
pass: smtpPass ?? "",
|
||||
},
|
||||
try {
|
||||
const pushResult = await sendShoutrrrNotification(notificationSettings.shoutrrrUrl, pushTitle, pushMessage);
|
||||
if (pushResult.success) {
|
||||
results.push = true;
|
||||
} else {
|
||||
results.errors.push(`Push: ${pushResult.error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
results.errors.push(`Push: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Build response message
|
||||
const sentChannels: string[] = [];
|
||||
if (results.email) sentChannels.push("email");
|
||||
if (results.push) sentChannels.push("push");
|
||||
|
||||
if (sentChannels.length > 0) {
|
||||
return reply.send({
|
||||
success: true,
|
||||
message: `Notification sent via ${sentChannels.join(" and ")}`,
|
||||
});
|
||||
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: email,
|
||||
subject: `MedAssist-ng - Supply Overview (${fromDate} - ${untilDate})`,
|
||||
text: plainText,
|
||||
html,
|
||||
});
|
||||
|
||||
return reply.send({ success: true, message: "Email sent successfully" });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
return reply.status(500).send({ error: `Failed to send email: ${errorMessage}` });
|
||||
} else if (results.errors.length > 0) {
|
||||
return reply.status(500).send({ error: results.errors.join("; ") });
|
||||
} else {
|
||||
return reply.status(400).send({ error: "No notification channels configured" });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -240,11 +367,66 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
shoutrrrUrl: userSettings.shoutrrrUrl || "",
|
||||
};
|
||||
|
||||
// Get translations based on user language
|
||||
const language = (userSettings.language as Language) || "en";
|
||||
const tr = getTranslations(language);
|
||||
|
||||
const results: { email?: boolean; push?: boolean; errors: string[] } = { errors: [] };
|
||||
|
||||
// Separate empty from low stock medications
|
||||
// Separate into 3 categories: empty, critical, and low stock
|
||||
const emptyMeds = lowStock.filter((r) => r.medsLeft <= 0);
|
||||
const lowMeds = lowStock.filter((r) => r.medsLeft > 0);
|
||||
const criticalMeds = lowStock.filter((r) => r.medsLeft > 0 && r.isCritical !== false);
|
||||
const lowStockMeds = lowStock.filter((r) => r.medsLeft > 0 && r.isCritical === false);
|
||||
|
||||
// Build shared notification content (method-agnostic)
|
||||
const titleParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
titleParts.push(`🚨 ${emptyMeds.length} ${tr.push.empty}`);
|
||||
}
|
||||
if (criticalMeds.length > 0) {
|
||||
titleParts.push(`🚨 ${criticalMeds.length} ${tr.push.critical}`);
|
||||
}
|
||||
if (lowStockMeds.length > 0) {
|
||||
titleParts.push(`⚠️ ${lowStockMeds.length} ${tr.push.lowStock}`);
|
||||
}
|
||||
const notificationTitle = `MedAssist-ng: ${titleParts.join(", ")} - ${tr.push.reorderNow}`;
|
||||
|
||||
// Build description text
|
||||
let descriptionText: string;
|
||||
if (emptyMeds.length > 0 && (criticalMeds.length > 0 || lowStockMeds.length > 0)) {
|
||||
descriptionText = tr.stockReminder.descriptionMixed;
|
||||
} else if (emptyMeds.length > 0) {
|
||||
descriptionText = tr.stockReminder.descriptionEmpty;
|
||||
} else if (criticalMeds.length > 0) {
|
||||
descriptionText = tr.stockReminder.description;
|
||||
} else {
|
||||
descriptionText = tr.stockReminder.descriptionLow;
|
||||
}
|
||||
|
||||
// Build section-based message (shared between email plain text and push)
|
||||
const messageParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.push.emptySection}:`);
|
||||
emptyMeds.forEach((r) => messageParts.push(` • ${r.name}`));
|
||||
}
|
||||
if (criticalMeds.length > 0) {
|
||||
if (messageParts.length > 0) messageParts.push("");
|
||||
messageParts.push(`🚨 ${tr.push.criticalSection}:`);
|
||||
criticalMeds.forEach((r) =>
|
||||
messageParts.push(
|
||||
` • ${r.name}: ${t(tr.push.pillsLeft, { count: r.medsLeft })}, ${t(tr.push.daysLeft, { count: r.daysLeft ?? 0 })}`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (lowStockMeds.length > 0) {
|
||||
if (messageParts.length > 0) messageParts.push("");
|
||||
messageParts.push(`⚠️ ${tr.push.lowStockSection}:`);
|
||||
lowStockMeds.forEach((r) =>
|
||||
messageParts.push(
|
||||
` • ${r.name}: ${t(tr.push.pillsLeft, { count: r.medsLeft })}, ${t(tr.push.daysLeft, { count: r.daysLeft ?? 0 })}`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Send email if enabled
|
||||
if (notificationSettings.emailEnabled && email) {
|
||||
@@ -256,52 +438,59 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
const smtpFrom = process.env.SMTP_FROM ?? smtpUser;
|
||||
|
||||
if (smtpHost && smtpUser) {
|
||||
// Build subject line based on what we have
|
||||
let subjectText: string;
|
||||
if (emptyMeds.length > 0 && lowMeds.length > 0) {
|
||||
subjectText = `🚨 ${emptyMeds.length} Empty, ⚠️ ${lowMeds.length} Running Low`;
|
||||
} else if (emptyMeds.length > 0) {
|
||||
subjectText = `🚨 ${emptyMeds.length} Medication${emptyMeds.length > 1 ? "s" : ""} Empty`;
|
||||
} else {
|
||||
subjectText = `⚠️ ${lowMeds.length} Medication${lowMeds.length > 1 ? "s" : ""} Running Low`;
|
||||
}
|
||||
// Build subject line from shared title parts
|
||||
const subjectText = titleParts.join(", ");
|
||||
|
||||
// Build alert box based on what we have
|
||||
let alertHtml: string;
|
||||
if (emptyMeds.length > 0 && lowMeds.length > 0) {
|
||||
alertHtml = `
|
||||
// Build alert boxes for each category
|
||||
const alertParts: string[] = [];
|
||||
|
||||
if (emptyMeds.length > 0) {
|
||||
const emptyAlert =
|
||||
emptyMeds.length === 1
|
||||
? tr.stockReminder.alertEmptySingle
|
||||
: t(tr.stockReminder.alertEmptyMultiple, { count: emptyMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fef2f2; border: 1px solid #dc2626;">
|
||||
<p style="margin: 0; color: #dc2626; font-weight: 600; font-size: 13px;">
|
||||
🚨 ${emptyMeds.length} medication${emptyMeds.length > 1 ? "s" : ""} EMPTY - reorder immediately!
|
||||
${emptyAlert}
|
||||
</p>
|
||||
</div>
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #fffbeb; border: 1px solid #f59e0b;">
|
||||
<p style="margin: 0; color: #b45309; font-weight: 500; font-size: 13px;">
|
||||
⚠️ ${lowMeds.length} medication${lowMeds.length > 1 ? "s" : ""} running low - reorder soon
|
||||
</p>
|
||||
</div>`;
|
||||
} else if (emptyMeds.length > 0) {
|
||||
alertHtml = `
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #fef2f2; border: 1px solid #dc2626;">
|
||||
<p style="margin: 0; color: #dc2626; font-weight: 600; font-size: 13px;">
|
||||
🚨 ${emptyMeds.length} medication${emptyMeds.length > 1 ? "s" : ""} EMPTY - reorder immediately!
|
||||
</p>
|
||||
</div>`;
|
||||
} else {
|
||||
alertHtml = `
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #fffbeb; border: 1px solid #f59e0b;">
|
||||
<p style="margin: 0; color: #b45309; font-weight: 500; font-size: 13px;">
|
||||
⚠️ ${lowMeds.length} medication${lowMeds.length > 1 ? "s" : ""} running low - reorder soon
|
||||
</p>
|
||||
</div>`;
|
||||
</div>`);
|
||||
}
|
||||
|
||||
if (criticalMeds.length > 0) {
|
||||
const criticalAlert =
|
||||
criticalMeds.length === 1
|
||||
? tr.stockReminder.alertLowSingle
|
||||
: t(tr.stockReminder.alertLowMultiple, { count: criticalMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fff7ed; border: 1px solid #ea580c;">
|
||||
<p style="margin: 0; color: #c2410c; font-weight: 600; font-size: 13px;">
|
||||
${criticalAlert}
|
||||
</p>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
if (lowStockMeds.length > 0) {
|
||||
const lowAlert =
|
||||
lowStockMeds.length === 1
|
||||
? tr.stockReminder.alertLowStockSingle
|
||||
: t(tr.stockReminder.alertLowStockMultiple, { count: lowStockMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fffbeb; border: 1px solid #f59e0b;">
|
||||
<p style="margin: 0; color: #b45309; font-weight: 500; font-size: 13px;">
|
||||
${lowAlert}
|
||||
</p>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
const alertHtml = alertParts.join("");
|
||||
|
||||
// Build table rows with status indicator
|
||||
const buildTableRow = (row: LowStockItem) => {
|
||||
const isEmpty = row.medsLeft <= 0;
|
||||
const statusIcon = isEmpty ? "🚨" : "⚠️";
|
||||
const rowBg = isEmpty ? "#fef2f2" : "white";
|
||||
// Escape user-provided strings and coerce numbers to prevent XSS
|
||||
const isCritical = row.isCritical !== false;
|
||||
const statusIcon = isEmpty ? "🚨" : isCritical ? "🚨" : "⚠️";
|
||||
const rowBg = isEmpty ? "#fef2f2" : isCritical ? "#fff7ed" : "white";
|
||||
const safeName = escapeHtml(row.name);
|
||||
const safeMedsLeft = Number(row.medsLeft) || 0;
|
||||
const safeDaysLeft = Number(row.daysLeft) || 0;
|
||||
@@ -311,26 +500,16 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${statusIcon} ${safeName}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap; ${isEmpty ? "color: #dc2626; font-weight: 600;" : ""}"><strong>${safeMedsLeft}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeDaysLeft}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${isEmpty ? "<strong>NOW</strong>" : safeDepletionDate}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${isEmpty ? `<strong>${tr.stockReminder.now}</strong>` : safeDepletionDate}</td>
|
||||
</tr>`;
|
||||
};
|
||||
|
||||
const tableRows = lowStock.map(buildTableRow).join("");
|
||||
|
||||
// Build description text
|
||||
let descriptionText: string;
|
||||
if (emptyMeds.length > 0 && lowMeds.length > 0) {
|
||||
descriptionText = "The following medications need to be reordered:";
|
||||
} else if (emptyMeds.length > 0) {
|
||||
descriptionText = "The following medications are EMPTY and need to be reordered immediately:";
|
||||
} else {
|
||||
descriptionText = "The following medications are running low and need to be reordered:";
|
||||
}
|
||||
|
||||
const html = `
|
||||
<div style="font-family: system-ui, -apple-system, sans-serif; max-width: 100%; margin: 0 auto; padding: 12px; background: #f9fafb;">
|
||||
<div style="background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${emptyMeds.length > 0 ? "🚨" : "⚠️"} MedAssist-ng - Reorder Reminder</h2>
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${emptyMeds.length > 0 ? "🚨" : "⚠️"} MedAssist-ng - ${tr.push.reorderNow}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${descriptionText}</p>
|
||||
|
||||
${alertHtml}
|
||||
@@ -339,10 +518,10 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
<table style="width: 100%; border-collapse: collapse; background: white; min-width: 400px;">
|
||||
<thead>
|
||||
<tr style="background: #f3f4f6;">
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">Medication</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">Pills</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">Days</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">Runs Out</th>
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.stockReminder.tableHeaders.medication}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.stockReminder.tableHeaders.pills}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.stockReminder.tableHeaders.days}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.stockReminder.tableHeaders.runsOut}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -351,34 +530,12 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">Sent from MedAssist-ng Medication Planner</p>
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 16px 0 0 0;">${getFooterHtml(language)}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Build plain text with sections
|
||||
let plainTextContent: string;
|
||||
if (emptyMeds.length > 0 && lowMeds.length > 0) {
|
||||
plainTextContent = `🚨 EMPTY (reorder immediately):
|
||||
${emptyMeds.map((r) => ` • ${r.name}`).join("\n")}
|
||||
|
||||
⚠️ RUNNING LOW (reorder soon):
|
||||
${lowMeds.map((r) => ` • ${r.name}: ${r.medsLeft} pills left, ${r.daysLeft ?? 0} days remaining`).join("\n")}`;
|
||||
} else if (emptyMeds.length > 0) {
|
||||
plainTextContent = `🚨 EMPTY (reorder immediately):
|
||||
${emptyMeds.map((r) => ` • ${r.name}`).join("\n")}`;
|
||||
} else {
|
||||
plainTextContent = `⚠️ Running low:
|
||||
${lowMeds.map((r) => ` • ${r.name}: ${r.medsLeft} pills left, ${r.daysLeft ?? 0} days remaining, runs out ${r.depletionDate ?? "soon"}`).join("\n")}`;
|
||||
}
|
||||
|
||||
const plainText = `MedAssist-ng - Reorder Reminder
|
||||
|
||||
${plainTextContent}
|
||||
|
||||
---
|
||||
Sent from MedAssist-ng Medication Planner`;
|
||||
const plainText = `MedAssist-ng - ${tr.push.reorderNow}\n\n${messageParts.join("\n")}\n\n---\n${getFooterPlain(language)}`;
|
||||
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
@@ -394,7 +551,7 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: email,
|
||||
subject: `MedAssist-ng - ${subjectText}`,
|
||||
subject: `MedAssist-ng: ${subjectText}`,
|
||||
text: plainText,
|
||||
html,
|
||||
});
|
||||
@@ -409,38 +566,10 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
|
||||
// Send push notification if enabled
|
||||
if (notificationSettings.shoutrrrEnabled && notificationSettings.shoutrrrUrl) {
|
||||
// Get translations based on user language (default to 'en')
|
||||
const tr = getTranslations((userSettings.language as Language) || "en");
|
||||
|
||||
// Build clear title
|
||||
const titleParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
titleParts.push(`🚨 ${emptyMeds.length} ${tr.push.empty}`);
|
||||
}
|
||||
if (lowMeds.length > 0) {
|
||||
titleParts.push(`⚠️ ${lowMeds.length} ${tr.push.low}`);
|
||||
}
|
||||
const title = `MedAssist: ${titleParts.join(", ")} - ${tr.push.reorderNow}`;
|
||||
|
||||
// Build clear message with sections
|
||||
const messageParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.push.emptySection}:`);
|
||||
emptyMeds.forEach((r) => messageParts.push(` • ${r.name}`));
|
||||
}
|
||||
if (lowMeds.length > 0) {
|
||||
if (emptyMeds.length > 0) messageParts.push("");
|
||||
messageParts.push(`⚠️ ${tr.push.lowSection}:`);
|
||||
lowMeds.forEach((r) =>
|
||||
messageParts.push(
|
||||
` • ${r.name}: ${t(tr.push.pillsLeft, { count: r.medsLeft })}, ${t(tr.push.daysLeft, { count: r.daysLeft ?? 0 })}`
|
||||
)
|
||||
);
|
||||
}
|
||||
const message = messageParts.join("\n");
|
||||
const message = messageParts.join("\n") + `\n\n---\n${getFooterPlain(language)}`;
|
||||
|
||||
try {
|
||||
const pushResult = await sendShoutrrrNotification(notificationSettings.shoutrrrUrl, title, message);
|
||||
const pushResult = await sendShoutrrrNotification(notificationSettings.shoutrrrUrl, notificationTitle, message);
|
||||
if (pushResult.success) {
|
||||
results.push = true;
|
||||
} else {
|
||||
@@ -458,7 +587,9 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
updateReminderSentTime("stock", channel);
|
||||
|
||||
// Also update user settings in database so frontend can display the info
|
||||
await updateUserReminderSentTime(userId, "stock", channel);
|
||||
const firstMed = lowStock[0];
|
||||
const medNames = lowStock.map((m: { name: string }) => m.name).join(", ");
|
||||
await updateUserReminderSentTime(userId, "stock", channel, medNames);
|
||||
}
|
||||
|
||||
// Build response message
|
||||
@@ -477,4 +608,212 @@ Sent from MedAssist-ng Medication Planner`;
|
||||
return reply.status(400).send({ error: "No notification channels configured" });
|
||||
}
|
||||
});
|
||||
|
||||
// Manual prescription reminder (supports email and push)
|
||||
app.post<{ Body: PrescriptionReminderBody }>("/reminder/send-prescription", async (request, reply) => {
|
||||
const { email, prescriptionLow } = request.body;
|
||||
|
||||
if (!prescriptionLow || prescriptionLow.length === 0) {
|
||||
return reply.status(400).send({ error: "Missing prescription reminder data" });
|
||||
}
|
||||
|
||||
const userId = await getUserId(request);
|
||||
const userSettings = await loadUserSettings(userId);
|
||||
const language = (userSettings.language as Language) || "en";
|
||||
const tr = getTranslations(language);
|
||||
|
||||
const emptyRx = prescriptionLow.filter((item) => item.remainingRefills <= 0);
|
||||
const lowRx = prescriptionLow.filter((item) => item.remainingRefills > 0);
|
||||
|
||||
const lines = prescriptionLow.map((item) => {
|
||||
const expirySuffix = item.expiryDate ? t(tr.prescriptionReminder.expiresSuffix, { date: item.expiryDate }) : "";
|
||||
if (item.remainingRefills <= 0) {
|
||||
return `- ${t(tr.prescriptionReminder.lineEmpty, {
|
||||
name: item.name,
|
||||
expirySuffix,
|
||||
})}`;
|
||||
}
|
||||
return `- ${t(tr.prescriptionReminder.line, {
|
||||
name: item.name,
|
||||
refills: item.remainingRefills,
|
||||
expirySuffix,
|
||||
})}`;
|
||||
});
|
||||
|
||||
const medNames = prescriptionLow.map((m: { name: string }) => m.name).join(", ");
|
||||
|
||||
const results: { email?: boolean; push?: boolean; errors: string[] } = { errors: [] };
|
||||
|
||||
if (userSettings.emailEnabled && userSettings.emailPrescriptionReminders && email) {
|
||||
const smtpHost = process.env.SMTP_HOST;
|
||||
const smtpUser = process.env.SMTP_USER;
|
||||
const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS;
|
||||
const smtpPort = parseInt(process.env.SMTP_PORT ?? "587", 10);
|
||||
const smtpSecure = process.env.SMTP_SECURE === "true";
|
||||
const smtpFrom = process.env.SMTP_FROM ?? smtpUser;
|
||||
|
||||
if (smtpHost && smtpUser) {
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
auth: {
|
||||
user: smtpUser,
|
||||
pass: smtpPass ?? "",
|
||||
},
|
||||
});
|
||||
|
||||
const subject =
|
||||
prescriptionLow.length === 1
|
||||
? tr.prescriptionReminder.subjectSingle
|
||||
: t(tr.prescriptionReminder.subjectMultiple, { count: prescriptionLow.length });
|
||||
|
||||
const bodyText =
|
||||
emptyRx.length > 0 ? tr.prescriptionReminder.descriptionEmpty : tr.prescriptionReminder.descriptionLow;
|
||||
const alertText =
|
||||
emptyRx.length > 0
|
||||
? emptyRx.length === 1
|
||||
? tr.prescriptionReminder.alertEmptySingle
|
||||
: t(tr.prescriptionReminder.alertEmptyMultiple, { count: emptyRx.length })
|
||||
: lowRx.length === 1
|
||||
? tr.prescriptionReminder.alertLowSingle
|
||||
: t(tr.prescriptionReminder.alertLowMultiple, { count: lowRx.length });
|
||||
|
||||
const tableRows = prescriptionLow
|
||||
.map((item) => {
|
||||
const isEmpty = item.remainingRefills <= 0;
|
||||
const safeName = escapeHtml(item.name);
|
||||
const safeRefills = Number(item.remainingRefills) || 0;
|
||||
const safeThreshold = Number(item.threshold) || 0;
|
||||
const safeExpiry = item.expiryDate ? escapeHtml(String(item.expiryDate)) : "-";
|
||||
const rowBg = isEmpty ? "#fef2f2" : "white";
|
||||
return `
|
||||
<tr style="background: ${rowBg};">
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${isEmpty ? "🚨" : "⚠️"} ${safeName}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap; ${isEmpty ? "color: #dc2626; font-weight: 600;" : ""}"><strong>${safeRefills}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeThreshold}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeExpiry}</td>
|
||||
</tr>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
const emailTitle = emptyRx.length > 0 ? tr.prescriptionReminder.titleEmpty : tr.prescriptionReminder.title;
|
||||
const text = `${emailTitle}\n\n${bodyText}\n\n${lines.join("\n")}\n\n---\n${getFooterPlain(language)}`;
|
||||
const html = `
|
||||
<div style="font-family: system-ui, -apple-system, sans-serif; max-width: 100%; margin: 0 auto; padding: 12px; background: #f9fafb;">
|
||||
<div style="background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${emailTitle}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${bodyText}</p>
|
||||
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; ${emptyRx.length > 0 ? "background: #fef2f2; border: 1px solid #dc2626;" : "background: #fffbeb; border: 1px solid #f59e0b;"}">
|
||||
<p style="margin: 0; ${emptyRx.length > 0 ? "color: #dc2626; font-weight: 600;" : "color: #b45309; font-weight: 500;"} font-size: 13px;">
|
||||
${alertText}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style="overflow-x: auto; -webkit-overflow-scrolling: touch;">
|
||||
<table style="width: 100%; border-collapse: collapse; background: white; min-width: 460px;">
|
||||
<thead>
|
||||
<tr style="background: #f3f4f6;">
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.medication}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.refillsLeft}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.reminderThreshold}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.prescriptionExpires}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${tableRows}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">${getFooterHtml(language)}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: email,
|
||||
subject,
|
||||
text,
|
||||
html,
|
||||
});
|
||||
|
||||
results.email = true;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
results.errors.push(`Email: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (userSettings.shoutrrrEnabled && userSettings.shoutrrrPrescriptionReminders && userSettings.shoutrrrUrl) {
|
||||
const titleParts: string[] = [];
|
||||
if (emptyRx.length > 0)
|
||||
titleParts.push(
|
||||
`🚨 ${emptyRx.length} ${emptyRx.length === 1 ? tr.prescriptionReminder.pushEmptySingle : tr.prescriptionReminder.pushEmpty}`
|
||||
);
|
||||
if (lowRx.length > 0)
|
||||
titleParts.push(
|
||||
`🚨 ${lowRx.length} ${lowRx.length === 1 ? tr.prescriptionReminder.pushLowSingle : tr.prescriptionReminder.pushLow}`
|
||||
);
|
||||
const title = `MedAssist-ng: ${titleParts.join(", ")} - ${tr.prescriptionReminder.pushRenewNow}`;
|
||||
|
||||
const messageParts: string[] = [];
|
||||
if (emptyRx.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.prescriptionReminder.pushEmptySection}:`);
|
||||
for (const m of emptyRx) {
|
||||
messageParts.push(` • ${m.name}`);
|
||||
}
|
||||
}
|
||||
if (lowRx.length > 0) {
|
||||
if (emptyRx.length > 0) messageParts.push("");
|
||||
messageParts.push(`🚨 ${tr.prescriptionReminder.pushLowSection}:`);
|
||||
for (const m of lowRx) {
|
||||
messageParts.push(
|
||||
` • ${m.name}: ${t(tr.prescriptionReminder.pushRefillsLeft, { count: m.remainingRefills })}`
|
||||
);
|
||||
}
|
||||
}
|
||||
const message = messageParts.join("\n") + `\n\n---\n${getFooterPlain(language)}`;
|
||||
|
||||
try {
|
||||
const pushResult = await sendShoutrrrNotification(userSettings.shoutrrrUrl, title, message);
|
||||
if (pushResult.success) {
|
||||
results.push = true;
|
||||
} else {
|
||||
results.errors.push(`Push: ${pushResult.error}`);
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
results.errors.push(`Push: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (results.email || results.push) {
|
||||
const channel = results.email && results.push ? "both" : results.email ? "email" : "push";
|
||||
updateReminderSentTime("prescription", channel);
|
||||
await updateUserReminderSentTime(userId, "prescription", channel, medNames);
|
||||
}
|
||||
|
||||
const sentChannels: string[] = [];
|
||||
if (results.email) sentChannels.push("email");
|
||||
if (results.push) sentChannels.push("push");
|
||||
|
||||
if (sentChannels.length > 0) {
|
||||
return reply.send({
|
||||
success: true,
|
||||
message: `Prescription reminder sent via ${sentChannels.join(" and ")}`,
|
||||
});
|
||||
}
|
||||
|
||||
if (results.errors.length > 0) {
|
||||
return reply.status(500).send({ error: results.errors.join("; ") });
|
||||
}
|
||||
|
||||
return reply.status(400).send({ error: "No notification channels configured" });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ const refillSchema = z
|
||||
.object({
|
||||
packsAdded: z.number().int().min(0).default(0),
|
||||
loosePillsAdded: z.number().int().min(0).default(0),
|
||||
usePrescription: z.boolean().default(false),
|
||||
})
|
||||
.refine((data) => data.packsAdded > 0 || data.loosePillsAdded > 0, {
|
||||
message: "Must add at least one pack or some loose pills",
|
||||
@@ -50,17 +51,32 @@ export async function refillRoutes(app: FastifyInstance) {
|
||||
.where(and(eq(medications.id, medId), eq(medications.userId, userId)));
|
||||
if (!med) return reply.notFound("Medication not found");
|
||||
|
||||
const { packsAdded, loosePillsAdded } = parsed.data;
|
||||
const { packsAdded, loosePillsAdded, usePrescription } = parsed.data;
|
||||
|
||||
if (usePrescription) {
|
||||
if (!(med.prescriptionEnabled ?? false)) {
|
||||
return reply.status(400).send({ error: "Prescription refill is not enabled for this medication" });
|
||||
}
|
||||
const remaining = med.prescriptionRemainingRefills ?? 0;
|
||||
if (remaining <= 0) {
|
||||
return reply.status(409).send({ error: "No remaining prescription refills" });
|
||||
}
|
||||
}
|
||||
|
||||
// Update medication stock
|
||||
const newPackCount = med.packCount + packsAdded;
|
||||
const newLooseTablets = med.looseTablets + loosePillsAdded;
|
||||
|
||||
const newRemainingRefills = usePrescription
|
||||
? Math.max(0, (med.prescriptionRemainingRefills ?? 0) - 1)
|
||||
: (med.prescriptionRemainingRefills ?? null);
|
||||
|
||||
await db
|
||||
.update(medications)
|
||||
.set({
|
||||
packCount: newPackCount,
|
||||
looseTablets: newLooseTablets,
|
||||
prescriptionRemainingRefills: newRemainingRefills,
|
||||
stockAdjustment: 0, // Reset offset since we're adding to base stock
|
||||
lastStockCorrectionAt: new Date(), // Reset consumed counter to now
|
||||
updatedAt: new Date(),
|
||||
@@ -75,12 +91,17 @@ export async function refillRoutes(app: FastifyInstance) {
|
||||
userId,
|
||||
packsAdded,
|
||||
loosePillsAdded,
|
||||
usedPrescription: usePrescription,
|
||||
})
|
||||
.returning();
|
||||
|
||||
// Calculate pills added for response
|
||||
const pillsPerPack = med.blistersPerPack * med.pillsPerBlister;
|
||||
const totalPillsAdded = packsAdded * pillsPerPack + loosePillsAdded;
|
||||
// Calculate pills added for response (packageType-aware)
|
||||
const isBottle = (med.packageType ?? "blister") === "bottle";
|
||||
const pillsPerPack = isBottle ? 0 : med.blistersPerPack * med.pillsPerBlister;
|
||||
const totalPillsAdded = isBottle ? loosePillsAdded : packsAdded * pillsPerPack + loosePillsAdded;
|
||||
const newTotalPills = isBottle
|
||||
? newLooseTablets + (med.stockAdjustment ?? 0)
|
||||
: newPackCount * pillsPerPack + newLooseTablets + (med.stockAdjustment ?? 0);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -94,7 +115,14 @@ export async function refillRoutes(app: FastifyInstance) {
|
||||
newStock: {
|
||||
packCount: newPackCount,
|
||||
looseTablets: newLooseTablets,
|
||||
totalPills: newPackCount * pillsPerPack + newLooseTablets,
|
||||
totalPills: newTotalPills,
|
||||
},
|
||||
prescription: {
|
||||
used: usePrescription,
|
||||
remainingRefills: newRemainingRefills,
|
||||
authorizedRefills: med.prescriptionAuthorizedRefills ?? null,
|
||||
lowRefillThreshold: med.prescriptionLowRefillThreshold ?? 1,
|
||||
enabled: med.prescriptionEnabled ?? false,
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -120,13 +148,15 @@ export async function refillRoutes(app: FastifyInstance) {
|
||||
.where(eq(refillHistory.medicationId, medId))
|
||||
.orderBy(desc(refillHistory.refillDate));
|
||||
|
||||
const pillsPerPack = med.blistersPerPack * med.pillsPerBlister;
|
||||
const isBottle = (med.packageType ?? "blister") === "bottle";
|
||||
const pillsPerPack = isBottle ? 0 : med.blistersPerPack * med.pillsPerBlister;
|
||||
|
||||
return refills.map((r) => ({
|
||||
id: r.id,
|
||||
packsAdded: r.packsAdded,
|
||||
loosePillsAdded: r.loosePillsAdded,
|
||||
totalPillsAdded: r.packsAdded * pillsPerPack + r.loosePillsAdded,
|
||||
totalPillsAdded: isBottle ? r.loosePillsAdded : r.packsAdded * pillsPerPack + r.loosePillsAdded,
|
||||
usedPrescription: r.usedPrescription ?? false,
|
||||
refillDate: r.refillDate,
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -15,10 +15,12 @@ export type UserSettings = {
|
||||
notificationEmail: string | null;
|
||||
emailStockReminders: boolean;
|
||||
emailIntakeReminders: boolean;
|
||||
emailPrescriptionReminders: boolean;
|
||||
shoutrrrEnabled: boolean;
|
||||
shoutrrrUrl: string | null;
|
||||
shoutrrrStockReminders: boolean;
|
||||
shoutrrrIntakeReminders: boolean;
|
||||
shoutrrrPrescriptionReminders: boolean;
|
||||
reminderDaysBefore: number;
|
||||
repeatDailyReminders: boolean;
|
||||
skipRemindersForTakenDoses: boolean;
|
||||
@@ -30,11 +32,18 @@ export type UserSettings = {
|
||||
highStockDays: number;
|
||||
language: Language;
|
||||
stockCalculationMode: "automatic" | "manual";
|
||||
shareStockStatus: boolean;
|
||||
lastAutoEmailSent: string | null;
|
||||
lastNotificationType: string | null;
|
||||
lastNotificationChannel: string | null;
|
||||
lastReminderMedName: string | null;
|
||||
lastReminderTakenBy: string | null;
|
||||
lastStockReminderSent: string | null;
|
||||
lastStockReminderChannel: string | null;
|
||||
lastStockReminderMedNames: string | null;
|
||||
lastPrescriptionReminderSent: string | null;
|
||||
lastPrescriptionReminderChannel: string | null;
|
||||
lastPrescriptionReminderMedNames: string | null;
|
||||
};
|
||||
|
||||
type SettingsBody = {
|
||||
@@ -49,14 +58,17 @@ type SettingsBody = {
|
||||
shoutrrrUrl: string;
|
||||
emailStockReminders: boolean;
|
||||
emailIntakeReminders: boolean;
|
||||
emailPrescriptionReminders: boolean;
|
||||
shoutrrrStockReminders: boolean;
|
||||
shoutrrrIntakeReminders: boolean;
|
||||
shoutrrrPrescriptionReminders: boolean;
|
||||
skipRemindersForTakenDoses: boolean;
|
||||
repeatRemindersEnabled: boolean;
|
||||
reminderRepeatIntervalMinutes: number;
|
||||
maxNaggingReminders: number;
|
||||
language: string;
|
||||
stockCalculationMode: "automatic" | "manual";
|
||||
shareStockStatus: boolean;
|
||||
};
|
||||
|
||||
type TestEmailBody = {
|
||||
@@ -89,10 +101,12 @@ function getDefaultSettings() {
|
||||
notificationEmail: process.env.DEFAULT_NOTIFICATION_EMAIL || null,
|
||||
emailStockReminders: envBool("DEFAULT_EMAIL_STOCK_REMINDERS", true),
|
||||
emailIntakeReminders: envBool("DEFAULT_EMAIL_INTAKE_REMINDERS", true),
|
||||
emailPrescriptionReminders: envBool("DEFAULT_EMAIL_PRESCRIPTION_REMINDERS", true),
|
||||
shoutrrrEnabled: envBool("DEFAULT_SHOUTRRR_ENABLED", false),
|
||||
shoutrrrUrl: process.env.DEFAULT_SHOUTRRR_URL || null,
|
||||
shoutrrrStockReminders: envBool("DEFAULT_SHOUTRRR_STOCK_REMINDERS", true),
|
||||
shoutrrrIntakeReminders: envBool("DEFAULT_SHOUTRRR_INTAKE_REMINDERS", true),
|
||||
shoutrrrPrescriptionReminders: envBool("DEFAULT_SHOUTRRR_PRESCRIPTION_REMINDERS", true),
|
||||
reminderDaysBefore: envInt("REMINDER_DAYS_BEFORE", 7),
|
||||
repeatDailyReminders: envBool("DEFAULT_REPEAT_DAILY_REMINDERS", false),
|
||||
skipRemindersForTakenDoses: envBool("DEFAULT_SKIP_REMINDERS_FOR_TAKEN_DOSES", false),
|
||||
@@ -104,11 +118,18 @@ function getDefaultSettings() {
|
||||
highStockDays: envInt("DEFAULT_HIGH_STOCK_DAYS", 180),
|
||||
language: (process.env.DEFAULT_LANGUAGE as "en" | "de") || "en",
|
||||
stockCalculationMode: (process.env.DEFAULT_STOCK_CALCULATION_MODE as "automatic" | "manual") || "automatic",
|
||||
shareStockStatus: envBool("DEFAULT_SHARE_STOCK_STATUS", true),
|
||||
lastAutoEmailSent: null,
|
||||
lastNotificationType: null,
|
||||
lastNotificationChannel: null,
|
||||
lastReminderMedName: null,
|
||||
lastReminderTakenBy: null,
|
||||
lastStockReminderSent: null,
|
||||
lastStockReminderChannel: null,
|
||||
lastStockReminderMedNames: null,
|
||||
lastPrescriptionReminderSent: null,
|
||||
lastPrescriptionReminderChannel: null,
|
||||
lastPrescriptionReminderMedNames: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -139,10 +160,12 @@ export async function loadUserSettings(userId: number): Promise<UserSettings> {
|
||||
notificationEmail: settings.notificationEmail,
|
||||
emailStockReminders: settings.emailStockReminders,
|
||||
emailIntakeReminders: settings.emailIntakeReminders,
|
||||
emailPrescriptionReminders: settings.emailPrescriptionReminders ?? true,
|
||||
shoutrrrEnabled: settings.shoutrrrEnabled,
|
||||
shoutrrrUrl: settings.shoutrrrUrl,
|
||||
shoutrrrStockReminders: settings.shoutrrrStockReminders,
|
||||
shoutrrrIntakeReminders: settings.shoutrrrIntakeReminders,
|
||||
shoutrrrPrescriptionReminders: settings.shoutrrrPrescriptionReminders ?? true,
|
||||
reminderDaysBefore: settings.reminderDaysBefore,
|
||||
repeatDailyReminders: settings.repeatDailyReminders,
|
||||
skipRemindersForTakenDoses: settings.skipRemindersForTakenDoses ?? false,
|
||||
@@ -154,11 +177,18 @@ export async function loadUserSettings(userId: number): Promise<UserSettings> {
|
||||
highStockDays: settings.highStockDays,
|
||||
language: settings.language as Language,
|
||||
stockCalculationMode: (settings.stockCalculationMode as "automatic" | "manual") ?? "automatic",
|
||||
shareStockStatus: settings.shareStockStatus ?? true,
|
||||
lastAutoEmailSent: settings.lastAutoEmailSent,
|
||||
lastNotificationType: settings.lastNotificationType,
|
||||
lastNotificationChannel: settings.lastNotificationChannel,
|
||||
lastReminderMedName: settings.lastReminderMedName ?? null,
|
||||
lastReminderTakenBy: settings.lastReminderTakenBy ?? null,
|
||||
lastStockReminderSent: settings.lastStockReminderSent ?? null,
|
||||
lastStockReminderChannel: settings.lastStockReminderChannel ?? null,
|
||||
lastStockReminderMedNames: settings.lastStockReminderMedNames ?? null,
|
||||
lastPrescriptionReminderSent: settings.lastPrescriptionReminderSent ?? null,
|
||||
lastPrescriptionReminderChannel: settings.lastPrescriptionReminderChannel ?? null,
|
||||
lastPrescriptionReminderMedNames: settings.lastPrescriptionReminderMedNames ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,10 +201,12 @@ export async function getAllUserSettings(): Promise<UserSettings[]> {
|
||||
notificationEmail: settings.notificationEmail,
|
||||
emailStockReminders: settings.emailStockReminders,
|
||||
emailIntakeReminders: settings.emailIntakeReminders,
|
||||
emailPrescriptionReminders: settings.emailPrescriptionReminders ?? true,
|
||||
shoutrrrEnabled: settings.shoutrrrEnabled,
|
||||
shoutrrrUrl: settings.shoutrrrUrl,
|
||||
shoutrrrStockReminders: settings.shoutrrrStockReminders,
|
||||
shoutrrrIntakeReminders: settings.shoutrrrIntakeReminders,
|
||||
shoutrrrPrescriptionReminders: settings.shoutrrrPrescriptionReminders ?? true,
|
||||
reminderDaysBefore: settings.reminderDaysBefore,
|
||||
repeatDailyReminders: settings.repeatDailyReminders,
|
||||
skipRemindersForTakenDoses: settings.skipRemindersForTakenDoses ?? false,
|
||||
@@ -186,11 +218,18 @@ export async function getAllUserSettings(): Promise<UserSettings[]> {
|
||||
highStockDays: settings.highStockDays,
|
||||
language: settings.language as Language,
|
||||
stockCalculationMode: (settings.stockCalculationMode as "automatic" | "manual") ?? "automatic",
|
||||
shareStockStatus: settings.shareStockStatus ?? true,
|
||||
lastAutoEmailSent: settings.lastAutoEmailSent,
|
||||
lastNotificationType: settings.lastNotificationType,
|
||||
lastNotificationChannel: settings.lastNotificationChannel,
|
||||
lastReminderMedName: settings.lastReminderMedName ?? null,
|
||||
lastReminderTakenBy: settings.lastReminderTakenBy ?? null,
|
||||
lastStockReminderSent: settings.lastStockReminderSent ?? null,
|
||||
lastStockReminderChannel: settings.lastStockReminderChannel ?? null,
|
||||
lastStockReminderMedNames: settings.lastStockReminderMedNames ?? null,
|
||||
lastPrescriptionReminderSent: settings.lastPrescriptionReminderSent ?? null,
|
||||
lastPrescriptionReminderChannel: settings.lastPrescriptionReminderChannel ?? null,
|
||||
lastPrescriptionReminderMedNames: settings.lastPrescriptionReminderMedNames ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -233,14 +272,17 @@ export async function settingsRoutes(app: FastifyInstance) {
|
||||
shoutrrrUrl: settings.shoutrrrUrl ?? "",
|
||||
emailStockReminders: settings.emailStockReminders,
|
||||
emailIntakeReminders: settings.emailIntakeReminders,
|
||||
emailPrescriptionReminders: settings.emailPrescriptionReminders ?? true,
|
||||
shoutrrrStockReminders: settings.shoutrrrStockReminders,
|
||||
shoutrrrIntakeReminders: settings.shoutrrrIntakeReminders,
|
||||
shoutrrrPrescriptionReminders: settings.shoutrrrPrescriptionReminders ?? true,
|
||||
skipRemindersForTakenDoses: settings.skipRemindersForTakenDoses,
|
||||
repeatRemindersEnabled: settings.repeatRemindersEnabled ?? false,
|
||||
reminderRepeatIntervalMinutes: settings.reminderRepeatIntervalMinutes ?? 30,
|
||||
maxNaggingReminders: settings.maxNaggingReminders ?? 5,
|
||||
language: settings.language,
|
||||
stockCalculationMode: settings.stockCalculationMode ?? "automatic",
|
||||
shareStockStatus: settings.shareStockStatus ?? true,
|
||||
// SMTP settings (from .env - shared/server-configured)
|
||||
smtpHost: process.env.SMTP_HOST ?? "",
|
||||
smtpPort: parseInt(process.env.SMTP_PORT ?? "587", 10),
|
||||
@@ -254,6 +296,14 @@ export async function settingsRoutes(app: FastifyInstance) {
|
||||
lastNotificationChannel: settings.lastNotificationChannel,
|
||||
lastReminderMedName: settings.lastReminderMedName ?? null,
|
||||
lastReminderTakenBy: settings.lastReminderTakenBy ?? null,
|
||||
// Stock reminder tracking (separate from intake)
|
||||
lastStockReminderSent: settings.lastStockReminderSent ?? null,
|
||||
lastStockReminderChannel: settings.lastStockReminderChannel ?? null,
|
||||
lastStockReminderMedNames: settings.lastStockReminderMedNames ?? null,
|
||||
// Prescription reminder tracking (separate from stock/intake)
|
||||
lastPrescriptionReminderSent: settings.lastPrescriptionReminderSent ?? null,
|
||||
lastPrescriptionReminderChannel: settings.lastPrescriptionReminderChannel ?? null,
|
||||
lastPrescriptionReminderMedNames: settings.lastPrescriptionReminderMedNames ?? null,
|
||||
// Server settings (from .env, read-only)
|
||||
expiryWarningDays: parseInt(process.env.EXPIRY_WARNING_DAYS ?? "30", 10),
|
||||
});
|
||||
@@ -281,10 +331,12 @@ export async function settingsRoutes(app: FastifyInstance) {
|
||||
notificationEmail: body.notificationEmail || null,
|
||||
emailStockReminders: body.emailStockReminders ?? true,
|
||||
emailIntakeReminders: body.emailIntakeReminders ?? true,
|
||||
emailPrescriptionReminders: body.emailPrescriptionReminders ?? true,
|
||||
shoutrrrEnabled: body.shoutrrrEnabled ?? false,
|
||||
shoutrrrUrl: body.shoutrrrUrl || null,
|
||||
shoutrrrStockReminders: body.shoutrrrStockReminders ?? true,
|
||||
shoutrrrIntakeReminders: body.shoutrrrIntakeReminders ?? true,
|
||||
shoutrrrPrescriptionReminders: body.shoutrrrPrescriptionReminders ?? true,
|
||||
reminderDaysBefore: body.reminderDaysBefore,
|
||||
repeatDailyReminders,
|
||||
skipRemindersForTakenDoses: body.skipRemindersForTakenDoses ?? false,
|
||||
@@ -296,6 +348,7 @@ export async function settingsRoutes(app: FastifyInstance) {
|
||||
highStockDays: body.highStockDays ?? 180,
|
||||
language: body.language ?? "en",
|
||||
stockCalculationMode: body.stockCalculationMode ?? "automatic",
|
||||
shareStockStatus: body.shareStockStatus ?? true,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
@@ -311,6 +364,30 @@ export async function settingsRoutes(app: FastifyInstance) {
|
||||
return reply.send({ success: true });
|
||||
});
|
||||
|
||||
// Update only the language setting (lightweight, called on dropdown change)
|
||||
app.put<{ Body: { language: string } }>("/settings/language", async (request, reply) => {
|
||||
const userId = await getUserId(request, reply);
|
||||
const { language } = request.body;
|
||||
|
||||
if (!language || !["en", "de"].includes(language)) {
|
||||
return reply.status(400).send({ error: "Invalid language" });
|
||||
}
|
||||
|
||||
const existingSettings = await db.select().from(userSettings).where(eq(userSettings.userId, userId));
|
||||
|
||||
if (existingSettings.length > 0) {
|
||||
await db.update(userSettings).set({ language, updatedAt: new Date() }).where(eq(userSettings.userId, userId));
|
||||
} else {
|
||||
await db.insert(userSettings).values({
|
||||
userId,
|
||||
...getDefaultSettings(),
|
||||
language,
|
||||
});
|
||||
}
|
||||
|
||||
return reply.send({ success: true });
|
||||
});
|
||||
|
||||
// Test email - use SMTP settings from process.env
|
||||
app.post<{ Body: TestEmailBody }>("/settings/test-email", async (request, reply) => {
|
||||
const { email } = request.body;
|
||||
@@ -510,7 +587,10 @@ export async function sendShoutrrrNotification(
|
||||
// This works for ntfy, Apprise, and most simple push services
|
||||
if (!isJsonWebhook) {
|
||||
targetUrl = sanitizedUrl;
|
||||
headers = { Title: cleanTitle, Tags: "pill" };
|
||||
// Use RFC 2047 Base64 encoding for Title header to safely pass non-ASCII
|
||||
// characters (umlauts, accents, etc.) through HTTP headers
|
||||
const encodedTitle = `=?UTF-8?B?${Buffer.from(cleanTitle, "utf-8").toString("base64")}?=`;
|
||||
headers = { Title: encodedTitle, Tags: "pill" };
|
||||
body = message;
|
||||
|
||||
// Add auth if present (extracted during sanitization)
|
||||
|
||||
@@ -114,7 +114,9 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
const takenByArray = parseTakenByJson(med.takenByJson);
|
||||
|
||||
const totalPills =
|
||||
med.packCount * med.blistersPerPack * med.pillsPerBlister + med.looseTablets + (med.stockAdjustment ?? 0);
|
||||
(med.packageType ?? "blister") === "bottle"
|
||||
? med.looseTablets + (med.stockAdjustment ?? 0)
|
||||
: med.packCount * med.blistersPerPack * med.pillsPerBlister + med.looseTablets + (med.stockAdjustment ?? 0);
|
||||
return {
|
||||
id: med.id,
|
||||
name: med.name,
|
||||
@@ -123,6 +125,7 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
doseUnit: med.doseUnit ?? "mg",
|
||||
imageUrl: med.imageUrl,
|
||||
totalPills,
|
||||
packageType: med.packageType ?? "blister",
|
||||
packCount: med.packCount,
|
||||
blistersPerPack: med.blistersPerPack,
|
||||
looseTablets: med.looseTablets,
|
||||
@@ -132,6 +135,8 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
blisters, // Legacy format for backward compat
|
||||
dismissedUntil: med.dismissedUntil,
|
||||
updatedAt: med.updatedAt, // For filtering out doses from previous schedule configurations
|
||||
lastStockCorrectionAt: med.lastStockCorrectionAt?.getTime() ?? null,
|
||||
stockAdjustment: med.stockAdjustment ?? 0,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -142,7 +147,13 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
medications: medicationsWithBlisters,
|
||||
stockThresholds: {
|
||||
lowStockDays: settings?.lowStockDays ?? 30,
|
||||
normalStockDays: settings?.normalStockDays ?? 60,
|
||||
highStockDays: settings?.highStockDays ?? 90,
|
||||
reminderDaysBefore: settings?.reminderDaysBefore ?? 7,
|
||||
expiryWarningDays: settings?.expiryWarningDays ?? 90,
|
||||
},
|
||||
stockCalculationMode: (settings?.stockCalculationMode as "automatic" | "manual") ?? "automatic",
|
||||
shareStockStatus: settings?.shareStockStatus ?? true,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -5,8 +5,16 @@ import nodemailer from "nodemailer";
|
||||
import { db } from "../db/client.js";
|
||||
import { getDataDir } from "../db/db-utils.js";
|
||||
import { doseTracking, medications } from "../db/schema.js";
|
||||
import { getDateLocale, getTranslations, type Language, t } from "../i18n/translations.js";
|
||||
import {
|
||||
getDateLocale,
|
||||
getFooterHtml,
|
||||
getFooterPlain,
|
||||
getTranslations,
|
||||
type Language,
|
||||
t,
|
||||
} from "../i18n/translations.js";
|
||||
import { getAllUserSettings, sendShoutrrrNotification, type UserSettings } from "../routes/settings.js";
|
||||
import type { ServiceLogger } from "../utils/logger.js";
|
||||
// Import shared utilities
|
||||
import {
|
||||
cleanOldIntakeReminders,
|
||||
@@ -149,7 +157,7 @@ async function sendIntakeReminderEmail(
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">
|
||||
${tr.intakeReminder.footer}
|
||||
${getFooterHtml(language)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -178,7 +186,7 @@ ${intakes
|
||||
.join("\n")}
|
||||
|
||||
---
|
||||
${tr.intakeReminder.footer}`;
|
||||
${getFooterPlain(language)}`;
|
||||
|
||||
const subject = isRepeat
|
||||
? `[Reminder] ${t(tr.intakeReminder.subject, { medications: intakes.map((i) => i.medName).join(", ") })}`
|
||||
@@ -210,21 +218,18 @@ ${tr.intakeReminder.footer}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAndSendIntakeReminders(logger: {
|
||||
info: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
}): Promise<void> {
|
||||
logger.info(`[IntakeReminder] Checking for intake reminders...`);
|
||||
async function checkAndSendIntakeReminders(logger: ServiceLogger): Promise<void> {
|
||||
logger.debug(`[IntakeReminder] Checking for intake reminders...`);
|
||||
|
||||
// Get all user settings to iterate over each user
|
||||
const allUserSettings = await getAllUserSettings();
|
||||
|
||||
if (allUserSettings.length === 0) {
|
||||
logger.info(`[IntakeReminder] No users with settings found`);
|
||||
logger.debug(`[IntakeReminder] No users with settings found`);
|
||||
return; // No users with settings
|
||||
}
|
||||
|
||||
logger.info(`[IntakeReminder] Found ${allUserSettings.length} users to check`);
|
||||
logger.debug(`[IntakeReminder] Found ${allUserSettings.length} users to check`);
|
||||
|
||||
for (const userSettings of allUserSettings) {
|
||||
await checkAndSendIntakeRemindersForUser(userSettings, logger);
|
||||
@@ -233,12 +238,12 @@ async function checkAndSendIntakeReminders(logger: {
|
||||
|
||||
async function checkAndSendIntakeRemindersForUser(
|
||||
settings: UserSettings & { userId: number },
|
||||
logger: { info: (msg: string) => void; error: (msg: string) => void }
|
||||
logger: ServiceLogger
|
||||
): Promise<void> {
|
||||
const language = settings.language;
|
||||
const tr = getTranslations(language);
|
||||
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] Checking user ${settings.userId} - repeat:${settings.repeatRemindersEnabled} skip:${settings.skipRemindersForTakenDoses}`
|
||||
);
|
||||
|
||||
@@ -247,13 +252,13 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const shoutrrrEnabled = settings.shoutrrrEnabled && settings.shoutrrrUrl && settings.shoutrrrIntakeReminders;
|
||||
|
||||
if (!emailEnabled && !shoutrrrEnabled) {
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: No intake notifications enabled (email:${emailEnabled}, shoutrrr:${shoutrrrEnabled})`
|
||||
);
|
||||
return; // No intake reminder notifications enabled for this user
|
||||
}
|
||||
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Notifications enabled (email:${emailEnabled}, shoutrrr:${shoutrrrEnabled})`
|
||||
);
|
||||
|
||||
@@ -266,11 +271,13 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const medsWithReminders = rows.filter((row) => row.intakeRemindersEnabled);
|
||||
|
||||
if (medsWithReminders.length === 0) {
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: No medications have reminders enabled`);
|
||||
logger.debug(`[IntakeReminder] User ${settings.userId}: No medications have reminders enabled`);
|
||||
return; // No medications have reminders enabled for this user
|
||||
}
|
||||
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: Found ${medsWithReminders.length} medications with reminders`);
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Found ${medsWithReminders.length} medications with reminders`
|
||||
);
|
||||
|
||||
const state = loadIntakeReminderState();
|
||||
const allUpcoming: (UpcomingIntake & { medicationId: number; blisterIndex: number })[] = [];
|
||||
@@ -285,7 +292,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const todayEnd = new Date(now.toLocaleString("en-US", { timeZone: tz }));
|
||||
todayEnd.setHours(23, 59, 59, 999);
|
||||
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Today range: ${todayStart.toISOString()} to ${todayEnd.toISOString()}`
|
||||
);
|
||||
|
||||
@@ -300,7 +307,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
// Medication-level takenBy (for fallback/display purposes)
|
||||
const medicationTakenBy = parseTakenByJson(med.takenByJson);
|
||||
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Processing medication "${med.name}" with ${intakes.length} intakes`
|
||||
);
|
||||
|
||||
@@ -308,7 +315,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const intakesWithReminders = intakes.filter((intake, idx) => {
|
||||
const hasReminder = intake.intakeRemindersEnabled || med.intakeRemindersEnabled;
|
||||
if (!hasReminder) {
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: Intake ${idx} has reminders disabled, skipping`);
|
||||
logger.debug(`[IntakeReminder] User ${settings.userId}: Intake ${idx} has reminders disabled, skipping`);
|
||||
}
|
||||
return hasReminder;
|
||||
});
|
||||
@@ -316,7 +323,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
// Process each intake separately to track blisterIndex
|
||||
intakesWithReminders.forEach((intake, blisterIndex) => {
|
||||
const actualIndex = intakes.indexOf(intake); // Get the actual index in original array
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Intake ${actualIndex} - start: ${intake.start}, every: ${intake.every} days, usage: ${intake.usage}, takenBy: ${intake.takenBy || "(none)"}`
|
||||
);
|
||||
|
||||
@@ -333,7 +340,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
med.id,
|
||||
med.doseUnit ?? "mg"
|
||||
);
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Intake ${actualIndex} found ${upcomingIntakes.length} upcoming intakes (reminder window)`
|
||||
);
|
||||
|
||||
@@ -358,13 +365,13 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
med.id,
|
||||
med.doseUnit ?? "mg"
|
||||
);
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Intake ${actualIndex} - all today's intakes: ${allTodaysIntakes.length}, times: ${allTodaysIntakes.map((i) => i.intakeTime.toISOString()).join(", ")}`
|
||||
);
|
||||
const missedIntakes = allTodaysIntakes.filter(
|
||||
(todayIntake) => todayIntake.intakeTime.getTime() < now.getTime()
|
||||
);
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Intake ${actualIndex} found ${missedIntakes.length} missed intakes (past intake time)`
|
||||
);
|
||||
|
||||
@@ -383,10 +390,10 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
});
|
||||
}
|
||||
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: Total ${allUpcoming.length} intakes for today`);
|
||||
logger.debug(`[IntakeReminder] User ${settings.userId}: Total ${allUpcoming.length} intakes for today`);
|
||||
|
||||
if (allUpcoming.length === 0) {
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: No intakes for today`);
|
||||
logger.debug(`[IntakeReminder] User ${settings.userId}: No intakes for today`);
|
||||
return; // No upcoming intakes for today
|
||||
}
|
||||
|
||||
@@ -409,15 +416,33 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
if (!existingEntry) {
|
||||
// New dose - send first reminder
|
||||
if (isIntakePast) {
|
||||
// Already missed - this is first nagging reminder (count=1)
|
||||
remindersToSend.push({ ...intake, currentSendCount: 1, maxReminders, isAdvanceReminder: false });
|
||||
logger.info(
|
||||
`[IntakeReminder] User ${settings.userId}: First nagging for missed "${intake.medName}" at ${intake.intakeTimeStr} (1/${maxReminders})`
|
||||
);
|
||||
// Intake time already passed and we have no state entry. Check how recently it was missed.
|
||||
const minutesSinceIntake = (nowMs - intakeTimeMs) / 60000;
|
||||
const gracePeriodMinutes = (settings.reminderRepeatIntervalMinutes ?? 30) + REMINDER_MINUTES_BEFORE;
|
||||
|
||||
if (minutesSinceIntake <= gracePeriodMinutes) {
|
||||
// Recently missed — scheduler likely recovered from sleep/restart.
|
||||
// Send a catch-up reminder (counts as first nagging reminder).
|
||||
remindersToSend.push({ ...intake, currentSendCount: 1, maxReminders, isAdvanceReminder: false });
|
||||
logger.info(
|
||||
`[IntakeReminder] User ${settings.userId}: Catch-up reminder for recently missed "${intake.medName}" at ${intake.intakeTimeStr} (${Math.round(minutesSinceIntake)} min ago)`
|
||||
);
|
||||
} else {
|
||||
// Long ago — seed state without notification (user likely already noticed)
|
||||
state.reminders[key] = {
|
||||
firstSentAt: nowMs,
|
||||
lastSentAt: nowMs,
|
||||
sendCount: 0,
|
||||
advanceSent: false,
|
||||
};
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Seeding state for old past "${intake.medName}" at ${intake.intakeTimeStr} (no notification — ${Math.round(minutesSinceIntake)} min ago)`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Upcoming - this is advance reminder (no counter)
|
||||
remindersToSend.push({ ...intake, currentSendCount: 0, maxReminders, isAdvanceReminder: true });
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Advance reminder for "${intake.medName}" at ${intake.intakeTimeStr}`
|
||||
);
|
||||
}
|
||||
@@ -432,13 +457,13 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
|
||||
if (currentNaggingCount >= maxReminders) {
|
||||
// Max nagging reminders reached - stop
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Max nagging (${maxReminders}) reached for "${intake.medName}" at ${intake.intakeTimeStr}`
|
||||
);
|
||||
} else if (timeSinceLastReminder >= intervalMs) {
|
||||
const nextSendCount = currentNaggingCount + 1;
|
||||
remindersToSend.push({ ...intake, currentSendCount: nextSendCount, maxReminders, isAdvanceReminder: false });
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Nagging reminder for "${intake.medName}" at ${intake.intakeTimeStr} (${nextSendCount}/${maxReminders})`
|
||||
);
|
||||
}
|
||||
@@ -478,7 +503,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const doseId = `${intake.medicationId}-${intake.blisterIndex}-${dateOnlyMs}-${intake.takenBy}`;
|
||||
const isTaken = takenDoseIds.has(doseId);
|
||||
if (isTaken) {
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Skipping "${intake.medName}" - dose ${doseId} already taken`
|
||||
);
|
||||
}
|
||||
@@ -488,7 +513,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
const doseId = `${intake.medicationId}-${intake.blisterIndex}-${dateOnlyMs}`;
|
||||
const isTaken = takenDoseIds.has(doseId);
|
||||
if (isTaken) {
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[IntakeReminder] User ${settings.userId}: Skipping "${intake.medName}" - dose ${doseId} already taken`
|
||||
);
|
||||
}
|
||||
@@ -497,7 +522,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
});
|
||||
|
||||
if (remindersToSend.length === 0) {
|
||||
logger.info(`[IntakeReminder] User ${settings.userId}: All doses taken, skipping reminders`);
|
||||
logger.debug(`[IntakeReminder] User ${settings.userId}: All doses taken, skipping reminders`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -551,7 +576,10 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
if (hasNaggingReminder && highestSendCount > 0) {
|
||||
// Nagging reminder - show counter
|
||||
const counterStr = `(${highestSendCount}/${maxReminderCount})`;
|
||||
title = language === "de" ? `⚠️ Medikamenten-Erinnerung ${counterStr}` : `⚠️ Medication Reminder ${counterStr}`;
|
||||
title =
|
||||
language === "de"
|
||||
? `⚠️ Erinnerung: Medikamenteneinnahme ${counterStr}`
|
||||
: `⚠️ Reminder: Medication intake ${counterStr}`;
|
||||
} else {
|
||||
// Advance reminder - no counter
|
||||
title = t(tr.push.intakeTitle, { minutes: REMINDER_MINUTES_BEFORE });
|
||||
@@ -590,7 +618,9 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
}
|
||||
return `• ${i.medName}${takenByStr}: ${dosage} @ ${i.intakeTimeStr}`;
|
||||
})
|
||||
.join("\n") + repeatNote;
|
||||
.join("\n") +
|
||||
repeatNote +
|
||||
`\n\n---\n${getFooterPlain(language)}`;
|
||||
|
||||
const result = await sendShoutrrrNotification(settings.shoutrrrUrl!, title, message);
|
||||
shoutrrrSuccess = result.success;
|
||||
@@ -668,10 +698,7 @@ async function checkAndSendIntakeRemindersForUser(
|
||||
|
||||
let intakeCheckInterval: NodeJS.Timeout | null = null;
|
||||
|
||||
export function startIntakeReminderScheduler(logger: {
|
||||
info: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
}): void {
|
||||
export function startIntakeReminderScheduler(logger: ServiceLogger): void {
|
||||
logger.info(`[IntakeReminder] Starting intake reminder scheduler (checks every minute)...`);
|
||||
|
||||
// Run immediately on start
|
||||
|
||||
@@ -5,9 +5,9 @@ import nodemailer from "nodemailer";
|
||||
import { db } from "../db/client.js";
|
||||
import { getDataDir } from "../db/db-utils.js";
|
||||
import { medications, userSettings } from "../db/schema.js";
|
||||
import { getTranslations, type Language, t } from "../i18n/translations.js";
|
||||
import { getFooterHtml, getFooterPlain, getTranslations, type Language, t } from "../i18n/translations.js";
|
||||
import { getAllUserSettings, sendShoutrrrNotification, type UserSettings } from "../routes/settings.js";
|
||||
|
||||
import type { ServiceLogger } from "../utils/logger.js";
|
||||
// Import shared utilities
|
||||
import {
|
||||
type Blister,
|
||||
@@ -24,6 +24,17 @@ import {
|
||||
type ReminderState,
|
||||
} from "../utils/scheduler-utils.js";
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
const htmlEscapes: Record<string, string> = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
};
|
||||
return text.replace(/[&<>"']/g, (char) => htmlEscapes[char] || char);
|
||||
}
|
||||
|
||||
const REMINDER_HOUR = parseInt(process.env.REMINDER_HOUR ?? "6", 10); // Default 6:00 AM local time
|
||||
|
||||
const reminderStateFile = resolve(getDataDir(), "reminder-state.json");
|
||||
@@ -48,7 +59,7 @@ export function getReminderState(): ReminderState {
|
||||
}
|
||||
|
||||
export function updateReminderSentTime(
|
||||
type: "stock" | "intake" = "stock",
|
||||
type: "stock" | "intake" | "prescription" = "stock",
|
||||
channel: "email" | "push" | "both" = "email"
|
||||
): void {
|
||||
const state = loadReminderState();
|
||||
@@ -63,24 +74,49 @@ export function updateReminderSentTime(
|
||||
}
|
||||
|
||||
// Update user settings in database when reminder is sent
|
||||
// Stock and intake reminders are tracked separately so neither overwrites the other
|
||||
export async function updateUserReminderSentTime(
|
||||
userId: number,
|
||||
type: "stock" | "intake" = "stock",
|
||||
type: "stock" | "intake" | "prescription" = "stock",
|
||||
channel: "email" | "push" | "both" = "email",
|
||||
medName?: string,
|
||||
takenBy?: string
|
||||
): Promise<void> {
|
||||
const now = new Date().toISOString();
|
||||
await db
|
||||
.update(userSettings)
|
||||
.set({
|
||||
lastAutoEmailSent: now,
|
||||
lastNotificationType: type,
|
||||
lastNotificationChannel: channel,
|
||||
lastReminderMedName: medName ?? null,
|
||||
lastReminderTakenBy: takenBy ?? null,
|
||||
})
|
||||
.where(eq(userSettings.userId, userId));
|
||||
if (type === "stock") {
|
||||
// Write to dedicated stock reminder columns only — do NOT touch the shared
|
||||
// lastNotificationType column, as that would block intake reminder display
|
||||
await db
|
||||
.update(userSettings)
|
||||
.set({
|
||||
lastStockReminderSent: now,
|
||||
lastStockReminderChannel: channel,
|
||||
lastStockReminderMedNames: medName ?? null,
|
||||
})
|
||||
.where(eq(userSettings.userId, userId));
|
||||
} else if (type === "prescription") {
|
||||
// Write to dedicated prescription reminder columns only
|
||||
await db
|
||||
.update(userSettings)
|
||||
.set({
|
||||
lastPrescriptionReminderSent: now,
|
||||
lastPrescriptionReminderChannel: channel,
|
||||
lastPrescriptionReminderMedNames: medName ?? null,
|
||||
})
|
||||
.where(eq(userSettings.userId, userId));
|
||||
} else {
|
||||
// Write to intake reminder columns
|
||||
await db
|
||||
.update(userSettings)
|
||||
.set({
|
||||
lastAutoEmailSent: now,
|
||||
lastNotificationType: type,
|
||||
lastNotificationChannel: channel,
|
||||
lastReminderMedName: medName ?? null,
|
||||
lastReminderTakenBy: takenBy ?? null,
|
||||
})
|
||||
.where(eq(userSettings.userId, userId));
|
||||
}
|
||||
}
|
||||
|
||||
function parseBlistersFromRow(row: { usageJson: string; everyJson: string; startJson: string }): Blister[] {
|
||||
@@ -92,11 +128,20 @@ type LowStockItem = {
|
||||
medsLeft: number;
|
||||
daysLeft: number | null;
|
||||
depletionDate: string | null;
|
||||
isCritical: boolean;
|
||||
};
|
||||
|
||||
type PrescriptionReminderItem = {
|
||||
name: string;
|
||||
remainingRefills: number;
|
||||
lowThreshold: number;
|
||||
expiryDate: string | null;
|
||||
};
|
||||
|
||||
async function getMedicationsNeedingReminder(
|
||||
userId: number,
|
||||
reminderDaysBefore: number,
|
||||
lowStockDays: number,
|
||||
language: Language
|
||||
): Promise<LowStockItem[]> {
|
||||
const rows = await db.select().from(medications).where(eq(medications.userId, userId)).orderBy(medications.id);
|
||||
@@ -106,16 +151,23 @@ async function getMedicationsNeedingReminder(
|
||||
for (const row of rows) {
|
||||
const blisters = parseBlistersFromRow(row);
|
||||
const totalPills =
|
||||
row.packCount * row.blistersPerPack * row.pillsPerBlister + row.looseTablets + (row.stockAdjustment ?? 0);
|
||||
(row.packageType ?? "blister") === "bottle"
|
||||
? row.looseTablets + (row.stockAdjustment ?? 0)
|
||||
: row.packCount * row.blistersPerPack * row.pillsPerBlister + row.looseTablets + (row.stockAdjustment ?? 0);
|
||||
const { daysLeft, depletionDate } = calculateDepletionInfo({ count: totalPills, blisters }, language);
|
||||
|
||||
// Check if medication runs out within reminderDaysBefore days
|
||||
if (daysLeft !== null && daysLeft <= reminderDaysBefore) {
|
||||
if (daysLeft === null) continue;
|
||||
|
||||
const isCritical = daysLeft <= reminderDaysBefore;
|
||||
const isLow = daysLeft < lowStockDays;
|
||||
|
||||
if (isCritical || isLow) {
|
||||
lowStock.push({
|
||||
name: row.name,
|
||||
medsLeft: totalPills,
|
||||
daysLeft,
|
||||
depletionDate,
|
||||
isCritical,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -123,6 +175,23 @@ async function getMedicationsNeedingReminder(
|
||||
return lowStock;
|
||||
}
|
||||
|
||||
async function getMedicationsNeedingPrescriptionReminder(userId: number): Promise<PrescriptionReminderItem[]> {
|
||||
const rows = await db.select().from(medications).where(eq(medications.userId, userId)).orderBy(medications.id);
|
||||
|
||||
return rows
|
||||
.filter(
|
||||
(row) =>
|
||||
(row.prescriptionEnabled ?? false) &&
|
||||
(row.prescriptionRemainingRefills ?? 0) <= (row.prescriptionLowRefillThreshold ?? 1)
|
||||
)
|
||||
.map((row) => ({
|
||||
name: row.name,
|
||||
remainingRefills: row.prescriptionRemainingRefills ?? 0,
|
||||
lowThreshold: row.prescriptionLowRefillThreshold ?? 1,
|
||||
expiryDate: row.prescriptionExpiryDate ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
async function sendReminderEmail(
|
||||
email: string,
|
||||
lowStock: LowStockItem[],
|
||||
@@ -141,35 +210,82 @@ async function sendReminderEmail(
|
||||
}
|
||||
|
||||
const tr = getTranslations(language);
|
||||
const tableRows = lowStock
|
||||
.map(
|
||||
(row) => `
|
||||
<tr>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${row.name}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;"><strong>${row.medsLeft}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${row.daysLeft ?? 0}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${row.depletionDate ?? "-"}</td>
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("");
|
||||
|
||||
const alertText =
|
||||
lowStock.length === 1
|
||||
? tr.stockReminder.alertSingle
|
||||
: t(tr.stockReminder.alertMultiple, { count: lowStock.length });
|
||||
// Separate into 3 categories: empty, critical, and low stock
|
||||
const emptyMeds = lowStock.filter((item) => item.medsLeft <= 0);
|
||||
const criticalMeds = lowStock.filter((item) => item.medsLeft > 0 && item.isCritical);
|
||||
const lowStockMeds = lowStock.filter((item) => item.medsLeft > 0 && !item.isCritical);
|
||||
|
||||
// Build per-category alert boxes
|
||||
const alertParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
const emptyAlert =
|
||||
emptyMeds.length === 1
|
||||
? tr.stockReminder.alertEmptySingle
|
||||
: t(tr.stockReminder.alertEmptyMultiple, { count: emptyMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fef2f2; border: 1px solid #dc2626;">
|
||||
<p style="margin: 0; color: #dc2626; font-weight: 600; font-size: 13px;">${emptyAlert}</p>
|
||||
</div>`);
|
||||
}
|
||||
if (criticalMeds.length > 0) {
|
||||
const criticalAlert =
|
||||
criticalMeds.length === 1
|
||||
? tr.stockReminder.alertLowSingle
|
||||
: t(tr.stockReminder.alertLowMultiple, { count: criticalMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fff7ed; border: 1px solid #ea580c;">
|
||||
<p style="margin: 0; color: #c2410c; font-weight: 600; font-size: 13px;">${criticalAlert}</p>
|
||||
</div>`);
|
||||
}
|
||||
if (lowStockMeds.length > 0) {
|
||||
const lowAlert =
|
||||
lowStockMeds.length === 1
|
||||
? tr.stockReminder.alertLowStockSingle
|
||||
: t(tr.stockReminder.alertLowStockMultiple, { count: lowStockMeds.length });
|
||||
alertParts.push(`
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #fffbeb; border: 1px solid #f59e0b;">
|
||||
<p style="margin: 0; color: #b45309; font-weight: 500; font-size: 13px;">${lowAlert}</p>
|
||||
</div>`);
|
||||
}
|
||||
const alertHtml = alertParts.join("");
|
||||
|
||||
// Build description text
|
||||
let descriptionText: string;
|
||||
if (emptyMeds.length > 0 && (criticalMeds.length > 0 || lowStockMeds.length > 0)) {
|
||||
descriptionText = tr.stockReminder.descriptionMixed;
|
||||
} else if (emptyMeds.length > 0) {
|
||||
descriptionText = tr.stockReminder.descriptionEmpty;
|
||||
} else if (criticalMeds.length > 0) {
|
||||
descriptionText = tr.stockReminder.description;
|
||||
} else {
|
||||
descriptionText = tr.stockReminder.descriptionLow;
|
||||
}
|
||||
|
||||
// Build table rows with status indicator
|
||||
const tableRows = lowStock
|
||||
.map((row) => {
|
||||
const isEmpty = row.medsLeft <= 0;
|
||||
const isCritical = row.isCritical;
|
||||
const statusIcon = isEmpty ? "🚨" : isCritical ? "🚨" : "⚠️";
|
||||
const rowBg = isEmpty ? "#fef2f2" : isCritical ? "#fff7ed" : "white";
|
||||
return `
|
||||
<tr style="background: ${rowBg};">
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${statusIcon} ${row.name}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap; ${isEmpty ? "color: #dc2626; font-weight: 600;" : ""}"><strong>${row.medsLeft}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${row.daysLeft ?? 0}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${isEmpty ? `<strong>${tr.stockReminder.now ?? "-"}</strong>` : (row.depletionDate ?? "-")}</td>
|
||||
</tr>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
const html = `
|
||||
<div style="font-family: system-ui, -apple-system, sans-serif; max-width: 100%; margin: 0 auto; padding: 12px; background: #f9fafb;">
|
||||
<div style="background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${tr.stockReminder.title}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${tr.stockReminder.description}</p>
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${emptyMeds.length > 0 ? "🚨" : "⚠️"} MedAssist-ng - ${tr.push.reorderNow}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${descriptionText}</p>
|
||||
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #fef2f2; border: 1px solid #fecaca;">
|
||||
<p style="margin: 0; color: #991b1b; font-weight: 500; font-size: 13px;">
|
||||
${alertText}
|
||||
</p>
|
||||
</div>
|
||||
${alertHtml}
|
||||
|
||||
<div style="overflow-x: auto; -webkit-overflow-scrolling: touch;">
|
||||
<table style="width: 100%; border-collapse: collapse; background: white; min-width: 400px;">
|
||||
@@ -189,7 +305,7 @@ async function sendReminderEmail(
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">
|
||||
${tr.stockReminder.footer}
|
||||
${getFooterHtml(language)}
|
||||
</p>
|
||||
${isRepeatDaily ? `<p style="color: #9ca3af; font-size: 11px; margin: 8px 0 0 0; font-style: italic;">${tr.stockReminder.repeatDailyNote}</p>` : ""}
|
||||
</div>
|
||||
@@ -203,7 +319,7 @@ ${tr.stockReminder.description}
|
||||
${lowStock.map((r) => `${r.name}: ${r.medsLeft} ${tr.common.pills}, ${r.daysLeft ?? 0} ${tr.common.days}, ${tr.stockReminder.tableHeaders.runsOut}: ${r.depletionDate ?? tr.common.soon}`).join("\n")}
|
||||
|
||||
---
|
||||
${tr.stockReminder.footer}${isRepeatDaily ? `\n\n${tr.stockReminder.repeatDailyNote}` : ""}`;
|
||||
${getFooterPlain(language)}${isRepeatDaily ? `\n\n${tr.stockReminder.repeatDailyNote}` : ""}`;
|
||||
|
||||
const subjectPlural = lowStock.length === 1 ? "" : language === "de" ? "e" : "s";
|
||||
const subject = t(tr.stockReminder.subject, { count: lowStock.length, s: subjectPlural, e: subjectPlural });
|
||||
@@ -222,7 +338,7 @@ ${tr.stockReminder.footer}${isRepeatDaily ? `\n\n${tr.stockReminder.repeatDailyN
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: email,
|
||||
subject: `⚠️ ${subject}`,
|
||||
subject,
|
||||
text: plainText,
|
||||
html,
|
||||
});
|
||||
@@ -234,15 +350,12 @@ ${tr.stockReminder.footer}${isRepeatDaily ? `\n\n${tr.stockReminder.repeatDailyN
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAndSendReminder(logger: {
|
||||
info: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
}): Promise<void> {
|
||||
async function checkAndSendReminder(logger: ServiceLogger): Promise<void> {
|
||||
// Get all user settings to iterate over each user
|
||||
const allUserSettings = await getAllUserSettings();
|
||||
|
||||
if (allUserSettings.length === 0) {
|
||||
logger.info("[Reminder] No users with settings found");
|
||||
logger.debug("[Reminder] No users with settings found");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,129 +366,312 @@ async function checkAndSendReminder(logger: {
|
||||
|
||||
async function checkAndSendReminderForUser(
|
||||
settings: UserSettings & { userId: number },
|
||||
logger: { info: (msg: string) => void; error: (msg: string) => void }
|
||||
logger: ServiceLogger
|
||||
): Promise<void> {
|
||||
const language = settings.language;
|
||||
const tr = getTranslations(language);
|
||||
|
||||
// Check if any stock reminder notifications are enabled (granular check)
|
||||
const emailEnabled = settings.emailEnabled && settings.notificationEmail && settings.emailStockReminders;
|
||||
const shoutrrrEnabled = settings.shoutrrrEnabled && settings.shoutrrrUrl && settings.shoutrrrStockReminders;
|
||||
const stockEmailEnabled = settings.emailEnabled && settings.notificationEmail && settings.emailStockReminders;
|
||||
const stockPushEnabled = settings.shoutrrrEnabled && settings.shoutrrrUrl && settings.shoutrrrStockReminders;
|
||||
const prescriptionEmailEnabled =
|
||||
settings.emailEnabled && settings.notificationEmail && settings.emailPrescriptionReminders;
|
||||
const prescriptionPushEnabled =
|
||||
settings.shoutrrrEnabled && settings.shoutrrrUrl && settings.shoutrrrPrescriptionReminders;
|
||||
|
||||
if (!emailEnabled && !shoutrrrEnabled) {
|
||||
return; // No stock reminder notifications enabled for this user
|
||||
if (!stockEmailEnabled && !stockPushEnabled && !prescriptionEmailEnabled && !prescriptionPushEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const state = loadReminderState();
|
||||
const today = getTodayInTimezone(); // YYYY-MM-DD in configured timezone
|
||||
const userStateKey = `user_${settings.userId}`;
|
||||
const userStockNotifiedKey = `${userStateKey}_${today}_stock`;
|
||||
const userPrescriptionNotifiedKey = `${userStateKey}_${today}_prescription`;
|
||||
|
||||
// Get all medications that need a reminder for this user
|
||||
const allLowStock = await getMedicationsNeedingReminder(settings.userId, settings.reminderDaysBefore, language);
|
||||
const allLowStock = await getMedicationsNeedingReminder(
|
||||
settings.userId,
|
||||
settings.reminderDaysBefore,
|
||||
settings.lowStockDays,
|
||||
language
|
||||
);
|
||||
const allPrescriptionLow = await getMedicationsNeedingPrescriptionReminder(settings.userId);
|
||||
|
||||
if (allLowStock.length === 0) {
|
||||
return; // No low stock for this user
|
||||
}
|
||||
|
||||
// Simple per-user tracking - check if we already sent today
|
||||
const userNotifiedKey = `${userStateKey}_${today}`;
|
||||
if (state.notifiedMedications.includes(userNotifiedKey) && !settings.repeatDailyReminders) {
|
||||
return; // Already notified this user today
|
||||
}
|
||||
|
||||
logger.info(`[Reminder] User ${settings.userId}: Sending reminder for ${allLowStock.length} medications...`);
|
||||
|
||||
let emailSuccess = false;
|
||||
let shoutrrrSuccess = false;
|
||||
|
||||
// Send email if enabled
|
||||
if (emailEnabled) {
|
||||
const result = await sendReminderEmail(
|
||||
settings.notificationEmail!,
|
||||
allLowStock,
|
||||
language,
|
||||
settings.repeatDailyReminders
|
||||
);
|
||||
emailSuccess = result.success;
|
||||
if (result.success) {
|
||||
logger.info(`[Reminder] User ${settings.userId}: Email sent successfully to ${settings.notificationEmail}`);
|
||||
} else {
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send email: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Send Shoutrrr notification if enabled
|
||||
if (shoutrrrEnabled) {
|
||||
// Separate empty from low stock medications
|
||||
const emptyMeds = allLowStock.filter((m) => m.medsLeft <= 0);
|
||||
const lowMeds = allLowStock.filter((m) => m.medsLeft > 0);
|
||||
|
||||
// Build clear title
|
||||
const titleParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
titleParts.push(`🚨 ${emptyMeds.length} ${tr.push.empty || "Empty"}`);
|
||||
}
|
||||
if (lowMeds.length > 0) {
|
||||
titleParts.push(`⚠️ ${lowMeds.length} ${tr.push.low || "Low"}`);
|
||||
}
|
||||
const title = `MedAssist: ${titleParts.join(", ")} - ${tr.push.reorderNow || "Reorder Now!"}`;
|
||||
|
||||
// Build clear message with sections
|
||||
const messageParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.push.emptySection || "EMPTY (reorder immediately)"}:`);
|
||||
emptyMeds.forEach((m) => messageParts.push(` • ${m.name}`));
|
||||
}
|
||||
if (lowMeds.length > 0) {
|
||||
if (emptyMeds.length > 0) messageParts.push("");
|
||||
messageParts.push(`⚠️ ${tr.push.lowSection || "RUNNING LOW (reorder soon)"}:`);
|
||||
lowMeds.forEach((m) =>
|
||||
messageParts.push(
|
||||
` • ${m.name}: ${t(tr.push.pillsLeft, { count: m.medsLeft })}, ${t(tr.push.daysLeft, { count: m.daysLeft ?? 0 })}`
|
||||
)
|
||||
if (allLowStock.length > 0 && (stockEmailEnabled || stockPushEnabled)) {
|
||||
if (!state.notifiedMedications.includes(userStockNotifiedKey) || settings.repeatDailyReminders) {
|
||||
logger.info(
|
||||
`[Reminder] User ${settings.userId}: Sending stock reminder for ${allLowStock.length} medications...`
|
||||
);
|
||||
}
|
||||
|
||||
if (settings.repeatDailyReminders) {
|
||||
messageParts.push("");
|
||||
messageParts.push(tr.push.repeatDailyNote);
|
||||
}
|
||||
let emailSuccess = false;
|
||||
let shoutrrrSuccess = false;
|
||||
|
||||
const message = messageParts.join("\n");
|
||||
if (stockEmailEnabled) {
|
||||
const result = await sendReminderEmail(
|
||||
settings.notificationEmail!,
|
||||
allLowStock,
|
||||
language,
|
||||
settings.repeatDailyReminders
|
||||
);
|
||||
emailSuccess = result.success;
|
||||
if (!result.success) {
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send stock email: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await sendShoutrrrNotification(settings.shoutrrrUrl!, title, message);
|
||||
shoutrrrSuccess = result.success;
|
||||
if (result.success) {
|
||||
logger.info(`[Reminder] User ${settings.userId}: Push notification sent successfully`);
|
||||
} else {
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send push notification: ${result.error}`);
|
||||
if (stockPushEnabled) {
|
||||
const emptyMeds = allLowStock.filter((m) => m.medsLeft <= 0);
|
||||
const criticalMeds = allLowStock.filter((m) => m.medsLeft > 0 && m.isCritical);
|
||||
const lowStockMeds = allLowStock.filter((m) => m.medsLeft > 0 && !m.isCritical);
|
||||
|
||||
const titleParts: string[] = [];
|
||||
if (emptyMeds.length > 0) titleParts.push(`🚨 ${emptyMeds.length} ${tr.push.empty}`);
|
||||
if (criticalMeds.length > 0) titleParts.push(`🚨 ${criticalMeds.length} ${tr.push.critical}`);
|
||||
if (lowStockMeds.length > 0) titleParts.push(`⚠️ ${lowStockMeds.length} ${tr.push.lowStock}`);
|
||||
const title = `MedAssist-ng: ${titleParts.join(", ")} - ${tr.push.reorderNow}`;
|
||||
|
||||
const messageParts: string[] = [];
|
||||
if (emptyMeds.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.push.emptySection}:`);
|
||||
emptyMeds.forEach((m) => messageParts.push(` • ${m.name}`));
|
||||
}
|
||||
if (criticalMeds.length > 0) {
|
||||
if (messageParts.length > 0) messageParts.push("");
|
||||
messageParts.push(`🚨 ${tr.push.criticalSection}:`);
|
||||
criticalMeds.forEach((m) =>
|
||||
messageParts.push(
|
||||
` • ${m.name}: ${t(tr.push.pillsLeft, { count: m.medsLeft })}, ${t(tr.push.daysLeft, { count: m.daysLeft ?? 0 })}`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (lowStockMeds.length > 0) {
|
||||
if (messageParts.length > 0) messageParts.push("");
|
||||
messageParts.push(`⚠️ ${tr.push.lowStockSection}:`);
|
||||
lowStockMeds.forEach((m) =>
|
||||
messageParts.push(
|
||||
` • ${m.name}: ${t(tr.push.pillsLeft, { count: m.medsLeft })}, ${t(tr.push.daysLeft, { count: m.daysLeft ?? 0 })}`
|
||||
)
|
||||
);
|
||||
}
|
||||
const message = messageParts.join("\n") + `\n\n---\n${getFooterPlain(language)}`;
|
||||
const result = await sendShoutrrrNotification(settings.shoutrrrUrl!, title, message);
|
||||
shoutrrrSuccess = result.success;
|
||||
if (!result.success) {
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send stock push: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (emailSuccess || shoutrrrSuccess) {
|
||||
const currentState = loadReminderState();
|
||||
const channel = emailSuccess && shoutrrrSuccess ? "both" : emailSuccess ? "email" : "push";
|
||||
saveReminderState({
|
||||
lastAutoEmailSent: new Date().toISOString(),
|
||||
lastAutoEmailDate: today,
|
||||
notifiedMedications: [...new Set([...currentState.notifiedMedications, userStockNotifiedKey])],
|
||||
nextScheduledCheck: currentState.nextScheduledCheck,
|
||||
lastNotificationType: "stock",
|
||||
lastNotificationChannel: channel,
|
||||
});
|
||||
|
||||
const firstMed = allLowStock[0];
|
||||
const medNames = allLowStock.map((m) => m.name).join(", ");
|
||||
await updateUserReminderSentTime(settings.userId, "stock", channel, medNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update state if any notification was sent successfully
|
||||
if (emailSuccess || shoutrrrSuccess) {
|
||||
const currentState = loadReminderState();
|
||||
const channel = emailSuccess && shoutrrrSuccess ? "both" : emailSuccess ? "email" : "push";
|
||||
saveReminderState({
|
||||
lastAutoEmailSent: new Date().toISOString(),
|
||||
lastAutoEmailDate: today,
|
||||
notifiedMedications: [...new Set([...currentState.notifiedMedications, userNotifiedKey])],
|
||||
nextScheduledCheck: currentState.nextScheduledCheck,
|
||||
lastNotificationType: "stock",
|
||||
lastNotificationChannel: channel,
|
||||
});
|
||||
if (allPrescriptionLow.length > 0 && (prescriptionEmailEnabled || prescriptionPushEnabled)) {
|
||||
if (!state.notifiedMedications.includes(userPrescriptionNotifiedKey) || settings.repeatDailyReminders) {
|
||||
logger.info(
|
||||
`[Reminder] User ${settings.userId}: Sending prescription reminder for ${allPrescriptionLow.length} medications...`
|
||||
);
|
||||
|
||||
// Also update user settings in database so frontend can display the info
|
||||
// For stock reminders, show the first medication name
|
||||
const firstMed = allLowStock[0];
|
||||
const medNames = allLowStock.length > 1 ? `${firstMed.name} (+${allLowStock.length - 1})` : firstMed?.name;
|
||||
await updateUserReminderSentTime(settings.userId, "stock", channel, medNames);
|
||||
const emptyRx = allPrescriptionLow.filter((m) => m.remainingRefills <= 0);
|
||||
const lowRx = allPrescriptionLow.filter((m) => m.remainingRefills > 0);
|
||||
const lines = allPrescriptionLow.map((m) => {
|
||||
const expirySuffix = m.expiryDate ? t(tr.prescriptionReminder.expiresSuffix, { date: m.expiryDate }) : "";
|
||||
if (m.remainingRefills <= 0) {
|
||||
return `- ${t(tr.prescriptionReminder.lineEmpty, {
|
||||
name: m.name,
|
||||
expirySuffix,
|
||||
})}`;
|
||||
}
|
||||
return `- ${t(tr.prescriptionReminder.line, {
|
||||
name: m.name,
|
||||
refills: m.remainingRefills,
|
||||
expirySuffix,
|
||||
})}`;
|
||||
});
|
||||
|
||||
let emailSuccess = false;
|
||||
let shoutrrrSuccess = false;
|
||||
|
||||
if (prescriptionEmailEnabled) {
|
||||
const smtpHost = process.env.SMTP_HOST;
|
||||
const smtpUser = process.env.SMTP_USER;
|
||||
const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS;
|
||||
const smtpPort = parseInt(process.env.SMTP_PORT ?? "587", 10);
|
||||
const smtpSecure = process.env.SMTP_SECURE === "true";
|
||||
const smtpFrom = process.env.SMTP_FROM ?? smtpUser;
|
||||
|
||||
if (smtpHost && smtpUser) {
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: smtpHost,
|
||||
port: smtpPort,
|
||||
secure: smtpSecure,
|
||||
auth: { user: smtpUser, pass: smtpPass ?? "" },
|
||||
});
|
||||
|
||||
const subject =
|
||||
allPrescriptionLow.length === 1
|
||||
? tr.prescriptionReminder.subjectSingle
|
||||
: t(tr.prescriptionReminder.subjectMultiple, { count: allPrescriptionLow.length });
|
||||
|
||||
const bodyText =
|
||||
emptyRx.length > 0 ? tr.prescriptionReminder.descriptionEmpty : tr.prescriptionReminder.descriptionLow;
|
||||
const alertText =
|
||||
emptyRx.length > 0
|
||||
? emptyRx.length === 1
|
||||
? tr.prescriptionReminder.alertEmptySingle
|
||||
: t(tr.prescriptionReminder.alertEmptyMultiple, { count: emptyRx.length })
|
||||
: lowRx.length === 1
|
||||
? tr.prescriptionReminder.alertLowSingle
|
||||
: t(tr.prescriptionReminder.alertLowMultiple, { count: lowRx.length });
|
||||
|
||||
const tableRows = allPrescriptionLow
|
||||
.map((item) => {
|
||||
const isEmpty = item.remainingRefills <= 0;
|
||||
const safeName = escapeHtml(item.name);
|
||||
const safeRefills = Number(item.remainingRefills) || 0;
|
||||
const safeThreshold = Number(item.lowThreshold) || 0;
|
||||
const safeExpiry = item.expiryDate ? escapeHtml(String(item.expiryDate)) : "-";
|
||||
const rowBg = isEmpty ? "#fef2f2" : "white";
|
||||
return `
|
||||
<tr style="background: ${rowBg};">
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap;">${isEmpty ? "🚨" : "⚠️"} ${safeName}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap; ${isEmpty ? "color: #dc2626; font-weight: 600;" : ""}"><strong>${safeRefills}</strong></td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeThreshold}</td>
|
||||
<td style="padding: 10px 12px; border-bottom: 1px solid #e5e7eb; text-align: center; white-space: nowrap;">${safeExpiry}</td>
|
||||
</tr>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
const html = `
|
||||
<div style="font-family: system-ui, -apple-system, sans-serif; max-width: 100%; margin: 0 auto; padding: 12px; background: #f9fafb;">
|
||||
<div style="background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
||||
<h2 style="color: #1f2937; margin: 0 0 8px; font-size: 18px;">${emptyRx.length > 0 ? tr.prescriptionReminder.titleEmpty : tr.prescriptionReminder.title}</h2>
|
||||
<p style="color: #6b7280; margin: 0 0 16px; font-size: 13px;">${bodyText}</p>
|
||||
|
||||
<div style="padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; ${
|
||||
emptyRx.length > 0
|
||||
? "background: #fef2f2; border: 1px solid #dc2626;"
|
||||
: "background: #fffbeb; border: 1px solid #f59e0b;"
|
||||
}">
|
||||
<p style="margin: 0; ${emptyRx.length > 0 ? "color: #dc2626; font-weight: 600;" : "color: #b45309; font-weight: 500;"} font-size: 13px;">
|
||||
${alertText}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style="overflow-x: auto; -webkit-overflow-scrolling: touch;">
|
||||
<table style="width: 100%; border-collapse: collapse; background: white; min-width: 460px;">
|
||||
<thead>
|
||||
<tr style="background: #f3f4f6;">
|
||||
<th style="padding: 10px 12px; text-align: left; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.medication}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.refillsLeft}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.reminderThreshold}</th>
|
||||
<th style="padding: 10px 12px; text-align: center; font-size: 11px; text-transform: uppercase; color: #6b7280; white-space: nowrap;">${tr.prescriptionReminder.tableHeaders.prescriptionExpires}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${tableRows}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 16px 0;" />
|
||||
<p style="color: #9ca3af; font-size: 11px; margin: 0;">
|
||||
${getFooterHtml(language)}
|
||||
</p>
|
||||
${settings.repeatDailyReminders ? `<p style="color: #9ca3af; font-size: 11px; margin: 8px 0 0 0; font-style: italic;">${tr.prescriptionReminder.repeatDailyNote}</p>` : ""}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
const text = `${emptyRx.length > 0 ? tr.prescriptionReminder.titleEmpty : tr.prescriptionReminder.title}\n\n${bodyText}\n\n${lines.join("\n")}\n\n---\n${getFooterPlain(language)}${settings.repeatDailyReminders ? `\n\n${tr.prescriptionReminder.repeatDailyNote}` : ""}`;
|
||||
|
||||
await transporter.sendMail({
|
||||
from: smtpFrom,
|
||||
to: settings.notificationEmail!,
|
||||
subject,
|
||||
text,
|
||||
html,
|
||||
});
|
||||
emailSuccess = true;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send prescription email: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prescriptionPushEnabled) {
|
||||
const titleParts: string[] = [];
|
||||
if (emptyRx.length > 0)
|
||||
titleParts.push(
|
||||
`🚨 ${emptyRx.length} ${emptyRx.length === 1 ? tr.prescriptionReminder.pushEmptySingle : tr.prescriptionReminder.pushEmpty}`
|
||||
);
|
||||
if (lowRx.length > 0)
|
||||
titleParts.push(
|
||||
`🚨 ${lowRx.length} ${lowRx.length === 1 ? tr.prescriptionReminder.pushLowSingle : tr.prescriptionReminder.pushLow}`
|
||||
);
|
||||
const title = `MedAssist-ng: ${titleParts.join(", ")} - ${tr.prescriptionReminder.pushRenewNow}`;
|
||||
|
||||
const messageParts: string[] = [];
|
||||
if (emptyRx.length > 0) {
|
||||
messageParts.push(`🚨 ${tr.prescriptionReminder.pushEmptySection}:`);
|
||||
for (const m of emptyRx) {
|
||||
messageParts.push(` • ${m.name}`);
|
||||
}
|
||||
}
|
||||
if (lowRx.length > 0) {
|
||||
if (emptyRx.length > 0) messageParts.push("");
|
||||
messageParts.push(`🚨 ${tr.prescriptionReminder.pushLowSection}:`);
|
||||
for (const m of lowRx) {
|
||||
messageParts.push(
|
||||
` • ${m.name}: ${t(tr.prescriptionReminder.pushRefillsLeft, { count: m.remainingRefills })}`
|
||||
);
|
||||
}
|
||||
}
|
||||
const message = messageParts.join("\n") + `\n\n---\n${getFooterPlain(language)}`;
|
||||
const result = await sendShoutrrrNotification(settings.shoutrrrUrl!, title, message);
|
||||
shoutrrrSuccess = result.success;
|
||||
if (!result.success) {
|
||||
logger.error(`[Reminder] User ${settings.userId}: Failed to send prescription push: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (emailSuccess || shoutrrrSuccess) {
|
||||
const currentState = loadReminderState();
|
||||
const channel = emailSuccess && shoutrrrSuccess ? "both" : emailSuccess ? "email" : "push";
|
||||
saveReminderState({
|
||||
lastAutoEmailSent: new Date().toISOString(),
|
||||
lastAutoEmailDate: today,
|
||||
notifiedMedications: [...new Set([...currentState.notifiedMedications, userPrescriptionNotifiedKey])],
|
||||
nextScheduledCheck: currentState.nextScheduledCheck,
|
||||
lastNotificationType: "prescription",
|
||||
lastNotificationChannel: channel,
|
||||
});
|
||||
|
||||
const firstMed = allPrescriptionLow[0];
|
||||
const medNames = allPrescriptionLow.map((m) => m.name).join(", ");
|
||||
await updateUserReminderSentTime(settings.userId, "prescription", channel, medNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let schedulerTimeout: NodeJS.Timeout | null = null;
|
||||
|
||||
function scheduleNextCheck(logger: { info: (msg: string) => void; error: (msg: string) => void }): void {
|
||||
function scheduleNextCheck(logger: ServiceLogger): void {
|
||||
const msUntilNext = getMsUntilNextCheck(REMINDER_HOUR);
|
||||
const nextTime = getNextScheduledTime(REMINDER_HOUR);
|
||||
|
||||
@@ -386,7 +682,7 @@ function scheduleNextCheck(logger: { info: (msg: string) => void; error: (msg: s
|
||||
nextScheduledCheck: nextTime.toISOString(),
|
||||
});
|
||||
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`[Reminder] Next check scheduled for ${formatInTimezone(nextTime)} (${getTimezone()}) (in ${Math.round(msUntilNext / 1000 / 60)} minutes)`
|
||||
);
|
||||
|
||||
@@ -397,7 +693,7 @@ function scheduleNextCheck(logger: { info: (msg: string) => void; error: (msg: s
|
||||
}, msUntilNext);
|
||||
}
|
||||
|
||||
export function startReminderScheduler(logger: { info: (msg: string) => void; error: (msg: string) => void }): void {
|
||||
export function startReminderScheduler(logger: ServiceLogger): void {
|
||||
logger.info(`[Reminder] Starting reminder scheduler (timezone: ${getTimezone()})...`);
|
||||
|
||||
// Check if we need to run immediately (missed today's check)
|
||||
|
||||
@@ -194,6 +194,29 @@ describe("Auth Routes (AUTH_ENABLED=true)", () => {
|
||||
expect(response.json().code).toBe("USERNAME_EXISTS");
|
||||
});
|
||||
|
||||
it("should reject duplicate username regardless of case", async () => {
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/auth/register",
|
||||
payload: {
|
||||
username: "CaseUser",
|
||||
password: "TestPassword123",
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/auth/register",
|
||||
payload: {
|
||||
username: "caseuser",
|
||||
password: "AnotherPassword123",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response.json().code).toBe("USERNAME_EXISTS");
|
||||
});
|
||||
|
||||
it("should reject short password", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
@@ -275,6 +298,21 @@ describe("Auth Routes (AUTH_ENABLED=true)", () => {
|
||||
expect(cookies.find((c: any) => c.name === "refresh_token")).toBeDefined();
|
||||
});
|
||||
|
||||
it("should login case-insensitively with different username casing", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/auth/login",
|
||||
payload: {
|
||||
username: "LOGINUSER",
|
||||
password: "TestPassword123",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().ok).toBe(true);
|
||||
expect(response.json().user.username).toBe("loginuser");
|
||||
});
|
||||
|
||||
it("should reject invalid password", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
|
||||
@@ -99,6 +99,11 @@ async function createSchema(client: Client) {
|
||||
expiry_date text,
|
||||
notes text,
|
||||
intake_reminders_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_authorized_refills integer,
|
||||
prescription_remaining_refills integer,
|
||||
prescription_low_refill_threshold integer NOT NULL DEFAULT 1,
|
||||
prescription_expiry_date text,
|
||||
dismissed_until text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
@@ -110,10 +115,12 @@ async function createSchema(client: Client) {
|
||||
notification_email text,
|
||||
email_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
email_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
email_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_enabled integer NOT NULL DEFAULT 0,
|
||||
shoutrrr_url text,
|
||||
shoutrrr_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
reminder_days_before integer NOT NULL DEFAULT 7,
|
||||
repeat_daily_reminders integer NOT NULL DEFAULT 0,
|
||||
skip_reminders_for_taken_doses integer NOT NULL DEFAULT 0,
|
||||
@@ -126,11 +133,18 @@ async function createSchema(client: Client) {
|
||||
expiry_warning_days integer NOT NULL DEFAULT 90,
|
||||
language text NOT NULL DEFAULT 'en',
|
||||
stock_calculation_mode text NOT NULL DEFAULT 'automatic',
|
||||
share_stock_status integer NOT NULL DEFAULT 1,
|
||||
last_auto_email_sent text,
|
||||
last_notification_type text,
|
||||
last_notification_channel text,
|
||||
last_reminder_med_name text,
|
||||
last_reminder_taken_by text,
|
||||
last_stock_reminder_sent text,
|
||||
last_stock_reminder_channel text,
|
||||
last_stock_reminder_med_names text,
|
||||
last_prescription_reminder_sent text,
|
||||
last_prescription_reminder_channel text,
|
||||
last_prescription_reminder_med_names text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)`,
|
||||
@@ -159,6 +173,7 @@ async function createSchema(client: Client) {
|
||||
user_id integer NOT NULL,
|
||||
packs_added integer NOT NULL DEFAULT 0,
|
||||
loose_pills_added integer NOT NULL DEFAULT 0,
|
||||
used_prescription integer NOT NULL DEFAULT 0,
|
||||
refill_date integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (medication_id) REFERENCES medications(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
@@ -1617,6 +1632,83 @@ describe("E2E Tests with Real Routes", () => {
|
||||
expect(data.newStock.looseTablets).toBe(15); // 5 + 10
|
||||
});
|
||||
|
||||
it("should decrement remaining refills and mark history when using prescription refill", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: {
|
||||
name: "Prescription Refill Med",
|
||||
packCount: 1,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 0,
|
||||
prescriptionEnabled: true,
|
||||
prescriptionAuthorizedRefills: 3,
|
||||
prescriptionRemainingRefills: 2,
|
||||
prescriptionLowRefillThreshold: 1,
|
||||
blisters: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
},
|
||||
});
|
||||
expect(createResponse.statusCode).toBe(200);
|
||||
const medId = createResponse.json().id;
|
||||
|
||||
const refillResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: `/medications/${medId}/refill`,
|
||||
payload: { packsAdded: 1, loosePillsAdded: 0, usePrescription: true },
|
||||
});
|
||||
|
||||
expect(refillResponse.statusCode).toBe(200);
|
||||
const refillData = refillResponse.json();
|
||||
expect(refillData.prescription.used).toBe(true);
|
||||
expect(refillData.prescription.remainingRefills).toBe(1);
|
||||
|
||||
const medsResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: "/medications",
|
||||
});
|
||||
expect(medsResponse.statusCode).toBe(200);
|
||||
const med = medsResponse.json().find((m: any) => m.id === medId);
|
||||
expect(med.prescriptionRemainingRefills).toBe(1);
|
||||
|
||||
const historyResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/medications/${medId}/refills`,
|
||||
});
|
||||
expect(historyResponse.statusCode).toBe(200);
|
||||
expect(historyResponse.json()[0].usedPrescription).toBe(true);
|
||||
});
|
||||
|
||||
it("should reject prescription refill when no remaining prescription refills are available", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: {
|
||||
name: "Prescription Empty Med",
|
||||
packCount: 1,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 0,
|
||||
prescriptionEnabled: true,
|
||||
prescriptionAuthorizedRefills: 2,
|
||||
prescriptionRemainingRefills: 0,
|
||||
prescriptionLowRefillThreshold: 1,
|
||||
blisters: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
},
|
||||
});
|
||||
expect(createResponse.statusCode).toBe(200);
|
||||
const medId = createResponse.json().id;
|
||||
|
||||
const refillResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: `/medications/${medId}/refill`,
|
||||
payload: { packsAdded: 1, loosePillsAdded: 0, usePrescription: true },
|
||||
});
|
||||
|
||||
expect(refillResponse.statusCode).toBe(409);
|
||||
expect(refillResponse.json().error).toContain("No remaining prescription refills");
|
||||
});
|
||||
|
||||
it("should return 400 when no packs or pills added", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
@@ -2214,4 +2306,250 @@ describe("E2E Tests with Real Routes", () => {
|
||||
expect(medsResponse.json()[0].packCount).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Package Type (bottle vs blister) Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe("Package type handling (bottle vs blister)", () => {
|
||||
const bottleMedication = {
|
||||
name: "Vitamin D Drops",
|
||||
packageType: "bottle",
|
||||
packCount: 0,
|
||||
blistersPerPack: 1,
|
||||
pillsPerBlister: 1,
|
||||
looseTablets: 120,
|
||||
blisters: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
};
|
||||
|
||||
const blisterMedication = {
|
||||
name: "Aspirin Blister",
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 5,
|
||||
blisters: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
};
|
||||
|
||||
it("should create and return bottle type medication", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: bottleMedication,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const data = response.json();
|
||||
expect(data.packageType).toBe("bottle");
|
||||
expect(data.looseTablets).toBe(120);
|
||||
});
|
||||
|
||||
it("should return packageType in shared schedule for bottle type", async () => {
|
||||
// Create bottle medication with takenBy
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: { ...bottleMedication, takenBy: ["Daniel"] },
|
||||
});
|
||||
|
||||
// Create share token
|
||||
const shareResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/share",
|
||||
payload: { takenBy: "Daniel", scheduleDays: 30 },
|
||||
});
|
||||
expect(shareResponse.statusCode).toBe(200);
|
||||
const { token } = shareResponse.json();
|
||||
|
||||
// Get shared schedule
|
||||
const scheduleResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/share/${token}`,
|
||||
});
|
||||
|
||||
expect(scheduleResponse.statusCode).toBe(200);
|
||||
const data = scheduleResponse.json();
|
||||
expect(data.medications).toHaveLength(1);
|
||||
expect(data.medications[0].packageType).toBe("bottle");
|
||||
// Bottle totalPills = looseTablets + stockAdjustment (no blister math)
|
||||
expect(data.medications[0].totalPills).toBe(120);
|
||||
});
|
||||
|
||||
it("should calculate correct totalPills for shared blister medication", async () => {
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: { ...blisterMedication, takenBy: ["Daniel"] },
|
||||
});
|
||||
|
||||
const shareResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/share",
|
||||
payload: { takenBy: "Daniel", scheduleDays: 30 },
|
||||
});
|
||||
const { token } = shareResponse.json();
|
||||
|
||||
const scheduleResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/share/${token}`,
|
||||
});
|
||||
|
||||
expect(scheduleResponse.statusCode).toBe(200);
|
||||
const data = scheduleResponse.json();
|
||||
expect(data.medications).toHaveLength(1);
|
||||
expect(data.medications[0].packageType).toBe("blister");
|
||||
// Blister totalPills = 2 * 3 * 10 + 5 = 65
|
||||
expect(data.medications[0].totalPills).toBe(65);
|
||||
});
|
||||
|
||||
it("should calculate correct refill totalPillsAdded for bottle type", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: bottleMedication,
|
||||
});
|
||||
const medId = createResponse.json().id;
|
||||
|
||||
// Refill bottle: only loosePillsAdded matters, packs should add 0 pills
|
||||
const refillResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: `/medications/${medId}/refill`,
|
||||
payload: { packsAdded: 0, loosePillsAdded: 30 },
|
||||
});
|
||||
|
||||
expect(refillResponse.statusCode).toBe(200);
|
||||
const data = refillResponse.json();
|
||||
expect(data.refill.totalPillsAdded).toBe(30);
|
||||
// newStock.totalPills should be looseTablets only (no blister math)
|
||||
expect(data.newStock.totalPills).toBe(150); // 120 + 30
|
||||
});
|
||||
|
||||
it("should calculate correct refill totalPillsAdded for blister type", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: blisterMedication,
|
||||
});
|
||||
const medId = createResponse.json().id;
|
||||
|
||||
// Refill blister: 1 pack = 3 blisters * 10 pills = 30 pills + 5 loose
|
||||
const refillResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: `/medications/${medId}/refill`,
|
||||
payload: { packsAdded: 1, loosePillsAdded: 5 },
|
||||
});
|
||||
|
||||
expect(refillResponse.statusCode).toBe(200);
|
||||
const data = refillResponse.json();
|
||||
expect(data.refill.totalPillsAdded).toBe(35); // 1*30 + 5
|
||||
});
|
||||
|
||||
it("should return correct totalPillsAdded in refill history for bottle type", async () => {
|
||||
const createResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: bottleMedication,
|
||||
});
|
||||
const medId = createResponse.json().id;
|
||||
|
||||
// Add refill
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: `/medications/${medId}/refill`,
|
||||
payload: { packsAdded: 0, loosePillsAdded: 25 },
|
||||
});
|
||||
|
||||
// Get refill history
|
||||
const historyResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/medications/${medId}/refills`,
|
||||
});
|
||||
|
||||
expect(historyResponse.statusCode).toBe(200);
|
||||
const refills = historyResponse.json();
|
||||
expect(refills).toHaveLength(1);
|
||||
// For bottle type, totalPillsAdded = loosePillsAdded only
|
||||
expect(refills[0].totalPillsAdded).toBe(25);
|
||||
});
|
||||
|
||||
it("should export and import bottle type medication correctly", async () => {
|
||||
// Create bottle medication
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: bottleMedication,
|
||||
});
|
||||
|
||||
// Export
|
||||
const exportResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: "/export",
|
||||
});
|
||||
|
||||
expect(exportResponse.statusCode).toBe(200);
|
||||
const exportData = exportResponse.json();
|
||||
expect(exportData.medications).toHaveLength(1);
|
||||
expect(exportData.medications[0].inventory.packageType).toBe("bottle");
|
||||
expect(exportData.medications[0].inventory.looseTablets).toBe(120);
|
||||
|
||||
// Clear and re-import
|
||||
await clearData(testClient);
|
||||
await testClient.execute(
|
||||
"INSERT INTO users (id, username, auth_provider) VALUES (999999999, '__anonymous__', 'anonymous')"
|
||||
);
|
||||
|
||||
const importResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/import",
|
||||
payload: exportData,
|
||||
});
|
||||
|
||||
expect(importResponse.statusCode).toBe(200);
|
||||
expect(importResponse.json().success).toBe(true);
|
||||
|
||||
// Verify imported medication has correct packageType
|
||||
const medsResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: "/medications",
|
||||
});
|
||||
|
||||
expect(medsResponse.json()).toHaveLength(1);
|
||||
const med = medsResponse.json()[0];
|
||||
expect(med.name).toBe("Vitamin D Drops");
|
||||
expect(med.packageType).toBe("bottle");
|
||||
expect(med.looseTablets).toBe(120);
|
||||
});
|
||||
|
||||
it("should default to blister when importing without packageType", async () => {
|
||||
const importData = {
|
||||
version: "1.0",
|
||||
exportedAt: new Date().toISOString(),
|
||||
medications: [
|
||||
{
|
||||
_exportId: "med-1",
|
||||
name: "Old Export Med",
|
||||
inventory: { packCount: 2, blistersPerPack: 3, pillsPerBlister: 10, looseTablets: 0 },
|
||||
schedules: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const importResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/import",
|
||||
payload: importData,
|
||||
});
|
||||
|
||||
expect(importResponse.statusCode).toBe(200);
|
||||
|
||||
const medsResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: "/medications",
|
||||
});
|
||||
|
||||
expect(medsResponse.json()).toHaveLength(1);
|
||||
expect(medsResponse.json()[0].packageType).toBe("blister");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,6 +94,11 @@ async function createSchema(client: Client) {
|
||||
expiry_date text,
|
||||
notes text,
|
||||
intake_reminders_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_authorized_refills integer,
|
||||
prescription_remaining_refills integer,
|
||||
prescription_low_refill_threshold integer NOT NULL DEFAULT 1,
|
||||
prescription_expiry_date text,
|
||||
dismissed_until text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
@@ -105,10 +110,12 @@ async function createSchema(client: Client) {
|
||||
notification_email text,
|
||||
email_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
email_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
email_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_enabled integer NOT NULL DEFAULT 0,
|
||||
shoutrrr_url text,
|
||||
shoutrrr_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
reminder_days_before integer NOT NULL DEFAULT 7,
|
||||
repeat_daily_reminders integer NOT NULL DEFAULT 0,
|
||||
skip_reminders_for_taken_doses integer NOT NULL DEFAULT 0,
|
||||
@@ -121,11 +128,18 @@ async function createSchema(client: Client) {
|
||||
expiry_warning_days integer NOT NULL DEFAULT 90,
|
||||
language text NOT NULL DEFAULT 'en',
|
||||
stock_calculation_mode text NOT NULL DEFAULT 'automatic',
|
||||
share_stock_status integer NOT NULL DEFAULT 1,
|
||||
last_auto_email_sent text,
|
||||
last_notification_type text,
|
||||
last_notification_channel text,
|
||||
last_reminder_med_name text,
|
||||
last_reminder_taken_by text,
|
||||
last_stock_reminder_sent text,
|
||||
last_stock_reminder_channel text,
|
||||
last_stock_reminder_med_names text,
|
||||
last_prescription_reminder_sent text,
|
||||
last_prescription_reminder_channel text,
|
||||
last_prescription_reminder_med_names text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)`,
|
||||
@@ -1181,6 +1195,92 @@ describe("Integration Tests", () => {
|
||||
expect(data[0].plannerUsage).toBe(10);
|
||||
expect(data[0].enough).toBe(true); // 45 > 10
|
||||
});
|
||||
|
||||
it("should use user-selected start date, not current time (fix asymmetric counting)", async () => {
|
||||
// Regression test: When a planner range starts today, the old code used
|
||||
// max(now, start) as the effective start. If now was between the morning
|
||||
// dose (07:00) and evening dose (20:00), morning was skipped but evening
|
||||
// counted, giving an asymmetric result (e.g., 5 instead of 6).
|
||||
//
|
||||
// Example: medication with daily morning (07:00) + evening (20:00) intakes,
|
||||
// planner range [today 01:00, today+3 01:00).
|
||||
// Old code at 15:00: morning 07:00 < 15:00 → skipped, evening 20:00 ≥ 15:00 → counted
|
||||
// Result: 2 morning + 3 evening = 5 instead of 3+3 = 6.
|
||||
|
||||
// Use a past start date so the intakes predate the planner range
|
||||
const intakeStart = "2025-01-01T07:00:00.000Z";
|
||||
const intakeEvening = "2025-01-01T20:00:00.000Z";
|
||||
|
||||
// Plan range: Feb 9 00:00 to Feb 12 00:00 UTC (3 full days)
|
||||
const planStart = "2026-02-09T00:00:00.000Z";
|
||||
const planEnd = "2026-02-12T00:00:00.000Z";
|
||||
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: {
|
||||
name: "Twice Daily Med Asymmetric",
|
||||
packCount: 5,
|
||||
blistersPerPack: 5,
|
||||
pillsPerBlister: 10,
|
||||
blisters: [
|
||||
{ usage: 1, every: 1, start: intakeStart },
|
||||
{ usage: 1, every: 1, start: intakeEvening },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications/usage",
|
||||
payload: {
|
||||
startDate: planStart,
|
||||
endDate: planEnd,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const data = response.json();
|
||||
// Both morning and evening should have exactly 3 occurrences each
|
||||
// (Feb 9, 10, 11) for a total of 6, regardless of current time
|
||||
expect(data[0].plannerUsage).toBe(6);
|
||||
});
|
||||
|
||||
it("should handle planner range starting before blister start", async () => {
|
||||
// Blister starts on Feb 10, planner range starts Feb 9
|
||||
// Should only count doses from Feb 10 onwards
|
||||
const intakeMorning = "2026-02-10T07:00:00.000Z";
|
||||
const intakeEvening = "2026-02-10T20:00:00.000Z";
|
||||
|
||||
await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications",
|
||||
payload: {
|
||||
name: "Recent Start Med",
|
||||
packCount: 1,
|
||||
blistersPerPack: 1,
|
||||
pillsPerBlister: 30,
|
||||
blisters: [
|
||||
{ usage: 1, every: 1, start: intakeMorning },
|
||||
{ usage: 1, every: 1, start: intakeEvening },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/medications/usage",
|
||||
payload: {
|
||||
startDate: "2026-02-09T00:00:00.000Z",
|
||||
endDate: "2026-02-12T00:00:00.000Z",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
const data = response.json();
|
||||
// Only Feb 10 and Feb 11 have doses (blister starts Feb 10)
|
||||
expect(data[0].plannerUsage).toBe(4); // 2 days × 2 intakes
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -86,6 +86,39 @@ async function createSchema(client: Client) {
|
||||
is_active integer NOT NULL DEFAULT 1,
|
||||
created_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now'))
|
||||
)`,
|
||||
`CREATE TABLE IF NOT EXISTS medications (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
user_id integer NOT NULL,
|
||||
name text NOT NULL,
|
||||
generic_name text,
|
||||
taken_by_json text NOT NULL DEFAULT '[]',
|
||||
package_type text NOT NULL DEFAULT 'blister',
|
||||
pack_count integer NOT NULL DEFAULT 1,
|
||||
blisters_per_pack integer NOT NULL DEFAULT 1,
|
||||
pills_per_blister integer NOT NULL DEFAULT 1,
|
||||
total_pills integer,
|
||||
loose_tablets integer NOT NULL DEFAULT 0,
|
||||
stock_adjustment integer NOT NULL DEFAULT 0,
|
||||
last_stock_correction_at integer,
|
||||
pill_weight_mg integer,
|
||||
dose_unit text DEFAULT 'mg',
|
||||
usage_json text NOT NULL DEFAULT '[]',
|
||||
every_json text NOT NULL DEFAULT '[]',
|
||||
start_json text NOT NULL DEFAULT '[]',
|
||||
intakes_json text NOT NULL DEFAULT '[]',
|
||||
image_url text,
|
||||
expiry_date text,
|
||||
notes text,
|
||||
intake_reminders_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_enabled integer NOT NULL DEFAULT 0,
|
||||
prescription_authorized_refills integer,
|
||||
prescription_remaining_refills integer,
|
||||
prescription_low_refill_threshold integer NOT NULL DEFAULT 1,
|
||||
prescription_expiry_date text,
|
||||
dismissed_until text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)`,
|
||||
`CREATE TABLE IF NOT EXISTS user_settings (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -94,10 +127,12 @@ async function createSchema(client: Client) {
|
||||
notification_email text,
|
||||
email_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
email_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
email_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_enabled integer NOT NULL DEFAULT 0,
|
||||
shoutrrr_url text,
|
||||
shoutrrr_stock_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_intake_reminders integer NOT NULL DEFAULT 1,
|
||||
shoutrrr_prescription_reminders integer NOT NULL DEFAULT 1,
|
||||
reminder_days_before integer NOT NULL DEFAULT 7,
|
||||
repeat_daily_reminders integer NOT NULL DEFAULT 0,
|
||||
skip_reminders_for_taken_doses integer NOT NULL DEFAULT 0,
|
||||
@@ -110,11 +145,18 @@ async function createSchema(client: Client) {
|
||||
expiry_warning_days integer NOT NULL DEFAULT 90,
|
||||
language text NOT NULL DEFAULT 'en',
|
||||
stock_calculation_mode text NOT NULL DEFAULT 'automatic',
|
||||
share_stock_status integer NOT NULL DEFAULT 1,
|
||||
last_auto_email_sent text,
|
||||
last_notification_type text,
|
||||
last_notification_channel text,
|
||||
last_reminder_med_name text,
|
||||
last_reminder_taken_by text,
|
||||
last_stock_reminder_sent text,
|
||||
last_stock_reminder_channel text,
|
||||
last_stock_reminder_med_names text,
|
||||
last_prescription_reminder_sent text,
|
||||
last_prescription_reminder_channel text,
|
||||
last_prescription_reminder_med_names text,
|
||||
updated_at integer NOT NULL DEFAULT (strftime('%s','now')),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)`,
|
||||
@@ -161,21 +203,6 @@ describe("Planner Routes", () => {
|
||||
});
|
||||
|
||||
describe("POST /planner/send-email", () => {
|
||||
it("should reject request with missing email", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
payload: {
|
||||
from: "2025-01-01",
|
||||
until: "2025-01-31",
|
||||
rows: [{ medicationName: "Test", totalPills: 10, plannerUsage: 5, enough: true }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json()).toEqual({ error: "Missing email or planner data" });
|
||||
});
|
||||
|
||||
it("should reject request with missing rows", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
@@ -189,10 +216,16 @@ describe("Planner Routes", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json()).toEqual({ error: "Missing email or planner data" });
|
||||
expect(response.json()).toEqual({ error: "Missing planner data" });
|
||||
});
|
||||
|
||||
it("should reject when SMTP is not configured", async () => {
|
||||
it("should return error when no notification channels configured", async () => {
|
||||
// User settings exist but email/shoutrrr disabled
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 0, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
@@ -217,7 +250,7 @@ describe("Planner Routes", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json()).toEqual({ error: "SMTP not configured" });
|
||||
expect(response.json()).toEqual({ error: "No notification channels configured" });
|
||||
});
|
||||
|
||||
it("should send email successfully when SMTP is configured", async () => {
|
||||
@@ -226,6 +259,12 @@ describe("Planner Routes", () => {
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
// Enable email in user settings
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
|
||||
const response = await app.inject({
|
||||
@@ -253,7 +292,7 @@ describe("Planner Routes", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toEqual({ success: true, message: "Email sent successfully" });
|
||||
expect(response.json()).toEqual({ success: true, message: "Notification sent via email" });
|
||||
expect(mockSendMail).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Cleanup
|
||||
@@ -267,6 +306,11 @@ describe("Planner Routes", () => {
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
|
||||
const response = await app.inject({
|
||||
@@ -308,7 +352,7 @@ describe("Planner Routes", () => {
|
||||
|
||||
// Check that HTML contains out of stock warning
|
||||
const mailCall = mockSendMail.mock.calls[0][0];
|
||||
expect(mailCall.html).toContain("Out of Stock");
|
||||
expect(mailCall.html).toContain("Empty");
|
||||
expect(mailCall.html).toContain("1 medication");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
@@ -321,6 +365,11 @@ describe("Planner Routes", () => {
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockRejectedValueOnce(new Error("Connection refused"));
|
||||
|
||||
const response = await app.inject({
|
||||
@@ -347,7 +396,7 @@ describe("Planner Routes", () => {
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(500);
|
||||
expect(response.json().error).toContain("Failed to send email");
|
||||
expect(response.json().error).toContain("Email:");
|
||||
expect(response.json().error).toContain("Connection refused");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
@@ -360,6 +409,12 @@ describe("Planner Routes", () => {
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
// User settings with German language
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'de')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
|
||||
const response = await app.inject({
|
||||
@@ -390,12 +445,178 @@ describe("Planner Routes", () => {
|
||||
|
||||
// German date format should be used
|
||||
const mailCall = mockSendMail.mock.calls[0][0];
|
||||
expect(mailCall.subject).toContain("Supply Overview");
|
||||
expect(mailCall.subject).toContain("Bestandsübersicht");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
delete process.env.SMTP_PASS;
|
||||
});
|
||||
|
||||
it("should send push notification when shoutrrr is enabled", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
from: "2025-01-01",
|
||||
until: "2025-01-31",
|
||||
rows: [
|
||||
{
|
||||
medicationId: 1,
|
||||
medicationName: "Aspirin",
|
||||
totalPills: 30,
|
||||
plannerUsage: 10,
|
||||
blisterSize: 10,
|
||||
blistersNeeded: 1,
|
||||
fullBlisters: 3,
|
||||
loosePills: 0,
|
||||
enough: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toEqual({ success: true, message: "Notification sent via push" });
|
||||
expect(mockSendShoutrrr).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Verify push message contains medication info
|
||||
const [_url, title, message] = mockSendShoutrrr.mock.calls[0];
|
||||
expect(title).toContain("Supply Overview");
|
||||
expect(message).toContain("Aspirin");
|
||||
});
|
||||
|
||||
it("should send both email and push when both enabled", async () => {
|
||||
process.env.SMTP_HOST = "smtp.test.com";
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 1, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
from: "2025-01-01",
|
||||
until: "2025-01-31",
|
||||
rows: [
|
||||
{
|
||||
medicationId: 1,
|
||||
medicationName: "Aspirin",
|
||||
totalPills: 5,
|
||||
plannerUsage: 30,
|
||||
blisterSize: 10,
|
||||
blistersNeeded: 3,
|
||||
fullBlisters: 0,
|
||||
loosePills: 5,
|
||||
enough: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toEqual({ success: true, message: "Notification sent via email and push" });
|
||||
expect(mockSendMail).toHaveBeenCalledTimes(1);
|
||||
expect(mockSendShoutrrr).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Verify push message contains out of stock info
|
||||
const [_url, _title, message] = mockSendShoutrrr.mock.calls[0];
|
||||
expect(message).toContain("Aspirin");
|
||||
expect(message).toContain("Empty");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
delete process.env.SMTP_PASS;
|
||||
});
|
||||
|
||||
it("should send push with German translations", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'de')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
from: "2025-01-01",
|
||||
until: "2025-01-31",
|
||||
rows: [
|
||||
{
|
||||
medicationId: 1,
|
||||
medicationName: "Aspirin",
|
||||
totalPills: 5,
|
||||
plannerUsage: 30,
|
||||
blisterSize: 10,
|
||||
blistersNeeded: 3,
|
||||
fullBlisters: 0,
|
||||
loosePills: 5,
|
||||
enough: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
// Check German translations in push
|
||||
const [_url, title] = mockSendShoutrrr.mock.calls[0];
|
||||
expect(title).toContain("Bestandsübersicht");
|
||||
});
|
||||
|
||||
it("should handle push error gracefully", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: false, error: "Connection failed" });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/planner/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
from: "2025-01-01",
|
||||
until: "2025-01-31",
|
||||
rows: [
|
||||
{
|
||||
medicationId: 1,
|
||||
medicationName: "Aspirin",
|
||||
totalPills: 30,
|
||||
plannerUsage: 10,
|
||||
blisterSize: 10,
|
||||
blistersNeeded: 1,
|
||||
fullBlisters: 3,
|
||||
loosePills: 0,
|
||||
enough: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(500);
|
||||
expect(response.json().error).toContain("Push:");
|
||||
expect(response.json().error).toContain("Connection failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /reminder/send-email", () => {
|
||||
@@ -503,10 +724,10 @@ describe("Planner Routes", () => {
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
// Check email contains EMPTY warning
|
||||
// Check email contains empty warning
|
||||
const mailCall = mockSendMail.mock.calls[0][0];
|
||||
expect(mailCall.subject).toContain("Empty");
|
||||
expect(mailCall.html).toContain("EMPTY");
|
||||
expect(mailCall.html).toContain("empty");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
@@ -541,7 +762,7 @@ describe("Planner Routes", () => {
|
||||
|
||||
const mailCall = mockSendMail.mock.calls[0][0];
|
||||
expect(mailCall.subject).toContain("Empty");
|
||||
expect(mailCall.subject).toContain("Running Low");
|
||||
expect(mailCall.subject).toContain("Critical");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
@@ -698,5 +919,205 @@ describe("Planner Routes", () => {
|
||||
expect(response.json().error).toContain("Push:");
|
||||
expect(response.json().error).toContain("Network error");
|
||||
});
|
||||
|
||||
it("should differentiate critical and low stock in push notification", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
lowStock: [
|
||||
{ name: "Aspirin", medsLeft: 5, daysLeft: 3, depletionDate: "2025-01-03", isCritical: true },
|
||||
{ name: "Ibuprofen", medsLeft: 49, daysLeft: 24, depletionDate: "2025-01-24", isCritical: false },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const [_url, title, message] = mockSendShoutrrr.mock.calls[0];
|
||||
// Title should contain both Critical and Low labels
|
||||
expect(title).toContain("Critical");
|
||||
expect(title).toContain("Low");
|
||||
// Message should have separate sections
|
||||
expect(message).toContain("Running critically low");
|
||||
expect(message).toContain("Aspirin");
|
||||
expect(message).toContain("Running low");
|
||||
expect(message).toContain("Ibuprofen");
|
||||
});
|
||||
|
||||
it("should differentiate critical and low stock in email", async () => {
|
||||
process.env.SMTP_HOST = "smtp.test.com";
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
lowStock: [
|
||||
{ name: "Aspirin", medsLeft: 5, daysLeft: 3, depletionDate: "2025-01-03", isCritical: true },
|
||||
{ name: "Ibuprofen", medsLeft: 49, daysLeft: 24, depletionDate: "2025-01-24", isCritical: false },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const mailCall = mockSendMail.mock.calls[0][0];
|
||||
// Subject should contain both Critical and Low
|
||||
expect(mailCall.subject).toContain("Critical");
|
||||
expect(mailCall.subject).toContain("Low");
|
||||
// HTML should have separate alert boxes
|
||||
expect(mailCall.html).toContain("critically low");
|
||||
expect(mailCall.html).toContain("running low");
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
delete process.env.SMTP_PASS;
|
||||
});
|
||||
|
||||
it("should label all meds as critical when isCritical not provided", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-email",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
lowStock: [{ name: "Aspirin", medsLeft: 5, daysLeft: 3, depletionDate: "2025-01-03" }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const [_url, title, message] = mockSendShoutrrr.mock.calls[0];
|
||||
// Should be treated as critical (backwards compat)
|
||||
expect(title).toContain("Critical");
|
||||
expect(title).not.toContain("Low");
|
||||
expect(message).toContain("Running critically low");
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /reminder/send-prescription", () => {
|
||||
it("should reject request with missing prescription data", async () => {
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-prescription",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
prescriptionLow: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json()).toEqual({ error: "Missing prescription reminder data" });
|
||||
});
|
||||
|
||||
it("should return error when no notification channels configured", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 0, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-prescription",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
prescriptionLow: [{ name: "Aspirin", remainingRefills: 0, threshold: 1, expiryDate: "2026-01-01" }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(400);
|
||||
expect(response.json()).toEqual({ error: "No notification channels configured" });
|
||||
});
|
||||
|
||||
it("should send prescription email reminder when email is enabled", async () => {
|
||||
process.env.SMTP_HOST = "smtp.test.com";
|
||||
process.env.SMTP_USER = "user@test.com";
|
||||
process.env.SMTP_PASS = "password";
|
||||
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, language) VALUES (?, 1, 0, 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendMail.mockResolvedValueOnce({ messageId: "123" });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-prescription",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
prescriptionLow: [
|
||||
{ name: "Aspirin", remainingRefills: 0, threshold: 1, expiryDate: "2026-01-01" },
|
||||
{ name: "Ibuprofen", remainingRefills: 1, threshold: 2, expiryDate: null },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toEqual({ success: true, message: "Prescription reminder sent via email" });
|
||||
expect(mockSendMail).toHaveBeenCalledTimes(1);
|
||||
expect(mockUpdateReminderSentTime).toHaveBeenCalledWith("prescription", "email");
|
||||
expect(mockUpdateUserReminderSentTime).toHaveBeenCalledWith(
|
||||
999999999,
|
||||
"prescription",
|
||||
"email",
|
||||
"Aspirin, Ibuprofen"
|
||||
);
|
||||
|
||||
delete process.env.SMTP_HOST;
|
||||
delete process.env.SMTP_USER;
|
||||
delete process.env.SMTP_PASS;
|
||||
});
|
||||
|
||||
it("should send prescription push reminder when shoutrrr is enabled", async () => {
|
||||
await testClient.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, email_enabled, shoutrrr_enabled, shoutrrr_url, language) VALUES (?, 0, 1, 'ntfy://localhost/test', 'en')`,
|
||||
args: [999999999],
|
||||
});
|
||||
|
||||
mockSendShoutrrr.mockResolvedValueOnce({ success: true });
|
||||
|
||||
const response = await app.inject({
|
||||
method: "POST",
|
||||
url: "/reminder/send-prescription",
|
||||
payload: {
|
||||
email: "test@example.com",
|
||||
prescriptionLow: [{ name: "Aspirin", remainingRefills: 1, threshold: 2, expiryDate: "2026-01-01" }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toEqual({ success: true, message: "Prescription reminder sent via push" });
|
||||
expect(mockSendShoutrrr).toHaveBeenCalledTimes(1);
|
||||
const [_url, title, message] = mockSendShoutrrr.mock.calls[0];
|
||||
expect(title).toContain("Renew Now");
|
||||
expect(message).toContain("Aspirin");
|
||||
expect(mockUpdateReminderSentTime).toHaveBeenCalledWith("prescription", "push");
|
||||
expect(mockUpdateUserReminderSentTime).toHaveBeenCalledWith(999999999, "prescription", "push", "Aspirin");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -388,6 +388,56 @@ describe("Scheduler Utils - Upcoming Intakes", () => {
|
||||
// Both should be found as they're within the window
|
||||
expect(result.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it("should catch up missed advance reminder when notify window passed but intake still future", () => {
|
||||
// Intake at 15:57, reminder 15 min before = 15:42
|
||||
// Scheduler was down at 15:42, now running at 15:50 (intake still in future)
|
||||
const intakes: Intake[] = [blisterToIntake({ usage: 1, every: 1, start: "2025-01-01T15:57:00" })];
|
||||
// "now" = 15:50 local time on the same day — past the 15:42 notify window, but before 15:57 intake
|
||||
const now = new Date(2025, 0, 1, 15, 50, 0).getTime();
|
||||
|
||||
const result = getUpcomingIntakes("TestMed", intakes, 15, [], null, "en-US", "UTC", now);
|
||||
|
||||
// Should still return the intake as a catch-up advance reminder
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].medName).toBe("TestMed");
|
||||
expect(result[0].usage).toBe(1);
|
||||
});
|
||||
|
||||
it("should catch up missed advance reminder even 1 minute before intake", () => {
|
||||
// Intake at 08:00, reminder at 07:45. Scheduler catches up at 07:59.
|
||||
const intakes: Intake[] = [blisterToIntake({ usage: 1, every: 1, start: "2025-01-01T08:00:00" })];
|
||||
const now = new Date(2025, 0, 1, 7, 59, 30).getTime();
|
||||
|
||||
const result = getUpcomingIntakes("TestMed", intakes, 15, [], null, "en-US", "UTC", now);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("should not catch up for intakes already in the past", () => {
|
||||
// Intake at 08:00, reminder at 07:45. Now = 08:05 (intake already past).
|
||||
const intakes: Intake[] = [blisterToIntake({ usage: 1, every: 1, start: "2025-01-01T08:00:00" })];
|
||||
const now = new Date(2025, 0, 1, 8, 5, 0).getTime();
|
||||
|
||||
const result = getUpcomingIntakes("TestMed", intakes, 15, [], null, "en-US", "UTC", now);
|
||||
|
||||
// Should NOT return — intake is past, handled by getTodaysIntakes instead
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should catch up for recurring intake on later day", () => {
|
||||
// Intake started Jan 1 at 10:00, every 1 day. Now = Jan 3 at 09:50 (past notify, before intake)
|
||||
const intakes: Intake[] = [blisterToIntake({ usage: 1, every: 1, start: "2025-01-01T10:00:00" })];
|
||||
const now = new Date(2025, 0, 3, 9, 50, 0).getTime();
|
||||
|
||||
const result = getUpcomingIntakes("TestMed", intakes, 15, [], null, "en-US", "UTC", now);
|
||||
|
||||
// Should return today's occurrence via catch-up
|
||||
expect(result).toHaveLength(1);
|
||||
// The intake time should be Jan 3 at 10:00
|
||||
expect(result[0].intakeTime.getHours()).toBe(10);
|
||||
expect(result[0].intakeTime.getDate()).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getTodaysIntakes", () => {
|
||||
|
||||
@@ -51,6 +51,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
expiryWarningDays: 90,
|
||||
language: "en",
|
||||
stockCalculationMode: "automatic",
|
||||
shareStockStatus: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
expiryWarningDays: s.expiry_warning_days,
|
||||
language: s.language,
|
||||
stockCalculationMode: s.stock_calculation_mode,
|
||||
shareStockStatus: Boolean(s.share_stock_status ?? 1),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -102,6 +104,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
expiryWarningDays?: number;
|
||||
language?: string;
|
||||
stockCalculationMode?: "automatic" | "manual";
|
||||
shareStockStatus?: boolean;
|
||||
};
|
||||
}>("/settings", async (request, reply) => {
|
||||
const userId = 1;
|
||||
@@ -150,8 +153,8 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
reminder_days_before, repeat_daily_reminders, skip_reminders_for_taken_doses,
|
||||
repeat_reminders_enabled, reminder_repeat_interval_minutes, max_nagging_reminders,
|
||||
low_stock_days, normal_stock_days, high_stock_days,
|
||||
expiry_warning_days, language, stock_calculation_mode
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
expiry_warning_days, language, stock_calculation_mode, share_stock_status
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
args: [
|
||||
userId,
|
||||
body.emailEnabled ? 1 : 0,
|
||||
@@ -174,6 +177,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
body.expiryWarningDays ?? 90,
|
||||
body.language || "en",
|
||||
body.stockCalculationMode || "automatic",
|
||||
body.shareStockStatus !== false ? 1 : 0,
|
||||
],
|
||||
});
|
||||
} else {
|
||||
@@ -200,6 +204,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
expiry_warning_days = ?,
|
||||
language = ?,
|
||||
stock_calculation_mode = ?,
|
||||
share_stock_status = ?,
|
||||
updated_at = strftime('%s','now')
|
||||
WHERE user_id = ?`,
|
||||
args: [
|
||||
@@ -223,6 +228,7 @@ async function registerSettingsRoutes(ctx: TestContext) {
|
||||
body.expiryWarningDays ?? 90,
|
||||
body.language || "en",
|
||||
body.stockCalculationMode || "automatic",
|
||||
body.shareStockStatus !== false ? 1 : 0,
|
||||
userId,
|
||||
],
|
||||
});
|
||||
@@ -542,6 +548,64 @@ describe("Settings API", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Share Stock Status
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe("Share Stock Status", () => {
|
||||
it("should default to true (show stock on shared links)", async () => {
|
||||
const response = await ctx.app.inject({
|
||||
method: "GET",
|
||||
url: "/settings",
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().shareStockStatus).toBe(true);
|
||||
});
|
||||
|
||||
it("should disable share stock status", async () => {
|
||||
const response = await ctx.app.inject({
|
||||
method: "PUT",
|
||||
url: "/settings",
|
||||
payload: { shareStockStatus: false },
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const getResponse = await ctx.app.inject({
|
||||
method: "GET",
|
||||
url: "/settings",
|
||||
});
|
||||
|
||||
expect(getResponse.json().shareStockStatus).toBe(false);
|
||||
});
|
||||
|
||||
it("should re-enable share stock status", async () => {
|
||||
// Disable first
|
||||
await ctx.app.inject({
|
||||
method: "PUT",
|
||||
url: "/settings",
|
||||
payload: { shareStockStatus: false },
|
||||
});
|
||||
|
||||
// Re-enable
|
||||
const response = await ctx.app.inject({
|
||||
method: "PUT",
|
||||
url: "/settings",
|
||||
payload: { shareStockStatus: true },
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const getResponse = await ctx.app.inject({
|
||||
method: "GET",
|
||||
url: "/settings",
|
||||
});
|
||||
|
||||
expect(getResponse.json().shareStockStatus).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Repeat Reminders & Skip Reminders Settings
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -216,13 +216,14 @@ export interface UpdateUserSettingsOptions {
|
||||
userId: number;
|
||||
stockCalculationMode?: "automatic" | "manual";
|
||||
lowStockDays?: number;
|
||||
shareStockStatus?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update user settings
|
||||
*/
|
||||
export async function setUserSettings(client: Client, options: UpdateUserSettingsOptions): Promise<void> {
|
||||
const { userId, stockCalculationMode = "automatic", lowStockDays = 30 } = options;
|
||||
const { userId, stockCalculationMode = "automatic", lowStockDays = 30, shareStockStatus } = options;
|
||||
|
||||
// Check if settings exist
|
||||
const existing = await client.execute({
|
||||
@@ -232,13 +233,19 @@ export async function setUserSettings(client: Client, options: UpdateUserSetting
|
||||
|
||||
if (existing.rows.length > 0) {
|
||||
await client.execute({
|
||||
sql: `UPDATE user_settings SET stock_calculation_mode = ?, low_stock_days = ? WHERE user_id = ?`,
|
||||
args: [stockCalculationMode, lowStockDays, userId],
|
||||
sql: `UPDATE user_settings SET stock_calculation_mode = ?, low_stock_days = ?${shareStockStatus !== undefined ? ", share_stock_status = ?" : ""} WHERE user_id = ?`,
|
||||
args:
|
||||
shareStockStatus !== undefined
|
||||
? [stockCalculationMode, lowStockDays, shareStockStatus ? 1 : 0, userId]
|
||||
: [stockCalculationMode, lowStockDays, userId],
|
||||
});
|
||||
} else {
|
||||
await client.execute({
|
||||
sql: `INSERT INTO user_settings (user_id, stock_calculation_mode, low_stock_days) VALUES (?, ?, ?)`,
|
||||
args: [userId, stockCalculationMode, lowStockDays],
|
||||
sql: `INSERT INTO user_settings (user_id, stock_calculation_mode, low_stock_days${shareStockStatus !== undefined ? ", share_stock_status" : ""}) VALUES (?, ?, ?${shareStockStatus !== undefined ? ", ?" : ""})`,
|
||||
args:
|
||||
shareStockStatus !== undefined
|
||||
? [userId, stockCalculationMode, lowStockDays, shareStockStatus ? 1 : 0]
|
||||
: [userId, stockCalculationMode, lowStockDays],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
createTestMedication,
|
||||
createTestShareToken,
|
||||
createTestUser,
|
||||
setUserSettings,
|
||||
type TestContext,
|
||||
} from "./setup.js";
|
||||
|
||||
@@ -141,6 +142,14 @@ async function registerShareRoutes(ctx: TestContext) {
|
||||
|
||||
const lowStockDays = settingsResult.rows.length > 0 ? (settingsResult.rows[0].low_stock_days as number) : 30;
|
||||
|
||||
// Get shareStockStatus setting
|
||||
const shareStockResult = await client.execute({
|
||||
sql: `SELECT share_stock_status FROM user_settings WHERE user_id = ?`,
|
||||
args: [share.user_id],
|
||||
});
|
||||
const shareStockStatus =
|
||||
shareStockResult.rows.length > 0 ? Boolean(shareStockResult.rows[0].share_stock_status ?? 1) : true;
|
||||
|
||||
return {
|
||||
takenBy: share.taken_by,
|
||||
sharedBy: share.owner_username,
|
||||
@@ -149,6 +158,7 @@ async function registerShareRoutes(ctx: TestContext) {
|
||||
stockThresholds: {
|
||||
lowStockDays,
|
||||
},
|
||||
shareStockStatus,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -421,6 +431,41 @@ describe("Share Link API", () => {
|
||||
expect(med.blisters).toHaveLength(1);
|
||||
expect(med.blisters[0].usage).toBe(1);
|
||||
expect(med.blisters[0].every).toBe(1);
|
||||
|
||||
// shareStockStatus should default to true
|
||||
expect(data.shareStockStatus).toBe(true);
|
||||
});
|
||||
|
||||
it("should respect shareStockStatus setting when disabled", async () => {
|
||||
// Create medication
|
||||
await createTestMedication(ctx.client, {
|
||||
userId,
|
||||
name: "TestMed",
|
||||
takenBy: ["Daniel"],
|
||||
packCount: 1,
|
||||
blistersPerPack: 1,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 0,
|
||||
blisters: [{ usage: 1, every: 1, start: "2025-01-01T08:00:00.000Z" }],
|
||||
});
|
||||
|
||||
// Set shareStockStatus to false
|
||||
await setUserSettings(ctx.client, { userId, shareStockStatus: false });
|
||||
|
||||
// Create share token
|
||||
const token = await createTestShareToken(ctx.client, {
|
||||
userId,
|
||||
takenBy: "Daniel",
|
||||
scheduleDays: 30,
|
||||
});
|
||||
|
||||
const response = await ctx.app.inject({
|
||||
method: "GET",
|
||||
url: `/share/${token}`,
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().shareStockStatus).toBe(false);
|
||||
});
|
||||
|
||||
it("should return 404 for invalid token", async () => {
|
||||
|
||||
@@ -69,8 +69,8 @@ describe("Translations Module", () => {
|
||||
});
|
||||
|
||||
it("should replace multiple placeholders", () => {
|
||||
const result = t("{count} {type} running low", { count: 3, type: "medications" });
|
||||
expect(result).toBe("3 medications running low");
|
||||
const result = t("{count} {type} running critically low", { count: 3, type: "medications" });
|
||||
expect(result).toBe("3 medications running critically low");
|
||||
});
|
||||
|
||||
it("should replace same placeholder multiple times", () => {
|
||||
@@ -98,7 +98,7 @@ describe("Translations Module", () => {
|
||||
|
||||
// Stock reminder subject
|
||||
const subject = t(translations.stockReminder.subject, { count: 3, s: "s" });
|
||||
expect(subject).toBe("MedAssist-ng Auto-Reminder: 3 Medications Running Low");
|
||||
expect(subject).toBe("MedAssist-ng: ⚠️ 3 Medications Running Critically Low");
|
||||
|
||||
// Intake reminder description
|
||||
const description = t(translations.intakeReminder.description, { minutes: 30 });
|
||||
@@ -113,7 +113,7 @@ describe("Translations Module", () => {
|
||||
const translations = getTranslations("de");
|
||||
|
||||
const subject = t(translations.stockReminder.subject, { count: 2, e: "e" });
|
||||
expect(subject).toBe("MedAssist-ng Auto-Erinnerung: 2 Medikamente wird knapp");
|
||||
expect(subject).toBe("MedAssist-ng: ⚠️ 2 Medikamente kritisch niedrig");
|
||||
|
||||
const takenBy = t(translations.intakeReminder.takenBy, { name: "Daniel" });
|
||||
expect(takenBy).toBe("für Daniel");
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Simple startup logger that respects LOG_LEVEL environment variable.
|
||||
* Used for code that runs before Fastify is initialized (db/client.ts, migrations).
|
||||
* Once Fastify is running, use app.log instead.
|
||||
*/
|
||||
|
||||
const LOG_LEVELS: Record<string, number> = {
|
||||
silent: 60,
|
||||
fatal: 60,
|
||||
error: 50,
|
||||
warn: 40,
|
||||
info: 30,
|
||||
debug: 20,
|
||||
trace: 10,
|
||||
};
|
||||
|
||||
function getLevel(): number {
|
||||
const envLevel = (process.env.LOG_LEVEL || "info").toLowerCase();
|
||||
return LOG_LEVELS[envLevel] ?? LOG_LEVELS.info;
|
||||
}
|
||||
|
||||
function shouldLog(level: string): boolean {
|
||||
return LOG_LEVELS[level] >= getLevel();
|
||||
}
|
||||
|
||||
export const log = {
|
||||
debug(msg: string): void {
|
||||
if (shouldLog("debug")) console.log(msg);
|
||||
},
|
||||
info(msg: string): void {
|
||||
if (shouldLog("info")) console.log(msg);
|
||||
},
|
||||
warn(msg: string): void {
|
||||
if (shouldLog("warn")) console.warn(msg);
|
||||
},
|
||||
error(msg: string): void {
|
||||
if (shouldLog("error")) console.error(msg);
|
||||
},
|
||||
};
|
||||
|
||||
/** Logger interface for services that receive a logger from the caller */
|
||||
export type ServiceLogger = {
|
||||
info: (msg: string) => void;
|
||||
debug: (msg: string) => void;
|
||||
error: (msg: string) => void;
|
||||
};
|
||||
@@ -432,6 +432,11 @@ export function getUpcomingIntakes(
|
||||
const currentNotifyTime = currentOccurrence - minutesBefore * 60 * 1000;
|
||||
if (currentNotifyTime >= currentMinuteStart && currentOccurrence > now) {
|
||||
nextTime = currentOccurrence;
|
||||
} else if (currentNotifyTime < currentMinuteStart && currentOccurrence > now) {
|
||||
// CATCH-UP: The notify window was missed (e.g. due to system sleep/restart)
|
||||
// but the intake time is still in the future — include it so the advance
|
||||
// reminder can still be sent rather than falling into a dead zone.
|
||||
nextTime = currentOccurrence;
|
||||
} else {
|
||||
nextTime = nextOccurrence;
|
||||
}
|
||||
@@ -440,8 +445,15 @@ export function getUpcomingIntakes(
|
||||
// Calculate when we should notify for this intake
|
||||
const notifyTime = nextTime - minutesBefore * 60 * 1000;
|
||||
|
||||
// Check if notifyTime falls within the current minute (precise matching)
|
||||
if (notifyTime >= currentMinuteStart && notifyTime < currentMinuteEnd) {
|
||||
// Match if:
|
||||
// 1. notifyTime falls within the current minute (normal case), OR
|
||||
// 2. notifyTime is in the past but intakeTime is still in the future (catch-up
|
||||
// for missed advance reminder window — e.g. scheduler was down during the
|
||||
// exact notification minute due to system sleep, restart, or heavy load)
|
||||
const isInCurrentMinute = notifyTime >= currentMinuteStart && notifyTime < currentMinuteEnd;
|
||||
const isMissedButStillUpcoming = notifyTime < currentMinuteStart && nextTime > now;
|
||||
|
||||
if (isInCurrentMinute || isMissedButStillUpcoming) {
|
||||
const intakeDate = new Date(nextTime);
|
||||
upcoming.push({
|
||||
medName,
|
||||
@@ -473,7 +485,7 @@ export type ReminderState = {
|
||||
lastAutoEmailDate: string | null;
|
||||
notifiedMedications: string[];
|
||||
nextScheduledCheck: string | null;
|
||||
lastNotificationType: "stock" | "intake" | null;
|
||||
lastNotificationType: "stock" | "intake" | "prescription" | null;
|
||||
lastNotificationChannel: "email" | "push" | "both" | null;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,5 +14,25 @@ export default defineConfig({
|
||||
},
|
||||
// Timeout for longer integration tests
|
||||
testTimeout: 10000,
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
reporter: ["text", "json", "html"],
|
||||
include: ["src/**/*.ts"],
|
||||
exclude: [
|
||||
"src/test/**",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/index.ts",
|
||||
"src/services/**",
|
||||
"src/utils/logger.ts",
|
||||
],
|
||||
thresholds: {
|
||||
global: {
|
||||
lines: 60,
|
||||
functions: 65,
|
||||
branches: 50,
|
||||
statements: 60,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@
|
||||
"style": {
|
||||
"noNonNullAssertion": "off",
|
||||
"useConst": "error",
|
||||
"noParameterAssign": "off"
|
||||
"noParameterAssign": "off",
|
||||
"noNestedTernary": "warn"
|
||||
},
|
||||
"correctness": {
|
||||
"noUnusedVariables": "warn",
|
||||
|
||||
@@ -11,6 +11,7 @@ services:
|
||||
- .env
|
||||
environment:
|
||||
- DATA_DIR=/app/data
|
||||
- RATE_LIMIT_MAX=1000
|
||||
ports:
|
||||
- "3000:3000"
|
||||
security_opt:
|
||||
@@ -29,6 +30,8 @@ services:
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
- frontend_node_modules:/app/node_modules
|
||||
environment:
|
||||
- BACKEND_URL=http://backend-dev:3000
|
||||
ports:
|
||||
- "5173:5173"
|
||||
security_opt:
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# GitHub Project Setup
|
||||
|
||||
This repository includes a GitHub Actions workflow that automatically adds new issues to a GitHub Project for tracking feature requests and bugs.
|
||||
|
||||
## Setup Steps
|
||||
|
||||
### 1. Create a GitHub Project
|
||||
|
||||
1. Go to your GitHub profile → **Projects** → **New project**
|
||||
2. Choose the **Board** template (recommended for feature tracking)
|
||||
3. Name it e.g. **MedAssist-ng Roadmap**
|
||||
4. Configure the default columns:
|
||||
- **Triage** – New issues land here
|
||||
- **Backlog** – Accepted but not yet started
|
||||
- **In Progress** – Currently being worked on
|
||||
- **Done** – Completed
|
||||
|
||||
### 2. Create a Personal Access Token (PAT)
|
||||
|
||||
The workflow needs a token with project permissions. The built-in `GITHUB_TOKEN` does not support GitHub Projects.
|
||||
|
||||
1. Go to **Settings** → **Developer settings** → **Personal access tokens** → **Fine-grained tokens**
|
||||
2. Click **Generate new token**
|
||||
3. Set:
|
||||
- **Token name**: `add-to-project`
|
||||
- **Expiration**: Choose an appropriate duration
|
||||
- **Repository access**: Select **Only select repositories** → `DanielVolz/medassist-ng`
|
||||
- **Permissions**:
|
||||
- Repository permissions: **Issues** → Read
|
||||
- Organization permissions (if applicable): **Projects** → Read and write
|
||||
- For **user-owned projects**, you need a **classic** token with the `project` scope instead
|
||||
4. Copy the generated token
|
||||
|
||||
### 3. Add Repository Secrets and Variables
|
||||
|
||||
1. Go to the repository → **Settings** → **Secrets and variables** → **Actions**
|
||||
2. Add a **secret**:
|
||||
- Name: `ADD_TO_PROJECT_PAT`
|
||||
- Value: The PAT from step 2
|
||||
3. Add a **variable** (under the **Variables** tab):
|
||||
- Name: `PROJECT_URL`
|
||||
- Value: The full URL of your GitHub Project (e.g. `https://github.com/users/DanielVolz/projects/1`)
|
||||
|
||||
### 4. Verify
|
||||
|
||||
1. Create a test issue using the **✨ Feature Request** template
|
||||
2. Check the **Actions** tab to see the workflow run
|
||||
3. Verify the issue appears in your GitHub Project under **Triage**
|
||||
|
||||
## How It Works
|
||||
|
||||
The workflow (`.github/workflows/add-to-project.yml`) triggers when:
|
||||
- A new issue is **opened**
|
||||
- A label is **added** to an existing issue
|
||||
|
||||
Issues with any of these labels are automatically added to the project:
|
||||
- `enhancement` – Feature requests
|
||||
- `bug` – Bug reports
|
||||
- `triage` – New issues needing review
|
||||
|
||||
Both the feature request and bug report issue templates automatically apply the `triage` label, so all new issues from templates are captured.
|
||||
|
||||
## Customization
|
||||
|
||||
### Adding more labels
|
||||
|
||||
Edit `.github/workflows/add-to-project.yml` and add labels to the `labeled` field:
|
||||
|
||||
```yaml
|
||||
labeled: enhancement, bug, triage, documentation
|
||||
```
|
||||
|
||||
### Restricting to feature requests only
|
||||
|
||||
Change the `labeled` field to only include `enhancement`:
|
||||
|
||||
```yaml
|
||||
labeled: enhancement
|
||||
label-operator: OR
|
||||
```
|
||||
+79
-44
@@ -6,8 +6,31 @@ import { TEST_USER } from "./fixtures";
|
||||
const authFile = path.join(import.meta.dirname, ".auth", "user.json");
|
||||
|
||||
/**
|
||||
* Global setup for authentication
|
||||
* This runs before all tests to ensure a test user exists and stores the authenticated state
|
||||
* Check if a JWT token is still valid (not expired) without making a
|
||||
* network request. Returns `true` when the token has at least 2 minutes
|
||||
* of remaining validity.
|
||||
*/
|
||||
function isTokenValid(token: string): boolean {
|
||||
try {
|
||||
const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString());
|
||||
// Require at least 10 minutes of remaining validity to ensure the token
|
||||
// lasts through the entire test run (which can take 7+ minutes)
|
||||
return typeof payload.exp === "number" && Date.now() / 1000 < payload.exp - 600;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global setup: ensure a test user exists and persist authenticated state.
|
||||
* Runs once before all test projects.
|
||||
*
|
||||
* Strategy:
|
||||
* 1. If a valid auth file exists whose access_token JWT has not expired,
|
||||
* reuse it without any network call (saves rate-limit budget).
|
||||
* 2. If auth is disabled (no login page), save state immediately.
|
||||
* 3. Try to register via API (idempotent — fails silently if user exists).
|
||||
* 4. Log in via the UI.
|
||||
*/
|
||||
setup("authenticate", async ({ page }) => {
|
||||
// Create .auth directory if it doesn't exist
|
||||
@@ -16,61 +39,73 @@ setup("authenticate", async ({ page }) => {
|
||||
fs.mkdirSync(authDir, { recursive: true });
|
||||
}
|
||||
|
||||
// ---- 1. Try to reuse an existing auth file (offline check) ----
|
||||
if (fs.existsSync(authFile)) {
|
||||
try {
|
||||
const saved = JSON.parse(fs.readFileSync(authFile, "utf-8"));
|
||||
const accessCookie = saved.cookies?.find((c: { name: string }) => c.name === "access_token");
|
||||
if (accessCookie?.value && isTokenValid(accessCookie.value)) {
|
||||
// Token still has enough validity — skip login entirely
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Invalid file — fall through to regular login
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 2. Check if auth is disabled ----
|
||||
await page.goto("/");
|
||||
|
||||
// Wait for the app to fully load (network idle + content visible)
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(page.locator("body")).not.toHaveText(/^$/, { timeout: 15000 });
|
||||
|
||||
// Check if auth is disabled (we can access dashboard directly)
|
||||
const dashboardVisible = await page
|
||||
.getByText(/dashboard|medications|schedule/i)
|
||||
const authDisabled = await page
|
||||
.locator("header.hero")
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
if (dashboardVisible) {
|
||||
// Auth is disabled - save empty state and return
|
||||
if (authDisabled) {
|
||||
await page.context().storageState({ path: authFile });
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we need to register (first user setup)
|
||||
const needsSetup = await page
|
||||
.getByText(/create.*first.*user|create.*account|register|first user setup/i)
|
||||
// Wait for auth container
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// ---- 3. Ensure the test user exists ----
|
||||
const baseURL = process.env.PLAYWRIGHT_BASE_URL || "http://localhost:5173";
|
||||
await page.request
|
||||
.post(`${baseURL}/api/auth/register`, {
|
||||
data: { username: TEST_USER.username, password: TEST_USER.password },
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
// ---- 4. Log in via UI ----
|
||||
const usernameField = page.locator("#username");
|
||||
const passwordField = page.locator("#password");
|
||||
|
||||
// Make sure we're on the login form (not register)
|
||||
const isOnRegister = await page
|
||||
.locator(".auth-subtitle")
|
||||
.filter({ hasText: /Create Account/i })
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
|
||||
if (needsSetup) {
|
||||
// Register the test user
|
||||
const usernameField = page.getByLabel(/username/i);
|
||||
const passwordField = page.getByLabel(/password/i).first();
|
||||
|
||||
await usernameField.fill(TEST_USER.username);
|
||||
await passwordField.fill(TEST_USER.password);
|
||||
|
||||
// Look for register/create button
|
||||
const registerButton = page.getByRole("button", { name: /register|create|sign up/i });
|
||||
await registerButton.click();
|
||||
|
||||
// Wait for successful registration and redirect
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 15000 });
|
||||
} else {
|
||||
// Need to login
|
||||
const usernameField = page.getByLabel(/username/i);
|
||||
const passwordField = page.getByLabel(/password/i);
|
||||
|
||||
// Check if we're on login page
|
||||
if (await usernameField.isVisible().catch(() => false)) {
|
||||
await usernameField.fill(TEST_USER.username);
|
||||
await passwordField.fill(TEST_USER.password);
|
||||
|
||||
const loginButton = page.getByRole("button", { name: /sign in|log in|login/i });
|
||||
await loginButton.click();
|
||||
|
||||
// Wait for successful login
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 15000 });
|
||||
if (isOnRegister) {
|
||||
const switchBtn = page.locator("button.auth-link-btn");
|
||||
if (await switchBtn.isVisible().catch(() => false)) {
|
||||
await switchBtn.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the authenticated state
|
||||
await usernameField.clear();
|
||||
await usernameField.fill(TEST_USER.username);
|
||||
await passwordField.clear();
|
||||
await passwordField.fill(TEST_USER.password);
|
||||
|
||||
// Click the submit button (not the SSO button)
|
||||
await page.locator('button.auth-submit[type="submit"]').click();
|
||||
|
||||
// Wait for successful auth — app header should appear
|
||||
await expect(page.locator("header.hero")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Persist authenticated state for all test projects
|
||||
await page.context().storageState({ path: authFile });
|
||||
});
|
||||
|
||||
+82
-87
@@ -1,118 +1,113 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, type Page, test } from "@playwright/test";
|
||||
|
||||
/**
|
||||
* Helper to wait for the app's auth state to be determined
|
||||
* The app shows Loading/Initializing until auth state is fetched
|
||||
*/
|
||||
async function waitForAuthReady(page: import("@playwright/test").Page): Promise<void> {
|
||||
// Wait for the loading indicator to disappear
|
||||
await page.waitForLoadState("networkidle");
|
||||
// The app should have loaded something meaningful
|
||||
await expect(page.locator("body")).not.toHaveText(/^$/, { timeout: 10000 });
|
||||
async function isAuthEnabled(page: Page): Promise<boolean> {
|
||||
try {
|
||||
const response = await page.request.get("/api/auth/state");
|
||||
if (!response.ok()) return true;
|
||||
const state = await response.json();
|
||||
return state?.authEnabled !== false;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication E2E Tests
|
||||
*
|
||||
* These tests verify the authentication flow including login, registration,
|
||||
* and logout functionality.
|
||||
* Tests the login/register UI when not authenticated.
|
||||
* Uses empty storage state to simulate unauthenticated access.
|
||||
*
|
||||
* NOTE: This file intentionally imports `test` from @playwright/test
|
||||
* (not from fixtures) because auth tests use empty storageState and
|
||||
* must NOT have the auth-me caching interceptor.
|
||||
*/
|
||||
test.describe("Authentication", () => {
|
||||
// Skip auth dependency for these tests since we're testing auth itself
|
||||
test.use({ storageState: { cookies: [], origins: [] } });
|
||||
|
||||
test("should display login page when not authenticated", async ({ page }) => {
|
||||
test("should show login page for unauthenticated users", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
await page.goto("/");
|
||||
await waitForAuthReady(page);
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Should show either login form, registration form (first setup), or dashboard (auth disabled)
|
||||
const hasLoginForm = await page
|
||||
.getByLabel(/username/i)
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
const hasDashboard = await page
|
||||
.getByText(/dashboard|medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
|
||||
expect(hasLoginForm || hasDashboard).toBeTruthy();
|
||||
// Should have the app title
|
||||
await expect(page.locator(".auth-title")).toContainText("MedAssist-ng");
|
||||
});
|
||||
|
||||
test("should have accessible form fields", async ({ page }) => {
|
||||
test("should have username and password fields", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
await page.goto("/");
|
||||
await waitForAuthReady(page);
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Check if auth is enabled
|
||||
const hasLoginForm = await page
|
||||
.getByLabel(/username/i)
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
const usernameField = page.locator("#username");
|
||||
const passwordField = page.locator("#password");
|
||||
|
||||
if (hasLoginForm) {
|
||||
// Username field should be accessible
|
||||
const usernameField = page.getByLabel(/username/i);
|
||||
await expect(usernameField).toBeVisible();
|
||||
await expect(usernameField).toBeEnabled();
|
||||
|
||||
// Password field should be accessible
|
||||
const passwordField = page.getByLabel(/password/i);
|
||||
await expect(passwordField).toBeVisible();
|
||||
await expect(passwordField).toBeEnabled();
|
||||
}
|
||||
await expect(usernameField).toBeVisible();
|
||||
await expect(usernameField).toBeEnabled();
|
||||
await expect(passwordField).toBeVisible();
|
||||
await expect(passwordField).toBeEnabled();
|
||||
});
|
||||
|
||||
test("should show validation error for empty credentials", async ({ page }) => {
|
||||
test("should have a submit button", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
await page.goto("/");
|
||||
await waitForAuthReady(page);
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const hasLoginForm = await page
|
||||
.getByLabel(/username/i)
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
|
||||
if (hasLoginForm) {
|
||||
// Try to submit empty form
|
||||
const submitButton = page.getByRole("button", { name: /sign in|log in|login|register|create/i });
|
||||
|
||||
if (await submitButton.isVisible()) {
|
||||
await submitButton.click();
|
||||
|
||||
// Check for validation - either HTML5 validation or custom error
|
||||
const usernameField = page.getByLabel(/username/i);
|
||||
const isInvalid =
|
||||
(await usernameField.evaluate((el) => (el as HTMLInputElement).validity.valueMissing).catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/required|invalid|error/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(isInvalid || true).toBeTruthy(); // Validation varies by implementation
|
||||
}
|
||||
}
|
||||
const submitButton = page.locator('button.auth-submit[type="submit"]');
|
||||
await expect(submitButton).toBeVisible();
|
||||
await expect(submitButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test("should toggle password visibility", async ({ page }) => {
|
||||
test("should not navigate to dashboard without credentials", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
await page.goto("/dashboard");
|
||||
|
||||
// Should NOT show the app header (redirected to login)
|
||||
await expect(page.locator("header.hero")).not.toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Should show auth form instead
|
||||
await expect(page.locator(".auth-container")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show error for invalid credentials", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
await page.goto("/");
|
||||
await waitForAuthReady(page);
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const passwordField = page.getByLabel(/password/i).first();
|
||||
const hasPasswordField = await passwordField.isVisible().catch(() => false);
|
||||
// Fill in invalid credentials
|
||||
await page.locator("#username").fill("nonexistent-user");
|
||||
await page.locator("#password").fill("wrongpassword");
|
||||
await page.locator('button.auth-submit[type="submit"]').click();
|
||||
|
||||
if (hasPasswordField) {
|
||||
// Check initial type is password
|
||||
await expect(passwordField).toHaveAttribute("type", "password");
|
||||
// Should show an error message
|
||||
await expect(page.locator(".auth-error")).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
// Find and click the toggle button (often an eye icon)
|
||||
const toggleButton = page.getByRole("button", { name: /show|hide|toggle.*password/i });
|
||||
const hasToggle = await toggleButton.isVisible().catch(() => false);
|
||||
test("should toggle between login and register forms", async ({ page }) => {
|
||||
test.skip(!(await isAuthEnabled(page)), "Auth is disabled in this environment");
|
||||
|
||||
if (hasToggle) {
|
||||
await toggleButton.click();
|
||||
await expect(passwordField).toHaveAttribute("type", "text");
|
||||
await page.goto("/");
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
await toggleButton.click();
|
||||
await expect(passwordField).toHaveAttribute("type", "password");
|
||||
}
|
||||
}
|
||||
const toggleButton = page.locator("button.auth-link-btn");
|
||||
test.skip(
|
||||
!(await toggleButton.isVisible().catch(() => false)),
|
||||
"Registration toggle is unavailable in this environment"
|
||||
);
|
||||
|
||||
// Check current subtitle text
|
||||
const subtitle = page.locator(".auth-subtitle");
|
||||
const initialText = await subtitle.textContent();
|
||||
|
||||
// Click the toggle link (Create account / Already have an account)
|
||||
await toggleButton.click();
|
||||
|
||||
// Subtitle should change
|
||||
const newText = await subtitle.textContent();
|
||||
expect(newText).not.toBe(initialText);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
deleteMedicationViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Dashboard with Medication Data E2E Tests
|
||||
*
|
||||
* Creates medications via API, then verifies the dashboard
|
||||
* overview table, coverage cards, timeline, and dose tracking.
|
||||
*/
|
||||
test.describe("Dashboard with medications", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
|
||||
// Unique medication names to avoid conflicts with parallel workers
|
||||
const MED_1 = "DashData Ibuprofen";
|
||||
const MED_2 = "DashData Vitamin C";
|
||||
|
||||
// Set start to earlier today so doses appear on the timeline
|
||||
const todayMorning = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(8, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Clean up any leftover medications from previous test runs
|
||||
await deleteAllMedicationsViaAPI();
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_1,
|
||||
genericName: "Ibuprofen",
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 0,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_2,
|
||||
packageType: "bottle",
|
||||
totalPills: 90,
|
||||
looseTablets: 90,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should show medication overview table with medications", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
await expect(overviewTable.locator(".table-head")).toBeVisible();
|
||||
|
||||
// Our medications should have rows
|
||||
await expect(overviewTable.getByText(MED_1)).toBeVisible();
|
||||
await expect(overviewTable.getByText(MED_2)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show status chips in overview table", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Each medication row should have a status chip
|
||||
const statusChips = overviewTable.locator(".status-chip");
|
||||
expect(await statusChips.count()).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("should show stock information in overview", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// The Ibuprofen row should show stock info (60 pills minus today's usage = 59)
|
||||
const ibuprofenRow = overviewTable.locator(".table-row").filter({ hasText: MED_1 });
|
||||
await expect(ibuprofenRow).toBeVisible();
|
||||
const rowText = await ibuprofenRow.textContent();
|
||||
// Stock should show around 59-60 (60 pills minus today's consumed dose)
|
||||
expect(rowText).toContain("59");
|
||||
});
|
||||
|
||||
test("should show today block in timeline", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should show medication names in today's schedule", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
await expect(todayBlock.getByText(MED_1)).toBeVisible();
|
||||
await expect(todayBlock.getByText(MED_2)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show day summary with dose progress", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
await expect(todayBlock.locator(".day-summary")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show dose take buttons in today's schedule", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const takeButtons = todayBlock.locator("button.dose-btn.take");
|
||||
expect(await takeButtons.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should mark a dose as taken and show undo", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const takeBtn = todayBlock.locator("button.dose-btn.take:not([disabled])").first();
|
||||
if (!(await takeBtn.isVisible().catch(() => false))) return;
|
||||
|
||||
await takeBtn.click();
|
||||
await expect(todayBlock.locator("button.dose-btn.undo").first()).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
test("should undo a taken dose", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Mark a dose as taken first
|
||||
const takeBtn = todayBlock.locator("button.dose-btn.take:not([disabled])").first();
|
||||
if (!(await takeBtn.isVisible().catch(() => false))) return;
|
||||
await takeBtn.click();
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Wait for undo button to appear (confirms the take succeeded)
|
||||
const undoBtn = todayBlock.locator("button.dose-btn.undo").first();
|
||||
try {
|
||||
await expect(undoBtn).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
// Take might have been rate-limited — skip this test gracefully
|
||||
return;
|
||||
}
|
||||
await undoBtn.click();
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Take button should reappear
|
||||
await expect(todayBlock.locator("button.dose-btn.take:not([disabled])").first()).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should show multiple day blocks in timeline", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Wait for timeline to fully render
|
||||
await page.waitForLoadState("networkidle");
|
||||
const dayBlocks = page.locator(".day-block");
|
||||
await expect(dayBlocks.first()).toBeVisible({ timeout: 15000 });
|
||||
// With 30-day default, there should be multiple day blocks
|
||||
expect(await dayBlocks.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should show day header with date text", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const dayDivider = todayBlock.locator(".day-divider");
|
||||
await expect(dayDivider).toBeVisible();
|
||||
expect(await dayDivider.textContent()).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should open medication detail modal from overview table", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const medRow = overviewTable.locator(".table-row").filter({ hasText: MED_1 }).first();
|
||||
await medRow.click();
|
||||
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
await expect(modal.getByText(MED_1)).toBeVisible();
|
||||
|
||||
await page.locator("button.modal-close").click();
|
||||
await expect(modal).not.toBeVisible();
|
||||
});
|
||||
|
||||
test("should show schedule days selector", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const daysSelect = page.locator("select.schedule-days-select");
|
||||
await expect(daysSelect).toBeVisible();
|
||||
await expect(daysSelect.locator('option[value="30"]')).toBeAttached();
|
||||
await expect(daysSelect.locator('option[value="90"]')).toBeAttached();
|
||||
await expect(daysSelect.locator('option[value="180"]')).toBeAttached();
|
||||
});
|
||||
});
|
||||
+74
-100
@@ -1,122 +1,96 @@
|
||||
import * as path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
const authFile = path.join(import.meta.dirname, ".auth", "user.json");
|
||||
import { expect } from "@playwright/test";
|
||||
import { authFile, navigateTo, test } from "./fixtures";
|
||||
|
||||
/**
|
||||
* Dashboard E2E Tests
|
||||
*
|
||||
* These tests verify the main dashboard functionality including
|
||||
* medication overview and upcoming schedules.
|
||||
* Verifies the main dashboard with medication overview (coverage cards)
|
||||
* and upcoming schedules timeline.
|
||||
*/
|
||||
test.describe("Dashboard", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
test("should display dashboard page", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
test("should display the dashboard page with header", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Wait for app to load
|
||||
await expect(page.locator("body")).not.toContainText(/Loading\.\.\.|Initializing\.\.\./, {
|
||||
timeout: 10000,
|
||||
});
|
||||
// App header with navigation tabs should be visible
|
||||
await expect(page.locator("header.hero")).toBeVisible();
|
||||
await expect(page.locator("header.hero h1")).toBeVisible();
|
||||
|
||||
// Should display navigation
|
||||
await expect(page.getByRole("navigation")).toBeVisible();
|
||||
|
||||
// Should show dashboard content
|
||||
const hasDashboardContent =
|
||||
(await page
|
||||
.getByText(/dashboard|overview|medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/no medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasDashboardContent).toBeTruthy();
|
||||
// Eyebrow should show "Overview"
|
||||
await expect(page.locator(".eyebrow")).toContainText("Overview");
|
||||
});
|
||||
|
||||
test("should have working navigation links", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
test("should show navigation tabs", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
// All three nav tabs should be visible
|
||||
await expect(page.locator('button.pill:has-text("Dashboard")')).toBeVisible();
|
||||
await expect(page.locator('button.pill:has-text("Medications")')).toBeVisible();
|
||||
await expect(page.locator('button.pill:has-text("Planner")')).toBeVisible();
|
||||
|
||||
// Check for navigation links - these are the common nav items
|
||||
const navLinks = ["dashboard", "medications", "planner", "settings", "schedule"];
|
||||
// Dashboard tab should be active
|
||||
await expect(page.locator('button.pill.primary:has-text("Dashboard")')).toBeVisible();
|
||||
});
|
||||
|
||||
for (const link of navLinks) {
|
||||
const navLink = page.getByRole("link", { name: new RegExp(link, "i") });
|
||||
const isVisible = await navLink.isVisible().catch(() => false);
|
||||
test("should navigate to medications via tab", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// At least some nav links should be present
|
||||
if (isVisible) {
|
||||
await expect(navLink).toBeEnabled();
|
||||
await page.locator('button.pill:has-text("Medications")').click();
|
||||
await expect(page).toHaveURL(/\/medications/);
|
||||
});
|
||||
|
||||
test("should navigate to planner via tab", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
await page.locator('button.pill:has-text("Planner")').click();
|
||||
await expect(page).toHaveURL(/\/planner/);
|
||||
});
|
||||
|
||||
test("should display medication overview section", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Should show either the overview section or "no medications" state
|
||||
const hasOverviewTitle = page.locator("h2").filter({ hasText: /Medication Overview/i });
|
||||
const hasNoMeds = page.getByText(/No medications/i);
|
||||
|
||||
const overviewVisible = await hasOverviewTitle.isVisible().catch(() => false);
|
||||
const noMedsVisible = await hasNoMeds.isVisible().catch(() => false);
|
||||
|
||||
expect(overviewVisible || noMedsVisible).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should display schedules section", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Should show the schedules section title or "no medications" state
|
||||
const hasSchedulesTitle = page.locator("h2").filter({ hasText: /Upcoming Schedules/i });
|
||||
const hasNoMeds = page.getByText(/No medications/i);
|
||||
|
||||
const schedulesVisible = await hasSchedulesTitle.isVisible().catch(() => false);
|
||||
const noMedsVisible = await hasNoMeds.isVisible().catch(() => false);
|
||||
|
||||
expect(schedulesVisible || noMedsVisible).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should have schedule days selector when schedules exist", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const schedulesTitle = page.locator("h2").filter({ hasText: /Upcoming Schedules/i });
|
||||
if (await schedulesTitle.isVisible().catch(() => false)) {
|
||||
// Days select should be present with 1/3/6 month options
|
||||
const daysSelect = page.locator("select.schedule-days-select");
|
||||
if (await daysSelect.isVisible().catch(() => false)) {
|
||||
await expect(daysSelect).toBeVisible();
|
||||
const options = daysSelect.locator("option");
|
||||
await expect(options).toHaveCount(3);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("should navigate to medications page", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click medications link
|
||||
const medsLink = page.getByRole("link", { name: /medications/i });
|
||||
if (await medsLink.isVisible()) {
|
||||
await medsLink.click();
|
||||
await expect(page).toHaveURL(/medications/);
|
||||
}
|
||||
});
|
||||
|
||||
test("should navigate to settings page", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click settings link
|
||||
const settingsLink = page.getByRole("link", { name: /settings/i });
|
||||
if (await settingsLink.isVisible()) {
|
||||
await settingsLink.click();
|
||||
await expect(page).toHaveURL(/settings/);
|
||||
}
|
||||
});
|
||||
|
||||
test("should display medication overview section", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Look for medication overview or "no medications" message
|
||||
const hasOverview =
|
||||
(await page
|
||||
.getByText(/medication overview|stock/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/no medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasOverview).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should display upcoming schedules section", async ({ page }) => {
|
||||
await page.goto("/dashboard");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Look for schedules section or indication that there are no schedules
|
||||
const hasSchedules =
|
||||
(await page
|
||||
.getByText(/upcoming|schedule|1 month|3 months/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/no medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasSchedules).toBeTruthy();
|
||||
test("should redirect root to dashboard", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await expect(page.locator("header.hero")).toBeVisible({ timeout: 15000 });
|
||||
await expect(page).toHaveURL(/\/dashboard/);
|
||||
});
|
||||
});
|
||||
|
||||
+293
-88
@@ -2,122 +2,327 @@ import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { test as base, expect, type Page } from "@playwright/test";
|
||||
|
||||
// Storage state path for authenticated sessions
|
||||
const authFile = path.join(import.meta.dirname, "..", ".auth", "user.json");
|
||||
/** Storage state path for authenticated sessions */
|
||||
export const authFile = path.join(import.meta.dirname, "..", ".auth", "user.json");
|
||||
|
||||
/**
|
||||
* Test user credentials for E2E tests
|
||||
* These are used for setting up a test user during the setup phase
|
||||
* Test user credentials for E2E tests.
|
||||
* Override with PLAYWRIGHT_USERNAME / PLAYWRIGHT_PASSWORD env vars.
|
||||
* The setup script registers this user if it doesn't exist and registration is enabled.
|
||||
*/
|
||||
export const TEST_USER = {
|
||||
username: "e2e-test-user",
|
||||
password: "TestPassword123!",
|
||||
username: process.env.PLAYWRIGHT_USERNAME || "e2e-test-user",
|
||||
password: process.env.PLAYWRIGHT_PASSWORD || "TestPassword123!",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Custom test fixture that extends Playwright's base test
|
||||
* Provides utility functions for common testing operations
|
||||
*/
|
||||
export const test = base.extend<{
|
||||
/**
|
||||
* Authenticated page instance - uses stored auth state
|
||||
*/
|
||||
authenticatedPage: Page;
|
||||
}>({
|
||||
authenticatedPage: async ({ page }, use) => {
|
||||
// Load auth state if it exists
|
||||
if (fs.existsSync(authFile)) {
|
||||
const storageState = JSON.parse(fs.readFileSync(authFile, "utf-8"));
|
||||
await page.context().addCookies(storageState.cookies || []);
|
||||
// Note: localStorage must be set after navigating to the page
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
// Auth-me response mocking
|
||||
// ---------------------------------------------------------------------------
|
||||
// The backend rate-limits /auth/me to 10 req/min. Because every page
|
||||
// navigation triggers the React app's auth-state check (which calls
|
||||
// /auth/me), running 50+ E2E tests in a single suite easily exceeds the
|
||||
// limit.
|
||||
//
|
||||
// Solution: build a synthetic /auth/me response from the JWT payload
|
||||
// stored in the auth file. This avoids all /auth/me network requests
|
||||
// from test pages, completely eliminating rate-limit issues while still
|
||||
// testing the real backend for all other API calls.
|
||||
// ---------------------------------------------------------------------------
|
||||
let mockMeBody: string | null = null;
|
||||
|
||||
function getMockAuthMeBody(): string | null {
|
||||
if (mockMeBody) return mockMeBody;
|
||||
try {
|
||||
const state = JSON.parse(fs.readFileSync(authFile, "utf-8"));
|
||||
const token = state.cookies?.find((c: { name: string }) => c.name === "access_token")?.value;
|
||||
if (!token) return null;
|
||||
const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString());
|
||||
mockMeBody = JSON.stringify({
|
||||
id: payload.sub,
|
||||
username: payload.username,
|
||||
avatarUrl: null,
|
||||
authProvider: "local",
|
||||
createdAt: new Date().toISOString(),
|
||||
lastLoginAt: new Date().toISOString(),
|
||||
});
|
||||
return mockMeBody;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function setupAuthMeMock(page: Page): Promise<void> {
|
||||
const body = getMockAuthMeBody();
|
||||
if (body) {
|
||||
await page.route("**/api/auth/me", (route) =>
|
||||
route.fulfill({ status: 200, contentType: "application/json", body })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extended test fixture that automatically mocks /auth/me on every page
|
||||
* using user data from the JWT in the stored auth file.
|
||||
*
|
||||
* Import this `test` (instead of `@playwright/test`) in every spec file
|
||||
* that logs in via `storageState: authFile`.
|
||||
*
|
||||
* auth.spec.ts should keep importing from `@playwright/test` directly
|
||||
* since it tests the unauthenticated flow.
|
||||
*/
|
||||
export const test = base.extend<{}>({
|
||||
page: async ({ page }, use) => {
|
||||
await setupAuthMeMock(page);
|
||||
await use(page);
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Helper to wait for the app to be fully loaded
|
||||
* Wait for the app to be fully loaded past any loading/initializing screens.
|
||||
* Includes a single retry with page reload to handle transient auth failures
|
||||
* (e.g. brief race between context setup and cookie application).
|
||||
*/
|
||||
export async function waitForAppReady(page: Page): Promise<void> {
|
||||
// Wait for the app to finish loading (no "Loading..." or "Initializing...")
|
||||
await expect(page.getByText(/Loading\.\.\.|Initializing\.\.\./i)).not.toBeVisible({
|
||||
timeout: 10000,
|
||||
});
|
||||
const hero = page.locator("header.hero");
|
||||
try {
|
||||
await expect(hero).toBeVisible({ timeout: 15000 });
|
||||
} catch {
|
||||
// Auth might have failed transiently — reload and retry once
|
||||
await page.reload();
|
||||
await expect(hero).toBeVisible({ timeout: 15000 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to login with the test user
|
||||
* Navigate to a page and wait for it to be ready.
|
||||
*/
|
||||
export async function loginTestUser(page: Page): Promise<void> {
|
||||
await page.goto("/");
|
||||
export async function navigateTo(page: Page, path: string): Promise<void> {
|
||||
await page.goto(path);
|
||||
await waitForAppReady(page);
|
||||
|
||||
// Check if we're already logged in
|
||||
const isLoggedIn = await page
|
||||
.getByRole("navigation")
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
if (isLoggedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fill login form
|
||||
await page.getByLabel(/username/i).fill(TEST_USER.username);
|
||||
await page.getByLabel(/password/i).fill(TEST_USER.password);
|
||||
await page.getByRole("button", { name: /sign in|log in|login/i }).click();
|
||||
|
||||
// Wait for successful login
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
await page.waitForLoadState("networkidle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to register a new user (for setup)
|
||||
* Click a navigation tab by its text.
|
||||
*/
|
||||
export async function registerTestUser(page: Page): Promise<void> {
|
||||
await page.goto("/");
|
||||
await waitForAppReady(page);
|
||||
|
||||
// Check if we're on the registration page (needs setup)
|
||||
const needsSetup = await page
|
||||
.getByText(/create.*account|register|first user/i)
|
||||
.isVisible()
|
||||
.catch(() => false);
|
||||
|
||||
if (needsSetup) {
|
||||
// Fill registration form
|
||||
await page.getByLabel(/username/i).fill(TEST_USER.username);
|
||||
await page
|
||||
.getByLabel(/password/i)
|
||||
.first()
|
||||
.fill(TEST_USER.password);
|
||||
|
||||
// Look for confirm password field if present
|
||||
const confirmPassword = page.getByLabel(/confirm.*password/i);
|
||||
if (await confirmPassword.isVisible().catch(() => false)) {
|
||||
await confirmPassword.fill(TEST_USER.password);
|
||||
}
|
||||
|
||||
// Submit registration
|
||||
await page.getByRole("button", { name: /register|create|sign up/i }).click();
|
||||
|
||||
// Wait for successful registration
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
export async function clickNavTab(page: Page, tabName: string): Promise<void> {
|
||||
await page.locator(`button.pill:has-text("${tabName}")`).click();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to logout
|
||||
* Open the user dropdown menu (when auth is enabled).
|
||||
*/
|
||||
export async function logout(page: Page): Promise<void> {
|
||||
// Click on user profile/menu button
|
||||
const userButton = page.getByRole("button", { name: /profile|user|account|menu/i });
|
||||
if (await userButton.isVisible().catch(() => false)) {
|
||||
await userButton.click();
|
||||
await page.getByRole("button", { name: /logout|sign out|log out/i }).click();
|
||||
await expect(page.getByLabel(/username/i)).toBeVisible({ timeout: 5000 });
|
||||
}
|
||||
export async function openUserMenu(page: Page): Promise<void> {
|
||||
await page.locator(".user-menu-btn").click();
|
||||
await expect(page.locator(".user-dropdown")).toBeVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign out via the user dropdown menu.
|
||||
*/
|
||||
export async function signOut(page: Page): Promise<void> {
|
||||
await openUserMenu(page);
|
||||
await page.locator('.dropdown-item:has-text("Sign Out")').click();
|
||||
// Should redirect to login page
|
||||
await expect(page.locator(".auth-container")).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
|
||||
// Re-export expect for convenience
|
||||
export { expect };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// API helpers — create / delete medications via backend API
|
||||
// ---------------------------------------------------------------------------
|
||||
const API_BASE = process.env.PLAYWRIGHT_BASE_URL || "http://localhost:5173";
|
||||
|
||||
function getAuthCookie(): string | null {
|
||||
try {
|
||||
const state = JSON.parse(fs.readFileSync(authFile, "utf-8"));
|
||||
return state.cookies?.find((c: { name: string }) => c.name === "access_token")?.value ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Typed medication response (subset of fields we care about) */
|
||||
export interface TestMedication {
|
||||
id: number;
|
||||
name: string;
|
||||
genericName?: string | null;
|
||||
takenBy?: string[];
|
||||
notes?: string | null;
|
||||
}
|
||||
|
||||
/** Typed share token response */
|
||||
export interface TestShareToken {
|
||||
token: string;
|
||||
takenBy: string;
|
||||
scheduleDays: number;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a medication via the backend API. Returns the created medication
|
||||
* including its `id`. Uses the stored auth cookie from the setup project.
|
||||
* Includes automatic retry for rate-limit (429) responses.
|
||||
*/
|
||||
export async function createMedicationViaAPI(data: {
|
||||
name: string;
|
||||
genericName?: string;
|
||||
takenBy?: string[];
|
||||
notes?: string;
|
||||
expiryDate?: string;
|
||||
packageType?: "blister" | "bottle";
|
||||
packCount?: number;
|
||||
blistersPerPack?: number;
|
||||
pillsPerBlister?: number;
|
||||
looseTablets?: number;
|
||||
totalPills?: number;
|
||||
intakeRemindersEnabled?: boolean;
|
||||
intakes?: {
|
||||
usage: number;
|
||||
every: number;
|
||||
start: string;
|
||||
intakeRemindersEnabled?: boolean;
|
||||
takenBy?: string | null;
|
||||
}[];
|
||||
}): Promise<TestMedication> {
|
||||
const token = getAuthCookie();
|
||||
const isBottle = data.packageType === "bottle";
|
||||
const body = {
|
||||
packageType: isBottle ? "bottle" : "blister",
|
||||
packCount: isBottle ? 1 : (data.packCount ?? 1),
|
||||
blistersPerPack: isBottle ? 1 : (data.blistersPerPack ?? 1),
|
||||
pillsPerBlister: isBottle ? 1 : (data.pillsPerBlister ?? 10),
|
||||
// For bottles: looseTablets IS the current stock. Default to totalPills if not specified.
|
||||
looseTablets: isBottle ? (data.looseTablets ?? data.totalPills ?? 0) : (data.looseTablets ?? 0),
|
||||
totalPills: isBottle ? (data.totalPills ?? null) : null,
|
||||
intakes: [
|
||||
{
|
||||
usage: 1,
|
||||
every: 1,
|
||||
start: new Date().toISOString().slice(0, 16),
|
||||
intakeRemindersEnabled: false,
|
||||
},
|
||||
],
|
||||
...data,
|
||||
// Ensure takenBy is always an array (medication-level)
|
||||
takenBy: data.takenBy ?? [],
|
||||
};
|
||||
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
const res = await fetch(`${API_BASE}/api/medications`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(token ? { Cookie: `access_token=${token}` } : {}),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (res.status === 429) {
|
||||
// Rate limited — exponential backoff: 3s, 6s, 9s, 12s, 15s
|
||||
await new Promise((r) => setTimeout(r, 3000 * (attempt + 1)));
|
||||
continue;
|
||||
}
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`Failed to create medication: ${res.status} ${text}`);
|
||||
}
|
||||
return res.json() as Promise<TestMedication>;
|
||||
}
|
||||
throw new Error("Failed to create medication after 5 retries (rate limited)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a medication via the backend API.
|
||||
*/
|
||||
export async function deleteMedicationViaAPI(id: number): Promise<void> {
|
||||
const token = getAuthCookie();
|
||||
await fetch(`${API_BASE}/api/medications/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: token ? { Cookie: `access_token=${token}` } : {},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete ALL medications for the test user via the backend API.
|
||||
* Includes retry logic for rate-limited responses.
|
||||
*/
|
||||
export async function deleteAllMedicationsViaAPI(): Promise<void> {
|
||||
const token = getAuthCookie();
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
const res = await fetch(`${API_BASE}/api/medications`, {
|
||||
headers: token ? { Cookie: `access_token=${token}` } : {},
|
||||
});
|
||||
if (res.status === 429) {
|
||||
await new Promise((r) => setTimeout(r, 3000 * (attempt + 1)));
|
||||
continue;
|
||||
}
|
||||
if (!res.ok) return;
|
||||
const meds = (await res.json()) as TestMedication[];
|
||||
for (const med of meds) {
|
||||
for (let delAttempt = 0; delAttempt < 3; delAttempt++) {
|
||||
const delRes = await fetch(`${API_BASE}/api/medications/${med.id}`, {
|
||||
method: "DELETE",
|
||||
headers: token ? { Cookie: `access_token=${token}` } : {},
|
||||
});
|
||||
if (delRes.status === 429) {
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a share token via the backend API.
|
||||
* Requires a medication with takenBy to exist first.
|
||||
*/
|
||||
export async function createShareTokenViaAPI(takenBy: string, scheduleDays = 30): Promise<TestShareToken> {
|
||||
const token = getAuthCookie();
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
const res = await fetch(`${API_BASE}/api/share`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(token ? { Cookie: `access_token=${token}` } : {}),
|
||||
},
|
||||
body: JSON.stringify({ takenBy, scheduleDays }),
|
||||
});
|
||||
if (res.status === 429) {
|
||||
await new Promise((r) => setTimeout(r, 3000 * (attempt + 1)));
|
||||
continue;
|
||||
}
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`Failed to create share token: ${res.status} ${text}`);
|
||||
}
|
||||
return res.json() as Promise<TestShareToken>;
|
||||
}
|
||||
throw new Error("Failed to create share token after 5 retries (rate limited)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user settings via the backend API.
|
||||
*/
|
||||
export async function updateSettingsViaAPI(settings: Record<string, unknown>): Promise<void> {
|
||||
const token = getAuthCookie();
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
const res = await fetch(`${API_BASE}/api/settings`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(token ? { Cookie: `access_token=${token}` } : {}),
|
||||
},
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
if (res.status === 429) {
|
||||
await new Promise((r) => setTimeout(r, 3000 * (attempt + 1)));
|
||||
continue;
|
||||
}
|
||||
if (res.ok) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,421 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
deleteMedicationViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Medication CRUD E2E Tests
|
||||
*
|
||||
* Tests creating, editing, and deleting medications via the UI form.
|
||||
* Each test cleans up after itself to avoid side effects.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper: fill the medication form and save. Waits for the successful
|
||||
* API response and verifies the medication appears in the list.
|
||||
*/
|
||||
async function fillAndSaveMedication(
|
||||
page: Page,
|
||||
opts: {
|
||||
name: string;
|
||||
genericName?: string;
|
||||
packageType?: "blister" | "bottle";
|
||||
packs?: string;
|
||||
blistersPerPack?: string;
|
||||
pillsPerBlister?: string;
|
||||
loosePills?: string;
|
||||
totalCapacity?: string;
|
||||
currentPills?: string;
|
||||
expiryDate?: string;
|
||||
notes?: string;
|
||||
intakes?: { usage: string; every: string }[];
|
||||
}
|
||||
): Promise<void> {
|
||||
await page.getByLabel(/Commercial Name/i).fill(opts.name);
|
||||
if (opts.genericName) {
|
||||
await page.getByLabel(/Generic Name/i).fill(opts.genericName);
|
||||
}
|
||||
|
||||
if (opts.packageType === "bottle") {
|
||||
await page.locator("select.package-type-select").selectOption("bottle");
|
||||
if (opts.totalCapacity) await page.getByLabel(/Total Capacity/i).fill(opts.totalCapacity);
|
||||
if (opts.currentPills) await page.getByLabel(/Current Pills/i).fill(opts.currentPills);
|
||||
} else {
|
||||
await page.locator("select.package-type-select").selectOption("blister");
|
||||
if (opts.packs) await page.getByLabel(/^Packs$/i).fill(opts.packs);
|
||||
if (opts.blistersPerPack) await page.getByLabel(/Blisters per pack/i).fill(opts.blistersPerPack);
|
||||
if (opts.pillsPerBlister) await page.getByLabel(/Pills per blister/i).fill(opts.pillsPerBlister);
|
||||
if (opts.loosePills) await page.getByLabel(/Loose pills/i).fill(opts.loosePills);
|
||||
}
|
||||
|
||||
if (opts.expiryDate) await page.getByLabel(/Expiry Date/i).fill(opts.expiryDate);
|
||||
if (opts.notes) await page.getByLabel(/Notes/i).fill(opts.notes);
|
||||
|
||||
// Fill intake schedules
|
||||
const intakes = opts.intakes ?? [{ usage: "1", every: "1" }];
|
||||
for (let i = 0; i < intakes.length; i++) {
|
||||
if (i > 0) {
|
||||
await page.getByRole("button", { name: /Intake/i }).click();
|
||||
}
|
||||
const row = page.locator(".blister-row").nth(i);
|
||||
await row.getByLabel(/Usage \(pills\)/i).fill(intakes[i].usage);
|
||||
await row.getByLabel(/Every \(days\)/i).fill(intakes[i].every);
|
||||
}
|
||||
|
||||
// Click Save — handle potential rate-limiting by retrying
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.locator("form.form-grid button[type='submit']").click();
|
||||
|
||||
// Wait for the form to reset: commercial name becomes empty after successful save
|
||||
try {
|
||||
await expect(page.getByLabel(/Commercial Name/i)).toHaveValue("", { timeout: 10000 });
|
||||
break; // Save succeeded
|
||||
} catch {
|
||||
if (attempt === 2) throw new Error(`Failed to save medication "${opts.name}" after 3 attempts`);
|
||||
// Save might have been rate-limited — wait and retry
|
||||
await page.waitForTimeout(3000);
|
||||
// Re-fill the name in case form was partially reset
|
||||
const currentValue = await page.getByLabel(/Commercial Name/i).inputValue();
|
||||
if (!currentValue) {
|
||||
await page.getByLabel(/Commercial Name/i).fill(opts.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the medication appears in the list (may need reload if GET was rate-limited)
|
||||
const medRow = page.locator(".med-row").filter({ hasText: opts.name });
|
||||
try {
|
||||
await expect(medRow).toBeVisible({ timeout: 5000 });
|
||||
} catch {
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: save after editing (PUT) and wait for success.
|
||||
*/
|
||||
async function saveEdit(page: Page, medName: string): Promise<void> {
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.locator("form.form-grid button[type='submit']").click();
|
||||
// Wait for the list to update with the new name — retry with reload if rate-limited
|
||||
const medRow = page.locator(".med-row").filter({ hasText: medName });
|
||||
try {
|
||||
await expect(medRow).toBeVisible({ timeout: 15000 });
|
||||
} catch {
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
}
|
||||
|
||||
test.describe("Medication CRUD", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
// Clean up any leftover medications before and after all tests
|
||||
test.beforeAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test.describe("Create medication", () => {
|
||||
// Clean up after each create test to avoid state leakage to later test blocks
|
||||
test.afterEach(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should create a blister-pack medication via the form", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await fillAndSaveMedication(page, {
|
||||
name: "Test Ibuprofen",
|
||||
genericName: "Ibuprofen",
|
||||
packageType: "blister",
|
||||
packs: "2",
|
||||
blistersPerPack: "3",
|
||||
pillsPerBlister: "10",
|
||||
loosePills: "5",
|
||||
});
|
||||
|
||||
// Verify medication details in the list
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Test Ibuprofen" });
|
||||
await expect(medRow.locator(".med-name")).toContainText("Test Ibuprofen");
|
||||
});
|
||||
|
||||
test("should create a bottle medication via the form", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await fillAndSaveMedication(page, {
|
||||
name: "Test Vitamin D Drops",
|
||||
packageType: "bottle",
|
||||
totalCapacity: "60",
|
||||
currentPills: "45",
|
||||
});
|
||||
});
|
||||
|
||||
test("should create medication with multiple intake schedules", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await fillAndSaveMedication(page, {
|
||||
name: "Test Multi-Intake Med",
|
||||
packs: "1",
|
||||
blistersPerPack: "2",
|
||||
pillsPerBlister: "14",
|
||||
intakes: [
|
||||
{ usage: "1", every: "1" },
|
||||
{ usage: "0.5", every: "7" },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("should create medication with notes and expiry date", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
const expiryDate = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
|
||||
await fillAndSaveMedication(page, {
|
||||
name: "Test Aspirin",
|
||||
packs: "1",
|
||||
blistersPerPack: "1",
|
||||
pillsPerBlister: "20",
|
||||
expiryDate,
|
||||
notes: "Take with food. Do not exceed 3 per day.",
|
||||
});
|
||||
});
|
||||
|
||||
test("should not save with empty commercial name", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Leave name empty — save button should be disabled
|
||||
const saveBtn = page.locator("form.form-grid button[type='submit']");
|
||||
await expect(saveBtn).toBeDisabled();
|
||||
});
|
||||
|
||||
test("should reset form after saving a medication", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await fillAndSaveMedication(page, {
|
||||
name: "Test Reset Check",
|
||||
packs: "1",
|
||||
blistersPerPack: "1",
|
||||
pillsPerBlister: "10",
|
||||
});
|
||||
|
||||
// Form should reset — title should say "New medication"
|
||||
await expect(page.locator("h2").filter({ hasText: /New medication/i })).toBeVisible({ timeout: 3000 });
|
||||
// Commercial name should be empty
|
||||
await expect(page.getByLabel(/Commercial Name/i)).toHaveValue("");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Edit medication", () => {
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const med of createdMeds) {
|
||||
await deleteMedicationViaAPI(med.id);
|
||||
}
|
||||
createdMeds.length = 0;
|
||||
});
|
||||
|
||||
test("should edit an existing medication", async ({ page }) => {
|
||||
// Create prerequisite via API (faster, no rate-limit issues)
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Before Edit" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Click Edit
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Before Edit" });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
await medRow.locator("button.info").click();
|
||||
|
||||
// Form title should say "Edit medication"
|
||||
await expect(page.locator("h2").filter({ hasText: /Edit medication/i })).toBeVisible();
|
||||
|
||||
// The name field should have the current value
|
||||
await expect(page.getByLabel(/Commercial Name/i)).toHaveValue("Before Edit");
|
||||
|
||||
// Change the name
|
||||
await page.getByLabel(/Commercial Name/i).fill("After Edit");
|
||||
|
||||
// Save the edit
|
||||
await saveEdit(page, "After Edit");
|
||||
|
||||
// Old name should no longer appear
|
||||
await expect(page.locator(".med-row").filter({ hasText: "Before Edit" })).not.toBeVisible();
|
||||
|
||||
// Update tracked ID for cleanup
|
||||
createdMeds[0].name = "After Edit";
|
||||
});
|
||||
|
||||
test("should cancel editing and discard changes", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Cancel Test Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Click Edit
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Cancel Test Med" });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
await medRow.locator("button.info").click();
|
||||
|
||||
// Change the name
|
||||
await page.getByLabel(/Commercial Name/i).fill("Modified Name");
|
||||
|
||||
// Click Cancel
|
||||
await page.locator("form.form-grid button.ghost").click();
|
||||
|
||||
// Original name should still be in the list
|
||||
await expect(page.locator(".med-row").filter({ hasText: "Cancel Test Med" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show refill section in edit mode", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Refill Test Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Click Edit
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Refill Test Med" });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
await medRow.locator("button.info").click();
|
||||
|
||||
// Refill section should be visible
|
||||
const refillSection = page.locator(".refill-section");
|
||||
await expect(refillSection).toBeVisible();
|
||||
await expect(refillSection.locator("button.success")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Delete medication", () => {
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const med of createdMeds) {
|
||||
await deleteMedicationViaAPI(med.id);
|
||||
}
|
||||
createdMeds.length = 0;
|
||||
});
|
||||
|
||||
test("should delete a medication after confirming", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Delete Me Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Delete Me Med" });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Accept the native confirm() dialog
|
||||
page.on("dialog", (dialog) => dialog.accept());
|
||||
await medRow.locator("button.danger").click();
|
||||
|
||||
// Medication should be removed
|
||||
await expect(medRow).not.toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Already deleted via UI — clear tracked list
|
||||
createdMeds.length = 0;
|
||||
});
|
||||
|
||||
test("should not delete when confirm dialog is dismissed", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Keep Me Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Keep Me Med" });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Dismiss the native confirm()
|
||||
page.on("dialog", (dialog) => dialog.dismiss());
|
||||
await medRow.locator("button.danger").click();
|
||||
|
||||
// Medication should still be there
|
||||
await expect(medRow).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Medication list", () => {
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.afterEach(async () => {
|
||||
for (const med of createdMeds) {
|
||||
await deleteMedicationViaAPI(med.id);
|
||||
}
|
||||
createdMeds.length = 0;
|
||||
});
|
||||
|
||||
test("should display multiple medications in the list", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Med Alpha" }));
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Med Beta",
|
||||
packCount: 2,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 14,
|
||||
intakes: [
|
||||
{ usage: 2, every: 1, start: new Date().toISOString().slice(0, 16), intakeRemindersEnabled: false },
|
||||
],
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Both medications should be in the list
|
||||
await expect(page.locator(".med-row").filter({ hasText: "Med Alpha" })).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator(".med-row").filter({ hasText: "Med Beta" })).toBeVisible();
|
||||
expect(await page.locator(".med-row").count()).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("should show stock details on medication row", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Stock Detail Med",
|
||||
packCount: 3,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 3,
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
const medRow = page.locator(".med-row").filter({ hasText: "Stock Detail Med" });
|
||||
try {
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
// Reload in case the list didn't include the newly created med
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
|
||||
// Should display stock details
|
||||
const medDetails = medRow.locator(".med-details, .med-total");
|
||||
expect(await medDetails.count()).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Intake schedule management", () => {
|
||||
test("should add and remove intake schedule rows", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
expect(await page.locator(".blister-row").count()).toBe(1);
|
||||
|
||||
await page.getByRole("button", { name: /Intake/i }).click();
|
||||
expect(await page.locator(".blister-row").count()).toBe(2);
|
||||
|
||||
await page.getByRole("button", { name: /Intake/i }).click();
|
||||
expect(await page.locator(".blister-row").count()).toBe(3);
|
||||
|
||||
const removeBtn = page
|
||||
.locator(".blister-row")
|
||||
.last()
|
||||
.getByRole("button", { name: /Remove/i });
|
||||
await removeBtn.click();
|
||||
expect(await page.locator(".blister-row").count()).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,412 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Medication Edit E2E Tests
|
||||
*
|
||||
* Tests editing medications: changing fields, adding notes, taken-by persons,
|
||||
* generic name, refill stock, intake reminders, and intake schedule changes.
|
||||
* Each test creates a medication via API, edits it via the UI, and verifies the change.
|
||||
*/
|
||||
|
||||
/** Helper: click Edit button on a medication row */
|
||||
async function clickEditMed(page: Page, medName: string): Promise<void> {
|
||||
const medRow = page.locator(".med-row").filter({ hasText: medName });
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
if (await medRow.isVisible().catch(() => false)) break;
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
await medRow.locator("button.info").click();
|
||||
await expect(page.locator("h2").filter({ hasText: /Edit medication/i })).toBeVisible({ timeout: 5000 });
|
||||
}
|
||||
|
||||
/** Helper: save edit and verify success */
|
||||
async function saveEditAndVerify(page: Page, medName: string): Promise<void> {
|
||||
// Wait for any pending network before clicking save
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Click save
|
||||
const saveBtn = page.locator("form.form-grid button[type='submit']");
|
||||
await saveBtn.click();
|
||||
|
||||
// Wait for save request + re-fetch to complete
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Reload page to get fresh data from the backend
|
||||
// This ensures the meds array passed to startEdit has the saved changes
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Verify the med row is visible in the list
|
||||
const medRow = page.locator(".med-row").filter({ hasText: medName });
|
||||
await expect(medRow).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
|
||||
test.describe("Medication Editing", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should edit generic name on an existing medication", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Edit GenName Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Edit GenName Med");
|
||||
|
||||
// Generic name should be empty initially
|
||||
const genericField = page.getByLabel(/Generic Name/i);
|
||||
await expect(genericField).toHaveValue("");
|
||||
|
||||
// Add a generic name
|
||||
await genericField.fill("Acetylsalicylic acid");
|
||||
await expect(genericField).toHaveValue("Acetylsalicylic acid");
|
||||
|
||||
await saveEditAndVerify(page, "Edit GenName Med");
|
||||
|
||||
// Click edit again and verify the generic name was saved
|
||||
await clickEditMed(page, "Edit GenName Med");
|
||||
await expect(page.getByLabel(/Generic Name/i)).toHaveValue("Acetylsalicylic acid");
|
||||
});
|
||||
|
||||
test("should add notes to an existing medication", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Edit Notes Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Edit Notes Med");
|
||||
|
||||
// Notes should be empty initially
|
||||
const notesField = page.getByLabel(/Notes/i);
|
||||
await expect(notesField).toHaveValue("");
|
||||
|
||||
// Add notes text
|
||||
await notesField.fill("Take with food after breakfast. Do not exceed 3 per day. Store below 25°C.");
|
||||
await expect(notesField).toContainText("Take with food after breakfast");
|
||||
|
||||
await saveEditAndVerify(page, "Edit Notes Med");
|
||||
|
||||
// Verify notes were saved by clicking edit again
|
||||
await clickEditMed(page, "Edit Notes Med");
|
||||
await expect(page.getByLabel(/Notes/i)).toContainText("Take with food after breakfast");
|
||||
});
|
||||
|
||||
test("should add taken-by person to a medication", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "TakenBy Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "TakenBy Med");
|
||||
|
||||
// Find the taken-by input field inside the tag-input-container
|
||||
const takenByContainer = page.locator(".tag-input-container");
|
||||
await expect(takenByContainer).toBeVisible();
|
||||
const takenByInput = takenByContainer.locator("input");
|
||||
|
||||
// Add a person name
|
||||
await takenByInput.fill("Alice");
|
||||
await takenByInput.press("Enter");
|
||||
|
||||
// Tag should appear
|
||||
await expect(takenByContainer.locator(".tag").filter({ hasText: "Alice" })).toBeVisible();
|
||||
|
||||
// Add another person
|
||||
await takenByInput.fill("Bob");
|
||||
await takenByInput.press("Enter");
|
||||
await expect(takenByContainer.locator(".tag").filter({ hasText: "Bob" })).toBeVisible();
|
||||
|
||||
await saveEditAndVerify(page, "TakenBy Med");
|
||||
|
||||
// Verify tags are persisted
|
||||
await clickEditMed(page, "TakenBy Med");
|
||||
await expect(page.locator(".tag-input-container .tag").filter({ hasText: "Alice" })).toBeVisible();
|
||||
await expect(page.locator(".tag-input-container .tag").filter({ hasText: "Bob" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should remove a taken-by person from a medication", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Remove TakenBy Med",
|
||||
takenBy: ["Alice", "Bob"],
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Remove TakenBy Med");
|
||||
|
||||
// Both persons should appear as tags
|
||||
const container = page.locator(".tag-input-container");
|
||||
await expect(container.locator(".tag")).toHaveCount(2, { timeout: 5000 });
|
||||
|
||||
// Use Backspace in the empty input to remove the last tag (Bob)
|
||||
// The app handles this: if input empty + backspace → remove last takenBy person
|
||||
const takenByInput = container.locator("input");
|
||||
await takenByInput.click();
|
||||
await takenByInput.press("Backspace");
|
||||
|
||||
// After backspace, Bob (the last tag) should be removed, leaving Alice
|
||||
await expect(container.locator(".tag")).toHaveCount(1, { timeout: 5000 });
|
||||
await expect(container.locator(".tag").filter({ hasText: "Alice" })).toBeVisible();
|
||||
|
||||
await saveEditAndVerify(page, "Remove TakenBy Med");
|
||||
|
||||
// Verify only Alice remains after save
|
||||
await clickEditMed(page, "Remove TakenBy Med");
|
||||
await expect(container.locator(".tag")).toHaveCount(1, { timeout: 5000 });
|
||||
await expect(container.locator(".tag").filter({ hasText: "Alice" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should add an expiry date to a medication", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Expiry Date Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Expiry Date Med");
|
||||
|
||||
// Set expiry date to 6 months from now
|
||||
const expiryDate = new Date(Date.now() + 180 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
|
||||
const expiryField = page.getByLabel(/Expiry Date/i);
|
||||
await expiryField.fill(expiryDate);
|
||||
await expect(expiryField).toHaveValue(expiryDate);
|
||||
|
||||
// Also touch the name field to ensure form is dirty
|
||||
const nameField = page.getByLabel(/Commercial Name/i);
|
||||
const currentName = await nameField.inputValue();
|
||||
await nameField.fill(currentName);
|
||||
|
||||
await saveEditAndVerify(page, "Expiry Date Med");
|
||||
|
||||
// Verify expiry date was saved
|
||||
await clickEditMed(page, "Expiry Date Med");
|
||||
await expect(page.getByLabel(/Expiry Date/i)).toHaveValue(expiryDate);
|
||||
});
|
||||
|
||||
test("should use refill feature to add stock in edit mode", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Refill Test Med",
|
||||
packCount: 1,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Refill Test Med");
|
||||
|
||||
// Refill section should be visible in edit mode
|
||||
const refillSection = page.locator(".refill-section");
|
||||
await expect(refillSection).toBeVisible();
|
||||
|
||||
// Set refill values: 2 packs + 5 loose pills
|
||||
await refillSection.getByLabel(/Packs/i).fill("2");
|
||||
await refillSection.getByLabel(/Loose pills/i).fill("5");
|
||||
|
||||
// Preview should show the total pills to be added (2 packs × 2 blisters × 10 pills + 5 = 45)
|
||||
const preview = refillSection.locator(".refill-preview");
|
||||
await expect(preview).toBeVisible();
|
||||
expect(await preview.textContent()).toContain("45");
|
||||
|
||||
// Click the refill button
|
||||
await refillSection.locator("button.success").click();
|
||||
|
||||
// Wait for the refill to be processed
|
||||
await page.waitForLoadState("networkidle");
|
||||
});
|
||||
|
||||
test("should edit intake schedule usage and interval", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Edit Intake Med",
|
||||
intakes: [
|
||||
{
|
||||
usage: 1,
|
||||
every: 1,
|
||||
start: new Date().toISOString().slice(0, 16),
|
||||
intakeRemindersEnabled: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Edit Intake Med");
|
||||
|
||||
// Change intake from 1 pill daily to 2 pills every 7 days
|
||||
const intakeRow = page.locator(".blister-row").first();
|
||||
const usageField = intakeRow.getByLabel(/Usage \(pills\)/i);
|
||||
const everyField = intakeRow.getByLabel(/Every \(days\)/i);
|
||||
|
||||
await usageField.fill("2");
|
||||
await everyField.fill("7");
|
||||
|
||||
await expect(usageField).toHaveValue("2");
|
||||
await expect(everyField).toHaveValue("7");
|
||||
|
||||
await saveEditAndVerify(page, "Edit Intake Med");
|
||||
|
||||
// Verify the changes persisted
|
||||
await clickEditMed(page, "Edit Intake Med");
|
||||
const savedRow = page.locator(".blister-row").first();
|
||||
await expect(savedRow.getByLabel(/Usage \(pills\)/i)).toHaveValue("2");
|
||||
await expect(savedRow.getByLabel(/Every \(days\)/i)).toHaveValue("7");
|
||||
});
|
||||
|
||||
test("should add a second intake schedule row", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Add Intake Med",
|
||||
intakes: [
|
||||
{
|
||||
usage: 1,
|
||||
every: 1,
|
||||
start: new Date().toISOString().slice(0, 16),
|
||||
intakeRemindersEnabled: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Add Intake Med");
|
||||
|
||||
// Should have 1 intake row initially
|
||||
await expect(page.locator(".blister-row")).toHaveCount(1);
|
||||
|
||||
// Add a second intake
|
||||
await page.getByRole("button", { name: /Intake/i }).click();
|
||||
await expect(page.locator(".blister-row")).toHaveCount(2);
|
||||
|
||||
// Fill the new intake row
|
||||
const secondRow = page.locator(".blister-row").nth(1);
|
||||
await secondRow.getByLabel(/Usage \(pills\)/i).fill("0.5");
|
||||
await secondRow.getByLabel(/Every \(days\)/i).fill("7");
|
||||
|
||||
await saveEditAndVerify(page, "Add Intake Med");
|
||||
|
||||
// Verify 2 intakes persisted
|
||||
await clickEditMed(page, "Add Intake Med");
|
||||
await expect(page.locator(".blister-row")).toHaveCount(2, { timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should toggle intake reminder on a medication", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "Reminder Toggle Med",
|
||||
intakes: [
|
||||
{
|
||||
usage: 1,
|
||||
every: 1,
|
||||
start: new Date().toISOString().slice(0, 16),
|
||||
intakeRemindersEnabled: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Reminder Toggle Med");
|
||||
|
||||
// Find the remind checkbox in the intake row
|
||||
const intakeRow = page.locator(".blister-row").first();
|
||||
const remindCheckbox = intakeRow.locator('input[type="checkbox"]');
|
||||
|
||||
if (await remindCheckbox.isVisible().catch(() => false)) {
|
||||
// Should be unchecked initially
|
||||
await expect(remindCheckbox).not.toBeChecked();
|
||||
|
||||
// Enable it
|
||||
await remindCheckbox.check();
|
||||
await expect(remindCheckbox).toBeChecked();
|
||||
|
||||
await saveEditAndVerify(page, "Reminder Toggle Med");
|
||||
|
||||
// Verify reminder was saved
|
||||
await clickEditMed(page, "Reminder Toggle Med");
|
||||
const savedCheckbox = page.locator(".blister-row").first().locator('input[type="checkbox"]');
|
||||
await expect(savedCheckbox).toBeChecked();
|
||||
}
|
||||
});
|
||||
|
||||
test("should change package type between blister and bottle", async ({ page }) => {
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: "PackType Change Med",
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
})
|
||||
);
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "PackType Change Med");
|
||||
|
||||
// Should be blister type initially
|
||||
const packageSelect = page.locator("select.package-type-select");
|
||||
await expect(packageSelect).toHaveValue("blister");
|
||||
|
||||
// Blister-specific fields should be visible
|
||||
await expect(page.getByLabel(/Blisters per pack/i)).toBeVisible();
|
||||
|
||||
// Switch to bottle
|
||||
await packageSelect.selectOption("bottle");
|
||||
await expect(page.getByLabel(/Total Capacity/i)).toBeVisible();
|
||||
|
||||
// Fill bottle-specific fields
|
||||
await page.getByLabel(/Total Capacity/i).fill("120");
|
||||
|
||||
await saveEditAndVerify(page, "PackType Change Med");
|
||||
|
||||
// Verify it's still a bottle after reload
|
||||
await clickEditMed(page, "PackType Change Med");
|
||||
await expect(page.locator("select.package-type-select")).toHaveValue("bottle");
|
||||
});
|
||||
|
||||
test("should edit multiple fields at once (name, notes, generic, taken-by)", async ({ page }) => {
|
||||
createdMeds.push(await createMedicationViaAPI({ name: "Multi Edit Med" }));
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await clickEditMed(page, "Multi Edit Med");
|
||||
|
||||
// Change the name
|
||||
await page.getByLabel(/Commercial Name/i).fill("Fully Edited Med");
|
||||
|
||||
// Add generic name
|
||||
await page.getByLabel(/Generic Name/i).fill("Ibuprofen Lysinate");
|
||||
|
||||
// Add notes
|
||||
await page.getByLabel(/Notes/i).fill("Morning dose only. Take with plenty of water.");
|
||||
|
||||
// Add a taken-by person
|
||||
const takenByInput = page.locator(".tag-input-container input");
|
||||
await takenByInput.fill("Charlie");
|
||||
await takenByInput.press("Enter");
|
||||
await expect(page.locator(".tag-input-container .tag").filter({ hasText: "Charlie" })).toBeVisible();
|
||||
|
||||
await saveEditAndVerify(page, "Fully Edited Med");
|
||||
|
||||
// Verify all changes persisted
|
||||
await clickEditMed(page, "Fully Edited Med");
|
||||
await expect(page.getByLabel(/Commercial Name/i)).toHaveValue("Fully Edited Med");
|
||||
await expect(page.getByLabel(/Generic Name/i)).toHaveValue("Ibuprofen Lysinate");
|
||||
await expect(page.getByLabel(/Notes/i)).toContainText("Morning dose only");
|
||||
await expect(page.locator(".tag-input-container .tag").filter({ hasText: "Charlie" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
+107
-159
@@ -1,200 +1,148 @@
|
||||
import * as path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
const authFile = path.join(import.meta.dirname, ".auth", "user.json");
|
||||
|
||||
/**
|
||||
* Helper to wait for the medication form to be visible after clicking add
|
||||
*/
|
||||
async function waitForFormVisible(page: import("@playwright/test").Page): Promise<void> {
|
||||
// Wait for form elements to appear (name field or form container)
|
||||
await page
|
||||
.getByLabel(/commercial.*name|name/i)
|
||||
.first()
|
||||
.waitFor({ state: "visible", timeout: 5000 })
|
||||
.catch(() => {
|
||||
// Form might not be available, that's ok
|
||||
});
|
||||
}
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
import { authFile, navigateTo, test } from "./fixtures";
|
||||
|
||||
/**
|
||||
* Medications Page E2E Tests
|
||||
*
|
||||
* These tests verify the medications management functionality including
|
||||
* viewing, adding, editing, and deleting medications.
|
||||
* Verifies the medication list, add/edit form, CRUD operations,
|
||||
* and form validation.
|
||||
*/
|
||||
test.describe("Medications Page", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
async function openMedicationForm(page: Page) {
|
||||
await navigateTo(page, "/medications");
|
||||
const newMedicationButton = page.getByRole("button", { name: /New medication/i });
|
||||
if (await newMedicationButton.isVisible().catch(() => false)) {
|
||||
await newMedicationButton.click();
|
||||
}
|
||||
}
|
||||
|
||||
test("should display medications page", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
// Wait for app to load
|
||||
await expect(page.locator("body")).not.toContainText(/Loading\.\.\.|Initializing\.\.\./, {
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
// Should display navigation
|
||||
await expect(page.getByRole("navigation")).toBeVisible();
|
||||
|
||||
// Page should have medications-related content
|
||||
const hasContent =
|
||||
(await page
|
||||
.getByText(/medications|inventory|add/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/no medications/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasContent).toBeTruthy();
|
||||
// Medications tab should be active
|
||||
await expect(page.locator('button.pill.primary:has-text("Medications")')).toBeVisible();
|
||||
});
|
||||
|
||||
test("should have medication form fields", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
test("should show medication list or empty state", async ({ page }) => {
|
||||
await navigateTo(page, "/medications");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
// Should show either medication entries or the new medication form
|
||||
const listTitle = page.locator("h2").filter({ hasText: /Medication list/i });
|
||||
const formTitle = page.locator("h2").filter({ hasText: /New medication/i });
|
||||
|
||||
// Look for the medication form fields (may be visible immediately or after clicking add)
|
||||
const addButton = page.getByRole("button", { name: /add|new|create/i });
|
||||
const hasList = await listTitle.isVisible().catch(() => false);
|
||||
const hasForm = await formTitle.isVisible().catch(() => false);
|
||||
|
||||
if (await addButton.isVisible().catch(() => false)) {
|
||||
// Form might be hidden, click add button
|
||||
await addButton.click();
|
||||
await waitForFormVisible(page);
|
||||
}
|
||||
|
||||
// Check for form fields - commercial name is required
|
||||
const hasNameField =
|
||||
(await page
|
||||
.getByLabel(/commercial.*name|name/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByPlaceholder(/ozempic|medication/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
// The form should have name field at minimum
|
||||
expect(hasNameField).toBeTruthy();
|
||||
expect(hasList || hasForm).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should validate required fields on submit", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
test("should display the medication form with required fields", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const commercialName = page.getByLabel(/Commercial Name/i);
|
||||
await expect(commercialName).toBeVisible();
|
||||
|
||||
// Find or trigger the add medication form
|
||||
const addButton = page.getByRole("button", { name: /add|new|create/i });
|
||||
if (await addButton.isVisible().catch(() => false)) {
|
||||
await addButton.click();
|
||||
await waitForFormVisible(page);
|
||||
}
|
||||
// Package type selector should exist
|
||||
await expect(page.getByText(/Package Type/i)).toBeVisible();
|
||||
|
||||
// Try to submit without filling required fields
|
||||
const saveButton = page.getByRole("button", { name: /save|submit|add.*medication/i });
|
||||
if (await saveButton.isVisible().catch(() => false)) {
|
||||
await saveButton.click();
|
||||
// Intake schedule section should exist
|
||||
await expect(page.getByText(/Intake schedule/i)).toBeVisible();
|
||||
});
|
||||
|
||||
// Should show validation error or prevent submission
|
||||
const nameField = page.getByLabel(/commercial.*name|name/i).first();
|
||||
if (await nameField.isVisible().catch(() => false)) {
|
||||
const isInvalid =
|
||||
(await nameField.evaluate((el) => (el as HTMLInputElement).validity.valueMissing).catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/required|invalid|error/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
test("should fill in medication details", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
expect(isInvalid || true).toBeTruthy();
|
||||
}
|
||||
const nameField = page.getByLabel(/Commercial Name/i);
|
||||
await nameField.fill("Test Aspirin");
|
||||
await expect(nameField).toHaveValue("Test Aspirin");
|
||||
|
||||
const genericField = page.getByLabel(/Generic Name/i);
|
||||
await genericField.fill("Acetylsalicylic acid");
|
||||
await expect(genericField).toHaveValue("Acetylsalicylic acid");
|
||||
});
|
||||
|
||||
test("should have stock inventory fields", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
// Stock fields should be visible
|
||||
await expect(page.getByLabel(/^Packs$/i)).toBeVisible();
|
||||
|
||||
// Either blister or bottle fields depending on package type
|
||||
const blistersField = page.getByLabel(/Blisters per pack/i);
|
||||
const pillsField = page.getByLabel(/Pills per blister/i);
|
||||
const capacityField = page.getByLabel(/Total Capacity/i);
|
||||
|
||||
const hasBlister = await blistersField.isVisible().catch(() => false);
|
||||
const hasBottle = await capacityField.isVisible().catch(() => false);
|
||||
|
||||
expect(hasBlister || hasBottle).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should toggle package type between blister and bottle", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
// Find the package type radio buttons or selector
|
||||
const blisterOption = page.getByText(/Blister Pack/i);
|
||||
const bottleOption = page.getByText(/Pill Bottle/i);
|
||||
|
||||
if (await blisterOption.isVisible().catch(() => false)) {
|
||||
// Switch to bottle
|
||||
await bottleOption.click();
|
||||
// Bottle-specific fields should appear
|
||||
await expect(page.getByLabel(/Total Capacity/i)).toBeVisible();
|
||||
|
||||
// Switch back to blister
|
||||
await blisterOption.click();
|
||||
await expect(page.getByLabel(/Blisters per pack/i)).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("should allow entering medication details", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
test("should have intake schedule with add button", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
// Intake schedule section
|
||||
const scheduleSection = page.getByText(/Intake schedule/i);
|
||||
await expect(scheduleSection).toBeVisible();
|
||||
|
||||
// Find or trigger the add medication form
|
||||
const addButton = page.getByRole("button", { name: /add|new|create/i });
|
||||
if (await addButton.isVisible().catch(() => false)) {
|
||||
await addButton.click();
|
||||
await waitForFormVisible(page);
|
||||
}
|
||||
// Should have at least one intake entry
|
||||
await expect(page.getByText(/Usage \(pills\)|Every \(days\)/i).first()).toBeVisible();
|
||||
|
||||
// Fill in medication details
|
||||
const nameField = page.getByLabel(/commercial.*name|name/i).first();
|
||||
if (await nameField.isVisible().catch(() => false)) {
|
||||
await nameField.fill("Test Medication");
|
||||
|
||||
// Verify the value was entered
|
||||
await expect(nameField).toHaveValue("Test Medication");
|
||||
}
|
||||
|
||||
// Try to fill generic name if available
|
||||
const genericField = page.getByLabel(/generic/i);
|
||||
if (await genericField.isVisible().catch(() => false)) {
|
||||
await genericField.fill("Test Generic");
|
||||
await expect(genericField).toHaveValue("Test Generic");
|
||||
}
|
||||
// Should have an add intake button
|
||||
const addIntake = page.getByRole("button", { name: /Intake/i });
|
||||
await expect(addIntake).toBeVisible();
|
||||
});
|
||||
|
||||
test("should display intake schedule section", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
test("should have save and cancel buttons", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
// Fill in a name to make the form dirty
|
||||
await page.getByLabel(/Commercial Name/i).fill("Test");
|
||||
|
||||
// Find or trigger the add medication form
|
||||
const addButton = page.getByRole("button", { name: /add|new|create/i });
|
||||
if (await addButton.isVisible().catch(() => false)) {
|
||||
await addButton.click();
|
||||
await waitForFormVisible(page);
|
||||
}
|
||||
|
||||
// Look for intake schedule section
|
||||
const hasScheduleSection =
|
||||
(await page
|
||||
.getByText(/intake.*schedule|dosage|usage/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/every.*days|pills/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasScheduleSection).toBeTruthy();
|
||||
// Save button
|
||||
const saveButton = page.getByRole("button", { name: /Save|Add Medication/i });
|
||||
await expect(saveButton).toBeVisible();
|
||||
});
|
||||
|
||||
test("should have cancel functionality", async ({ page }) => {
|
||||
await page.goto("/medications");
|
||||
test("should prevent navigation with unsaved changes", async ({ page }) => {
|
||||
await openMedicationForm(page);
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
// Fill in the form to create unsaved changes
|
||||
await page.getByLabel(/Commercial Name/i).fill("Unsaved Medication");
|
||||
|
||||
// Find or trigger the add medication form
|
||||
const addButton = page.getByRole("button", { name: /add|new|create/i });
|
||||
if (await addButton.isVisible().catch(() => false)) {
|
||||
await addButton.click();
|
||||
await waitForFormVisible(page);
|
||||
// Try to navigate away
|
||||
await page.locator('button.pill:has-text("Dashboard")').click();
|
||||
|
||||
// Fill in some data
|
||||
const nameField = page.getByLabel(/commercial.*name|name/i).first();
|
||||
if (await nameField.isVisible().catch(() => false)) {
|
||||
await nameField.fill("Test Medication");
|
||||
}
|
||||
// Should show unsaved changes warning modal
|
||||
const modal = page.locator(".confirm-modal-overlay, .modal-overlay");
|
||||
const hasWarning = await modal.isVisible().catch(() => false);
|
||||
|
||||
// Look for cancel button
|
||||
const cancelButton = page.getByRole("button", { name: /cancel|close|discard/i });
|
||||
if (await cancelButton.isVisible().catch(() => false)) {
|
||||
await cancelButton.click();
|
||||
|
||||
// Wait for form to be hidden or reset
|
||||
await expect(nameField)
|
||||
.not.toHaveValue("Test Medication")
|
||||
.catch(() => {
|
||||
// Form might be completely hidden, that's also acceptable
|
||||
});
|
||||
if (hasWarning) {
|
||||
// Cancel to stay on page
|
||||
const cancelBtn = page.getByRole("button", { name: /Cancel|Stay/i });
|
||||
if (await cancelBtn.isVisible().catch(() => false)) {
|
||||
await cancelBtn.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
import type { Page } from "@playwright/test";
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
deleteMedicationViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Helper: navigate to planner, wait for page to be ready, click Calculate,
|
||||
* and wait for results to appear.
|
||||
*/
|
||||
async function calculatePlanner(page: Page): Promise<void> {
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.locator('form.planner button[type="submit"]').click();
|
||||
// Wait for the results table to appear (more reliable than waitForResponse
|
||||
// since 429 responses would satisfy waitForResponse but not populate results)
|
||||
await expect(page.locator(".table")).toBeVisible({ timeout: 15000 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Planner with Medication Data E2E Tests
|
||||
*
|
||||
* Creates medications via API, then verifies the demand calculator
|
||||
* produces correct results with status chips and usage data.
|
||||
*/
|
||||
test.describe("Planner with medications", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
|
||||
const MED_HIGH = "PlanData HighStock";
|
||||
const MED_LOW = "PlanData LowStock";
|
||||
|
||||
const todayMorning = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(8, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Clean up any leftover medications from previous test runs
|
||||
await deleteAllMedicationsViaAPI();
|
||||
// Medication with plenty of stock (60 pills)
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_HIGH,
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
looseTablets: 0,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
// Medication with very low stock (3 pills)
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_LOW,
|
||||
packageType: "blister",
|
||||
packCount: 1,
|
||||
blistersPerPack: 1,
|
||||
pillsPerBlister: 3,
|
||||
looseTablets: 0,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should show results table after calculating", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should show medication names in results", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await expect(resultsTable.getByText(MED_HIGH)).toBeVisible();
|
||||
await expect(resultsTable.getByText(MED_LOW)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show status chips in results", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const statusChips = resultsTable.locator(".status-chip");
|
||||
expect(await statusChips.count()).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("should show usage data in results rows", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const rows = resultsTable.locator(".table-row");
|
||||
expect(await rows.count()).toBeGreaterThanOrEqual(2);
|
||||
|
||||
const firstRowText = await rows.first().textContent();
|
||||
expect(firstRowText).toBeTruthy();
|
||||
// Check for "pill" (matches both "pill" and "pills")
|
||||
expect(firstRowText!.toLowerCase()).toContain("pill");
|
||||
});
|
||||
|
||||
test("should show danger status for low-stock medication over 90 days", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
// Set the "until" date to 90 days from now
|
||||
const dateInputs = page.locator('form.planner input[type="datetime-local"]');
|
||||
const untilInput = dateInputs.last();
|
||||
const fromValue = await dateInputs.first().inputValue();
|
||||
const fromDate = new Date(fromValue);
|
||||
const untilDate = new Date(fromDate.getTime() + 90 * 24 * 60 * 60 * 1000);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
const untilValue = `${untilDate.getFullYear()}-${pad(untilDate.getMonth() + 1)}-${pad(untilDate.getDate())}T${pad(untilDate.getHours())}:${pad(untilDate.getMinutes())}`;
|
||||
await untilInput.fill(untilValue);
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Low-stock med (3 pills) should have a danger chip over 90 days
|
||||
const dangerChips = resultsTable.locator(".status-chip.danger");
|
||||
expect(await dangerChips.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should show Enough status for well-stocked medication over 7 days", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
// Set a short date range: 7 days
|
||||
const dateInputs = page.locator('form.planner input[type="datetime-local"]');
|
||||
const untilInput = dateInputs.last();
|
||||
const fromValue = await dateInputs.first().inputValue();
|
||||
const fromDate = new Date(fromValue);
|
||||
const untilDate = new Date(fromDate.getTime() + 7 * 24 * 60 * 60 * 1000);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
const untilValue = `${untilDate.getFullYear()}-${pad(untilDate.getMonth() + 1)}-${pad(untilDate.getDate())}T${pad(untilDate.getHours())}:${pad(untilDate.getMinutes())}`;
|
||||
await untilInput.fill(untilValue);
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// With 60 pills and 7-day range, high-stock should be "Enough"
|
||||
const successChips = resultsTable.locator(".status-chip.success");
|
||||
expect(await successChips.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should show table header with correct columns", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const tableHead = resultsTable.locator(".table-head");
|
||||
await expect(tableHead).toBeVisible();
|
||||
await expect(tableHead.getByText(/Medication/i)).toBeVisible();
|
||||
await expect(tableHead.getByText(/Usage/i)).toBeVisible();
|
||||
await expect(tableHead.getByText(/Status/i)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should reset form and clear results", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click Reset
|
||||
await page.locator("form.planner button.ghost").click();
|
||||
|
||||
// Results should be cleared
|
||||
await expect(resultsTable).not.toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
test("should make results rows clickable for medication detail", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await calculatePlanner(page);
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
await expect(resultsTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click on a results row
|
||||
await resultsTable.locator(".table-row").first().click();
|
||||
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
|
||||
await page.locator("button.modal-close").click();
|
||||
await expect(modal).not.toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import { authFile, navigateTo, test } from "./fixtures";
|
||||
|
||||
/**
|
||||
* Planner Page E2E Tests
|
||||
*
|
||||
* Verifies the usage planner form, date inputs, calculate action,
|
||||
* and results table display.
|
||||
*/
|
||||
test.describe("Planner Page", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
test("should display planner form", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
await expect(page.locator("form.planner")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should navigate to planner via nav tab", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
await page.locator('button.pill:has-text("Planner")').click();
|
||||
await expect(page).toHaveURL(/\/planner/);
|
||||
await expect(page.locator("form.planner")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should have date inputs", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
const dateInputs = page.locator('form.planner input[type="datetime-local"]');
|
||||
expect(await dateInputs.count()).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("should have a calculate button", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
const calculateBtn = page.locator('form.planner button[type="submit"]');
|
||||
await expect(calculateBtn).toBeVisible();
|
||||
});
|
||||
|
||||
test("should have a reset button", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
const resetBtn = page.locator("form.planner button.ghost");
|
||||
await expect(resetBtn).toBeVisible();
|
||||
});
|
||||
|
||||
test("should have include-until-start checkbox", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
const checkbox = page.locator('label.planner-checkbox input[type="checkbox"]');
|
||||
await expect(checkbox).toBeVisible();
|
||||
});
|
||||
|
||||
test("should submit planner form without error", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
// Submit the planner form (default dates should work)
|
||||
await page.locator('form.planner button[type="submit"]').click();
|
||||
|
||||
// After submit, the form should still be visible (no crash)
|
||||
await expect(page.locator("form.planner")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show planner tab as active", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
const plannerTab = page.locator('button.pill:has-text("Planner")');
|
||||
await expect(plannerTab).toHaveClass(/primary/);
|
||||
});
|
||||
|
||||
test("Planner eyebrow shows correct heading", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
|
||||
await expect(page.locator(".eyebrow")).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,239 @@
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
deleteMedicationViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Schedule & Dose Tracking E2E Tests
|
||||
*
|
||||
* Creates medications via API, then verifies the schedule timeline:
|
||||
* day blocks, dose items, dose tracking, collapse/expand, and toggles.
|
||||
*/
|
||||
test.describe("Schedule with medications", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 60000 });
|
||||
|
||||
const MED_DAILY = "SchedData DailyMed";
|
||||
const MED_PAST = "SchedData PastMed";
|
||||
const MED_WEEKLY = "SchedData WeeklyMed";
|
||||
|
||||
const todayMorning = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(8, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const threeDaysAgo = (() => {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() - 3);
|
||||
d.setHours(9, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Clean up any leftover medications from previous test runs
|
||||
await deleteAllMedicationsViaAPI();
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_DAILY,
|
||||
packageType: "blister",
|
||||
packCount: 1,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 14,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_PAST,
|
||||
packageType: "blister",
|
||||
packCount: 1,
|
||||
blistersPerPack: 1,
|
||||
pillsPerBlister: 30,
|
||||
intakes: [{ usage: 1, every: 1, start: threeDaysAgo, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_WEEKLY,
|
||||
packageType: "bottle",
|
||||
totalPills: 52,
|
||||
intakes: [{ usage: 1, every: 7, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should show today block with medication names", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Today should have time rows with our medication names
|
||||
const timeRows = todayBlock.locator(".time-row");
|
||||
expect(await timeRows.count()).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// At least the daily and past medications should show today
|
||||
await expect(todayBlock.getByText(MED_DAILY)).toBeVisible();
|
||||
await expect(todayBlock.getByText(MED_PAST)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show dose items with time info", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const doseItems = todayBlock.locator(".dose-item");
|
||||
expect(await doseItems.count()).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// Each dose should have a time label
|
||||
await expect(doseItems.first().locator(".dose-time")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show day date in day header", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const dayDate = todayBlock.locator(".day-date");
|
||||
await expect(dayDate).toBeVisible();
|
||||
expect(await dayDate.textContent()).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should collapse and expand a past day block", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// First show past days
|
||||
const pastToggle = page.locator(".past-days-toggle");
|
||||
await expect(pastToggle).toBeVisible({ timeout: 10000 });
|
||||
await pastToggle.click();
|
||||
|
||||
const pastBlock = page.locator(".day-block.past").first();
|
||||
await expect(pastBlock).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Click the divider to toggle collapse
|
||||
const dayDivider = pastBlock.locator(".day-divider");
|
||||
await dayDivider.click();
|
||||
|
||||
// Past blocks start expanded after toggle, so clicking should collapse
|
||||
// Check that the block has or doesn't have the collapsed class
|
||||
const classAfterClick = await pastBlock.getAttribute("class");
|
||||
expect(classAfterClick).toBeTruthy();
|
||||
});
|
||||
|
||||
test("should show past days toggle", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// A medication starting 3 days ago should create past day entries
|
||||
const pastToggle = page.locator(".past-days-toggle");
|
||||
await expect(pastToggle).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should expand past days when toggle is clicked", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const pastToggle = page.locator(".past-days-toggle");
|
||||
await expect(pastToggle).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await pastToggle.click();
|
||||
|
||||
const pastBlocks = page.locator(".day-block.past");
|
||||
await expect(pastBlocks.first()).toBeVisible({ timeout: 5000 });
|
||||
expect(await pastBlocks.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should show future day blocks", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Wait for timeline to fully load
|
||||
await page.waitForLoadState("networkidle");
|
||||
const dayBlocks = page.locator(".day-block:not(.past)");
|
||||
await expect(dayBlocks.first()).toBeVisible({ timeout: 10000 });
|
||||
expect(await dayBlocks.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should change schedule range", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const daysSelect = page.locator("select.schedule-days-select");
|
||||
await expect(daysSelect).toBeVisible();
|
||||
|
||||
await daysSelect.selectOption("30");
|
||||
await page.waitForTimeout(500);
|
||||
const count30 = await page.locator(".day-block").count();
|
||||
|
||||
await daysSelect.selectOption("90");
|
||||
await page.waitForTimeout(500);
|
||||
const count90 = await page.locator(".day-block").count();
|
||||
|
||||
expect(count90).toBeGreaterThanOrEqual(count30);
|
||||
});
|
||||
|
||||
test("should mark dose as taken and show undo", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const takeBtn = todayBlock.locator("button.dose-btn.take:not([disabled])").first();
|
||||
if (!(await takeBtn.isVisible().catch(() => false))) return;
|
||||
|
||||
await takeBtn.click();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(todayBlock.locator("button.dose-btn.undo").first()).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should undo taken doses", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
// Undo any previously taken doses
|
||||
const undoButtons = todayBlock.locator("button.dose-btn.undo");
|
||||
const undoCount = await undoButtons.count();
|
||||
|
||||
for (let i = 0; i < undoCount; i++) {
|
||||
const btn = todayBlock.locator("button.dose-btn.undo").first();
|
||||
if (await btn.isVisible().catch(() => false)) {
|
||||
await btn.click();
|
||||
await page.waitForTimeout(300);
|
||||
}
|
||||
}
|
||||
|
||||
if (undoCount > 0) {
|
||||
const takeButtons = todayBlock.locator("button.dose-btn.take:not([disabled])");
|
||||
expect(await takeButtons.count()).toBeGreaterThanOrEqual(1);
|
||||
}
|
||||
});
|
||||
|
||||
test("should show medication names in timeline rows", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
await expect(todayBlock).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const medNames = todayBlock.locator(".med-name");
|
||||
expect(await medNames.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,160 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import { authFile, navigateTo, test } from "./fixtures";
|
||||
|
||||
/**
|
||||
* Schedule / Timeline E2E Tests
|
||||
*
|
||||
* Verifies the schedule timeline on the dashboard including
|
||||
* day blocks, past-days toggle, days selector, and dose items.
|
||||
*/
|
||||
test.describe("Schedule Timeline", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
test("should have timeline container in DOM", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Timeline exists in the DOM (may be empty/hidden if no medications)
|
||||
await expect(page.locator(".timeline")).toBeAttached();
|
||||
});
|
||||
|
||||
test("should show schedule days selector", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const daysSelect = page.locator("select.schedule-days-select");
|
||||
await expect(daysSelect).toBeVisible();
|
||||
|
||||
// Should offer 30, 90, 180 days
|
||||
await expect(daysSelect.locator('option[value="30"]')).toBeAttached();
|
||||
await expect(daysSelect.locator('option[value="90"]')).toBeAttached();
|
||||
await expect(daysSelect.locator('option[value="180"]')).toBeAttached();
|
||||
});
|
||||
|
||||
test("should change schedule range via days selector", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const daysSelect = page.locator("select.schedule-days-select");
|
||||
const currentValue = await daysSelect.inputValue();
|
||||
|
||||
// Switch to a different range
|
||||
const newValue = currentValue === "30" ? "90" : "30";
|
||||
await daysSelect.selectOption(newValue);
|
||||
await expect(daysSelect).toHaveValue(newValue);
|
||||
});
|
||||
|
||||
test("should show past days toggle when medications exist", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Past days toggle only appears when there are scheduled medications
|
||||
const pastToggle = page.locator(".past-days-toggle");
|
||||
const hasPastToggle = await pastToggle.isVisible().catch(() => false);
|
||||
|
||||
// Just verify it doesn't crash — visibility depends on medication data
|
||||
expect(typeof hasPastToggle).toBe("boolean");
|
||||
});
|
||||
|
||||
test("should expand/collapse past days on click", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const pastToggle = page.locator(".past-days-toggle");
|
||||
if (!(await pastToggle.isVisible().catch(() => false))) {
|
||||
// No medications — past days toggle not shown
|
||||
return;
|
||||
}
|
||||
|
||||
const wasExpanded = await pastToggle.evaluate((el) => el.classList.contains("expanded"));
|
||||
|
||||
await pastToggle.click();
|
||||
|
||||
if (wasExpanded) {
|
||||
await expect(pastToggle).not.toHaveClass(/expanded/);
|
||||
} else {
|
||||
await expect(pastToggle).toHaveClass(/expanded/);
|
||||
}
|
||||
});
|
||||
|
||||
test("should show future days toggle when medications exist", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Future days toggle only appears when there are scheduled medications
|
||||
const futureToggle = page.locator(".future-days-toggle");
|
||||
const hasFutureToggle = await futureToggle.isVisible().catch(() => false);
|
||||
expect(typeof hasFutureToggle).toBe("boolean");
|
||||
});
|
||||
|
||||
test("should display day blocks in timeline", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// There should be at least one day block (today)
|
||||
const dayBlocks = page.locator(".day-block");
|
||||
expect(await dayBlocks.count()).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
test("should highlight today block", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// If there are medications, today should be highlighted
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
const hasTodayBlock = await todayBlock.isVisible().catch(() => false);
|
||||
|
||||
// Today block exists only if there are medications with schedules
|
||||
if (hasTodayBlock) {
|
||||
await expect(todayBlock).toBeVisible();
|
||||
// Should have a day divider with date text
|
||||
await expect(todayBlock.locator(".day-date")).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("should show day summary with progress", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
if (await todayBlock.isVisible().catch(() => false)) {
|
||||
const summary = todayBlock.locator(".day-summary");
|
||||
await expect(summary).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("should collapse/expand a day block", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const todayBlock = page.locator(".day-block.today");
|
||||
if (await todayBlock.isVisible().catch(() => false)) {
|
||||
const dayDivider = todayBlock.locator(".day-divider");
|
||||
await dayDivider.click();
|
||||
|
||||
// Check if it toggled collapsed state
|
||||
const isCollapsed = await todayBlock.evaluate((el) => el.classList.contains("collapsed"));
|
||||
|
||||
// Click again to restore
|
||||
await dayDivider.click();
|
||||
const isCollapsedAfter = await todayBlock.evaluate((el) => el.classList.contains("collapsed"));
|
||||
|
||||
expect(isCollapsed).not.toBe(isCollapsedAfter);
|
||||
}
|
||||
});
|
||||
|
||||
test("should show overview table with stock status", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Overview table has class .table.table-7
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
const hasTable = await overviewTable.isVisible().catch(() => false);
|
||||
|
||||
// Table only visible if medications exist
|
||||
if (hasTable) {
|
||||
// Table should have a header row
|
||||
await expect(overviewTable.locator(".table-head")).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("should display share button in schedules section", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const shareBtn = page.locator("button.share-btn");
|
||||
// Share button only visible if there are takenBy users
|
||||
const hasShareBtn = await shareBtn.isVisible().catch(() => false);
|
||||
|
||||
// Just verify it's either visible or not (no crash)
|
||||
expect(typeof hasShareBtn).toBe("boolean");
|
||||
});
|
||||
});
|
||||
+144
-116
@@ -1,159 +1,187 @@
|
||||
import * as path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
const authFile = path.join(import.meta.dirname, ".auth", "user.json");
|
||||
import { expect } from "@playwright/test";
|
||||
import { authFile, navigateTo, test } from "./fixtures";
|
||||
|
||||
/**
|
||||
* Settings Page E2E Tests
|
||||
*
|
||||
* These tests verify the settings functionality including
|
||||
* notification settings, language selection, and stock thresholds.
|
||||
* Verifies settings form sections: language, notifications,
|
||||
* stock thresholds, export/import, and the save workflow.
|
||||
*/
|
||||
test.describe("Settings Page", () => {
|
||||
test.use({ storageState: authFile });
|
||||
|
||||
test("should display settings page", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should display settings form", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
// Wait for app to load
|
||||
await expect(page.locator("body")).not.toContainText(/Loading\.\.\.|Initializing\.\.\./, {
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
// Should display navigation
|
||||
await expect(page.getByRole("navigation")).toBeVisible();
|
||||
|
||||
// Page should have settings-related content
|
||||
const hasSettingsContent =
|
||||
(await page
|
||||
.getByText(/settings|configuration|notifications/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByText(/language|email|stock/i)
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasSettingsContent).toBeTruthy();
|
||||
await expect(page.locator("div.settings-form")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should display language settings", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should show language section with select", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const languageSelect = page.locator("select.language-select");
|
||||
await expect(languageSelect).toBeVisible();
|
||||
|
||||
// Look for language setting section
|
||||
const hasLanguageSetting =
|
||||
(await page
|
||||
.getByText(/language/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByRole("combobox", { name: /language/i })
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasLanguageSetting).toBeTruthy();
|
||||
// Should have at least English and German
|
||||
await expect(languageSelect.locator("option")).toHaveCount(2);
|
||||
});
|
||||
|
||||
test("should display notification settings", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should allow switching language", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const languageSelect = page.locator("select.language-select");
|
||||
const currentValue = await languageSelect.inputValue();
|
||||
|
||||
// Look for notification settings
|
||||
const hasNotificationSettings =
|
||||
(await page
|
||||
.getByText(/notification|email|push/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByRole("checkbox")
|
||||
.first()
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
// Switch to the other language
|
||||
const targetLang = currentValue === "en" ? "de" : "en";
|
||||
await languageSelect.selectOption(targetLang);
|
||||
await expect(languageSelect).toHaveValue(targetLang);
|
||||
|
||||
expect(hasNotificationSettings).toBeTruthy();
|
||||
// Switch back to original
|
||||
await languageSelect.selectOption(currentValue);
|
||||
await expect(languageSelect).toHaveValue(currentValue);
|
||||
});
|
||||
|
||||
test("should display stock threshold settings", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should show notification matrix", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const matrix = page.locator("div.notification-matrix");
|
||||
await expect(matrix).toBeVisible();
|
||||
|
||||
// Look for stock threshold settings
|
||||
const hasStockSettings =
|
||||
(await page
|
||||
.getByText(/stock|threshold|days|reminder/i)
|
||||
.isVisible()
|
||||
.catch(() => false)) ||
|
||||
(await page
|
||||
.getByRole("spinbutton")
|
||||
.first()
|
||||
.isVisible()
|
||||
.catch(() => false));
|
||||
|
||||
expect(hasStockSettings).toBeTruthy();
|
||||
// Matrix contains toggle switches
|
||||
const toggles = matrix.locator("label.toggle-switch");
|
||||
expect(await toggles.count()).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("should have a save button", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should show stock settings section with threshold inputs", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const thresholdGroup = page.locator("div.threshold-chips-group");
|
||||
await expect(thresholdGroup).toBeVisible();
|
||||
|
||||
// Look for save button
|
||||
const saveButton = page.getByRole("button", { name: /save/i });
|
||||
const hasSaveButton = await saveButton.isVisible().catch(() => false);
|
||||
|
||||
expect(hasSaveButton).toBeTruthy();
|
||||
// Should have three threshold number inputs
|
||||
const thresholdInputs = thresholdGroup.locator('input[type="text"]');
|
||||
await expect(thresholdInputs).toHaveCount(3);
|
||||
});
|
||||
|
||||
test("should allow toggling notification checkboxes", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should show calculation mode radio cards", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const modeGroup = page.locator("div.calculation-mode-group");
|
||||
await expect(modeGroup).toBeVisible();
|
||||
|
||||
// Find first checkbox and test toggle
|
||||
const checkbox = page.getByRole("checkbox").first();
|
||||
const hasCheckbox = await checkbox.isVisible().catch(() => false);
|
||||
// Two radio cards: automatic and manual
|
||||
const radioCards = modeGroup.locator("label.radio-card");
|
||||
await expect(radioCards).toHaveCount(2);
|
||||
|
||||
if (hasCheckbox) {
|
||||
const initialState = await checkbox.isChecked();
|
||||
// One should be selected
|
||||
await expect(modeGroup.locator("label.radio-card.selected")).toHaveCount(1);
|
||||
});
|
||||
|
||||
// Toggle the checkbox
|
||||
await checkbox.click();
|
||||
test("should toggle calculation mode", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
// Wait for checkbox state to change (auto-waiting via assertion)
|
||||
if (initialState) {
|
||||
await expect(checkbox).not.toBeChecked();
|
||||
} else {
|
||||
await expect(checkbox).toBeChecked();
|
||||
const modeGroup = page.locator("div.calculation-mode-group");
|
||||
const radioCards = modeGroup.locator("label.radio-card");
|
||||
|
||||
// Find the non-selected card and click it
|
||||
const firstSelected = await radioCards.first().evaluate((el) => el.classList.contains("selected"));
|
||||
const targetCard = firstSelected ? radioCards.nth(1) : radioCards.first();
|
||||
|
||||
await targetCard.click();
|
||||
await expect(targetCard).toHaveClass(/selected/);
|
||||
|
||||
// Click the other one back
|
||||
const otherCard = firstSelected ? radioCards.first() : radioCards.nth(1);
|
||||
await otherCard.click();
|
||||
await expect(otherCard).toHaveClass(/selected/);
|
||||
});
|
||||
|
||||
test("should have export action button", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
const exportButton = page.getByRole("button", { name: /Export Data|Daten exportieren/i });
|
||||
await expect(exportButton).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show export/import section", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
// Export button
|
||||
const exportBtn = page.locator("div.action-card button.secondary").first();
|
||||
await expect(exportBtn).toBeVisible();
|
||||
});
|
||||
|
||||
test("should toggle a notification switch", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
// Find all toggle-switch labels on the entire settings page
|
||||
const allToggleLabels = page.locator("label.toggle-switch");
|
||||
const count = await allToggleLabels.count();
|
||||
|
||||
// Find the first toggle that is NOT disabled
|
||||
let enabledToggle = null;
|
||||
for (let i = 0; i < count; i++) {
|
||||
const label = allToggleLabels.nth(i);
|
||||
const isDisabled = await label.evaluate((el) => el.classList.contains("disabled"));
|
||||
if (!isDisabled) {
|
||||
enabledToggle = label;
|
||||
break;
|
||||
}
|
||||
|
||||
// Toggle back
|
||||
await checkbox.click();
|
||||
await expect(checkbox).toHaveJSProperty("checked", initialState);
|
||||
}
|
||||
|
||||
if (!enabledToggle) {
|
||||
// All toggles disabled (no notification channels configured) — skip
|
||||
return;
|
||||
}
|
||||
|
||||
const checkbox = enabledToggle.locator('input[type="checkbox"]');
|
||||
const initialState = await checkbox.isChecked();
|
||||
|
||||
// Click the label to toggle
|
||||
await enabledToggle.click();
|
||||
|
||||
if (initialState) {
|
||||
await expect(checkbox).not.toBeChecked();
|
||||
} else {
|
||||
await expect(checkbox).toBeChecked();
|
||||
}
|
||||
|
||||
// Toggle back to restore original state
|
||||
await enabledToggle.click();
|
||||
await expect(checkbox).toHaveJSProperty("checked", initialState);
|
||||
});
|
||||
|
||||
test("should persist settings page on navigation", async ({ page }) => {
|
||||
await page.goto("/settings");
|
||||
test("should validate stock thresholds", async ({ page }) => {
|
||||
await navigateTo(page, "/settings");
|
||||
|
||||
await expect(page.getByRole("navigation")).toBeVisible({ timeout: 10000 });
|
||||
const thresholdGroup = page.locator("div.threshold-chips-group");
|
||||
const inputs = thresholdGroup.locator('input[type="text"]');
|
||||
|
||||
// Navigate away and back
|
||||
const dashboardLink = page.getByRole("link", { name: /dashboard/i });
|
||||
if (await dashboardLink.isVisible()) {
|
||||
await dashboardLink.click();
|
||||
await expect(page).toHaveURL(/dashboard/);
|
||||
// Set an invalid value (critical > low)
|
||||
const criticalInput = inputs.first();
|
||||
await criticalInput.fill("999");
|
||||
|
||||
// Navigate back to settings
|
||||
const settingsLink = page.getByRole("link", { name: /settings/i });
|
||||
await settingsLink.click();
|
||||
await expect(page).toHaveURL(/settings/);
|
||||
// Should show validation error
|
||||
const validationError = page.locator("p.threshold-validation-error");
|
||||
await expect(validationError).toBeVisible();
|
||||
});
|
||||
|
||||
// Settings content should still be there
|
||||
await expect(page.getByRole("navigation")).toBeVisible();
|
||||
}
|
||||
test("should reach settings via user menu", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const userMenuButton = page.locator("button.user-menu-btn");
|
||||
test.skip(!(await userMenuButton.isVisible().catch(() => false)), "User menu is unavailable when auth is disabled");
|
||||
|
||||
// Open user menu
|
||||
await userMenuButton.click();
|
||||
|
||||
// Click settings option in dropdown
|
||||
const settingsOption = page.locator(".user-dropdown").getByText(/Settings/i);
|
||||
await expect(settingsOption).toBeVisible();
|
||||
await settingsOption.click();
|
||||
|
||||
await expect(page).toHaveURL(/\/settings/);
|
||||
await expect(page.locator("div.settings-form")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
createShareTokenViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Share Schedule E2E Tests
|
||||
*
|
||||
* Tests the share workflow: creating medications with taken-by persons,
|
||||
* generating share links via the Share Dialog, visiting shared schedule pages,
|
||||
* and verifying calendar data on the shared view.
|
||||
*/
|
||||
test.describe("Share Schedule", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 90000 });
|
||||
|
||||
const MED_ALICE = "ShareTest AliceMed";
|
||||
const MED_BOB = "ShareTest BobMed";
|
||||
const PERSON_ALICE = "Alice";
|
||||
const PERSON_BOB = "Bob";
|
||||
|
||||
const todayMorning = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(8, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
|
||||
// Create medication for Alice
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_ALICE,
|
||||
genericName: "Paracetamol",
|
||||
takenBy: [PERSON_ALICE],
|
||||
notes: "Take every 6 hours as needed",
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false, takenBy: PERSON_ALICE }],
|
||||
})
|
||||
);
|
||||
|
||||
// Create medication for Bob
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_BOB,
|
||||
takenBy: [PERSON_BOB],
|
||||
packageType: "bottle",
|
||||
totalPills: 60,
|
||||
looseTablets: 60,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false, takenBy: PERSON_BOB }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should show taken-by badges on dashboard overview table", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Alice's medication should show "Alice" badge
|
||||
const aliceRow = overviewTable.locator(".table-row").filter({ hasText: MED_ALICE });
|
||||
await expect(aliceRow).toBeVisible();
|
||||
await expect(aliceRow.locator(".taken-by-badge").filter({ hasText: PERSON_ALICE })).toBeVisible();
|
||||
|
||||
// Bob's medication should show "Bob" badge
|
||||
const bobRow = overviewTable.locator(".table-row").filter({ hasText: MED_BOB });
|
||||
await expect(bobRow).toBeVisible();
|
||||
await expect(bobRow.locator(".taken-by-badge").filter({ hasText: PERSON_BOB })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show Share button on dashboard when medications have taken-by", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Share button should appear near the schedules section
|
||||
const shareBtn = page.locator("button.share-btn");
|
||||
await expect(shareBtn).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
test("should open share dialog with person list", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Click the share button
|
||||
const shareBtn = page.locator("button.share-btn");
|
||||
await expect(shareBtn).toBeVisible({ timeout: 10000 });
|
||||
await shareBtn.click();
|
||||
|
||||
// Share dialog modal should appear
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Should show a person select dropdown (first select in the modal)
|
||||
const personSelect = modal.locator("select").first();
|
||||
await expect(personSelect).toBeVisible();
|
||||
|
||||
// Should contain Alice and Bob options
|
||||
await expect(personSelect.locator("option")).toHaveCount(2);
|
||||
|
||||
// Close
|
||||
await page.locator("button.modal-close").click();
|
||||
await expect(modal).not.toBeVisible();
|
||||
});
|
||||
|
||||
test("should generate a share link for Alice", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// Open share dialog
|
||||
await page.locator("button.share-btn").click();
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Select Alice
|
||||
const personSelect = modal.locator("select").first();
|
||||
await personSelect.selectOption(PERSON_ALICE);
|
||||
|
||||
// Click Generate Link button
|
||||
const generateBtn = modal.getByRole("button", { name: /Generate/i });
|
||||
await expect(generateBtn).toBeVisible();
|
||||
await generateBtn.click();
|
||||
|
||||
// Wait for link to be generated
|
||||
const shareLinkInput = modal.locator("input.share-link-input");
|
||||
await expect(shareLinkInput).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// The share link should contain /share/
|
||||
const linkValue = await shareLinkInput.inputValue();
|
||||
expect(linkValue).toContain("/share/");
|
||||
|
||||
// Copy button should be visible
|
||||
await expect(modal.locator("button.btn-copy")).toBeVisible();
|
||||
|
||||
// Close
|
||||
await page.locator("button.modal-close").click();
|
||||
});
|
||||
|
||||
test("should navigate to shared schedule page via API-created token", async ({ page }) => {
|
||||
// Create a share token via API (faster, more reliable)
|
||||
const shareToken = await createShareTokenViaAPI(PERSON_ALICE, 30);
|
||||
expect(shareToken.token).toBeTruthy();
|
||||
|
||||
// Navigate to the shared schedule page (no auth needed)
|
||||
await page.goto(`/share/${shareToken.token}`);
|
||||
|
||||
// Should show the shared schedule page (not the login page)
|
||||
// Wait for either the schedule content or an error
|
||||
const sharedContent = page.locator(".shared-schedule, .share-page");
|
||||
const dayBlock = page.locator(".day-block");
|
||||
const medName = page.getByText(MED_ALICE);
|
||||
|
||||
// At least one of these should be visible — indicating the share page loaded
|
||||
try {
|
||||
await expect(medName).toBeVisible({ timeout: 15000 });
|
||||
} catch {
|
||||
// The page might use a different layout — check if any schedule content loaded
|
||||
await expect(dayBlock.first()).toBeVisible({ timeout: 5000 });
|
||||
}
|
||||
});
|
||||
|
||||
test("should show medication schedule on shared page", async ({ page }) => {
|
||||
const shareToken = await createShareTokenViaAPI(PERSON_ALICE, 30);
|
||||
|
||||
await page.goto(`/share/${shareToken.token}`);
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Wait for page content to load
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
// The page should show Alice's medication name
|
||||
const content = page.getByText(MED_ALICE);
|
||||
try {
|
||||
await expect(content).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
// Reload and retry — sometimes the initial load misses
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(content).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
});
|
||||
|
||||
test("should show dose tracking on shared page", async ({ page }) => {
|
||||
const shareToken = await createShareTokenViaAPI(PERSON_ALICE, 30);
|
||||
|
||||
await page.goto(`/share/${shareToken.token}`);
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Wait for the schedule to render
|
||||
const dayBlock = page.locator(".day-block").first();
|
||||
try {
|
||||
await expect(dayBlock).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(dayBlock).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
|
||||
// Dose items should be visible
|
||||
const doseItems = page.locator(".dose-item");
|
||||
expect(await doseItems.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
test("should generate separate share links for different people", async ({ page }) => {
|
||||
// Create share tokens for both Alice and Bob
|
||||
const aliceToken = await createShareTokenViaAPI(PERSON_ALICE, 30);
|
||||
const bobToken = await createShareTokenViaAPI(PERSON_BOB, 30);
|
||||
|
||||
// Tokens should be different
|
||||
expect(aliceToken.token).not.toBe(bobToken.token);
|
||||
|
||||
// Visit Alice's share — should show Alice's med
|
||||
await page.goto(`/share/${aliceToken.token}`);
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
try {
|
||||
await expect(page.getByText(MED_ALICE)).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(page.getByText(MED_ALICE)).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
|
||||
// Visit Bob's share — should show Bob's med
|
||||
await page.goto(`/share/${bobToken.token}`);
|
||||
await page.waitForLoadState("networkidle");
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
try {
|
||||
await expect(page.getByText(MED_BOB)).toBeVisible({ timeout: 10000 });
|
||||
} catch {
|
||||
await page.reload();
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(page.getByText(MED_BOB)).toBeVisible({ timeout: 10000 });
|
||||
}
|
||||
});
|
||||
|
||||
test("should show notes icon on dashboard for medication with notes", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Alice's med has notes — should show the 📝 icon
|
||||
const aliceRow = overviewTable.locator(".table-row").filter({ hasText: MED_ALICE });
|
||||
await expect(aliceRow).toBeVisible();
|
||||
await expect(aliceRow.locator(".notes-icon")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show notes in medication detail modal", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click on Alice's med to open detail modal
|
||||
const aliceRow = overviewTable.locator(".table-row").filter({ hasText: MED_ALICE });
|
||||
await aliceRow.click();
|
||||
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Modal should show the notes
|
||||
await expect(modal.getByText("Take every 6 hours as needed")).toBeVisible();
|
||||
|
||||
await page.locator("button.modal-close").click();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,317 @@
|
||||
import {
|
||||
authFile,
|
||||
createMedicationViaAPI,
|
||||
deleteAllMedicationsViaAPI,
|
||||
expect,
|
||||
navigateTo,
|
||||
type TestMedication,
|
||||
test,
|
||||
updateSettingsViaAPI,
|
||||
} from "./fixtures";
|
||||
|
||||
/**
|
||||
* Stock Status & Coverage E2E Tests
|
||||
*
|
||||
* Creates medications with different stock levels, then verifies the dashboard
|
||||
* overview table shows correct status chips (High, Normal, Low, Critical, Out of Stock).
|
||||
* Also tests the reorder reminder card and medication detail modal stock info.
|
||||
*/
|
||||
test.describe("Stock Status Levels", () => {
|
||||
test.use({ storageState: authFile });
|
||||
test.describe.configure({ timeout: 90000 });
|
||||
|
||||
// Medication with lots of stock → High status
|
||||
const MED_HIGH = "StockHigh Vitamin D";
|
||||
// Medication with moderate stock → Normal status
|
||||
const MED_NORMAL = "StockNormal Ibuprofen";
|
||||
// Medication with low stock → Low/Warning status
|
||||
const MED_LOW = "StockLow Aspirin";
|
||||
// Medication with very low stock → Critical/Danger status
|
||||
const MED_CRITICAL = "StockCrit Metformin";
|
||||
// Medication with zero stock → Out of Stock/Danger
|
||||
const MED_DEPLETED = "StockEmpty Omeprazol";
|
||||
|
||||
const todayMorning = (() => {
|
||||
const d = new Date();
|
||||
d.setHours(8, 0, 0, 0);
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
})();
|
||||
|
||||
const createdMeds: TestMedication[] = [];
|
||||
|
||||
test.beforeAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
|
||||
// Set stock thresholds:
|
||||
// lowStockDays=30, criticalStockDays=7, highStockDays=90
|
||||
// This means:
|
||||
// > 90 days = High (green high)
|
||||
// 30-90 days = Normal (green success)
|
||||
// 7-29 days = Low (yellow warning)
|
||||
// 1-7 days = Critical (red danger)
|
||||
// 0 = Out of Stock (red danger)
|
||||
await updateSettingsViaAPI({
|
||||
lowStockDays: 30,
|
||||
criticalStockDays: 7,
|
||||
expiryWarningDays: 30,
|
||||
});
|
||||
|
||||
// High stock: 300 pills, 1/day = 300 days → High status
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_HIGH,
|
||||
packageType: "blister",
|
||||
packCount: 10,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
|
||||
// Normal stock: 60 pills, 1/day = 60 days → Normal status
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_NORMAL,
|
||||
genericName: "Ibuprofen 400mg",
|
||||
packageType: "blister",
|
||||
packCount: 2,
|
||||
blistersPerPack: 3,
|
||||
pillsPerBlister: 10,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
|
||||
// Low stock: 20 pills, 1/day = 20 days → Low/Warning status
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_LOW,
|
||||
packageType: "blister",
|
||||
packCount: 1,
|
||||
blistersPerPack: 2,
|
||||
pillsPerBlister: 10,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
|
||||
// Critical stock: 5 pills, 1/day = 5 days → Critical/Danger status
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_CRITICAL,
|
||||
genericName: "Metformin 500mg",
|
||||
packageType: "bottle",
|
||||
totalPills: 5,
|
||||
looseTablets: 5,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
|
||||
// Depleted: bottle with stated capacity 1 but 0 pills in stock → Out of Stock
|
||||
createdMeds.push(
|
||||
await createMedicationViaAPI({
|
||||
name: MED_DEPLETED,
|
||||
packageType: "bottle",
|
||||
totalPills: 1,
|
||||
looseTablets: 0,
|
||||
intakes: [{ usage: 1, every: 1, start: todayMorning, intakeRemindersEnabled: false }],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await deleteAllMedicationsViaAPI();
|
||||
});
|
||||
|
||||
test("should show all medications in overview table", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// All 5 medications should appear
|
||||
await expect(overviewTable.getByText(MED_HIGH)).toBeVisible();
|
||||
await expect(overviewTable.getByText(MED_NORMAL)).toBeVisible();
|
||||
await expect(overviewTable.getByText(MED_LOW)).toBeVisible();
|
||||
await expect(overviewTable.getByText(MED_CRITICAL)).toBeVisible();
|
||||
await expect(overviewTable.getByText(MED_DEPLETED)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show High status chip for well-stocked medication", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// High stock med row should have a .status-chip.high
|
||||
const highRow = overviewTable.locator(".table-row").filter({ hasText: MED_HIGH });
|
||||
await expect(highRow).toBeVisible();
|
||||
await expect(highRow.locator(".status-chip.high")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show Normal status chip for moderate stock medication", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const normalRow = overviewTable.locator(".table-row").filter({ hasText: MED_NORMAL });
|
||||
await expect(normalRow).toBeVisible();
|
||||
await expect(normalRow.locator(".status-chip.success")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show Warning status chip for low stock medication", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const lowRow = overviewTable.locator(".table-row").filter({ hasText: MED_LOW });
|
||||
await expect(lowRow).toBeVisible();
|
||||
await expect(lowRow.locator(".status-chip.warning")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show Danger status chip for critical stock medication", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const criticalRow = overviewTable.locator(".table-row").filter({ hasText: MED_CRITICAL });
|
||||
await expect(criticalRow).toBeVisible();
|
||||
await expect(criticalRow.locator(".status-chip.danger")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show Danger status chip for depleted medication", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
const depletedRow = overviewTable.locator(".table-row").filter({ hasText: MED_DEPLETED });
|
||||
await expect(depletedRow).toBeVisible();
|
||||
await expect(depletedRow.locator(".status-chip.danger")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show days-left and runs-out date in overview", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// High stock should show many days (around 299)
|
||||
const highRow = overviewTable.locator(".table-row").filter({ hasText: MED_HIGH });
|
||||
const highRowText = await highRow.textContent();
|
||||
// Should contain a 3-digit number for days
|
||||
expect(highRowText).toMatch(/\d{2,3}/);
|
||||
|
||||
// Depleted should show 0 or very low number
|
||||
const depletedRow = overviewTable.locator(".table-row").filter({ hasText: MED_DEPLETED });
|
||||
const depletedText = await depletedRow.textContent();
|
||||
expect(depletedText).toContain("0");
|
||||
});
|
||||
|
||||
test("should show reorder reminder card with low-stock medications", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
// The reorder card should mention low-stock medications
|
||||
const reorderCard = page.locator("article.card").filter({ hasText: /Reorder|low|running|refill/i });
|
||||
if (await reorderCard.isVisible().catch(() => false)) {
|
||||
// Should mention at least one of the low stock meds
|
||||
const cardText = await reorderCard.textContent();
|
||||
const mentionsLow =
|
||||
cardText?.includes(MED_LOW) || cardText?.includes(MED_CRITICAL) || cardText?.includes(MED_DEPLETED);
|
||||
expect(mentionsLow).toBeTruthy();
|
||||
}
|
||||
});
|
||||
|
||||
test("should color-code stock values depending on status", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// High stock row should have success-text class on stock cells
|
||||
const highRow = overviewTable.locator(".table-row").filter({ hasText: MED_HIGH });
|
||||
const highStockSpan = highRow.locator("span.success-text, span.high-text").first();
|
||||
if (await highStockSpan.isVisible().catch(() => false)) {
|
||||
await expect(highStockSpan).toBeVisible();
|
||||
}
|
||||
|
||||
// Critical stock should have danger-text class
|
||||
const criticalRow = overviewTable.locator(".table-row").filter({ hasText: MED_CRITICAL });
|
||||
const criticalSpan = criticalRow.locator("span.danger-text").first();
|
||||
if (await criticalSpan.isVisible().catch(() => false)) {
|
||||
await expect(criticalSpan).toBeVisible();
|
||||
}
|
||||
|
||||
// Low stock should have warning-text class
|
||||
const lowRow = overviewTable.locator(".table-row").filter({ hasText: MED_LOW });
|
||||
const warningSpan = lowRow.locator("span.warning-text").first();
|
||||
if (await warningSpan.isVisible().catch(() => false)) {
|
||||
await expect(warningSpan).toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test("should open medication detail modal showing stock info", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click on the critical stock medication row
|
||||
const criticalRow = overviewTable.locator(".table-row").filter({ hasText: MED_CRITICAL });
|
||||
await criticalRow.click();
|
||||
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
await expect(modal.getByText(MED_CRITICAL)).toBeVisible();
|
||||
|
||||
// Modal should show stock/coverage details
|
||||
const modalText = await modal.textContent();
|
||||
expect(modalText).toBeTruthy();
|
||||
|
||||
// Close modal
|
||||
await page.locator("button.modal-close").click();
|
||||
await expect(modal).not.toBeVisible();
|
||||
});
|
||||
|
||||
test("should show generic name in overview for medications that have one", async ({ page }) => {
|
||||
await navigateTo(page, "/dashboard");
|
||||
|
||||
const overviewTable = page.locator(".table.table-7");
|
||||
await expect(overviewTable).toBeVisible({ timeout: 10000 });
|
||||
|
||||
// Click on the normal stock med (has generic name "Ibuprofen 400mg")
|
||||
const normalRow = overviewTable.locator(".table-row").filter({ hasText: MED_NORMAL });
|
||||
await normalRow.click();
|
||||
|
||||
const modal = page.locator(".modal-overlay");
|
||||
await expect(modal).toBeVisible({ timeout: 5000 });
|
||||
// Modal should show the generic name somewhere
|
||||
await expect(modal.getByText("Ibuprofen 400mg")).toBeVisible();
|
||||
|
||||
await page.locator("button.modal-close").click();
|
||||
});
|
||||
|
||||
test("should show different stock levels in planner results", async ({ page }) => {
|
||||
await navigateTo(page, "/planner");
|
||||
await page.waitForLoadState("networkidle");
|
||||
|
||||
// Calculate for 30-day default range
|
||||
await page.locator('form.planner button[type="submit"]').click();
|
||||
await expect(page.locator(".table")).toBeVisible({ timeout: 15000 });
|
||||
|
||||
const resultsTable = page.locator(".table");
|
||||
|
||||
// Should show status chips with different levels
|
||||
const successChips = resultsTable.locator(".status-chip.success");
|
||||
const dangerChips = resultsTable.locator(".status-chip.danger");
|
||||
const warningChips = resultsTable.locator(".status-chip.warning");
|
||||
|
||||
const totalChips = (await successChips.count()) + (await dangerChips.count()) + (await warningChips.count());
|
||||
expect(totalChips).toBeGreaterThanOrEqual(2);
|
||||
|
||||
// The depleted/critical meds should have danger chips
|
||||
expect(await dangerChips.count()).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
Generated
+251
-272
@@ -1,35 +1,35 @@
|
||||
{
|
||||
"name": "medassist-ng-frontend",
|
||||
"version": "1.8.3",
|
||||
"version": "1.10.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "medassist-ng-frontend",
|
||||
"version": "1.8.3",
|
||||
"version": "1.10.3",
|
||||
"dependencies": {
|
||||
"i18next": "^24.2.2",
|
||||
"i18next-browser-languagedetector": "^8.0.4",
|
||||
"i18next": "^25.8.7",
|
||||
"i18next-browser-languagedetector": "^8.2.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-i18next": "^15.4.1",
|
||||
"react-router-dom": "^7.12.0",
|
||||
"zod": "^3.23.8"
|
||||
"react-router-dom": "^7.13.0",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.12",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@biomejs/biome": "^2.3.15",
|
||||
"@playwright/test": "^1.58.2",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"@types/react": "^18.3.4",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"@vitejs/plugin-react": "^4.3.2",
|
||||
"@vitest/coverage-v8": "^4.0.17",
|
||||
"jsdom": "^27.4.0",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"jsdom": "^28.0.0",
|
||||
"typescript": "^5.5.4",
|
||||
"vite": "^7.3.0",
|
||||
"vite": "^7.3.1",
|
||||
"vitest": "^4.0.17"
|
||||
}
|
||||
},
|
||||
@@ -103,13 +103,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
"version": "7.27.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz",
|
||||
"integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz",
|
||||
"integrity": "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/helper-validator-identifier": "^7.27.1",
|
||||
"@babel/helper-validator-identifier": "^7.28.5",
|
||||
"js-tokens": "^4.0.0",
|
||||
"picocolors": "^1.1.1"
|
||||
},
|
||||
@@ -118,9 +118,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/compat-data": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.28.5.tgz",
|
||||
"integrity": "sha512-6uFXyCayocRbqhZOB+6XcuZbkMNimwfVGFji8CTZnCzOHVGvDqzvitu1re2AU5LROliz7eQPhB8CpAMvnx9EjA==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.29.0.tgz",
|
||||
"integrity": "sha512-T1NCJqT/j9+cn8fvkt7jtwbLBfLC/1y1c7NtCeXFRgzGTsafi68MRv8yzkYSapBnFA6L3U2VSc02ciDzoAJhJg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -128,21 +128,21 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/core": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.5.tgz",
|
||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz",
|
||||
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
"@babel/helper-compilation-targets": "^7.27.2",
|
||||
"@babel/helper-module-transforms": "^7.28.3",
|
||||
"@babel/helpers": "^7.28.4",
|
||||
"@babel/parser": "^7.28.5",
|
||||
"@babel/template": "^7.27.2",
|
||||
"@babel/traverse": "^7.28.5",
|
||||
"@babel/types": "^7.28.5",
|
||||
"@babel/code-frame": "^7.29.0",
|
||||
"@babel/generator": "^7.29.0",
|
||||
"@babel/helper-compilation-targets": "^7.28.6",
|
||||
"@babel/helper-module-transforms": "^7.28.6",
|
||||
"@babel/helpers": "^7.28.6",
|
||||
"@babel/parser": "^7.29.0",
|
||||
"@babel/template": "^7.28.6",
|
||||
"@babel/traverse": "^7.29.0",
|
||||
"@babel/types": "^7.29.0",
|
||||
"@jridgewell/remapping": "^2.3.5",
|
||||
"convert-source-map": "^2.0.0",
|
||||
"debug": "^4.1.0",
|
||||
@@ -159,14 +159,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/generator": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.5.tgz",
|
||||
"integrity": "sha512-3EwLFhZ38J4VyIP6WNtt2kUdW9dokXA9Cr4IVIFHuCpZ3H8/YFOl5JjZHisrn1fATPBmKKqXzDFvh9fUwHz6CQ==",
|
||||
"version": "7.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.1.tgz",
|
||||
"integrity": "sha512-qsaF+9Qcm2Qv8SRIMMscAvG4O3lJ0F1GuMo5HR/Bp02LopNgnZBC/EkbevHFeGs4ls/oPz9v+Bsmzbkbe+0dUw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.28.5",
|
||||
"@babel/types": "^7.28.5",
|
||||
"@babel/parser": "^7.29.0",
|
||||
"@babel/types": "^7.29.0",
|
||||
"@jridgewell/gen-mapping": "^0.3.12",
|
||||
"@jridgewell/trace-mapping": "^0.3.28",
|
||||
"jsesc": "^3.0.2"
|
||||
@@ -176,13 +176,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-compilation-targets": {
|
||||
"version": "7.27.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.2.tgz",
|
||||
"integrity": "sha512-2+1thGUUWWjLTYTHZWK1n8Yga0ijBz1XAhUXcKy81rd5g6yh7hGqMp45v7cadSbEHc9G3OTv45SyneRN3ps4DQ==",
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.28.6.tgz",
|
||||
"integrity": "sha512-JYtls3hqi15fcx5GaSNL7SCTJ2MNmjrkHXg4FSpOA/grxK8KwyZ5bubHsCq8FXCkua6xhuaaBit+3b7+VZRfcA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/compat-data": "^7.27.2",
|
||||
"@babel/compat-data": "^7.28.6",
|
||||
"@babel/helper-validator-option": "^7.27.1",
|
||||
"browserslist": "^4.24.0",
|
||||
"lru-cache": "^5.1.1",
|
||||
@@ -203,29 +203,29 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-module-imports": {
|
||||
"version": "7.27.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.27.1.tgz",
|
||||
"integrity": "sha512-0gSFWUPNXNopqtIPQvlD5WgXYI5GY2kP2cCvoT8kczjbfcfuIljTbcWrulD1CIPIX2gt1wghbDy08yE1p+/r3w==",
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.28.6.tgz",
|
||||
"integrity": "sha512-l5XkZK7r7wa9LucGw9LwZyyCUscb4x37JWTPz7swwFE/0FMQAGpiWUZn8u9DzkSBWEcK25jmvubfpw2dnAMdbw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/traverse": "^7.27.1",
|
||||
"@babel/types": "^7.27.1"
|
||||
"@babel/traverse": "^7.28.6",
|
||||
"@babel/types": "^7.28.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-module-transforms": {
|
||||
"version": "7.28.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.28.3.tgz",
|
||||
"integrity": "sha512-gytXUbs8k2sXS9PnQptz5o0QnpLL51SwASIORY6XaBKF88nsOT0Zw9szLqlSGQDP/4TljBAD5y98p2U1fqkdsw==",
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.28.6.tgz",
|
||||
"integrity": "sha512-67oXFAYr2cDLDVGLXTEABjdBJZ6drElUSI7WKp70NrpyISso3plG9SAGEF6y7zbha/wOzUByWWTJvEDVNIUGcA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/helper-module-imports": "^7.27.1",
|
||||
"@babel/helper-validator-identifier": "^7.27.1",
|
||||
"@babel/traverse": "^7.28.3"
|
||||
"@babel/helper-module-imports": "^7.28.6",
|
||||
"@babel/helper-validator-identifier": "^7.28.5",
|
||||
"@babel/traverse": "^7.28.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
@@ -275,27 +275,27 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helpers": {
|
||||
"version": "7.28.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.4.tgz",
|
||||
"integrity": "sha512-HFN59MmQXGHVyYadKLVumYsA9dBFun/ldYxipEjzA4196jpLZd8UjEEBLkbEkvfYreDqJhZxYAWFPtrfhNpj4w==",
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.6.tgz",
|
||||
"integrity": "sha512-xOBvwq86HHdB7WUDTfKfT/Vuxh7gElQ+Sfti2Cy6yIWNW05P8iUslOVcZ4/sKbE+/jQaukQAdz/gf3724kYdqw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.27.2",
|
||||
"@babel/types": "^7.28.4"
|
||||
"@babel/template": "^7.28.6",
|
||||
"@babel/types": "^7.28.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/parser": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.5.tgz",
|
||||
"integrity": "sha512-KKBU1VGYR7ORr3At5HAtUQ+TV3SzRCXmA/8OdDZiLDBIZxVyzXuztPjfLd3BV1PRAQGCMWWSHYhL0F8d5uHBDQ==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.0.tgz",
|
||||
"integrity": "sha512-IyDgFV5GeDUVX4YdF/3CPULtVGSXXMLh1xVIgdCgxApktqnQV0r7/8Nqthg+8YLGaAtdyIlo2qIdZrbCv4+7ww==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.28.5"
|
||||
"@babel/types": "^7.29.0"
|
||||
},
|
||||
"bin": {
|
||||
"parser": "bin/babel-parser.js"
|
||||
@@ -346,33 +346,33 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/template": {
|
||||
"version": "7.27.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz",
|
||||
"integrity": "sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==",
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.28.6.tgz",
|
||||
"integrity": "sha512-YA6Ma2KsCdGb+WC6UpBVFJGXL58MDA6oyONbjyF/+5sBgxY/dwkhLogbMT2GXXyU84/IhRw/2D1Os1B/giz+BQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/parser": "^7.27.2",
|
||||
"@babel/types": "^7.27.1"
|
||||
"@babel/code-frame": "^7.28.6",
|
||||
"@babel/parser": "^7.28.6",
|
||||
"@babel/types": "^7.28.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/traverse": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.5.tgz",
|
||||
"integrity": "sha512-TCCj4t55U90khlYkVV/0TfkJkAkUg3jZFA3Neb7unZT8CPok7iiRfaX0F+WnqWqt7OxhOn0uBKXCw4lbL8W0aQ==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.0.tgz",
|
||||
"integrity": "sha512-4HPiQr0X7+waHfyXPZpWPfWL/J7dcN1mx9gL6WdQVMbPnF3+ZhSMs8tCxN7oHddJE9fhNE7+lxdnlyemKfJRuA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
"@babel/code-frame": "^7.29.0",
|
||||
"@babel/generator": "^7.29.0",
|
||||
"@babel/helper-globals": "^7.28.0",
|
||||
"@babel/parser": "^7.28.5",
|
||||
"@babel/template": "^7.27.2",
|
||||
"@babel/types": "^7.28.5",
|
||||
"@babel/parser": "^7.29.0",
|
||||
"@babel/template": "^7.28.6",
|
||||
"@babel/types": "^7.29.0",
|
||||
"debug": "^4.3.1"
|
||||
},
|
||||
"engines": {
|
||||
@@ -380,9 +380,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/types": {
|
||||
"version": "7.28.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.28.5.tgz",
|
||||
"integrity": "sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz",
|
||||
"integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -404,9 +404,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/biome": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.3.12.tgz",
|
||||
"integrity": "sha512-AR7h4aSlAvXj7TAajW/V12BOw2EiS0AqZWV5dGozf4nlLoUF/ifvD0+YgKSskT0ylA6dY1A8AwgP8kZ6yaCQnA==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.3.15.tgz",
|
||||
"integrity": "sha512-u+jlPBAU2B45LDkjjNNYpc1PvqrM/co4loNommS9/sl9oSxsAQKsNZejYuUztvToB5oXi1tN/e62iNd6ESiY3g==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"bin": {
|
||||
@@ -420,20 +420,20 @@
|
||||
"url": "https://opencollective.com/biome"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@biomejs/cli-darwin-arm64": "2.3.12",
|
||||
"@biomejs/cli-darwin-x64": "2.3.12",
|
||||
"@biomejs/cli-linux-arm64": "2.3.12",
|
||||
"@biomejs/cli-linux-arm64-musl": "2.3.12",
|
||||
"@biomejs/cli-linux-x64": "2.3.12",
|
||||
"@biomejs/cli-linux-x64-musl": "2.3.12",
|
||||
"@biomejs/cli-win32-arm64": "2.3.12",
|
||||
"@biomejs/cli-win32-x64": "2.3.12"
|
||||
"@biomejs/cli-darwin-arm64": "2.3.15",
|
||||
"@biomejs/cli-darwin-x64": "2.3.15",
|
||||
"@biomejs/cli-linux-arm64": "2.3.15",
|
||||
"@biomejs/cli-linux-arm64-musl": "2.3.15",
|
||||
"@biomejs/cli-linux-x64": "2.3.15",
|
||||
"@biomejs/cli-linux-x64-musl": "2.3.15",
|
||||
"@biomejs/cli-win32-arm64": "2.3.15",
|
||||
"@biomejs/cli-win32-x64": "2.3.15"
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-darwin-arm64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.3.12.tgz",
|
||||
"integrity": "sha512-cO6fn+KiMBemva6EARDLQBxeyvLzgidaFRJi8G7OeRqz54kWK0E+uSjgFaiHlc3DZYoa0+1UFE8mDxozpc9ieg==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.3.15.tgz",
|
||||
"integrity": "sha512-SDCdrJ4COim1r8SNHg19oqT50JfkI/xGZHSyC6mGzMfKrpNe/217Eq6y98XhNTc0vGWDjznSDNXdUc6Kg24jbw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -448,9 +448,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-darwin-x64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.3.12.tgz",
|
||||
"integrity": "sha512-/fiF/qmudKwSdvmSrSe/gOTkW77mHHkH8Iy7YC2rmpLuk27kbaUOPa7kPiH5l+3lJzTUfU/t6x1OuIq/7SGtxg==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.3.15.tgz",
|
||||
"integrity": "sha512-RkyeSosBtn3C3Un8zQnl9upX0Qbq4E3QmBa0qjpOh1MebRbHhNlRC16jk8HdTe/9ym5zlfnpbb8cKXzW+vlTxw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -465,9 +465,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-linux-arm64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.3.12.tgz",
|
||||
"integrity": "sha512-nbOsuQROa3DLla5vvsTZg+T5WVPGi9/vYxETm9BOuLHBJN3oWQIg3MIkE2OfL18df1ZtNkqXkH6Yg9mdTPem7A==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.3.15.tgz",
|
||||
"integrity": "sha512-FN83KxrdVWANOn5tDmW6UBC0grojchbGmcEz6JkRs2YY6DY63sTZhwkQ56x6YtKhDVV1Unz7FJexy8o7KwuIhg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -482,9 +482,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-linux-arm64-musl": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.3.12.tgz",
|
||||
"integrity": "sha512-aqkeSf7IH+wkzFpKeDVPSXy9uDjxtLpYA6yzkYsY+tVjwFFirSuajHDI3ul8en90XNs1NA0n8kgBrjwRi5JeyA==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.3.15.tgz",
|
||||
"integrity": "sha512-SSSIj2yMkFdSkXqASzIBdjySBXOe65RJlhKEDlri7MN19RC4cpez+C0kEwPrhXOTgJbwQR9QH1F4+VnHkC35pg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -499,9 +499,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-linux-x64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-2.3.12.tgz",
|
||||
"integrity": "sha512-CQtqrJ+qEEI8tgRSTjjzk6wJAwfH3wQlkIGsM5dlecfRZaoT+XCms/mf7G4kWNexrke6mnkRzNy6w8ebV177ow==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-2.3.15.tgz",
|
||||
"integrity": "sha512-T8n9p8aiIKOrAD7SwC7opiBM1LYGrE5G3OQRXWgbeo/merBk8m+uxJ1nOXMPzfYyFLfPlKF92QS06KN1UW+Zbg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -516,9 +516,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-linux-x64-musl": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.3.12.tgz",
|
||||
"integrity": "sha512-kVGWtupRRsOjvw47YFkk5mLiAdpCPMWBo1jOwAzh+juDpUb2sWarIp+iq+CPL1Wt0LLZnYtP7hH5kD6fskcxmg==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.3.15.tgz",
|
||||
"integrity": "sha512-dbjPzTh+ijmmNwojFYbQNMFp332019ZDioBYAMMJj5Ux9d8MkM+u+J68SBJGVwVeSHMYj+T9504CoxEzQxrdNw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -533,9 +533,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-win32-arm64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.3.12.tgz",
|
||||
"integrity": "sha512-Re4I7UnOoyE4kHMqpgtG6UvSBGBbbtvsOvBROgCCoH7EgANN6plSQhvo2W7OCITvTp7gD6oZOyZy72lUdXjqZg==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.3.15.tgz",
|
||||
"integrity": "sha512-puMuenu/2brQdgqtQ7geNwQlNVxiABKEZJhMRX6AGWcmrMO8EObMXniFQywy2b81qmC+q+SDvlOpspNwz0WiOA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -550,9 +550,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@biomejs/cli-win32-x64": {
|
||||
"version": "2.3.12",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-2.3.12.tgz",
|
||||
"integrity": "sha512-qqGVWqNNek0KikwPZlOIoxtXgsNGsX+rgdEzgw82Re8nF02W+E2WokaQhpF5TdBh/D/RQ3TLppH+otp6ztN0lw==",
|
||||
"version": "2.3.15",
|
||||
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-2.3.15.tgz",
|
||||
"integrity": "sha512-kDZr/hgg+igo5Emi0LcjlgfkoGZtgIpJKhnvKTRmMBv6FF/3SDyEV4khBwqNebZIyMZTzvpca9sQNSXJ39pI2A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1144,9 +1144,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@exodus/bytes": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@exodus/bytes/-/bytes-1.9.0.tgz",
|
||||
"integrity": "sha512-lagqsvnk09NKogQaN/XrtlWeUF8SRhT12odMvbTIIaVObqzwAogL6jhR4DAp0gPuKoM1AOVrKUshJpRdpMFrww==",
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@exodus/bytes/-/bytes-1.14.1.tgz",
|
||||
"integrity": "sha512-OhkBFWI6GcRMUroChZiopRiSp2iAMvEBK47NhJooDqz1RERO4QuZIZnjP63TXX8GAiLABkYmX+fuQsdJ1dd2QQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -1212,13 +1212,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.58.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.1.tgz",
|
||||
"integrity": "sha512-6LdVIUERWxQMmUSSQi0I53GgCBYgM2RpGngCPY7hSeju+VrKjq3lvs7HpJoPbDiY5QM5EYRtRX5fvrinnMAz3w==",
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.2.tgz",
|
||||
"integrity": "sha512-akea+6bHYBBfA9uQqSYmlJXn61cTa+jbO87xVLCWbTqbWadRVmhxlXATaOjOgcBaWU4ePo0wB41KMFv3o35IXA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright": "1.58.1"
|
||||
"playwright": "1.58.2"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
@@ -1228,9 +1228,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/pluginutils": {
|
||||
"version": "1.0.0-beta.27",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz",
|
||||
"integrity": "sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==",
|
||||
"version": "1.0.0-rc.3",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.3.tgz",
|
||||
"integrity": "sha512-eybk3TjzzzV97Dlj5c+XrBFW57eTNhzod66y9HrBlzJ6NsCrWCp/2kaPS3K9wJmurBC0Tdw4yPjXKZqlznim3Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -1776,35 +1776,35 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitejs/plugin-react": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.7.0.tgz",
|
||||
"integrity": "sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA==",
|
||||
"version": "5.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-5.1.4.tgz",
|
||||
"integrity": "sha512-VIcFLdRi/VYRU8OL/puL7QXMYafHmqOnwTZY50U1JPlCNj30PxCMx65c494b1K9be9hX83KVt0+gTEwTWLqToA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.28.0",
|
||||
"@babel/core": "^7.29.0",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.27.1",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.27.1",
|
||||
"@rolldown/pluginutils": "1.0.0-beta.27",
|
||||
"@rolldown/pluginutils": "1.0.0-rc.3",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"react-refresh": "^0.17.0"
|
||||
"react-refresh": "^0.18.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.18.0 || >=16.0.0"
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/coverage-v8": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.0.17.tgz",
|
||||
"integrity": "sha512-/6zU2FLGg0jsd+ePZcwHRy3+WpNTBBhDY56P4JTRqUN/Dp6CvOEa9HrikcQ4KfV2b2kAHUFB4dl1SuocWXSFEw==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.0.18.tgz",
|
||||
"integrity": "sha512-7i+N2i0+ME+2JFZhfuz7Tg/FqKtilHjGyGvoHYQ6iLV0zahbsJ9sljC9OcFcPDbhYKCet+sG8SsVqlyGvPflZg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@bcoe/v8-coverage": "^1.0.2",
|
||||
"@vitest/utils": "4.0.17",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"ast-v8-to-istanbul": "^0.3.10",
|
||||
"istanbul-lib-coverage": "^3.2.2",
|
||||
"istanbul-lib-report": "^3.0.1",
|
||||
@@ -1818,8 +1818,8 @@
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vitest/browser": "4.0.17",
|
||||
"vitest": "4.0.17"
|
||||
"@vitest/browser": "4.0.18",
|
||||
"vitest": "4.0.18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vitest/browser": {
|
||||
@@ -1828,16 +1828,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.17.tgz",
|
||||
"integrity": "sha512-mEoqP3RqhKlbmUmntNDDCJeTDavDR+fVYkSOw8qRwJFaW/0/5zA9zFeTrHqNtcmwh6j26yMmwx2PqUDPzt5ZAQ==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.18.tgz",
|
||||
"integrity": "sha512-8sCWUyckXXYvx4opfzVY03EOiYVxyNrHS5QxX3DAIi5dpJAAkyJezHCP77VMX4HKA2LDT/Jpfo8i2r5BE3GnQQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.0.0",
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/spy": "4.0.17",
|
||||
"@vitest/utils": "4.0.17",
|
||||
"@vitest/spy": "4.0.18",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"chai": "^6.2.1",
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
@@ -1846,13 +1846,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/mocker": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.17.tgz",
|
||||
"integrity": "sha512-+ZtQhLA3lDh1tI2wxe3yMsGzbp7uuJSWBM1iTIKCbppWTSBN09PUC+L+fyNlQApQoR+Ps8twt2pbSSXg2fQVEQ==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.18.tgz",
|
||||
"integrity": "sha512-HhVd0MDnzzsgevnOWCBj5Otnzobjy5wLBe4EdeeFGv8luMsGcYqDuFRMcttKWZA5vVO8RFjexVovXvAM4JoJDQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/spy": "4.0.17",
|
||||
"@vitest/spy": "4.0.18",
|
||||
"estree-walker": "^3.0.3",
|
||||
"magic-string": "^0.30.21"
|
||||
},
|
||||
@@ -1873,9 +1873,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/pretty-format": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.17.tgz",
|
||||
"integrity": "sha512-Ah3VAYmjcEdHg6+MwFE17qyLqBHZ+ni2ScKCiW2XrlSBV4H3Z7vYfPfz7CWQ33gyu76oc0Ai36+kgLU3rfF4nw==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.18.tgz",
|
||||
"integrity": "sha512-P24GK3GulZWC5tz87ux0m8OADrQIUVDPIjjj65vBXYG17ZeU3qD7r+MNZ1RNv4l8CGU2vtTRqixrOi9fYk/yKw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -1886,13 +1886,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/runner": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.17.tgz",
|
||||
"integrity": "sha512-JmuQyf8aMWoo/LmNFppdpkfRVHJcsgzkbCA+/Bk7VfNH7RE6Ut2qxegeyx2j3ojtJtKIbIGy3h+KxGfYfk28YQ==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.18.tgz",
|
||||
"integrity": "sha512-rpk9y12PGa22Jg6g5M3UVVnTS7+zycIGk9ZNGN+m6tZHKQb7jrP7/77WfZy13Y/EUDd52NDsLRQhYKtv7XfPQw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/utils": "4.0.17",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
"funding": {
|
||||
@@ -1900,13 +1900,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.17.tgz",
|
||||
"integrity": "sha512-npPelD7oyL+YQM2gbIYvlavlMVWUfNNGZPcu0aEUQXt7FXTuqhmgiYupPnAanhKvyP6Srs2pIbWo30K0RbDtRQ==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.18.tgz",
|
||||
"integrity": "sha512-PCiV0rcl7jKQjbgYqjtakly6T1uwv/5BQ9SwBLekVg/EaYeQFPiXcgrC2Y7vDMA8dM1SUEAEV82kgSQIlXNMvA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.0.17",
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"magic-string": "^0.30.21",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
@@ -1915,9 +1915,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/spy": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.17.tgz",
|
||||
"integrity": "sha512-I1bQo8QaP6tZlTomQNWKJE6ym4SHf3oLS7ceNjozxxgzavRAgZDc06T7kD8gb9bXKEgcLNt00Z+kZO6KaJ62Ew==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.18.tgz",
|
||||
"integrity": "sha512-cbQt3PTSD7P2OARdVW3qWER5EGq7PHlvE+QfzSC0lbwO+xnt7+XH06ZzFjFRgzUX//JmpxrCu92VdwvEPlWSNw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
@@ -1925,13 +1925,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.17.tgz",
|
||||
"integrity": "sha512-RG6iy+IzQpa9SB8HAFHJ9Y+pTzI+h8553MrciN9eC6TFBErqrQaTas4vG+MVj8S4uKk8uTT2p0vgZPnTdxd96w==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.18.tgz",
|
||||
"integrity": "sha512-msMRKLMVLWygpK3u2Hybgi4MNjcYJvwTb0Ru09+fOyCXIgT5raYP041DRRdiJiI3k/2U6SEbAETB3YtBrUkCFA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.0.17",
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
"funding": {
|
||||
@@ -2013,9 +2013,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/baseline-browser-mapping": {
|
||||
"version": "2.9.11",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.11.tgz",
|
||||
"integrity": "sha512-Sg0xJUNDU1sJNGdfGWhVHX0kkZ+HWcvmVymJbj6NSgZZmW/8S9Y2HQ5euytnIgakgxN6papOAWiwDo1ctFDcoQ==",
|
||||
"version": "2.9.19",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.19.tgz",
|
||||
"integrity": "sha512-ipDqC8FrAl/76p2SSWKSI+H9tFwm7vYqXQrItCuiVPt26Km0jS+NzSsBWAaBusvSbQcfJG+JitdMm+wZAgTYqg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
@@ -2067,9 +2067,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001761",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
|
||||
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
|
||||
"version": "1.0.30001769",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001769.tgz",
|
||||
"integrity": "sha512-BCfFL1sHijQlBGWBMuJyhZUhzo7wer5sVj9hqekB/7xn0Ypy+pER/edCYQm4exbXj4WiySGp40P8UuTh6w1srg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -2172,27 +2172,17 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/data-urls": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/data-urls/-/data-urls-6.0.1.tgz",
|
||||
"integrity": "sha512-euIQENZg6x8mj3fO6o9+fOW8MimUI4PpD/fZBhJfeioZVy9TUpM4UY7KjQNVZFlqwJ0UdzRDzkycB997HEq1BQ==",
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/data-urls/-/data-urls-7.0.0.tgz",
|
||||
"integrity": "sha512-23XHcCF+coGYevirZceTVD7NdJOqVn+49IHyxgszm+JIiHLoB2TkmPtsYkNWT1pvRSGkc35L6NHs0yHkN2SumA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"whatwg-mimetype": "^5.0.0",
|
||||
"whatwg-url": "^15.1.0"
|
||||
"whatwg-url": "^16.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/data-urls/node_modules/whatwg-mimetype": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz",
|
||||
"integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
@@ -2239,9 +2229,9 @@
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.5.267",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.267.tgz",
|
||||
"integrity": "sha512-0Drusm6MVRXSOJpGbaSVgcQsuB4hEkMpHXaVstcPmhu5LIedxs1xNK/nIxmQIU/RPC0+1/o0AVZfBTkTNJOdUw==",
|
||||
"version": "1.5.286",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.286.tgz",
|
||||
"integrity": "sha512-9tfDXhJ4RKFNerfjdCcZfufu49vg620741MNs26a9+bhLThdB+plgMeou98CAaHu/WATj2iHOOHTp1hWtABj2A==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
@@ -2448,9 +2438,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/i18next": {
|
||||
"version": "24.2.3",
|
||||
"resolved": "https://registry.npmjs.org/i18next/-/i18next-24.2.3.tgz",
|
||||
"integrity": "sha512-lfbf80OzkocvX7nmZtu7nSTNbrTYR52sLWxPtlXX1zAhVw8WEnFk4puUkCR4B1dNQwbSpEHHHemcZu//7EcB7A==",
|
||||
"version": "25.8.7",
|
||||
"resolved": "https://registry.npmjs.org/i18next/-/i18next-25.8.7.tgz",
|
||||
"integrity": "sha512-ttxxc5+67S/0hhoeVdEgc1lRklZhdfcUSEPp1//uUG2NB88X3667gRsDar+ZWQFdysnOsnb32bcoMsa4mtzhkQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -2467,7 +2457,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.26.10"
|
||||
"@babel/runtime": "^7.28.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
@@ -2479,9 +2469,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/i18next-browser-languagedetector": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.2.0.tgz",
|
||||
"integrity": "sha512-P+3zEKLnOF0qmiesW383vsLdtQVyKtCNA9cjSoKCppTKPQVfKd2W8hbVo5ZhNJKDqeM7BOcvNoKJOjpHh4Js9g==",
|
||||
"version": "8.2.1",
|
||||
"resolved": "https://registry.npmjs.org/i18next-browser-languagedetector/-/i18next-browser-languagedetector-8.2.1.tgz",
|
||||
"integrity": "sha512-bZg8+4bdmaOiApD7N7BPT9W8MLZG+nPTOFlLiJiT8uzKXFjhxw4v2ierCXOwB5sFDMtuA5G4kgYZ0AznZxQ/cw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.23.2"
|
||||
@@ -2550,17 +2540,17 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/jsdom": {
|
||||
"version": "27.4.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-27.4.0.tgz",
|
||||
"integrity": "sha512-mjzqwWRD9Y1J1KUi7W97Gja1bwOOM5Ug0EZ6UDK3xS7j7mndrkwozHtSblfomlzyB4NepioNt+B2sOSzczVgtQ==",
|
||||
"version": "28.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-28.0.0.tgz",
|
||||
"integrity": "sha512-KDYJgZ6T2TKdU8yBfYueq5EPG/EylMsBvCaenWMJb2OXmjgczzwveRCoJ+Hgj1lXPDyasvrgneSn4GBuR1hYyA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@acemir/cssom": "^0.9.28",
|
||||
"@acemir/cssom": "^0.9.31",
|
||||
"@asamuzakjp/dom-selector": "^6.7.6",
|
||||
"@exodus/bytes": "^1.6.0",
|
||||
"cssstyle": "^5.3.4",
|
||||
"data-urls": "^6.0.0",
|
||||
"@exodus/bytes": "^1.11.0",
|
||||
"cssstyle": "^5.3.7",
|
||||
"data-urls": "^7.0.0",
|
||||
"decimal.js": "^10.6.0",
|
||||
"html-encoding-sniffer": "^6.0.0",
|
||||
"http-proxy-agent": "^7.0.2",
|
||||
@@ -2570,11 +2560,11 @@
|
||||
"saxes": "^6.0.0",
|
||||
"symbol-tree": "^3.2.4",
|
||||
"tough-cookie": "^6.0.0",
|
||||
"undici": "^7.20.0",
|
||||
"w3c-xmlserializer": "^5.0.0",
|
||||
"webidl-conversions": "^8.0.0",
|
||||
"whatwg-mimetype": "^4.0.0",
|
||||
"whatwg-url": "^15.1.0",
|
||||
"ws": "^8.18.3",
|
||||
"webidl-conversions": "^8.0.1",
|
||||
"whatwg-mimetype": "^5.0.0",
|
||||
"whatwg-url": "^16.0.0",
|
||||
"xml-name-validator": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -2801,13 +2791,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.58.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.1.tgz",
|
||||
"integrity": "sha512-+2uTZHxSCcxjvGc5C891LrS1/NlxglGxzrC4seZiVjcYVQfUa87wBL6rTDqzGjuoWNjnBzRqKmF6zRYGMvQUaQ==",
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.2.tgz",
|
||||
"integrity": "sha512-vA30H8Nvkq/cPBnNw4Q8TWz1EJyqgpuinBcHET0YVJVFldr8JDNiU9LaWAE1KqSkRYazuaBhTpB5ZzShOezQ6A==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.58.1"
|
||||
"playwright-core": "1.58.2"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
@@ -2820,9 +2810,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.58.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.1.tgz",
|
||||
"integrity": "sha512-bcWzOaTxcW+VOOGBCQgnaKToLJ65d6AqfLVKEWvexyS3AS6rbXl+xdpYRMGSRBClPvyj44njOWoxjNdL/H9UNg==",
|
||||
"version": "1.58.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.2.tgz",
|
||||
"integrity": "sha512-yZkEtftgwS8CsfYo7nm0KE8jsvm6i/PTgVtB8DL726wNf6H2IMsDuxCpJj59KDaxCtSnrWan2AeDqM7JBaultg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
@@ -2962,9 +2952,9 @@
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/react-refresh": {
|
||||
"version": "0.17.0",
|
||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||
"integrity": "sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==",
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz",
|
||||
"integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -2972,9 +2962,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/react-router": {
|
||||
"version": "7.12.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.12.0.tgz",
|
||||
"integrity": "sha512-kTPDYPFzDVGIIGNLS5VJykK0HfHLY5MF3b+xj0/tTyNYL1gF1qs7u67Z9jEhQk2sQ98SUaHxlG31g1JtF7IfVw==",
|
||||
"version": "7.13.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.13.0.tgz",
|
||||
"integrity": "sha512-PZgus8ETambRT17BUm/LL8lX3Of+oiLaPuVTRH3l1eLvSPpKO3AvhAEb5N7ihAFZQrYDqkvvWfFh9p0z9VsjLw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cookie": "^1.0.1",
|
||||
@@ -2994,12 +2984,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/react-router-dom": {
|
||||
"version": "7.12.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.12.0.tgz",
|
||||
"integrity": "sha512-pfO9fiBcpEfX4Tx+iTYKDtPbrSLLCbwJ5EqP+SPYQu1VYCXdy79GSj0wttR0U4cikVdlImZuEZ/9ZNCgoaxwBA==",
|
||||
"version": "7.13.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.13.0.tgz",
|
||||
"integrity": "sha512-5CO/l5Yahi2SKC6rGZ+HDEjpjkGaG/ncEP7eWFTvFxbHP8yeeI0PxTDjimtpXYlR3b3i9/WIL4VJttPrESIf2g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"react-router": "7.12.0"
|
||||
"react-router": "7.13.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
@@ -3281,6 +3271,16 @@
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "7.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.21.0.tgz",
|
||||
"integrity": "sha512-Hn2tCQpoDt1wv23a68Ctc8Cr/BHpUSfaPYrkajTXOS9IKpxVRx/X5m1K2YkbK2ipgZgxXSgsUinl3x+2YdSSfg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20.18.1"
|
||||
}
|
||||
},
|
||||
"node_modules/update-browserslist-db": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.2.3.tgz",
|
||||
@@ -3313,9 +3313,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "7.3.0",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.0.tgz",
|
||||
"integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==",
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz",
|
||||
"integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -3388,19 +3388,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vitest": {
|
||||
"version": "4.0.17",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.17.tgz",
|
||||
"integrity": "sha512-FQMeF0DJdWY0iOnbv466n/0BudNdKj1l5jYgl5JVTwjSsZSlqyXFt/9+1sEyhR6CLowbZpV7O1sCHrzBhucKKg==",
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.18.tgz",
|
||||
"integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/expect": "4.0.17",
|
||||
"@vitest/mocker": "4.0.17",
|
||||
"@vitest/pretty-format": "4.0.17",
|
||||
"@vitest/runner": "4.0.17",
|
||||
"@vitest/snapshot": "4.0.17",
|
||||
"@vitest/spy": "4.0.17",
|
||||
"@vitest/utils": "4.0.17",
|
||||
"@vitest/expect": "4.0.18",
|
||||
"@vitest/mocker": "4.0.18",
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"@vitest/runner": "4.0.18",
|
||||
"@vitest/snapshot": "4.0.18",
|
||||
"@vitest/spy": "4.0.18",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"es-module-lexer": "^1.7.0",
|
||||
"expect-type": "^1.2.2",
|
||||
"magic-string": "^0.30.21",
|
||||
@@ -3428,10 +3428,10 @@
|
||||
"@edge-runtime/vm": "*",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
|
||||
"@vitest/browser-playwright": "4.0.17",
|
||||
"@vitest/browser-preview": "4.0.17",
|
||||
"@vitest/browser-webdriverio": "4.0.17",
|
||||
"@vitest/ui": "4.0.17",
|
||||
"@vitest/browser-playwright": "4.0.18",
|
||||
"@vitest/browser-preview": "4.0.18",
|
||||
"@vitest/browser-webdriverio": "4.0.18",
|
||||
"@vitest/ui": "4.0.18",
|
||||
"happy-dom": "*",
|
||||
"jsdom": "*"
|
||||
},
|
||||
@@ -3498,27 +3498,28 @@
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-mimetype": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz",
|
||||
"integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==",
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz",
|
||||
"integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-url": {
|
||||
"version": "15.1.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-15.1.0.tgz",
|
||||
"integrity": "sha512-2ytDk0kiEj/yu90JOAp44PVPUkO9+jVhyf+SybKlRHSDlvOOZhdPIrr7xTH64l4WixO2cP+wQIcgujkGBPPz6g==",
|
||||
"version": "16.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-16.0.0.tgz",
|
||||
"integrity": "sha512-9CcxtEKsf53UFwkSUZjG+9vydAsFO4lFHBpJUtjBcoJOCJpKnSJNwCw813zrYJHpCJ7sgfbtOe0V5Ku7Pa1XMQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@exodus/bytes": "^1.11.0",
|
||||
"tr46": "^6.0.0",
|
||||
"webidl-conversions": "^8.0.0"
|
||||
"webidl-conversions": "^8.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/why-is-node-running": {
|
||||
@@ -3538,28 +3539,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.19.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.19.0.tgz",
|
||||
"integrity": "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/xml-name-validator": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz",
|
||||
@@ -3585,9 +3564,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "3.25.76",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
|
||||
+12
-12
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "medassist-ng-frontend",
|
||||
"private": true,
|
||||
"version": "1.8.6",
|
||||
"version": "1.10.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -14,35 +14,35 @@
|
||||
"test": "vitest",
|
||||
"test:run": "vitest run",
|
||||
"test:coverage": "vitest run --coverage",
|
||||
"test:e2e": "playwright test",
|
||||
"test:e2e": "rm -rf test-results && playwright test --project=chromium --project=chromium-data --workers=1; find \"$PWD/test-results\" -name video.webm -not -path '*retry*' -print0 | xargs -0 ls -tr | sed \"s/^/file '/\" | sed \"s/$/'/ \" > /tmp/e2e-videos.txt && ffmpeg -y -f concat -safe 0 -i /tmp/e2e-videos.txt -c copy test-results/all-tests.webm && open -a 'Google Chrome' test-results/all-tests.webm",
|
||||
"test:e2e:ui": "playwright test --ui",
|
||||
"test:e2e:headed": "playwright test --headed",
|
||||
"test:e2e:debug": "playwright test --debug",
|
||||
"test:e2e:report": "playwright show-report"
|
||||
},
|
||||
"dependencies": {
|
||||
"i18next": "^24.2.2",
|
||||
"i18next-browser-languagedetector": "^8.0.4",
|
||||
"i18next": "^25.8.7",
|
||||
"i18next-browser-languagedetector": "^8.2.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-i18next": "^15.4.1",
|
||||
"react-router-dom": "^7.12.0",
|
||||
"zod": "^3.23.8"
|
||||
"react-router-dom": "^7.13.0",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.12",
|
||||
"@playwright/test": "^1.58.1",
|
||||
"@biomejs/biome": "^2.3.15",
|
||||
"@playwright/test": "^1.58.2",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"@types/react": "^18.3.4",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"@vitejs/plugin-react": "^4.3.2",
|
||||
"@vitest/coverage-v8": "^4.0.17",
|
||||
"jsdom": "^27.4.0",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"jsdom": "^28.0.0",
|
||||
"typescript": "^5.5.4",
|
||||
"vite": "^7.3.0",
|
||||
"vite": "^7.3.1",
|
||||
"vitest": "^4.0.17"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ export default defineConfig({
|
||||
// Capture screenshot on failure
|
||||
screenshot: "only-on-failure",
|
||||
|
||||
// Record video on first retry
|
||||
video: "on-first-retry",
|
||||
// Record video for every test so runs can be reviewed
|
||||
video: "on",
|
||||
|
||||
// Default viewport size
|
||||
viewport: { width: 1280, height: 720 },
|
||||
|
||||
// Wait for network idle before considering navigation complete
|
||||
navigationTimeout: 10000,
|
||||
navigationTimeout: 30000,
|
||||
|
||||
// Accept cookies and local storage
|
||||
actionTimeout: 5000,
|
||||
@@ -83,66 +83,71 @@ export default defineConfig({
|
||||
testMatch: /.*\.setup\.ts/,
|
||||
},
|
||||
|
||||
// Desktop browsers
|
||||
// Desktop Chrome — primary test browser, always runs
|
||||
// Excludes data/crud tests (those run in chromium-data to avoid DB conflicts)
|
||||
{
|
||||
name: "chromium",
|
||||
use: {
|
||||
...devices["Desktop Chrome"],
|
||||
},
|
||||
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
||||
dependencies: ["setup"],
|
||||
retries: 1,
|
||||
},
|
||||
|
||||
// Desktop Firefox — runs locally and optionally in CI
|
||||
// Excludes data/crud/edit/status/schedule tests (those run in chromium-data to avoid DB conflicts)
|
||||
{
|
||||
name: "firefox",
|
||||
use: {
|
||||
...devices["Desktop Firefox"],
|
||||
},
|
||||
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
||||
dependencies: ["setup"],
|
||||
},
|
||||
|
||||
// Desktop Safari — runs locally and optionally in CI
|
||||
// Excludes data/crud/edit/status/schedule tests (those run in chromium-data to avoid DB conflicts)
|
||||
{
|
||||
name: "webkit",
|
||||
use: {
|
||||
...devices["Desktop Safari"],
|
||||
},
|
||||
testIgnore: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
||||
dependencies: ["setup"],
|
||||
},
|
||||
|
||||
// Mobile browsers (optional)
|
||||
// Data tests — only Chromium, run serially to avoid DB conflicts
|
||||
// These tests create/edit/delete medications and must not run concurrently
|
||||
// across browsers since all share the same backend database.
|
||||
{
|
||||
name: "mobile-chrome",
|
||||
name: "chromium-data",
|
||||
testMatch: /.*-(?:data|crud|edit|status|schedule)\.spec\.ts/,
|
||||
use: {
|
||||
...devices["Pixel 5"],
|
||||
},
|
||||
dependencies: ["setup"],
|
||||
},
|
||||
|
||||
{
|
||||
name: "mobile-safari",
|
||||
use: {
|
||||
...devices["iPhone 12"],
|
||||
...devices["Desktop Chrome"],
|
||||
},
|
||||
dependencies: ["setup"],
|
||||
fullyParallel: false,
|
||||
retries: 1,
|
||||
},
|
||||
],
|
||||
|
||||
// Directory for test output files (screenshots, traces, videos)
|
||||
outputDir: "test-results/",
|
||||
|
||||
// Web server configuration - automatically start dev server if not running
|
||||
// Commented out by default as you typically run the dev servers separately
|
||||
// webServer: [
|
||||
// {
|
||||
// command: 'cd ../backend && npm run dev',
|
||||
// url: 'http://localhost:3000/health',
|
||||
// reuseExistingServer: !process.env.CI,
|
||||
// timeout: 120 * 1000,
|
||||
// },
|
||||
// {
|
||||
// command: 'npm run dev',
|
||||
// url: 'http://localhost:5173',
|
||||
// reuseExistingServer: !process.env.CI,
|
||||
// timeout: 120 * 1000,
|
||||
// },
|
||||
// ],
|
||||
// Web server configuration — automatically start dev servers in CI
|
||||
webServer: [
|
||||
{
|
||||
command: "cd ../backend && npm run dev",
|
||||
url: "http://localhost:3000/health",
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
{
|
||||
command: "npm run dev",
|
||||
url: "http://localhost:5173",
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
+9
-10
@@ -127,6 +127,8 @@ function AppContent() {
|
||||
setRefillPacks,
|
||||
refillLoose,
|
||||
setRefillLoose,
|
||||
usePrescriptionRefill,
|
||||
setUsePrescriptionRefill,
|
||||
refillSaving,
|
||||
refillHistory,
|
||||
refillHistoryExpanded,
|
||||
@@ -322,20 +324,15 @@ function AppContent() {
|
||||
useEffect(() => {
|
||||
const isModalOpen = selectedMed || selectedUser || showProfile || showAbout || showShareDialog;
|
||||
if (isModalOpen) {
|
||||
const scrollY = window.scrollY;
|
||||
document.documentElement.classList.add("modal-open");
|
||||
document.body.classList.add("modal-open");
|
||||
document.body.style.top = `-${scrollY}px`;
|
||||
} else {
|
||||
const scrollY = document.body.style.top;
|
||||
document.documentElement.classList.remove("modal-open");
|
||||
document.body.classList.remove("modal-open");
|
||||
document.body.style.top = "";
|
||||
if (scrollY) {
|
||||
window.scrollTo(0, parseInt(scrollY || "0", 10) * -1);
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
document.documentElement.classList.remove("modal-open");
|
||||
document.body.classList.remove("modal-open");
|
||||
document.body.style.top = "";
|
||||
};
|
||||
}, [selectedMed, selectedUser, showProfile, showAbout, showShareDialog]);
|
||||
|
||||
@@ -360,8 +357,8 @@ function AppContent() {
|
||||
};
|
||||
|
||||
// For MedDetailModal: refill without form update (not editing)
|
||||
const handleSubmitRefill = async (medId: number) => {
|
||||
await ctx.submitRefill(medId, null, () => {}, loadMeds);
|
||||
const handleSubmitRefill = async (medId: number, usePrescription: boolean = false) => {
|
||||
await ctx.submitRefill(medId, null, () => {}, loadMeds, usePrescription);
|
||||
};
|
||||
|
||||
// Wrapper for openEditStockModal (provides selectedMed and coverage)
|
||||
@@ -435,6 +432,8 @@ function AppContent() {
|
||||
onRefillPacksChange={setRefillPacks}
|
||||
refillLoose={refillLoose}
|
||||
onRefillLooseChange={setRefillLoose}
|
||||
usePrescriptionRefill={usePrescriptionRefill}
|
||||
onUsePrescriptionRefillChange={setUsePrescriptionRefill}
|
||||
refillSaving={refillSaving}
|
||||
refillHistory={refillHistory}
|
||||
refillHistoryExpanded={refillHistoryExpanded}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { FRONTEND_VERSION, GITHUB_URL } from "../App";
|
||||
interface UpdateCheckResult {
|
||||
status: "up-to-date" | "update-available" | "error";
|
||||
latestVersion?: string;
|
||||
lastChecked?: string;
|
||||
}
|
||||
|
||||
interface AboutModalProps {
|
||||
@@ -18,21 +17,10 @@ export default function AboutModal({ isOpen, onClose }: AboutModalProps) {
|
||||
const [isChecking, setIsChecking] = useState(false);
|
||||
const [updateCheckResult, setUpdateCheckResult] = useState<UpdateCheckResult | null>(null);
|
||||
|
||||
// Load cached update check result on mount
|
||||
// Reset check result when modal opens so stale results are never shown
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
// Load cached update check result
|
||||
const cached = sessionStorage.getItem("updateCheckResult");
|
||||
if (cached) {
|
||||
try {
|
||||
const parsed = JSON.parse(cached);
|
||||
if (parsed && typeof parsed === "object") {
|
||||
setUpdateCheckResult(parsed);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
if (isOpen) {
|
||||
setUpdateCheckResult(null);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
@@ -49,14 +37,10 @@ export default function AboutModal({ isOpen, onClose }: AboutModalProps) {
|
||||
const latestVersion = (data.tag_name || "").replace(/^v/, "");
|
||||
const currentVersion = FRONTEND_VERSION.replace(/^v/, "");
|
||||
const isUpToDate = latestVersion === currentVersion;
|
||||
const result: UpdateCheckResult = {
|
||||
setUpdateCheckResult({
|
||||
status: isUpToDate ? "up-to-date" : "update-available",
|
||||
latestVersion,
|
||||
lastChecked: new Date().toISOString(),
|
||||
};
|
||||
setUpdateCheckResult(result);
|
||||
// Cache the result
|
||||
sessionStorage.setItem("updateCheckResult", JSON.stringify(result));
|
||||
});
|
||||
} catch {
|
||||
setUpdateCheckResult({ status: "error" });
|
||||
} finally {
|
||||
@@ -114,11 +98,11 @@ export default function AboutModal({ isOpen, onClose }: AboutModalProps) {
|
||||
{updateCheckResult && (
|
||||
<div className={`about-update-result ${updateCheckResult.status}`}>
|
||||
{updateCheckResult.status === "up-to-date" && (
|
||||
<span className="update-status-text">✓ {t("about.upToDate", "You are up to date!")}</span>
|
||||
<span className="update-status-text">✓ {t("about.upToDate", "You are up to date!")}</span>
|
||||
)}
|
||||
{updateCheckResult.status === "update-available" && (
|
||||
<span className="update-status-text">
|
||||
⬆ {t("about.updateAvailable", "Update available")}:{" "}
|
||||
⬆ {t("about.updateAvailable", "Update available")}:{" "}
|
||||
<strong>v{updateCheckResult.latestVersion}</strong>
|
||||
<a
|
||||
href={`${GITHUB_URL}/releases/latest`}
|
||||
@@ -131,11 +115,8 @@ export default function AboutModal({ isOpen, onClose }: AboutModalProps) {
|
||||
</span>
|
||||
)}
|
||||
{updateCheckResult.status === "error" && (
|
||||
<span className="update-status-text">⚠ {t("about.checkFailed", "Could not check for updates")}</span>
|
||||
)}
|
||||
{updateCheckResult.lastChecked && (
|
||||
<span className="update-last-checked">
|
||||
{t("about.lastChecked", "Last checked")}: {new Date(updateCheckResult.lastChecked).toLocaleString()}
|
||||
<span className="update-status-text">
|
||||
⚠ {t("about.checkFailed", "Could not check for updates")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* AppHeader - Main application header with navigation and user menu
|
||||
*/
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { useUnsavedChanges } from "../context";
|
||||
import type { ThemePreference } from "../hooks";
|
||||
import { useTheme } from "../hooks";
|
||||
import { useAuth } from "./Auth";
|
||||
|
||||
@@ -19,9 +20,25 @@ export function AppHeader({ onOpenProfile, onOpenAbout }: AppHeaderProps) {
|
||||
const location = useLocation();
|
||||
const currentPath = location.pathname;
|
||||
const { user, authState, logout } = useAuth();
|
||||
const { theme, toggleTheme } = useTheme();
|
||||
const { theme, themePreference, setThemePreference } = useTheme();
|
||||
const { confirmNavigation } = useUnsavedChanges();
|
||||
|
||||
// Theme dropdown state
|
||||
const [themeMenuOpen, setThemeMenuOpen] = useState(false);
|
||||
const themeMenuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Close theme dropdown when clicking outside
|
||||
useEffect(() => {
|
||||
if (!themeMenuOpen) return;
|
||||
const handleClickOutside = (e: MouseEvent) => {
|
||||
if (themeMenuRef.current && !themeMenuRef.current.contains(e.target as Node)) {
|
||||
setThemeMenuOpen(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener("click", handleClickOutside);
|
||||
return () => document.removeEventListener("click", handleClickOutside);
|
||||
}, [themeMenuOpen]);
|
||||
|
||||
// Safe navigation that checks for unsaved changes first
|
||||
const safeNavigate = async (path: string) => {
|
||||
if (await confirmNavigation()) {
|
||||
@@ -94,13 +111,62 @@ export function AppHeader({ onOpenProfile, onOpenAbout }: AppHeaderProps) {
|
||||
⚙️
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
className="icon-btn"
|
||||
onClick={toggleTheme}
|
||||
title={theme === "dark" ? t("tooltips.lightMode") : t("tooltips.darkMode")}
|
||||
>
|
||||
{theme === "dark" ? "☀️" : "🌙"}
|
||||
</button>
|
||||
<div className={`theme-menu ${themeMenuOpen ? "open" : ""}`} ref={themeMenuRef}>
|
||||
<button className="icon-btn" onClick={() => setThemeMenuOpen(!themeMenuOpen)} title={t("theme.title")}>
|
||||
{theme === "dark" ? "🌙" : "☀️"}
|
||||
</button>
|
||||
<div className="theme-dropdown">
|
||||
<button
|
||||
className={`theme-dropdown-item${themePreference === "light" ? " active" : ""}`}
|
||||
onClick={() => {
|
||||
setThemePreference("light");
|
||||
setThemeMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="12" cy="12" r="5" />
|
||||
<line x1="12" y1="1" x2="12" y2="3" />
|
||||
<line x1="12" y1="21" x2="12" y2="23" />
|
||||
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64" />
|
||||
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78" />
|
||||
<line x1="1" y1="12" x2="3" y2="12" />
|
||||
<line x1="21" y1="12" x2="23" y2="12" />
|
||||
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36" />
|
||||
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22" />
|
||||
</svg>
|
||||
{t("theme.light")}
|
||||
{themePreference === "light" && <span className="theme-check">✓</span>}
|
||||
</button>
|
||||
<button
|
||||
className={`theme-dropdown-item${themePreference === "dark" ? " active" : ""}`}
|
||||
onClick={() => {
|
||||
setThemePreference("dark");
|
||||
setThemeMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
|
||||
</svg>
|
||||
{t("theme.dark")}
|
||||
{themePreference === "dark" && <span className="theme-check">✓</span>}
|
||||
</button>
|
||||
<button
|
||||
className={`theme-dropdown-item${themePreference === "system" ? " active" : ""}`}
|
||||
onClick={() => {
|
||||
setThemePreference("system");
|
||||
setThemeMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="2" y="3" width="20" height="14" rx="2" ry="2" />
|
||||
<line x1="8" y1="21" x2="16" y2="21" />
|
||||
<line x1="12" y1="17" x2="12" y2="21" />
|
||||
</svg>
|
||||
{t("theme.system")}
|
||||
{themePreference === "system" && <span className="theme-check">✓</span>}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{authState?.authEnabled && user && (
|
||||
<div className={`user-menu ${userDropdownOpen ? "open" : ""}`}>
|
||||
<button className="user-menu-btn" onClick={() => setUserDropdownOpen(!userDropdownOpen)}>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createContext, type ReactNode, useCallback, useContext, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { log } from "../utils/logger";
|
||||
import { ConfirmModal } from "./ConfirmModal";
|
||||
import { PasswordInput } from "./PasswordInput";
|
||||
|
||||
@@ -109,7 +110,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
setLoading(false);
|
||||
} catch (err) {
|
||||
console.error(`Failed to fetch auth state (attempt ${retryCount + 1}/${maxRetries + 1}):`, err);
|
||||
log.error(`Failed to fetch auth state (attempt ${retryCount + 1}/${maxRetries + 1}):`, err);
|
||||
|
||||
// Retry on connection errors or 5xx errors (server might be restarting)
|
||||
if (retryCount < maxRetries) {
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface ConfirmModalProps {
|
||||
onCancel: () => void;
|
||||
isLoading?: boolean;
|
||||
confirmVariant?: "primary" | "danger" | "success";
|
||||
overlayClassName?: string;
|
||||
}
|
||||
|
||||
export function ConfirmModal({
|
||||
@@ -24,9 +25,10 @@ export function ConfirmModal({
|
||||
onCancel,
|
||||
isLoading = false,
|
||||
confirmVariant = "primary",
|
||||
overlayClassName,
|
||||
}: ConfirmModalProps) {
|
||||
return (
|
||||
<div className="modal-overlay" onClick={onCancel}>
|
||||
<div className={`modal-overlay${overlayClassName ? ` ${overlayClassName}` : ""}`} onClick={onCancel}>
|
||||
<div className="modal-content" onClick={(e) => e.stopPropagation()} style={{ maxWidth: "450px" }}>
|
||||
<button className="modal-close" onClick={onCancel}>
|
||||
×
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* 1. Context mode: Uses useAppContext() for all state (when no props provided)
|
||||
* 2. Props mode: Accepts all required data as props (for gradual adoption)
|
||||
*/
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Lightbox, MedicationAvatar } from "../components";
|
||||
import type { Coverage, Medication, RefillEntry, StockThresholds } from "../types";
|
||||
@@ -83,11 +84,13 @@ export interface MedDetailModalProps {
|
||||
onRefillPacksChange: (value: number) => void;
|
||||
refillLoose: number;
|
||||
onRefillLooseChange: (value: number) => void;
|
||||
usePrescriptionRefill: boolean;
|
||||
onUsePrescriptionRefillChange: (value: boolean) => void;
|
||||
refillSaving: boolean;
|
||||
refillHistory: RefillEntry[];
|
||||
refillHistoryExpanded: boolean;
|
||||
onRefillHistoryExpandedChange: (value: boolean) => void;
|
||||
onSubmitRefill: (medId: number) => Promise<void>;
|
||||
onSubmitRefill: (medId: number, usePrescription?: boolean) => Promise<void>;
|
||||
// Edit stock state
|
||||
editStockFullBlisters: number;
|
||||
onEditStockFullBlistersChange: (value: number) => void;
|
||||
@@ -115,6 +118,8 @@ export function MedDetailModal({
|
||||
onRefillPacksChange,
|
||||
refillLoose,
|
||||
onRefillLooseChange,
|
||||
usePrescriptionRefill,
|
||||
onUsePrescriptionRefillChange,
|
||||
refillSaving,
|
||||
refillHistory,
|
||||
refillHistoryExpanded,
|
||||
@@ -128,6 +133,20 @@ export function MedDetailModal({
|
||||
onSubmitStockCorrection,
|
||||
}: MedDetailModalProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [editStockFullInput, setEditStockFullInput] = useState("0");
|
||||
const [editStockPartialInput, setEditStockPartialInput] = useState("0");
|
||||
|
||||
const parseStockInput = (value: string): number => {
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isNaN(parsed) ? 0 : parsed;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (showEditStockModal) {
|
||||
setEditStockFullInput(String(editStockFullBlisters));
|
||||
setEditStockPartialInput(String(editStockPartialBlisterPills));
|
||||
}
|
||||
}, [showEditStockModal, editStockFullBlisters, editStockPartialBlisterPills]);
|
||||
|
||||
if (!selectedMed) return null;
|
||||
|
||||
@@ -138,6 +157,7 @@ export function MedDetailModal({
|
||||
const textClass =
|
||||
status?.className === "danger" ? "danger-text" : status?.className === "warning" ? "warning-text" : "success-text";
|
||||
const stock = getBlisterStock(currentStock, selectedMed.pillsPerBlister, selectedMed.looseTablets, packageSize);
|
||||
const fullForBounds = Math.max(0, parseStockInput(editStockFullInput));
|
||||
|
||||
return (
|
||||
<div className="modal-overlay" onClick={onClose}>
|
||||
@@ -195,6 +215,16 @@ export function MedDetailModal({
|
||||
<span className={`med-detail-value ${textClass}`}>
|
||||
{currentStock} /{" "}
|
||||
{selectedMed.packageType === "bottle" ? (selectedMed.totalPills ?? packageSize) : packageSize}
|
||||
{currentStock >
|
||||
(selectedMed.packageType === "bottle" ? (selectedMed.totalPills ?? packageSize) : packageSize) && (
|
||||
<span
|
||||
className="info-tooltip tooltip-align-left warning-text"
|
||||
data-tooltip={t("tooltips.stockExceedsCapacity")}
|
||||
>
|
||||
{" "}
|
||||
⚠️
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -202,7 +232,10 @@ export function MedDetailModal({
|
||||
|
||||
{/* Package Details Section */}
|
||||
<div className="med-detail-section">
|
||||
<h3>{t("modal.packageDetails")}</h3>
|
||||
<h3>
|
||||
{t("modal.packageDetails")} (
|
||||
{selectedMed.packageType === "bottle" ? t("form.packageTypeBottle") : t("form.packageTypeBlister")})
|
||||
</h3>
|
||||
<div className="med-detail-grid">
|
||||
{selectedMed.packageType === "blister" ? (
|
||||
<>
|
||||
@@ -222,7 +255,7 @@ export function MedDetailModal({
|
||||
) : (
|
||||
<div className="med-detail-item">
|
||||
<span className="med-detail-label">{t("form.totalCapacity")}</span>
|
||||
<span className="med-detail-value">{selectedMed.totalPills ?? "—"}</span>
|
||||
<span className="med-detail-value">{(selectedMed.totalPills ?? packageSize) || "—"}</span>
|
||||
</div>
|
||||
)}
|
||||
{selectedMed.pillWeightMg && (
|
||||
@@ -250,6 +283,42 @@ export function MedDetailModal({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Prescription Details Section */}
|
||||
{selectedMed.prescriptionEnabled && (
|
||||
<div className="med-detail-section">
|
||||
<h3>{t("form.sections.prescription")}</h3>
|
||||
<div className="med-detail-grid">
|
||||
<div className="med-detail-item">
|
||||
<span className="med-detail-label">{t("prescription.authorizedRefills")}</span>
|
||||
<span className="med-detail-value">{selectedMed.prescriptionAuthorizedRefills ?? "—"}</span>
|
||||
</div>
|
||||
<div className="med-detail-item">
|
||||
<span className="med-detail-label">{t("prescription.remainingRefills")}</span>
|
||||
<span className="med-detail-value">{selectedMed.prescriptionRemainingRefills ?? "—"}</span>
|
||||
</div>
|
||||
<div className="med-detail-item">
|
||||
<span className="med-detail-label">{t("prescription.lowThreshold")}</span>
|
||||
<span className="med-detail-value">{selectedMed.prescriptionLowRefillThreshold ?? "—"}</span>
|
||||
</div>
|
||||
<div className="med-detail-item">
|
||||
<span className="med-detail-label">{t("prescription.expiryDate")}</span>
|
||||
<span className="med-detail-value">
|
||||
{selectedMed.prescriptionExpiryDate
|
||||
? new Date(selectedMed.prescriptionExpiryDate).toLocaleDateString(
|
||||
getSystemLocale(i18n.language),
|
||||
{
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
}
|
||||
)
|
||||
: "—"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Intake Schedule Section */}
|
||||
{selectedMed.blisters.length > 0 && (
|
||||
<div className="med-detail-section">
|
||||
@@ -263,7 +332,12 @@ export function MedDetailModal({
|
||||
</h3>
|
||||
<div className="med-detail-schedules">
|
||||
{selectedMed.blisters.map((blister, idx) => {
|
||||
const personCount = Math.max(1, selectedMed.takenBy?.length || 1);
|
||||
// When using new intakes format with per-intake takenBy,
|
||||
// each intake already represents one person's dose — don't multiply.
|
||||
// For legacy intakes (no per-intake takenBy), multiply by personCount.
|
||||
const intake = selectedMed.intakes?.[idx];
|
||||
const hasPerIntakeTakenBy = !!intake?.takenBy;
|
||||
const personCount = hasPerIntakeTakenBy ? 1 : Math.max(1, selectedMed.takenBy?.length || 1);
|
||||
const totalUsage = blister.usage * personCount;
|
||||
return (
|
||||
<div key={idx} className="med-schedule-item">
|
||||
@@ -347,10 +421,20 @@ export function MedDetailModal({
|
||||
})}
|
||||
</span>
|
||||
<span className="refill-amount">
|
||||
+
|
||||
{entry.packsAdded * selectedMed.blistersPerPack * selectedMed.pillsPerBlister +
|
||||
entry.loosePillsAdded}{" "}
|
||||
{t("common.pills")}
|
||||
{(() => {
|
||||
const total =
|
||||
selectedMed.packageType === "bottle"
|
||||
? entry.loosePillsAdded
|
||||
: entry.packsAdded * selectedMed.blistersPerPack * selectedMed.pillsPerBlister +
|
||||
entry.loosePillsAdded;
|
||||
return `+${total} ${total === 1 ? t("common.pill") : t("common.pills")}`;
|
||||
})()}
|
||||
{entry.usedPrescription && (
|
||||
<span className="refill-prescription-badge" title={t("refill.viaPrescription")}>
|
||||
{" "}
|
||||
📋
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -405,24 +489,55 @@ export function MedDetailModal({
|
||||
<p className="refill-med-name">{selectedMed.name}</p>
|
||||
|
||||
<div className="refill-form">
|
||||
<label>
|
||||
{t("refill.packs")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillPacks}
|
||||
onChange={(e) => onRefillPacksChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("refill.loosePills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
{selectedMed.packageType === "blister" ? (
|
||||
<>
|
||||
<label>
|
||||
{t("refill.packs")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillPacks}
|
||||
onChange={(e) => onRefillPacksChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("refill.loosePills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<label>
|
||||
{t("refill.pillsToAdd")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
|
||||
{selectedMed.prescriptionEnabled && (
|
||||
<div className="refill-prescription-row full">
|
||||
<label className="refill-prescription-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={usePrescriptionRefill}
|
||||
onChange={(e) => onUsePrescriptionRefillChange(e.target.checked)}
|
||||
disabled={(Number(selectedMed.prescriptionRemainingRefills) || 0) <= 0}
|
||||
/>
|
||||
<span className="refill-prescription-label-text">{t("prescription.useForRefill")}</span>
|
||||
</label>
|
||||
<span className="refill-remaining-badge">
|
||||
{t("prescription.remainingRefills")}: {Number(selectedMed.prescriptionRemainingRefills) || 0}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="modal-footer">
|
||||
@@ -432,17 +547,22 @@ export function MedDetailModal({
|
||||
<div className="refill-footer-right">
|
||||
<button
|
||||
className="success"
|
||||
onClick={() => onSubmitRefill(selectedMed.id)}
|
||||
onClick={() => onSubmitRefill(selectedMed.id, usePrescriptionRefill)}
|
||||
disabled={(refillPacks < 1 && refillLoose < 1) || refillSaving}
|
||||
>
|
||||
{refillSaving ? t("common.saving") : t("refill.button")}
|
||||
</button>
|
||||
{(refillPacks > 0 || refillLoose > 0) && (
|
||||
<span className="refill-preview">
|
||||
+{refillPacks * selectedMed.blistersPerPack * selectedMed.pillsPerBlister + refillLoose}{" "}
|
||||
{t("common.pills")}
|
||||
</span>
|
||||
)}
|
||||
{(() => {
|
||||
const totalRefill =
|
||||
selectedMed.packageType === "blister"
|
||||
? refillPacks * selectedMed.blistersPerPack * selectedMed.pillsPerBlister + refillLoose
|
||||
: refillLoose;
|
||||
return totalRefill > 0 ? (
|
||||
<span className="refill-preview">
|
||||
+{totalRefill} {totalRefill === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
) : null;
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -469,50 +589,98 @@ export function MedDetailModal({
|
||||
{(() => {
|
||||
const dbTotal = getMedTotal(selectedMed);
|
||||
const currentTotal = medCoverage ? Math.round(medCoverage.medsLeft) : dbTotal;
|
||||
const newTotal = editStockFullBlisters * selectedMed.pillsPerBlister + editStockPartialBlisterPills;
|
||||
const isBottle = selectedMed.packageType === "bottle";
|
||||
const newTotal = isBottle
|
||||
? editStockPartialBlisterPills
|
||||
: editStockFullBlisters * selectedMed.pillsPerBlister + editStockPartialBlisterPills;
|
||||
const difference = newTotal - currentTotal;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="edit-stock-form">
|
||||
<label>
|
||||
{t("editStock.fullBlisters")}{" "}
|
||||
{t("editStock.pillsPerBlister", { count: selectedMed.pillsPerBlister })}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={editStockFullBlisters}
|
||||
onChange={(e) => onEditStockFullBlistersChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("editStock.partialBlisterPills")}
|
||||
<input
|
||||
type="number"
|
||||
min={editStockFullBlisters > 0 ? -(selectedMed.pillsPerBlister - 1) : 0}
|
||||
max={selectedMed.pillsPerBlister}
|
||||
value={editStockPartialBlisterPills}
|
||||
onChange={(e) => {
|
||||
const val = parseInt(e.target.value, 10) || 0;
|
||||
const min = editStockFullBlisters > 0 ? -(selectedMed.pillsPerBlister - 1) : 0;
|
||||
const max = selectedMed.pillsPerBlister;
|
||||
onEditStockPartialBlisterPillsChange(Math.max(min, Math.min(val, max)));
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
{isBottle ? (
|
||||
<label>
|
||||
{t("editStock.totalPills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={editStockPartialInput}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
setEditStockPartialInput(raw);
|
||||
onEditStockPartialBlisterPillsChange(raw === "" ? 0 : Math.max(0, parseStockInput(raw)));
|
||||
}}
|
||||
onBlur={() => {
|
||||
const normalized = Math.max(0, parseStockInput(editStockPartialInput));
|
||||
onEditStockPartialBlisterPillsChange(normalized);
|
||||
setEditStockPartialInput(String(normalized));
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
) : (
|
||||
<>
|
||||
<label>
|
||||
{t("editStock.fullBlisters")}{" "}
|
||||
{t("editStock.pillsPerBlister", { count: selectedMed.pillsPerBlister })}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={editStockFullInput}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
setEditStockFullInput(raw);
|
||||
onEditStockFullBlistersChange(raw === "" ? 0 : Math.max(0, parseStockInput(raw)));
|
||||
}}
|
||||
onBlur={() => {
|
||||
const normalized = Math.max(0, parseStockInput(editStockFullInput));
|
||||
onEditStockFullBlistersChange(normalized);
|
||||
setEditStockFullInput(String(normalized));
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("editStock.partialBlisterPills")}
|
||||
<input
|
||||
type="number"
|
||||
min={fullForBounds > 0 ? -(selectedMed.pillsPerBlister - 1) : 0}
|
||||
max={selectedMed.pillsPerBlister}
|
||||
value={editStockPartialInput}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
setEditStockPartialInput(raw);
|
||||
if (raw === "") {
|
||||
onEditStockPartialBlisterPillsChange(0);
|
||||
return;
|
||||
}
|
||||
const val = parseStockInput(raw);
|
||||
const min = fullForBounds > 0 ? -(selectedMed.pillsPerBlister - 1) : 0;
|
||||
const max = selectedMed.pillsPerBlister;
|
||||
onEditStockPartialBlisterPillsChange(Math.max(min, Math.min(val, max)));
|
||||
}}
|
||||
onBlur={() => {
|
||||
const min = fullForBounds > 0 ? -(selectedMed.pillsPerBlister - 1) : 0;
|
||||
const max = selectedMed.pillsPerBlister;
|
||||
const normalized = Math.max(min, Math.min(parseStockInput(editStockPartialInput), max));
|
||||
onEditStockPartialBlisterPillsChange(normalized);
|
||||
setEditStockPartialInput(String(normalized));
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="edit-stock-summary">
|
||||
<div className="summary-row">
|
||||
<span>{t("editStock.currentTotal")}:</span>
|
||||
<span>
|
||||
{currentTotal} {t("common.pills")}
|
||||
{currentTotal} {currentTotal === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
</div>
|
||||
<div className="summary-row">
|
||||
<span>{t("editStock.newTotal")}:</span>
|
||||
<span>
|
||||
{newTotal} {t("common.pills")}
|
||||
{newTotal} {newTotal === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
@@ -521,7 +689,7 @@ export function MedDetailModal({
|
||||
<span>{t("editStock.difference")}:</span>
|
||||
<span>
|
||||
{difference > 0 ? "+" : ""}
|
||||
{difference} {t("common.pills")}
|
||||
{difference} {Math.abs(difference) === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -41,12 +41,14 @@ export interface MobileEditModalProps {
|
||||
onAddIntake: (takenBy?: string) => void;
|
||||
onRemoveIntake: (idx: number) => void;
|
||||
// Value change handler for numeric fields
|
||||
onHandleValueChange: <K extends keyof FormState>(field: K, value: string) => void;
|
||||
onHandleValueChange: <K extends keyof FormState>(field: K, value: FormState[K]) => void;
|
||||
// Refill state (for edit mode)
|
||||
refillPacks: number;
|
||||
onRefillPacksChange: (value: number) => void;
|
||||
refillLoose: number;
|
||||
onRefillLooseChange: (value: number) => void;
|
||||
usePrescriptionRefill: boolean;
|
||||
onUsePrescriptionRefillChange: (value: boolean) => void;
|
||||
refillSaving: boolean;
|
||||
onSubmitRefill: (medId: number) => Promise<void>;
|
||||
// Image handling
|
||||
@@ -99,6 +101,8 @@ export function MobileEditModal({
|
||||
onRefillPacksChange,
|
||||
refillLoose,
|
||||
onRefillLooseChange,
|
||||
usePrescriptionRefill,
|
||||
onUsePrescriptionRefillChange,
|
||||
refillSaving,
|
||||
onSubmitRefill,
|
||||
meds,
|
||||
@@ -121,6 +125,9 @@ export function MobileEditModal({
|
||||
×
|
||||
</button>
|
||||
<div className="edit-modal-header">
|
||||
<button type="button" className="ghost small" onClick={onClose}>
|
||||
← {t("common.back")}
|
||||
</button>
|
||||
<h2>{editingId ? t("form.editEntry") : t("form.newEntry")}</h2>
|
||||
</div>
|
||||
<form
|
||||
@@ -137,266 +144,386 @@ export function MobileEditModal({
|
||||
onSaveMedication(e);
|
||||
}}
|
||||
>
|
||||
<label className={`full ${fieldErrors.name ? "has-error" : ""}`}>
|
||||
{t("form.commercialName")}
|
||||
<input
|
||||
value={form.name}
|
||||
onChange={(e) => onFormChange({ ...form, name: e.target.value })}
|
||||
placeholder={t("form.placeholders.commercial")}
|
||||
maxLength={FIELD_LIMITS.name.max}
|
||||
required
|
||||
/>
|
||||
{fieldErrors.name && <span className="field-error">{fieldErrors.name}</span>}
|
||||
</label>
|
||||
<label className={`full ${fieldErrors.genericName ? "has-error" : ""}`}>
|
||||
{t("form.genericName")}
|
||||
<input
|
||||
value={form.genericName}
|
||||
onChange={(e) => onFormChange({ ...form, genericName: e.target.value })}
|
||||
placeholder={t("form.placeholders.generic")}
|
||||
maxLength={FIELD_LIMITS.genericName.max}
|
||||
/>
|
||||
{fieldErrors.genericName && <span className="field-error">{fieldErrors.genericName}</span>}
|
||||
</label>
|
||||
<label className={`full ${fieldErrors.takenBy ? "has-error" : ""}`}>
|
||||
{t("form.takenBy")}
|
||||
<div className="tag-input-container">
|
||||
{form.takenBy.map((person) => (
|
||||
<span key={person} className="tag">
|
||||
{person}
|
||||
<button type="button" className="tag-remove" onClick={() => onRemoveTakenByPerson(person)}>
|
||||
×
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
<div className="full form-category">
|
||||
<h4 className="form-category-title">{t("form.sections.general")}</h4>
|
||||
<label className={`full ${fieldErrors.name ? "has-error" : ""}`}>
|
||||
{t("form.commercialName")}
|
||||
<input
|
||||
value={takenByInput}
|
||||
onChange={(e) => onTakenByInputChange(e.target.value)}
|
||||
onKeyDown={onTakenByKeyDown}
|
||||
onBlur={() => {
|
||||
if (takenByInput.trim()) onAddTakenByPerson(takenByInput);
|
||||
}}
|
||||
placeholder={
|
||||
form.takenBy.length === 0 ? t("form.placeholders.takenBy") : t("form.placeholders.addPerson")
|
||||
}
|
||||
maxLength={FIELD_LIMITS.takenBy.max}
|
||||
list="takenby-suggestions-modal"
|
||||
value={form.name}
|
||||
onChange={(e) => onFormChange({ ...form, name: e.target.value })}
|
||||
placeholder={t("form.placeholders.commercial")}
|
||||
maxLength={FIELD_LIMITS.name.max}
|
||||
required
|
||||
/>
|
||||
<datalist id="takenby-suggestions-modal">
|
||||
{existingPeople
|
||||
.filter((p) => !form.takenBy.includes(p))
|
||||
.map((person) => (
|
||||
<option key={person} value={person} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
{fieldErrors.takenBy && <span className="field-error">{fieldErrors.takenBy}</span>}
|
||||
</label>
|
||||
<label className="full">
|
||||
{t("form.packageType")}
|
||||
<select
|
||||
className="package-type-select"
|
||||
value={form.packageType}
|
||||
onChange={(e) => onHandleValueChange("packageType", e.target.value)}
|
||||
>
|
||||
<option value="blister">{t("form.packageTypeBlister")}</option>
|
||||
<option value="bottle">{t("form.packageTypeBottle")}</option>
|
||||
</select>
|
||||
</label>
|
||||
{form.packageType === "blister" ? (
|
||||
<>
|
||||
<label>
|
||||
{t("form.packs")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={form.packCount}
|
||||
onChange={(e) => onHandleValueChange("packCount", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.blistersPerPack")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={form.blistersPerPack}
|
||||
onChange={(e) => onHandleValueChange("blistersPerPack", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.pillsPerBlister")}
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
value={form.pillsPerBlister}
|
||||
onChange={(e) => onHandleValueChange("pillsPerBlister", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.loosePills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={form.looseTablets}
|
||||
onChange={(e) => onHandleValueChange("looseTablets", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<label>
|
||||
{t("form.totalCapacity")}
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
value={form.totalPills}
|
||||
onChange={(e) => onHandleValueChange("totalPills", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.currentPills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={form.looseTablets}
|
||||
onChange={(e) => onHandleValueChange("looseTablets", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
<div className="full">
|
||||
<p className="sub">
|
||||
<strong>{t("form.total")}:</strong> {deriveTotalFromForm(form)} {t("common.pills")}
|
||||
</p>
|
||||
</div>
|
||||
<label className="full">
|
||||
{t("form.pillWeight")} ({form.doseUnit})
|
||||
<div className="dose-input-group">
|
||||
{fieldErrors.name && <span className="field-error">{fieldErrors.name}</span>}
|
||||
</label>
|
||||
<label className={`full ${fieldErrors.genericName ? "has-error" : ""}`}>
|
||||
{t("form.genericName")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.1"
|
||||
value={form.pillWeightMg}
|
||||
onChange={(e) => onFormChange({ ...form, pillWeightMg: e.target.value })}
|
||||
placeholder={t("form.placeholders.weight")}
|
||||
value={form.genericName}
|
||||
onChange={(e) => onFormChange({ ...form, genericName: e.target.value })}
|
||||
placeholder={t("form.placeholders.generic")}
|
||||
maxLength={FIELD_LIMITS.genericName.max}
|
||||
/>
|
||||
<select
|
||||
value={form.doseUnit}
|
||||
onChange={(e) => onFormChange({ ...form, doseUnit: e.target.value as DoseUnit })}
|
||||
className="dose-unit-select"
|
||||
>
|
||||
{DOSE_UNITS.map((unit) => (
|
||||
<option key={unit.value} value={unit.value}>
|
||||
{unit.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</label>
|
||||
<label className="full">
|
||||
{t("form.expiryDate")}
|
||||
<input
|
||||
type="date"
|
||||
value={form.expiryDate}
|
||||
onChange={(e) => onFormChange({ ...form, expiryDate: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{/* Refill section - only shown when editing (mobile) */}
|
||||
{editingId && (
|
||||
<div className="full refill-section">
|
||||
<h4 className="refill-title">{t("refill.title")}</h4>
|
||||
<div className="refill-form-inline">
|
||||
<label>
|
||||
{t("refill.packs")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillPacks}
|
||||
onChange={(e) => onRefillPacksChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("refill.loosePills")}
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className="success"
|
||||
onClick={() => onSubmitRefill(editingId)}
|
||||
disabled={(refillPacks < 1 && refillLoose < 1) || refillSaving}
|
||||
>
|
||||
{refillSaving ? t("common.saving") : t("refill.button")}
|
||||
</button>
|
||||
{(refillPacks > 0 || refillLoose > 0) && (
|
||||
<span className="refill-preview">
|
||||
+{refillPacks * Number(form.blistersPerPack || 0) * Number(form.pillsPerBlister || 1) + refillLoose}{" "}
|
||||
{t("common.pills")}
|
||||
{fieldErrors.genericName && <span className="field-error">{fieldErrors.genericName}</span>}
|
||||
</label>
|
||||
<label className={`full ${fieldErrors.takenBy ? "has-error" : ""}`}>
|
||||
{t("form.takenBy")}
|
||||
<div className="tag-input-container">
|
||||
{form.takenBy.map((person) => (
|
||||
<span key={person} className="tag">
|
||||
{person}
|
||||
<button type="button" className="tag-remove" onClick={() => onRemoveTakenByPerson(person)}>
|
||||
×
|
||||
</button>
|
||||
</span>
|
||||
)}
|
||||
))}
|
||||
<input
|
||||
value={takenByInput}
|
||||
onChange={(e) => onTakenByInputChange(e.target.value)}
|
||||
onKeyDown={onTakenByKeyDown}
|
||||
onBlur={() => {
|
||||
if (takenByInput.trim()) onAddTakenByPerson(takenByInput);
|
||||
}}
|
||||
placeholder={
|
||||
form.takenBy.length === 0 ? t("form.placeholders.takenBy") : t("form.placeholders.addPerson")
|
||||
}
|
||||
maxLength={FIELD_LIMITS.takenBy.max}
|
||||
list="takenby-suggestions-modal"
|
||||
/>
|
||||
<datalist id="takenby-suggestions-modal">
|
||||
{existingPeople
|
||||
.filter((p) => !form.takenBy.includes(p))
|
||||
.map((person) => (
|
||||
<option key={person} value={person} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<label className={`full ${fieldErrors.notes ? "has-error" : ""}`}>
|
||||
{t("form.notes")}
|
||||
<textarea
|
||||
value={form.notes}
|
||||
onChange={(e) => onFormChange({ ...form, notes: e.target.value })}
|
||||
placeholder={t("form.placeholders.notes")}
|
||||
rows={2}
|
||||
maxLength={FIELD_LIMITS.notes.max}
|
||||
className="auto-resize"
|
||||
onInput={(e) => {
|
||||
const target = e.target as HTMLTextAreaElement;
|
||||
target.style.height = "auto";
|
||||
target.style.height = `${target.scrollHeight}px`;
|
||||
}}
|
||||
/>
|
||||
{form.notes.length > 0 && (
|
||||
<span className={`char-count ${form.notes.length > FIELD_LIMITS.notes.max * 0.9 ? "warning" : ""}`}>
|
||||
{t("common.validation.tooLong", { current: form.notes.length, max: FIELD_LIMITS.notes.max })}
|
||||
</span>
|
||||
)}
|
||||
{fieldErrors.notes && <span className="field-error">{fieldErrors.notes}</span>}
|
||||
</label>
|
||||
|
||||
{editingId && currentMed?.imageUrl ? (
|
||||
<div className="full image-field">
|
||||
<span className="field-label">{t("form.medicationImage")}</span>
|
||||
<div className="image-preview">
|
||||
<img src={`/api/images/${currentMed.imageUrl}`} alt={currentMed.name} />
|
||||
<button type="button" className="danger" onClick={() => onDeleteMedImage(editingId)}>
|
||||
{t("form.removeImage")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : editingId ? (
|
||||
{fieldErrors.takenBy && <span className="field-error">{fieldErrors.takenBy}</span>}
|
||||
</label>
|
||||
<label className="full">
|
||||
{t("form.medicationImage")}
|
||||
{t("form.packageType")}
|
||||
<select
|
||||
className="package-type-select"
|
||||
value={form.packageType}
|
||||
onChange={(e) => onHandleValueChange("packageType", e.target.value)}
|
||||
>
|
||||
<option value="blister">{t("form.packageTypeBlister")}</option>
|
||||
<option value="bottle">{t("form.packageTypeBottle")}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="full form-category">
|
||||
<h4 className="form-category-title">{t("form.sections.stock")}</h4>
|
||||
{form.packageType === "blister" ? (
|
||||
<>
|
||||
<label>
|
||||
{t("form.packs")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.packCount}
|
||||
onChange={(e) => onHandleValueChange("packCount", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.blistersPerPack")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.blistersPerPack}
|
||||
onChange={(e) => onHandleValueChange("blistersPerPack", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.pillsPerBlister")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.pillsPerBlister}
|
||||
onChange={(e) => onHandleValueChange("pillsPerBlister", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.loosePills")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.looseTablets}
|
||||
onChange={(e) => onHandleValueChange("looseTablets", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<label>
|
||||
{t("form.totalCapacity")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.totalPills}
|
||||
onChange={(e) => onHandleValueChange("totalPills", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("form.currentPills")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.looseTablets}
|
||||
onChange={(e) => onHandleValueChange("looseTablets", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
<div className="full">
|
||||
<p className="sub">
|
||||
<strong>{t("form.total")}:</strong> {deriveTotalFromForm(form)}{" "}
|
||||
{deriveTotalFromForm(form) === 1 ? t("common.pill") : t("common.pills")}
|
||||
</p>
|
||||
</div>
|
||||
<label className="full">
|
||||
{t("form.pillWeight")} ({form.doseUnit})
|
||||
<div className="dose-input-group">
|
||||
<input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
pattern="[0-9]*\.?[0-9]*"
|
||||
value={form.pillWeightMg}
|
||||
onChange={(e) => onFormChange({ ...form, pillWeightMg: e.target.value })}
|
||||
placeholder={t("form.placeholders.weight")}
|
||||
/>
|
||||
<select
|
||||
value={form.doseUnit}
|
||||
onChange={(e) => onFormChange({ ...form, doseUnit: e.target.value as DoseUnit })}
|
||||
className="dose-unit-select"
|
||||
>
|
||||
{DOSE_UNITS.map((unit) => (
|
||||
<option key={unit.value} value={unit.value}>
|
||||
{unit.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</label>
|
||||
<label className="full">
|
||||
{t("form.expiryDate")}
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={(e) => e.target.files?.[0] && onUploadMedImage(editingId, e.target.files[0])}
|
||||
type="date"
|
||||
value={form.expiryDate}
|
||||
onChange={(e) => onFormChange({ ...form, expiryDate: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
<label className={`full ${fieldErrors.notes ? "has-error" : ""}`}>
|
||||
{t("form.notes")}
|
||||
<textarea
|
||||
value={form.notes}
|
||||
onChange={(e) => onFormChange({ ...form, notes: e.target.value })}
|
||||
placeholder={t("form.placeholders.notes")}
|
||||
rows={2}
|
||||
maxLength={FIELD_LIMITS.notes.max}
|
||||
className="auto-resize"
|
||||
onInput={(e) => {
|
||||
const target = e.target as HTMLTextAreaElement;
|
||||
target.style.height = "auto";
|
||||
target.style.height = `${target.scrollHeight}px`;
|
||||
}}
|
||||
/>
|
||||
{form.notes.length > 0 && (
|
||||
<span className={`char-count ${form.notes.length > FIELD_LIMITS.notes.max * 0.9 ? "warning" : ""}`}>
|
||||
{t("common.validation.tooLong", { current: form.notes.length, max: FIELD_LIMITS.notes.max })}
|
||||
</span>
|
||||
)}
|
||||
{fieldErrors.notes && <span className="field-error">{fieldErrors.notes}</span>}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<fieldset className="full blister-section">
|
||||
<legend>{t("form.blisters.title")}</legend>
|
||||
<div className="full form-category">
|
||||
<h4 className="form-category-title">{t("form.sections.prescription")}</h4>
|
||||
<label className="full">
|
||||
{t("prescription.enabled")}
|
||||
<label className="toggle-switch small">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.prescriptionEnabled}
|
||||
onChange={(e) => onHandleValueChange("prescriptionEnabled", e.target.checked)}
|
||||
/>
|
||||
<span className="toggle-slider"></span>
|
||||
</label>
|
||||
</label>
|
||||
{form.prescriptionEnabled && (
|
||||
<>
|
||||
<label className="prescription-field">
|
||||
{t("prescription.authorizedRefills")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.prescriptionAuthorizedRefills}
|
||||
onChange={(e) => onHandleValueChange("prescriptionAuthorizedRefills", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="prescription-field">
|
||||
{t("prescription.remainingRefills")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.prescriptionRemainingRefills}
|
||||
onChange={(e) => onHandleValueChange("prescriptionRemainingRefills", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="prescription-field">
|
||||
{t("prescription.lowThreshold")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={form.prescriptionLowRefillThreshold}
|
||||
onChange={(e) => onHandleValueChange("prescriptionLowRefillThreshold", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="prescription-field">
|
||||
{t("prescription.expiryDate")}
|
||||
<input
|
||||
type="date"
|
||||
value={form.prescriptionExpiryDate}
|
||||
onChange={(e) => onHandleValueChange("prescriptionExpiryDate", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="full form-category refill-section">
|
||||
<h4 className="form-category-title">{t("refill.title")}</h4>
|
||||
{editingId ? (
|
||||
<>
|
||||
{form.packageType === "blister" ? (
|
||||
<>
|
||||
<label>
|
||||
{t("refill.packs")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={refillPacks}
|
||||
onChange={(e) => onRefillPacksChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t("refill.loosePills")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<label className="full">
|
||||
{t("refill.pillsToAdd")}
|
||||
<input
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={refillLoose}
|
||||
onChange={(e) => onRefillLooseChange(parseInt(e.target.value, 10) || 0)}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
<div className="refill-submit-row full">
|
||||
<button
|
||||
type="button"
|
||||
className="success"
|
||||
onClick={() => onSubmitRefill(editingId)}
|
||||
disabled={(refillPacks < 1 && refillLoose < 1) || refillSaving}
|
||||
>
|
||||
{refillSaving ? t("common.saving") : t("refill.button")}
|
||||
</button>
|
||||
{(() => {
|
||||
const totalRefill =
|
||||
form.packageType === "blister"
|
||||
? refillPacks * Number(form.blistersPerPack || 0) * Number(form.pillsPerBlister || 1) +
|
||||
refillLoose
|
||||
: refillLoose;
|
||||
return totalRefill > 0 ? (
|
||||
<span className="refill-preview">
|
||||
+{totalRefill} {totalRefill === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
) : null;
|
||||
})()}
|
||||
</div>
|
||||
{form.prescriptionEnabled && (
|
||||
<div className="refill-prescription-row full">
|
||||
<label className="refill-prescription-toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={usePrescriptionRefill}
|
||||
onChange={(e) => onUsePrescriptionRefillChange(e.target.checked)}
|
||||
disabled={(Number(form.prescriptionRemainingRefills) || 0) <= 0}
|
||||
/>
|
||||
<span className="refill-prescription-label-text">{t("prescription.useForRefill")}</span>
|
||||
</label>
|
||||
<span className="refill-remaining-badge">
|
||||
{t("prescription.remainingRefills")}: {Number(form.prescriptionRemainingRefills) || 0}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="refill-unavailable">{t("refill.saveFirst", "Save medication first to enable refill")}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{editingId && (
|
||||
<div className="full form-category image-section">
|
||||
<h4 className="form-category-title">{t("form.medicationImage")}</h4>
|
||||
{currentMed?.imageUrl ? (
|
||||
<div className="image-preview">
|
||||
<img src={`/api/images/${currentMed.imageUrl}`} alt={currentMed.name} />
|
||||
<button type="button" className="danger" onClick={() => onDeleteMedImage(editingId)}>
|
||||
{t("form.removeImage")}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={(e) => e.target.files?.[0] && onUploadMedImage(editingId, e.target.files[0])}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="full form-category intake-section">
|
||||
<div className="form-category-header">
|
||||
<h4 className="form-category-title">{t("form.blisters.title")}</h4>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost add-blister"
|
||||
onClick={() => onAddIntake(form.takenBy.length === 1 ? form.takenBy[0] : undefined)}
|
||||
>
|
||||
+ {t("form.blisters.addIntake")}
|
||||
</button>
|
||||
</div>
|
||||
{form.intakes.map((intake, idx) => (
|
||||
<div key={idx} className="blister-row">
|
||||
<label className="compact">
|
||||
<span>{t("form.blisters.usage")}</span>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.1"
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
pattern="[0-9]*\.?[0-9]*"
|
||||
value={intake.usage}
|
||||
onChange={(e) => onSetIntakeValue(idx, "usage", e.target.value)}
|
||||
/>
|
||||
@@ -404,8 +531,9 @@ export function MobileEditModal({
|
||||
<label className="compact">
|
||||
<span>{t("form.blisters.everyDays")}</span>
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
value={intake.every}
|
||||
onChange={(e) => onSetIntakeValue(idx, "every", e.target.value)}
|
||||
/>
|
||||
@@ -426,26 +554,29 @@ export function MobileEditModal({
|
||||
onChange={(e) => onSetIntakeValue(idx, "startTime", e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="compact full-row">
|
||||
<span>{t("form.blisters.takenByIntake")}</span>
|
||||
<select value={intake.takenBy} onChange={(e) => onSetIntakeValue(idx, "takenBy", e.target.value)}>
|
||||
<option value="">{t("form.blisters.takenByEveryone")}</option>
|
||||
{existingPeople.map((person) => (
|
||||
<option key={person} value={person}>
|
||||
{person}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="toggle-switch small" title={t("form.blisters.remindTooltip")}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={intake.intakeRemindersEnabled}
|
||||
onChange={(e) => onSetIntakeValue(idx, "intakeRemindersEnabled", e.target.checked)}
|
||||
/>
|
||||
<span className="toggle-slider"></span>
|
||||
</label>
|
||||
<span className="legend-hint">🔔</span>
|
||||
{form.takenBy.length === 0 ? null : (
|
||||
<label className="compact full-row">
|
||||
<span>{t("form.blisters.takenByIntake")}</span>
|
||||
<select value={intake.takenBy} onChange={(e) => onSetIntakeValue(idx, "takenBy", e.target.value)}>
|
||||
{form.takenBy.map((person) => (
|
||||
<option key={person} value={person}>
|
||||
{person}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
<div className="remind-toggle-row" title={t("form.blisters.remindTooltip")}>
|
||||
<span className="legend-hint">🔔</span>
|
||||
<label className="toggle-switch small">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={intake.intakeRemindersEnabled}
|
||||
onChange={(e) => onSetIntakeValue(idx, "intakeRemindersEnabled", e.target.checked)}
|
||||
/>
|
||||
<span className="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
{form.intakes.length > 1 && (
|
||||
<button type="button" className="danger remove-blister-btn" onClick={() => onRemoveIntake(idx)}>
|
||||
{t("common.remove")}
|
||||
@@ -453,10 +584,7 @@ export function MobileEditModal({
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<button type="button" className="ghost add-blister" onClick={() => onAddIntake()}>
|
||||
+ {t("form.blisters.addIntake")}
|
||||
</button>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div className="modal-footer">
|
||||
<button type="button" className="ghost" onClick={onClose}>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -66,7 +66,8 @@ export function UserFilterModal({
|
||||
</div>
|
||||
<div className="user-med-stats">
|
||||
<span className="user-med-pills">
|
||||
{currentStock}/{formatNumber(packageSize)} {t("common.pills")}
|
||||
{currentStock}/{formatNumber(packageSize)}{" "}
|
||||
{packageSize === 1 ? t("common.pill") : t("common.pills")}
|
||||
</span>
|
||||
{status && <span className={`status-chip ${status.className}`}>{t(status.label)}</span>}
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useAuth } from "../components/Auth";
|
||||
import { useCollapsedDays, useDoses, useMedications, useRefill, useSettings, useShare } from "../hooks";
|
||||
import type { Coverage, Medication, ScheduleEvent, StockThresholds } from "../types";
|
||||
import { getSystemLocale } from "../utils/formatters";
|
||||
import { log } from "../utils/logger";
|
||||
import { buildSchedulePreview, calculateCoverage, computeMissedPastDoseIds, isDoseDismissed } from "../utils/schedule";
|
||||
|
||||
// =============================================================================
|
||||
@@ -17,6 +18,7 @@ export type DoseInfo = {
|
||||
when: number;
|
||||
usage: number;
|
||||
takenBy: string[];
|
||||
intakeRemindersEnabled: boolean;
|
||||
};
|
||||
|
||||
export type DayMedEntry = {
|
||||
@@ -58,7 +60,7 @@ export interface AppContextValue {
|
||||
testingShoutrrr: boolean;
|
||||
testShoutrrrResult: { success: boolean; message: string } | null;
|
||||
loadSettings: () => void;
|
||||
saveSettings: (e: React.FormEvent) => Promise<void>;
|
||||
saveSettings: (e?: React.FormEvent) => Promise<void>;
|
||||
testEmail: () => Promise<void>;
|
||||
testShoutrrr: () => Promise<void>;
|
||||
|
||||
@@ -105,6 +107,8 @@ export interface AppContextValue {
|
||||
setRefillPacks: React.Dispatch<React.SetStateAction<number>>;
|
||||
refillLoose: number;
|
||||
setRefillLoose: React.Dispatch<React.SetStateAction<number>>;
|
||||
usePrescriptionRefill: boolean;
|
||||
setUsePrescriptionRefill: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
refillSaving: boolean;
|
||||
refillHistory: ReturnType<typeof useRefill>["refillHistory"];
|
||||
refillHistoryExpanded: boolean;
|
||||
@@ -121,7 +125,8 @@ export interface AppContextValue {
|
||||
medId: number,
|
||||
editingId: number | null,
|
||||
setForm: React.Dispatch<React.SetStateAction<any>>,
|
||||
loadMeds: () => void
|
||||
loadMeds: () => void,
|
||||
usePrescription?: boolean
|
||||
) => Promise<void>;
|
||||
submitStockCorrection: (medId: number, selectedMed: Medication, loadMeds: () => void) => Promise<void>;
|
||||
openRefillModal: () => void;
|
||||
@@ -278,7 +283,8 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
systemLocale,
|
||||
settingsHook.settings.reminderDaysBefore,
|
||||
settingsHook.settings.stockCalculationMode,
|
||||
doses.takenDoses
|
||||
doses.takenDoses,
|
||||
doses.takenDoseTimestamps
|
||||
),
|
||||
[
|
||||
medications.meds,
|
||||
@@ -287,6 +293,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
settingsHook.settings.reminderDaysBefore,
|
||||
settingsHook.settings.stockCalculationMode,
|
||||
doses.takenDoses,
|
||||
doses.takenDoseTimestamps,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -380,6 +387,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
when: event.when,
|
||||
usage: event.usage,
|
||||
takenBy: event.takenBy ? [event.takenBy] : [],
|
||||
intakeRemindersEnabled: event.intakeRemindersEnabled,
|
||||
});
|
||||
medEntry.lastWhen = Math.max(medEntry.lastWhen, event.when);
|
||||
day.meds.set(event.medName, medEntry);
|
||||
@@ -507,7 +515,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
console.error("Export error:", err);
|
||||
log.error("Export error:", err);
|
||||
}
|
||||
setExporting(false);
|
||||
},
|
||||
@@ -561,7 +569,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
try {
|
||||
data = text ? JSON.parse(text) : {};
|
||||
} catch {
|
||||
console.error("Import response parse error:", text);
|
||||
log.error("Import response parse error:", text);
|
||||
alert(`${t("exportImport.importError")}: Server returned invalid response`);
|
||||
return;
|
||||
}
|
||||
@@ -583,7 +591,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
settingsHook.loadSettings();
|
||||
doses.loadTakenDoses();
|
||||
} catch (err) {
|
||||
console.error("Import error:", err);
|
||||
log.error("Import error:", err);
|
||||
alert(t("exportImport.importError"));
|
||||
}
|
||||
|
||||
@@ -600,6 +608,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
settings.notificationEmail !== savedSettings.notificationEmail ||
|
||||
settings.emailStockReminders !== savedSettings.emailStockReminders ||
|
||||
settings.emailIntakeReminders !== savedSettings.emailIntakeReminders ||
|
||||
settings.emailPrescriptionReminders !== savedSettings.emailPrescriptionReminders ||
|
||||
settings.reminderDaysBefore !== savedSettings.reminderDaysBefore ||
|
||||
settings.repeatDailyReminders !== savedSettings.repeatDailyReminders ||
|
||||
settings.lowStockDays !== savedSettings.lowStockDays ||
|
||||
@@ -609,11 +618,14 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
settings.shoutrrrUrl !== savedSettings.shoutrrrUrl ||
|
||||
settings.shoutrrrStockReminders !== savedSettings.shoutrrrStockReminders ||
|
||||
settings.shoutrrrIntakeReminders !== savedSettings.shoutrrrIntakeReminders ||
|
||||
settings.shoutrrrPrescriptionReminders !== savedSettings.shoutrrrPrescriptionReminders ||
|
||||
settings.skipRemindersForTakenDoses !== savedSettings.skipRemindersForTakenDoses ||
|
||||
settings.repeatRemindersEnabled !== savedSettings.repeatRemindersEnabled ||
|
||||
settings.reminderRepeatIntervalMinutes !== savedSettings.reminderRepeatIntervalMinutes ||
|
||||
settings.maxNaggingReminders !== savedSettings.maxNaggingReminders ||
|
||||
settings.stockCalculationMode !== savedSettings.stockCalculationMode
|
||||
settings.stockCalculationMode !== savedSettings.stockCalculationMode ||
|
||||
settings.shareStockStatus !== savedSettings.shareStockStatus ||
|
||||
settings.expiryWarningDays !== savedSettings.expiryWarningDays
|
||||
);
|
||||
}, [settingsHook.settings, settingsHook.savedSettings]);
|
||||
|
||||
@@ -731,6 +743,8 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
|
||||
setRefillPacks: refill.setRefillPacks,
|
||||
refillLoose: refill.refillLoose,
|
||||
setRefillLoose: refill.setRefillLoose,
|
||||
usePrescriptionRefill: refill.usePrescriptionRefill,
|
||||
setUsePrescriptionRefill: refill.setUsePrescriptionRefill,
|
||||
refillSaving: refill.refillSaving,
|
||||
refillHistory: refill.refillHistory,
|
||||
refillHistoryExpanded: refill.refillHistoryExpanded,
|
||||
|
||||
@@ -14,7 +14,7 @@ export type { Settings, UseSettingsReturn } from "./useSettings";
|
||||
export { useSettings } from "./useSettings";
|
||||
export type { UseShareReturn } from "./useShare";
|
||||
export { useShare } from "./useShare";
|
||||
export type { Theme, UseThemeReturn } from "./useTheme";
|
||||
export type { Theme, ThemePreference, UseThemeReturn } from "./useTheme";
|
||||
export { useTheme } from "./useTheme";
|
||||
export type { UseUnsavedChangesWarningReturn } from "./useUnsavedChangesWarning";
|
||||
export { useUnsavedChangesWarning } from "./useUnsavedChangesWarning";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user