# PedScribe Mobile App

Native mobile wrapper for Pediatric AI Scribe using Capacitor. Provides background audio recording, push notifications, haptic feedback, deep linking, and share intent support on both iOS and Android.

## Features

- Background recording that survives screen lock (foreground service on Android, background audio on iOS)
- Configurable server URL (supports self-hosted instances)
- Haptic feedback on recording start/stop
- Keep screen awake during recording
- Deep linking (pedscribe:// and https://app.pedshub.com)
- Share intent (receive text/PDFs from other apps)
- Push notification support
- App Store and Play Store ready

## Prerequisites

- Node.js 18+
- Android Studio (for Android builds): `sudo snap install android-studio --classic`
- Xcode 15+ (for iOS builds, macOS only)
- Apple Developer account ($99/yr for App Store)
- Google Play Developer account ($25 one-time)

## Setup

```bash
cd mobile
npm install
npx cap sync
```

## Build Android

```bash
# Open in Android Studio
npx cap open android

# Build menu: Build > Generate Signed Bundle / APK > APK
# Sign with your keystore (create one on first build)
# APK output: android/app/build/outputs/apk/release/

# Or build from command line:
cd android && ./gradlew assembleRelease
```

## Build iOS (macOS only)

```bash
# Open in Xcode
npx cap open ios

# In Xcode:
# 1. Select your team/signing certificate
# 2. Product > Archive
# 3. Distribute App > App Store Connect
```

## How It Works

1. App launches with a local launcher page
2. First launch: user enters their PedScribe server URL (default: app.pedshub.com)
3. URL is saved locally for future launches
4. App navigates to the remote web app inside a native WebView
5. Native plugins provide background recording, haptics, and push notifications

### Background Recording

**Android:** `AudioRecordingService` is a foreground service that:
- Acquires a partial wake lock (CPU stays active, screen can sleep)
- Shows a persistent notification ("Recording in progress...")
- Includes a "Stop Recording" quick action in the notification
- Maximum 1-hour wake lock duration

**iOS:** Uses `UIBackgroundModes: audio` in Info.plist, which tells iOS to keep the app alive for audio capture when backgrounded or screen-locked.

### Deep Linking

- `pedscribe://` custom URL scheme opens the app directly
- `https://app.pedshub.com` links open in the app instead of the browser (Android App Links)

### Share Intent (Android)

Other apps can share text or PDFs directly into PedScribe:
- Share a lab result from your email into the Chart Review tab
- Share a referral note into the Hospital Course tab

## Capacitor Plugins Included

| Plugin | Purpose |
|--------|---------|
| @capacitor/app | App lifecycle management |
| @capacitor/haptics | Vibration feedback on recording start/stop |
| @capacitor/keyboard | Keyboard management for WebView |
| @capacitor/push-notifications | Push notification support |
| @capacitor/screen-orientation | Screen orientation control |
| @capacitor/share | Native share dialog |
| @capacitor/splash-screen | Launch splash screen |
| @capacitor/status-bar | Status bar styling |

## App Structure

```
mobile/
  capacitor.config.json    # Capacitor configuration
  package.json             # Dependencies
  src/
    index.html             # Launcher page (server URL config)
    launcher.js            # Auto-redirect + native feature init
    launcher.css            # Launcher styles
  android/                 # Android native project
    app/src/main/
      java/com/pedshub/scribe/
        MainActivity.java
        AudioRecordingService.java
      AndroidManifest.xml  # Permissions, deep links, share intent
  ios/                     # iOS native project
    App/App/
      Info.plist           # Background audio, microphone, deep links
```

## Updating the Web App

The mobile app wraps the remote web app — updating the server automatically updates all mobile clients. No app store update needed for web changes.

To update native features (plugins, permissions, splash screen):
```bash
cd mobile
npm install
npx cap sync
# Then rebuild in Android Studio / Xcode
```

## Generating App Icons

Replace the default Capacitor icons with PedScribe branding:

1. Create a 1024x1024 PNG icon
2. Install the assets tool: `npm install -D @capacitor/assets`
3. Place your icon as `assets/icon-only.png` and `assets/splash.png`
4. Run: `npx capacitor-assets generate`

This generates all required sizes for both platforms.

## App Store Listing Suggestions

**Title:** PedScribe - Pediatric AI Scribe
**Subtitle:** Voice-to-Note Clinical Documentation
**Category:** Medical
**Keywords:** pediatric, scribe, medical, documentation, HPI, SOAP, clinical, AI, voice

**Description:**
PedScribe is an AI-powered clinical documentation tool for pediatric physicians. Record patient encounters, and the AI generates structured medical notes — HPIs, SOAP notes, hospital courses, chart reviews, and more. Includes pediatric calculators, developmental milestone tracking, and a learning hub with quizzes. Self-hosted for maximum privacy with HIPAA-compliant AI providers.
