# Remote Monitoring Workflow

## Overview

The Remote Monitoring system manages the complete lifecycle of patient enrollment in remote care programs (RPM, RTM, CCM). The workflow involves three main actors: **Staff**, **Patients**, and **Doctors**.

---

## Workflow Stages

### Stage 1: Patient Intake (Staff → Patient Data Collection)

**Actor**: Staff Member
**Route**: `staff.remote-monitoring.staff.intake`
**Form**: Patient Intake Form (filled out BY staff, contains data ABOUT patients)

#### What Happens:
1. Staff member navigates to patient's profile
2. Clicks "Remote Monitoring" button
3. Completes **Patient Intake Form** with 3 sections:
   - **Section 1**: Condition & Symptom Screening
     - Hypertension, Diabetes, Heart Failure, Chronic Pain, Arthritis, COPD/Asthma
     - Two or more conditions flag
   - **Section 2**: Medication Reconciliation & Requests
     - Current medications list
     - Medication request type (refill/new)
     - Reason for request
   - **Section 3**: Tech & Support Qualification
     - Smartphone/tablet availability
     - Willingness to use monitoring devices
     - Caregiver support availability

#### Data Stored:
- **Model**: `PatientIntake`
- **Table**: `patient_intakes`
- **Related Tables**:
  - `staff_intake_medications` (current medications)
  - `staff_intake_medication_requests` (medication requests)

#### Service Path Determination:
The system automatically determines the appropriate service path:
- **CCM** (Chronic Care Management): 2+ conditions
- **RPM** (Remote Physiologic Monitoring): Hypertension, Diabetes, or Heart Failure
- **RTM** (Remote Therapeutic Monitoring): Chronic Pain, Arthritis, COPD, or Asthma

#### Success Flow:
- Toast notification: "Patient intake created successfully!"
- Redirect to staff dashboard
- Patient intake record is now available for doctor review

---

### Stage 2: Doctor Order (Doctor → Service Authorization)

**Actor**: Doctor/Physician
**Route**: `doctor.remote-monitoring.doctor.order`
**Form**: Physician Order Form

#### How Doctors Find Patients Ready for Orders

Doctors can discover patients ready for physician orders through:

1. **Pending Orders View** - Route: `doctor.remote-monitoring.pending-orders`
   - Shows all assigned patients with completed intake but no doctor order yet
   - Displays service path, intake completion date, and warning badges for multiple conditions
   - One-click access to create physician order
2. **Patient List** - View all assigned patients and create orders individually
3. **Dashboard Quick Actions** - "Pending Orders" button for quick access

#### What Happens

1. Doctor navigates to pending orders view or patient's profile
2. Clicks "Create Physician Order" button
3. Completes **Doctor Order Form** with 4 sections:
   - **Section 1**: Clinical Indications & Service Selection
     - Primary diagnosis
     - Service selection (RPM, RTM Musculoskeletal, RTM Respiratory, CCM)
   - **Section 2**: Medical Necessity & Plan of Care
     - Clinical goals (stabilize, therapy adherence, medication management, care coordination)
   - **Section 3**: Patient Consent & Attestation
     - Authorization consent
     - Data privacy consent
     - Financial responsibility consent
     - Engagement consent
   - **Section 4**: Provider Authorization
     - Provider NPI
     - Provider printed name
     - Automatic timestamp of authorization

#### Data Stored:
- **Model**: `DoctorOrder`
- **Table**: `doctor_orders`
- **Status**: `pending_insurance_verification`

#### Success Flow:
- Toast notification: "Physician order created successfully!"
- Redirect to doctor dashboard
- Doctor order status is set to `pending_insurance_verification`

---

### Stage 3: Insurance Verification (Staff → Insurance Validation)

**Actor**: Staff Member
**Routes**:
- `staff.remote-monitoring.insurance.index` - View pending verifications
- `staff.remote-monitoring.insurance.add-form` - Add insurance (if patient missing)
- `staff.remote-monitoring.insurance.add-store` - Store insurance
- `staff.remote-monitoring.insurance.form` - Verify insurance

#### What Happens:

**Step 1: Check Insurance Status**
1. Staff member navigates to pending insurance verifications list
2. System checks if patient has active insurance on file
3. Visual indicators show insurance status:
   - ✅ **Blue "Verify Insurance" button** - Patient HAS active insurance
   - ⚠️ **Orange "Add Insurance" button** - Patient LACKS active insurance
   - 🔴 **Red "No Insurance" badge** - Visual indicator of missing insurance

**Step 2A: If Patient HAS Insurance → Proceed to Verification**
1. Staff clicks "Verify Insurance" button
2. Completes **Insurance Verification Form** with 4 parts:

**Step 2B: If Patient LACKS Insurance → Add Insurance First**
1. Staff clicks "Add Insurance" button
2. Completes **Add Insurance Form** with sections:
   - **Insurance Provider**: Provider name, policy number, group number
   - **Plan Details**: Plan type (HMO/PPO/POS/EPO/HDHP), coverage dates, prior auth
   - **Cost Information**: Copay, deductible, coverage limit
   - **Additional Information**: Formulary type
3. Insurance is created with `status = 'active'`
4. Staff is automatically redirected to insurance verification form
5. Proceeds with verification (Step 2A)

#### Insurance Verification Form (4 Parts):

**Part 1: Initial Connection**
- Member ID
- Date of Birth

**Part 2: Plan Information**
- Insurance company
- Plan type (POS/PPO)
- Referral requirements
- Prior authorization requirements
- Telehealth restrictions

**Part 3: Benefit Details**
- Out-of-Network deductible
- Deductible met status
- Out-of-Network coinsurance percentage
- Reimbursement basis

**Part 4: Documentation**
- Reference number
- Representative name
- Notes

**CPT Code Verification**:
For each CPT code in the doctor order, staff verifies:
- Status: OK, Out of Network, Authorization Required, Referral Required, No OON Coverage
- Notes for any issues

#### Data Stored:
- **Model**: `InsuranceVerification`
- **Table**: `insurance_verifications`
- **Related**: `cpt_code_verifications` (one per CPT code)

#### Doctor Order Status Update:
- Status changes from `pending_insurance_verification` → `insurance_verified`
- Verification timestamp recorded
- Verified by staff member ID recorded

#### Success Flow:
- Toast notification: "Insurance verification completed successfully!"
- Redirect to verification results page
- Doctor order is now ready for doctor approval

---

### Stage 4: Doctor Approval (Doctor → Final Authorization)

**Actor**: Doctor/Physician
**Status**: `insurance_verified` → `approved_by_doctor`

#### What Happens:
1. Doctor reviews insurance verification results
2. Confirms all CPT codes are covered
3. Approves the order (status updates to `approved_by_doctor`)
4. Patient enrollment is activated

#### Success Flow:
- Patient is now enrolled in remote monitoring program
- Monitoring can begin
- Patient receives enrollment confirmation

---

### Stage 5: Patient Daily Wellness Check-In (Patient → Ongoing Monitoring)

**Actor**: Patient
**Route**: `patient.remote-monitoring.wellness-check-in`
**Form**: Monthly Wellness Check-In Form (Est. 60-90 seconds)

#### What Happens:
1. Patient logs into their portal
2. Completes **Monthly Wellness Check-In Form** with 6 sections:

**Section 1: Daily Health & Vitals Check**
- **Group A (RTM - Therapy, Mobility, Breathing)**:
  - Chronic back, neck, or joint pain (0-10 scale)
  - Arthritis or limited mobility
  - COPD, asthma, or shortness of breath (inhaler usage)
  - Functional impact on daily activities
- **Group B (CCM - Vitals, Heart, General Health)**:
  - Blood pressure readings
  - Blood sugar readings
  - Heart failure or heart issues
  - Height & weight tracking
  - Mental health (anxiety, depression, sleep)

**Section 2: Recent Care & Hospitalizations**
- Emergency room visits or hospital discharges
- Reason for hospitalization

**Section 3: Medication Reconciliation & Requests**
- Current medication adherence status
- List of current medications
- New drug allergies
- Medication refill or new medication requests
- Reason for medication request

**Section 4: Telehealth & Program Benefits**
- Acknowledgment of telehealth delivery
- Smartphone return policy
- Drug plan details (23-month formulary benefit)

**Section 5: Unified Program Consents**
- Consent to telehealth & coordinated care
- SMS, communication, & TCPA consent
- Smartphone, drug plan, & equipment agreement

**Section 6: Financial & Hardship Certification**
- Medicaid status OR financial hardship certification
- Income threshold verification ($40,800 annual)

#### Data Stored:
- **Model**: `PatientDailyWellnessCheckIn`
- **Table**: `patient_daily_wellness_check_ins`
- **Related Tables**:
  - `patient_wellness_vitals` (vital readings)
  - `patient_wellness_medications` (medication status)
  - `patient_wellness_consents` (consent records)

#### Success Flow:
- Toast notification: "Wellness check-in submitted successfully!"
- Data is recorded for care team review
- Alerts triggered if critical values detected
- Care team can follow up if needed

---

## Data Models & Relationships

### PatientIntake
```
- patient_id (FK → users)
- staff_id (FK → users)
- has_hypertension, has_diabetes, has_heart_failure, has_chronic_pain, has_arthritis, has_copd_asthma
- has_two_or_more_conditions
- service_path (rpm, rtm, ccm)
- has_smartphone, willing_to_use_devices, has_caregiver_support
- Relationships: patient(), staff(), medications(), medicationRequest()
```

### DoctorOrder
```
- patient_id (FK → users)
- doctor_id (FK → users)
- service_rpm, service_rtm_musculoskeletal, service_rtm_respiratory, service_ccm
- primary_diagnosis
- goal_stabilize_physiological, goal_therapy_adherence, goal_medication_management, goal_care_coordination
- consent_authorization, consent_data_privacy, consent_financial_responsibility, consent_engagement
- provider_npi, provider_printed_name
- status (pending_insurance_verification, insurance_verified, approved_by_doctor)
- Relationships: patient(), doctor(), insuranceVerification()
```

### InsuranceVerification
```
- doctor_order_id (FK → doctor_orders)
- insurance_id (FK → insurances)
- member_id, date_of_birth
- plan_type, referral_required, prior_auth_required, telehealth_restrictions
- oon_deductible, oon_deductible_met, oon_coinsurance_percentage, reimbursement_basis
- reference_number, representative_name
- verification_status, verified_by, verified_at
- Relationships: doctorOrder(), insurance(), cptCodeVerifications(), verifiedBy()
```

### CptCodeVerification
```
- insurance_verification_id (FK → insurance_verifications)
- cpt_code, cpt_description
- verification_status (ok, out_of_network, authorization_required, referral_required, no_oon_coverage)
- notes
- Relationship: insuranceVerification()
```

---

## Status Flow Diagram

```
Patient Intake (Staff)
        ↓
Doctor Order (Doctor)
        ↓
Insurance Verification (Staff)
        ↓
Doctor Approval (Doctor)
        ↓
Patient Enrollment Active
        ↓
Patient Daily Wellness Check-In (Patient - Ongoing)
        ↓
Care Team Review & Follow-up
```

---

## Key Features

✅ **Automated Service Path Determination** - Based on patient conditions
✅ **CPT Code Verification** - Track coverage for each service code
✅ **Multi-stage Workflow** - Clear progression through intake → order → verification → approval
✅ **Role-based Access** - Staff, Doctor, and Patient specific views
✅ **Comprehensive Validation** - All forms have detailed validation rules
✅ **Audit Trail** - Timestamps and user tracking for all actions
✅ **Error Handling** - Graceful error messages and logging

---

## Routes Summary

### Staff Routes
- `GET /staff/remote-monitoring/intake/{user}` - Show intake form
- `POST /staff/remote-monitoring/intake` - Store intake
- `GET /staff/remote-monitoring/intake/{patientIntake}` - View intake
- `GET /staff/remote-monitoring/insurance-pending` - List pending verifications
- `GET /staff/remote-monitoring/insurance/add/{doctorOrder}` - Show add insurance form (NEW)
- `POST /staff/remote-monitoring/insurance/add` - Store insurance for patient (NEW)
- `GET /staff/remote-monitoring/insurance/{doctorOrder}` - Show verification form
- `POST /staff/remote-monitoring/insurance` - Store verification
- `GET /staff/remote-monitoring/insurance-result/{verification}` - View results

### Doctor Routes
- `GET /doctor/remote-monitoring/order/{user}` - Show order form
- `POST /doctor/remote-monitoring/order` - Store order
- `GET /doctor/remote-monitoring/order/{doctorOrder}` - View order

### Patient Routes
- `GET /patient/remote-monitoring/wellness-check-in` - Show wellness check-in form
- `POST /patient/remote-monitoring/wellness-check-in` - Store wellness check-in
- `GET /patient/remote-monitoring/wellness-check-in/{checkIn}` - View check-in history
- `GET /patient/remote-monitoring/dashboard` - Patient remote monitoring dashboard

