Prototype scaffolding for a modular EMR in Swift, aligned with the clean-architecture blueprint and FHIR/SMART on FHIR. The repo already includes reference targets for macOS (AppKit), iOS/iPadOS (SwiftUI), and watchOS, plus shared domain, use-case, data, and UI modules.
git clone https://github.com/ThalesMMS/bEMR.git
cd bEMR
xcodebuild -list -workspace bEMR.xcworkspace
swift test
open bEMR.xcworkspaceThen run the EMRMac scheme on macOS 14+ for the fastest first look.
- Prototype, not production-ready.
- Default experience is demo-first. If
FHIR_BASE_URLandFHIR_STATIC_TOKENare not set,AppEnvironmentFactory.makeDefault()falls back to demo data. - Fastest deeper reads:
DEMO.mdfor the current UI/demo surface,Blueprint.mdfor the larger architecture plan.
AppEnvironmentFactory.makeDefault() starts in demo mode unless it can build a live FHIR environment from process environment variables.
| Mode | Where it applies | What you need | What happens |
|---|---|---|---|
| Demo (default) | All app targets | Nothing extra | Uses the in-repo demo patient, encounter, and observation repositories for quick UI exploration |
| Mock Live | EMRMac only, via the top toolbar Source picker |
Select Mock Live while running the macOS app |
Keeps using local simulated data, but swaps the macOS agenda, chart review, prescription, and progress-note services to their mock-live variants. This does not call the FHIR client or replace the core patient list/summary repositories |
| Live FHIR | All app targets | FHIR_BASE_URL and FHIR_STATIC_TOKEN |
Uses the live FHIR composition for the shared patient list and patient summary pipeline, with a persistent SwiftData cache when available |
Important: the macOS Source picker and the env-var-based live FHIR switch are separate controls. If you launch with FHIR_BASE_URL / FHIR_STATIC_TOKEN set and then choose Mock Live in EMRMac, the agenda/chart-review/prescription/progress-note surfaces still stay on simulated data.
Set these before running/compiling to use a live FHIR endpoint:
FHIR_BASE_URL=https://fhir.sandbox.example.com
FHIR_STATIC_TOKEN=ey...For production, replace the static token with LiveAuthFactory.makeTokenProvider using a refresh closure (SMART on FHIR + PKCE) that returns AuthToken and persists it in the Keychain. LocalContainerFactory.makePersistent() is already used in the live factory; switch to in-memory storage if needed.
On macOS, the last Source picker choice is remembered between launches.
- Patient list and patient summary demo flows across the Apple-platform targets.
- Mock clinical modules such as history, diagnoses, allergies, exams, prescriptions, progress notes, and agenda views.
swift testcoverage for the core domain and use-case layers.- A modular SwiftPM/Xcode workspace layout that is ready for deeper FHIR and SMART-on-FHIR integration work.
| Patient List (macOS) | Patient Health Record (macOS) |
|---|---|
![]() |
![]() |
| Patient List (iPad) | Schedule (iPad) |
|---|---|
![]() |
![]() |
CoreDomain: entities and repository protocols.CoreUseCases: use cases (list, summary, lookup by identifier, encounter timeline, vitals).FHIRModelsKit: re-exportsModelsR4(Apple FHIRModels).SecurityKit: session/token (Keychain, refresh).DataFHIR:FHIRClient+ remote repositories and domain↔FHIR mappers.DataLocal: local caches via SwiftData (persistent or in-memoryModelContainer) and decorators.SharedPresentation: shared view models.AppSharedUI: dependency composition (demo or live) + reusable SwiftUI views.
Apps/EMRiOS: SwiftUINavigationStack.Apps/EMRiPadOS:NavigationSplitView.Apps/EMRMac: AppKit withNSHostingView.Apps/EMRWatch: lightweight patient list.Apps/SharedUI: composition (AppEnvironmentFactory,LiveComposition,DemoComposition) and views (PatientListView,PatientSummaryView).
For live/demo configuration, see Runtime data modes.
- Run:
swift test - Current coverage:
CoreDomainTests,CoreUseCasesTests. (Suggestion: add tests for FHIR→domain mapping and SwiftData cache.)
- Add the local package (
Package.swift) to the workspace/project. - Point app targets to the
AppSharedUImodule and enable minimum platforms (macOS 14 / iOS 17 / watchOS 10) for SwiftData. - Configure schemes to inject
FHIR_BASE_URLand token via env vars or implement the SMART flow in the refresh closure.
- Implement the full SMART on FHIR flow (Authorization Code + PKCE) in the
AuthSessionManagerrefresh closure. - Adjust FHIR→domain mappings per server (local terminologies, MRN, encounter class).
- Add integration tests for FHIRClient/repositories using a SMART sandbox.
- Harden local persistence (per-platform file protection, avoid PHI in logs).
- Expand use cases/view models for orders, meds, labs, and secure messaging.
- The repo still contains the original
bEMR.xcodeprojtemplate; use the new SwiftPM layout to build the workspace. - Network dependencies point to
https://github.com/apple/FHIRModels.git(R4). Configure the SMART on FHIR endpoint and scopes per provider.



