# Business Logic

This document describes the core domain of Pluscare: who uses the system, how users and data flow through it, and which entities operators can manage.

## User roles

There are four types of users:

| Role | Access |
|------|--------|
| **Admin** | All data and functionalities across the platform |
| **Company admin** | All data and functionalities related to their company |
| **Medical operator** | All data related to their assigned patients |
| **User** (patient) | Their own data only |

## User lifecycle

When a new user is created, they receive an email asking them to complete registration. Registration includes:

1. Choosing a password
2. Enabling their smart devices

Each user can set their preferred notification method (email or WhatsApp). That preference is used for all notifications sent to them.

After registration and device activation are complete, health data is synced from connected devices. See [Withings Integration](features/withings-integration.md) for sync details (webhooks with scheduled fallback).

Gathered data powers the user dashboard: charts and related details. Each chart can be printed and exported as CSV.

Metric detail pages open on the most recent day with data. The date label opens a calendar where only days with measures are selectable, and the arrows jump to the previous/next day with data. On numeric metrics (heart rate, SpO2, temperature, glucose, lab, activity, blood pressure, body composition, sleep) the calendar also accepts a from–to period: the chart switches to per-day aggregates (per-month beyond 92 days) with average/min/max summary cards for the period. ECG, spirometry and holter stay day-only, being single reports.

## Entities and permissions

### Devices

**Admin** and **company admin** can assign devices to users.

### Alerts

**Admin**, **company admin**, and **medical operator** can create alerts for users.

An alert defines a threshold. When the threshold is reached, a notification is sent to the user. Alerts help inform users or caregivers about anomalies in registered health data.

See [Metric Alerts](features/metric-alerts.md) for the supported metrics, how the period is interpreted per metric family, and the once-per-episode notification lifecycle.

### Contacts

**Admin** and **company admin** can create contacts for users.

A contact can receive notifications related to the user (e.g. caregivers or family members).

### Exams

**Admin**, **company admin**, and **medical operator** can create exams for users.

An exam records medical exam results related to the user.

### Drugs

**Admin** can create drugs. Drugs appear wherever a drug input is required (e.g. drug prescriptions). Drugs are visible to all companies.

### Drug prescriptions

**Admin**, **company admin**, and **medical operator** can create drug prescriptions for users.

A drug prescription defines a reminder sent to a user about medication they need to take. Prescriptions can also define a reminder to re-stock a drug when the user's supply is about to run out.

**Recurring administration intervals** can be configured on a prescription. For example, a prescription can be scheduled to be administered every 2 days for a total duration of 30 days.

### Companies

**Admin** can create companies. Users can be assigned to a company.

## Related feature documentation

| Topic | Document |
|-------|----------|
| Scheduled reminders | [features/reminders.md](features/reminders.md) |
| Notifications (email, WhatsApp, CTA) | [features/notifications.md](features/notifications.md) |
| Health data sync (Withings) | [features/withings-integration.md](features/withings-integration.md) |
| Documents | [features/documents.md](features/documents.md) |
| Audit logging | [features/audit-logs.md](features/audit-logs.md) |
| Two-factor authentication | [features/two-factor-auth.md](features/two-factor-auth.md) |
