# Lumii — Practice Management App
### Full Xcode Project Setup Guide

---

## Quick Start (5 steps)

### 1. Create Xcode Project
1. Open Xcode → **File → New → Project**
2. Choose **iOS → App** (or **Multiplatform → App** for macOS+iOS)
3. Name: `Lumii`, Organisation Identifier: `com.yourname.lumii`
4. Interface: **SwiftUI**, Language: **Swift**
5. **Uncheck** "Include Tests" (optional)
6. Click **Create**

---

### 2. Add Firebase via Swift Package Manager
1. In Xcode: **File → Add Package Dependencies...**
2. Paste URL: `https://github.com/firebase/firebase-ios-sdk`
3. Click **Add Package**
4. Select these packages:
   - ✅ **FirebaseAuth**
   - ✅ **FirebaseFirestore**
   - ✅ **FirebaseFirestoreSwift**
   - ✅ **FirebaseStorage**
   - ✅ **FirebaseMessaging**
5. Click **Add Package**

---

### 3. Set Up Firebase Project
1. Go to [console.firebase.google.com](https://console.firebase.google.com)
2. Click **Add project** → name it "Lumii"
3. **Register your iOS app**:
   - iOS Bundle ID: `com.yourname.lumii` (must match Xcode)
4. **Download `GoogleService-Info.plist`**
5. Drag it into your Xcode project root (check "Copy items if needed")
6. In Firebase Console, enable:
   - **Authentication → Sign-in method → Email/Password** ✅
   - **Firestore Database** → Start in **production mode**
   - **Storage** → Default rules

---

### 4. Add Source Files to Xcode
Copy all Swift files from this package into your Xcode project, **maintaining the folder structure**:

```
Lumii/
├── LumiiApp.swift
├── AppState.swift
├── ContentView.swift
├── Models/
│   └── Models.swift
├── Services/
│   ├── AuthService.swift
│   └── FirestoreService.swift
├── ViewModels/
│   ├── AuthViewModel.swift
│   ├── AppointmentViewModel.swift
│   ├── PatientViewModel.swift
│   ├── DashboardViewModel.swift
│   └── InvoiceViewModel.swift
└── Views/
    ├── Auth/
    │   └── AuthViews.swift
    ├── Dashboard/
    │   └── DashboardView.swift
    ├── Appointments/
    │   └── AppointmentBookView.swift
    ├── Patients/
    │   └── PatientViews.swift
    ├── Settings/
    │   └── SettingsView.swift
    ├── Shared/
    │   ├── LumiiDesignSystem.swift
    │   └── TopBarView.swift
    └── BillingReportsView.swift
```

**How to add files:**
- In Xcode Project Navigator, right-click the `Lumii` group → **Add Files to "Lumii"...**
- Select all `.swift` files from this package
- Check **"Copy items if needed"** and **"Create groups"**

---

### 5. Deploy Firestore Security Rules
1. Install Firebase CLI: `npm install -g firebase-tools`
2. In the project root (where `firestore.rules` is): `firebase login`
3. `firebase init firestore` → select your project
4. Replace the generated `firestore.rules` with the one in this package
5. `firebase deploy --only firestore:rules`

---

## Build Settings to Check

### Info.plist entries needed:
Add these keys to your `Info.plist`:
```xml
<key>NSCameraUsageDescription</key>
<string>Used for capturing patient photos and document scanning.</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Used for uploading patient files and photos.</string>

<key>NSMicrophoneUsageDescription</key>
<string>Used for voice dictation in clinical notes.</string>
```

### Signing & Capabilities:
- Set your Team in **Signing & Capabilities**
- Add **Push Notifications** capability (for Firebase Messaging)
- Add **Background Modes → Remote notifications**

---

## Architecture Overview

```
┌─────────────────────────────────────┐
│  SwiftUI Views                      │
│  (Auth / Dashboard / Appointments   │
│   Patients / Billing / Settings)    │
└──────────────────┬──────────────────┘
                   │ @StateObject / @EnvironmentObject
┌──────────────────▼──────────────────┐
│  ViewModels (ObservableObject)      │
│  Auth / Appointment / Patient /     │
│  Dashboard / Invoice                │
└──────────────────┬──────────────────┘
                   │ async/await
┌──────────────────▼──────────────────┐
│  Services (Singletons)              │
│  AuthService · FirestoreService     │
└──────────────────┬──────────────────┘
                   │ Firebase SDK
┌──────────────────▼──────────────────┐
│  Firebase                           │
│  Auth · Firestore · Storage · FCM   │
└─────────────────────────────────────┘
```

---

## Data Architecture (Firestore)

```
/clinics/{clinicId}
    .name, .ownerUID, .subscriptionStatus, .trialStartDate ...
    /patients/{patientId}
    /appointments/{appointmentId}
    /invoices/{invoiceId}
    /clinicalNotes/{noteId}
    /practitioners/{practitionerId}
    /appointmentTypes/{typeId}
    /feeCategories/{catId}
    /rosterRules/{ruleId}
    /rosterOverrides/{overrideId}
    /waitingList/{entryId}
    /messages/{msgId}
    /noteTemplates/{templateId}
    /products/{productId}
    /userTasks/{taskId}
    /auditLog/{logId}
    /patientForms/{formId}
    /patientPortal/{docId}       ← public, for online booking widget

/users/{uid}
    .clinicId, .role, .permissions ...
```

---

## Key Features Implemented

| Module | Status | Notes |
|--------|--------|-------|
| Authentication | ✅ | Email/password, trial management |
| Dashboard | ✅ | Stats, billing chart, noticeboard, tasks |
| Appointment Book | ✅ | Grid, roster rules, booking, cancellation |
| Patient Files | ✅ | 8-tab detail, all sub-data |
| Billing (Invoices) | ✅ | List view, ViewModel complete |
| Reports | ✅ | Category browser, date range selector |
| Settings | ✅ | All 16 sections implemented |
| Firestore Security | ✅ | Role-based rules for all collections |
| Double-booking prevention | ✅ | Atomic Firestore transaction |
| Audit logging | ✅ | All mutations logged |
| Soft deletes | ✅ | Nothing is hard deleted |
| Online booking | ✅ | Portal URL + patient app readiness |

---

## Pending / Next Steps

### High Priority
- [ ] **GoogleService-Info.plist** — must be downloaded from Firebase Console and added to Xcode project
- [ ] **Cloud Functions** — subscription enforcement, SMS/email triggers via Twilio/SendGrid
- [ ] **Invoice creation sheet** — UI for creating invoices (ViewModel is complete)
- [ ] **Roster builder UI** — visual roster editor (data model complete)
- [ ] **Clinical note template builder** — drag-and-drop field editor

### Integrations to implement
- [ ] Tyro Health (EFTPOS terminal SDK)
- [ ] Medicare / DVA Online Claiming (HealthPoint)
- [ ] Xero accounting sync
- [ ] Twilio SMS gateway
- [ ] SendGrid email delivery
- [ ] Stripe subscriptions

### Patient App
The data layer is fully prepared for the Lumii Patient App:
- Shared `/patientPortal` Firestore collections
- FCM token storage on patient records
- Firebase real-time sync ready

---

## ISO 27001 Compliance Checklist

- ✅ 256-bit AES encryption at rest (Firebase default)
- ✅ TLS 1.3 in transit (Firebase default)
- ✅ Role-based access control (RBAC) with Firestore security rules
- ✅ Immutable audit log (Firestore, delete-locked)
- ✅ Soft deletes (no permanent data destruction)
- ✅ Multi-factor authentication ready (Firebase Auth)
- ⬜ Penetration testing (arrange independently)
- ⬜ Data Processing Agreement with Firebase / Google Cloud
- ⬜ Business Associate Agreement (for healthcare data)
- ⬜ Annual security review

---

## Support

Built with:
- **SwiftUI** (iOS 16+ / macOS 13+)
- **Firebase iOS SDK** 11.x
- **Swift** 5.9+
- **Xcode** 15+
