Delivered remotely for a business based in Perth, Australia. Names withheld by agreement.
Project Overview
Self-administered injectable therapies demand precision under imperfect conditions: small mechanical dials, low-contrast etched syringe graduations, shaky hands, and dim bedside lighting. For patients living with diabetic retinopathy, age-related macular degeneration, or post-treatment fatigue in Perth and regional Western Australia, verifying whether an injector is dialed to the prescribed units can become a daily barrier to independence. We engineered an offline-first iOS accessibility application in Swift and SwiftUI that turns the iPhone camera into a deterministic, voice-guided dose verifier, backed by an optional Laravel clinical adherence portal.
Business Bottleneck
Existing patient support apps offered static reminder alarms and manual logbooks—requiring users to squint at the injector and self-report what they thought they dialed. Cloud-based OCR solutions proved unworkable for three reasons: patients in regional homes lacked consistent bandwidth at dosing time, network round-trips broke real-time camera aiming, and uploading continuous video frames of home medications triggered severe privacy compliance concerns. Meanwhile, standard text-recognition libraries struggled with cylindrical pen barrels, metallic foil reflections, and partial dial windows.
Architectural Strategy
We built a zero-cloud-inference, safety-gated mobile architecture. Every optical operation—injector localization, dial window cropping, numeral/graduation classification, and temporal smoothing—executes inside an isolated Swift concurrency pipeline on the Apple Neural Engine via Vision and CoreML. The SwiftUI interface treats accessibility as the primary navigation contract rather than an afterthought, coordinating VoiceOver, spoken prompts, and distinct haptic signatures. Once a patient confirms administration, CoreData commits a structured adherence record locally and synchronizes asynchronously with the Laravel web API only when authorized and online.
Core Capabilities
- On-Device Injector & Dial Verification: Real-time detection of supported pen injectors and syringe windows running completely offline in airplane mode.
- VoiceOver & Haptic Aiming Guidance: Directional audio and tactile cues guide low-vision users to center the device window without needing to read visual bounding boxes.
- Multi-Frame Temporal Consensus: Requires consistent, blur-free agreement across consecutive frames before speaking or displaying a verified dose reading.
- Regime Guardrails & Mismatch Alerts: Compares detected dial values against the patient's active CoreData prescription schedule, flagging under- or over-doses immediately with distinct warning tones.
- Zero-Image Adherence Sync: Stores structured dose events locally and syncs compact compliance summaries to a Laravel care-program portal when network access returns.
Technical Architecture
Flow: AVFoundation Camera Buffer -> Swift Inference Actor (Vision + CoreML Quantized Models) -> Temporal Consensus Gate -> SwiftUI / VoiceOver / CoreHaptics -> CoreData Encrypted Store -> Background URLSession -> Laravel Care API
AVFoundation captures CVPixelBuffer frames at 30 fps on a dedicated serial capture queue, throttling inference submissions to avoid thermal throttling on older iPhones. Each candidate frame passes luminance and Laplacian blur checks before entering a two-stage CoreML pipeline orchestrated via VNCoreMLRequest: stage one locates the injector body and isolates the rotated dial region of interest, while stage two classifies the visible dose readout.
Candidate predictions flow into a sliding-window consensus buffer inside a Swift actor. Only when consecutive sharp detections agree on both injector class and dose value—and remain free of high-glare warnings—does the state machine emit a VerifiedDose event to the SwiftUI layer, triggering AVSpeechSynthesizer or VoiceOver announcement alongside a CoreHaptics confirmation pulse. Raw pixel buffers are immediately deallocated; CoreData persists solely the resulting metadata event.
Technology Stack
| Category | Technology detail |
|---|---|
| iOS language & UI | Swift 5 and SwiftUI with Dynamic Type and full VoiceOver support |
| Camera pipeline | AVFoundation real-time pixel buffer capture with torch and focus control |
| Vision & ML inference | CoreML quantized detection models orchestrated via Apple Vision requests |
| Local persistence | CoreData encrypted SQLite store for schedules, regimes, and dose history |
| Accessibility feedback | UIAccessibility announcements, AVSpeechSynthesizer, and CoreHaptics cues |
| Backend API | Laravel (PHP) REST endpoints for optional regimen sync and care portal feeds |
| Concurrency model | Swift structured concurrency isolating camera inference from main UI thread |
| Privacy architecture | Zero-retention in-memory frame processing; no raw camera images persisted |
Engineering Trade-offs & Solutions
| Architectural Dilemma | Chosen Solution & Rationale |
|---|---|
| Single-frame speed vs. multi-frame reliability | Instant single-frame OCR flickers wildly as hands tremble or cylinders rotate. Enforcing a multi-frame consensus window adds a brief hold requirement while eliminating transient misreads before audio output fires. |
| Generic OCR vs. constrained CoreML dial models | General-purpose text recognizers misinterpret curved reflections and partial adjacent numbers on rotating drums. Training compact quantized CoreML models specifically on dial windows and perspective-corrected crops improved resilience under angled viewing. |
| Continuous 30 fps inference vs. thermal budget | Running Neural Engine inference on every frame drains battery and heats the handset. Gating inference on frame sharpness and dropping queued frames while a pass is in flight keeps CPU/GPU thermals stable. |
| Cloud image audit vs. strict local ephemerality | Retaining camera snapshots for troubleshooting would expose sensitive health environments. Discarding every buffer after inference and syncing only numerical verification records simplifies regulatory posture and patient trust. |
Security & Reliability
All CoreData SQLite files leverage iOS Data Protection (NSFileProtectionComplete), ensuring regimen schedules and historical dose logs remain encrypted while the device is locked. Model weights are bundled inside the signed app binary and integrity-checked at load time so verification behavior cannot drift across network states. Optional synchronization to the Laravel care-program API uses TLS with short-lived OAuth tokens stored in the iOS Keychain, allowing patients to use the verification engine indefinitely even if they opt out of cloud sharing entirely.
Performance & Scale
Quantized CoreML models keep app bundle size compact and achieve single-frame inference within tens of milliseconds on A-series Neural Engines without blocking SwiftUI animations or VoiceOver responsiveness. On the server side, because heavy visual inference stays on the edge device, the Laravel adherence API processes only lightweight JSON event batches—scaling smoothly across large patient cohorts without GPU server infrastructure.
Operational Outcomes
Patients with low vision or dexterity challenges gained an independent, repeatable check before administering injections—receiving spoken confirmation of dialed units even without cellular reception. Care educators and adherence programs received structured, trustworthy dosing logs free of manual transcription gaps, while the platform avoided the cost, latency, and privacy exposure of streaming home camera feeds to cloud servers.