# Patient Service

This service provides a comprehensive API for managing patient-related data within the application. It handles the creation, retrieval, and updating of patient profiles, as well as their sensitive, medical, and location-based information.

## Core Responsibilities

- **Patient Profile Management**: Creating standard (user-linked) and manual (offline) patient profiles.
- **Data Segregation**: Manages different aspects of patient data in separate sub-collections for enhanced security and privacy:
  - `sensitive-info`: Personal Identifiable Information (PII) like name, DOB, and contact details.
  - `medical-info`: Health-related data including allergies, conditions, and medications.
  - `location-info`: Geolocation data for search and mapping features.
- **Security**: Enforces role-based access control, ensuring that only authorized users (patients, practitioners, clinic admins) can access or modify patient data.

## Key Methods

### `createPatientProfile(data: CreatePatientProfileData)`

- Creates a standard patient profile linked to an existing, authenticated user account via `userRef`.
- This is the standard flow for patients registering through the application.

### `createManualPatient(data: CreateManualPatientData, requester: RequesterInfo)`

- Allows a `clinic_admin` to create a patient profile that is **not** linked to a user account.
- This is designed for managing "offline" patients within the clinic's ecosystem.
- The `isManual` flag is set to `true` on the profile.
- The patient is automatically associated with the admin's clinic.

### `getPatientProfile(patientId: string)`

- Retrieves the public-facing profile of a patient.

### `getSensitiveInfo(patientId: string, requesterUserId: string)`

- Retrieves the sensitive PII of a patient. Access is restricted and requires proper authorization.

### `getMedicalInfo(patientId:string)`

- Retrieves the medical information for a patient. Access is strictly controlled based on the requester's permissions.

## Data Models

The main data models used by this service are:

- `PatientProfile`: The core, top-level patient document.
- `PatientSensitiveInfo`: Sub-collection for private, personal data.
- `PatientMedicalInfo`: Sub-collection for health records.

For detailed information on the data structures, see `Api/src/types/patient/index.ts`.
