HealthKit Clinical Data Sync Architecture Specification
Design a resilient HealthKit background sync engine for clinical FHIR records and patient telemetry.
Use this template when architecting an enterprise iOS pipeline to ingest patient vitals and electronic health records into HealthKit. It guides engineers through permission handling, background delivery, and encrypted local storage design.
Role: Principal iOS HealthKit Architect with 10+ years specializing in Apple digital health frameworks and HL7 FHIR compliance.
Context
- Target healthcare partner: {{clinical_institution_name}}
- Required FHIR resource types: {{target_fhir_resources}}
- HealthKit sample types: {{healthkit_sample_types}}
- Background delivery polling rate: {{sync_frequency_minutes}}
- Local payload cryptographic standard: {{encryption_standard_level}}
- Secure audit log retention window: {{audit_retention_period}}
Task
Draft a comprehensive technical specification detailing the iOS HealthKit ingestion layer, background synchronization architecture, and FHIR resource mapping pipeline for {{clinical_institution_name}}.
Method
- Specify the HKHealthStore initialization pattern, handling authorization requests and clinical record entitlement verification.
- Detail the exact mapping schema between incoming {{target_fhir_resources}} and native {{healthkit_sample_types}}.
- Architect the HKObserverQuery and HKAnchoredObjectQuery background execution lifecycle matching {{sync_frequency_minutes}} intervals.
- Define local persistence using CoreData backed by {{encryption_standard_level}} SQLCipher encryption for cached telemetry.
- Design the conflict resolution policy for overlapping clinical timestamp data received from remote hospital endpoints.
- Detail error recovery, exponential backoff handling, and zero-data-loss buffering during network disconnects.
- Establish the audit trail logging mechanism adhering to {{audit_retention_period}} retention without storing plain-text PHI.
Constraints
- MUST enforce explicit read/write permission segregation across all {{healthkit_sample_types}}.
- MUST NOT log raw Protected Health Information (PHI) to standard os_log or console streams.
- All background handlers MUST complete within the 30-second iOS background execution budget.
- Target Swift 6 concurrency models with strict Sendable checking across query boundaries.
- Total specification length MUST stay between 600 and 900 words.
Output format
Provide the specification organized under the following exact section headers:
- HealthKit Authorization & Entitlements Contract
- FHIR to HKObjectType Data Mapping Schema
- Background Delivery & Query Orchestration
- Cryptographic Storage & Offline Buffering
- Clinical Audit Logging & Error Recovery
Self-review
- Confirm every variable from {{clinical_institution_name}} through {{audit_retention_period}} is addressed.
- Verify that strict iOS background runtime constraints are respected in the delivery sequence.
- Check that no sensitive clinical record fields are exposed in plain text within the architectural diagrams.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.