Implementing SMART on FHIR with local-first storage starts with one question: what may stay on the phone or laptop after the session ends? The launch and its scopes decide what the app may read. Retention needs its own rules for resources, encryption, wipe on sign-out and a changed server copy.
Digital health founders and hospital CTOs or CIOs planning a SMART app that keeps a short cache will find those rules below, with the tests to run before release. Agnotic Technologies builds that cache as a snapshot of the last session, never as a second chart.
What does implementing SMART on FHIR with local-first storage involve?
Implementing SMART on FHIR with local-first storage means fixing the short list of FHIR resources a SMART app may keep on the device after the session ends, then encrypting that cache, wiping it on sign-out, and checking it against the server copy on the next launch. The server stays the chart; the device holds a snapshot.
Building a SMART app that keeps data on the device?
Agnotic Technologies designs SMART on FHIR apps with an explicit device cache: which resources stay, how they are encrypted, and when they are wiped.
The server remains the chart. The device holds a snapshot. Until a new session reads the server, the app either shows that snapshot with its as-of time or shows an empty state. The product owner picks one and writes it down.
The SMART App Launch implementation guide uses OAuth 2.0 and OpenID Connect so that apps can launch from an EHR with the user's and patient's context and only the access scopes they were granted.
Those scopes decide what the session was allowed to read. Retention after the session is a separate app rule: a resource list, a lifetime, encryption, and a wipe.
Which FHIR resources belong in the device cache?
The device cache holds only the resources the screen still needs after the session, and only for the patient the session was about. The default list is short, and anything not on it is not written to disk.
Agnotic aligns the cached resources to the US Core profiles the EHR actually serves, so the snapshot and the next server read share a shape. A typical rounding cache is the Patient banner, AllergyIntolerance, the active MedicationRequest list, and Observations from a dated window the clinical owner sets. Problems may be included when the screen shows them. Documents, images, and the full historical chart stay on the server.
- Patient: the banner fields the screen shows, for the launched patient only.
- AllergyIntolerance and active medications, because a stale omission here is the harm the cache has to justify.
- Observations limited to the agreed window, each with its effective time.
- The session's as-of time and the version id of each cached resource.
- Nothing for a different patient, and nothing the granted scopes did not include.
The list is configuration, reviewed with the privacy officer, not a folder the app fills with every resource the session happened to touch. A debug log of full responses is not part of the cache.
How should the device cache be encrypted?
Encrypt the device cache at rest, with a key the operating system holds, and drop that key when the user signs out. The files and the key do not sit in the same store.
The cache is electronic protected health information when the app handles it for a covered entity or business associate, so the HIPAA Security Rule's safeguards apply to it. Agnotic keeps the key in the platform key store and the cache as ciphertext. If a device backup would copy the cache, the cache is excluded from backup.
The app opens the cache only after the user has passed the device lock screen and the app session is still valid.
When is the device cache wiped?
The cache is wiped on sign-out, when a different user signs in on the same device, and before the device is handed to someone else. Wipe means the files are deleted and the key is deleted, so a leftover file is not readable.
Under the HIPAA Security Rule device and media controls, a covered entity needs procedures that remove electronic protected health information from electronic media before those media are reused, and policies for disposing of ePHI and the hardware or media that stored it.
Sign-out is the ordinary case of that requirement for a phone or a shared workstation. Agnotic runs the wipe as a single function the sign-out button, the session timeout, and the user-switch path all call. A second function is how caches survive in one of those paths. The function deletes the cache directory, deletes the key, and deletes any temporary export the app created during the session.
- User sign-out, including a sign-out that still ends the session.
- Session timeout, using the inactivity period already set for workstations.
- A different user on the same install.
- App removal, confirmed by inspecting device storage afterward.
The clinical snapshot and the session credential are separate stores, and the wipe clears both. The credential is not a field inside the clinical snapshot.
What happens when the server copy has changed?
When the server copy has changed, the device snapshot is stale. The app does not present it as the current chart, and it does not write the snapshot back over the server.
In HL7 FHIR R4, resource metadata may include meta.versionId, which changes when the resource content changes, and meta.lastUpdated, which a reader can use to judge how current that content is. Version-aware updates do not depend on lastUpdated.
Agnotic stores meta.versionId, meta.lastUpdated, and the session as-of time with each cached resource. On the next launch, after the server read, it compares version ids. A different version id means the content changed, so the app discards that cached resource or labels it with the old as-of time until the fresh read replaces it. LastUpdated is a hint. Staleness uses versionId, because version-aware updates do not depend on lastUpdated, and version ids are not an ordered sequence.
The cache stays on the device. Agnotic gives it no path that writes those resources back to the EHR. A local annotation stays in an app note until a person files it during a new session.
- Same version id: the snapshot still matches the server version from the last session.
- Different version id: discard the snapshot or label it stale, then show the server read.
- Server read failed: show the labeled snapshot or show an empty state. Do not relabel the snapshot as current.
- No write-back of cached resources, regardless of which copy looks newer.
What must stay off the device?
Anything that is not on the resource list stays off the device. That includes other patients, full documents, images, and the raw payload of every call the session made.
Agnotic also keeps these out of the clinical snapshot:
- The session credential, which stays in the platform credential store and is cleared with the wipe.
- Resources for any patient other than the launched patient.
- Documents, images, and other binary content.
- Error bodies and full request logs. A support log may keep a correlation id and a status code.
- Resources outside the scopes the session held. The app drops them before saving.
A crash report is a common leak. The reporter is configured to strip request and response bodies. A stack trace that includes a patient name fails review.
How do you choose the cache from what the session was allowed to read?
Start from the scopes the session was granted, then cut that set down to the resource list. The cache is the intersection of the two, for one patient, for one time window.
A granted scope allows a read during the session. Agnotic saves a resource only when the type is on the cache list, the patient is the launched patient, and the session's scopes covered it. A wider scope on a later launch leaves the cache list unchanged until that list is reviewed.
Write the list in the same review packet as the scopes the app requests. Privacy review then sees both questions at once: what the app asks to read, and what it asks to keep.
How should the app behave on the next launch?
On the next launch the app starts a new session, reads the server, and compares version ids before it shows clinical data. The snapshot is a fallback with a visible as-of time, or it is hidden, according to the rule chosen for the product.
The user launches from the EHR, the app reads the cache list, and it compares version ids. Matches may be shown. Differences are replaced from the server and the old snapshot for that resource is deleted. If the read fails, the app follows the written fallback: a labeled snapshot or an empty state.
The as-of time is visible whenever the snapshot is visible. A banner that says the data is from the previous session, with that time, is part of the screen, not a log line only a developer can see.
How do you test device storage before release?
Test device storage by inspecting the device after sign-out, after a user switch, and after a server resource changes. A test that only looks at the screen during the session misses the retention bugs.
- After a session, only listed resource types for the launched patient are on disk, as ciphertext.
- A readable type that is off the cache list is absent from disk.
- After sign-out and after timeout, the cache directory and the key are gone.
- A second user cannot read the first user's snapshot.
- After a MedicationRequest changes on the server, the old list is not shown as current.
- The app has no call that updates the EHR from the cache.
Run the file inspection on a real device build, not only on a desktop mock of the storage API. The key store and the backup flags differ by platform, and the test needs to see those platforms.
How long should the device cache live?
Each resource type gets a lifetime the clinical owner signs, and expired entries are deleted on launch. Give allergies and medications the shortest lifetime the screen can tolerate, because a stale list there is the riskier error.
What should the app log about the cache?
Log cache writes, wipes and version mismatches with a resource type, a count and a time. Keep resource ids out of any log that leaves the device, and never log a resource body.
A worked example: a rounding list opened with no signal
- Step 1, the clinician launches from the EHR at the start of rounds, and the app caches allergies, medications and recent vitals.
- Step 2, in a corridor with no network, the app shows that snapshot under a banner with the session time.
- Step 3, back on the network, a new launch reads the server and finds a changed medication version.
- Step 4, the app drops the old medication list and shows the server copy.
Who signs off the cache list?
The product owner proposes the list, the privacy officer approves it, and the clinical owner sets each lifetime. Each change is reviewed the same way.
What are the common mistakes with local-first storage in a SMART app?
Most retention bugs come from treating the device as a convenient place to keep whatever the session read.
- Caching every response the session touched instead of a reviewed resource list.
- Keeping the encryption key next to the cache files, or leaving the cache inside device backups.
- Wiping on sign-out but not on timeout or user switch, because each path has its own cleanup code.
- Showing a snapshot without its as-of time, so a stale medication list looks current.
- Adding a write-back path from the cache to the EHR.
- Leaking resource bodies through crash reports and debug logs.
How can Agnotic help with SMART on FHIR local-first storage?
Agnotic Technologies builds SMART on FHIR apps with the cache list, encryption, wipe function and version check designed in from the start, and runs the device inspection tests on real builds. Your privacy officer and clinical owner sign the list and the lifetimes.
Related reading on Agnotic
SMART on FHIR apps, scopes, data minimization and FHIR integration.


