Palamond Docs
Building Patient-Facing Apps

Querying

Cache, invalidate, and refresh FHIR data for a responsive UI.

A responsive patient app reads the same data many times and needs it to stay fresh. Two habits cover it: use the client cache for fast reads, and re-read after actions.

The client cache

The client caches reads in memory. Repeat reads of the same resource or search within the cacheTime window return from cache instead of hitting the network, which keeps navigation snappy.

const palamond = new PalamondClient({
  clientId: 'your-public-client-id',
  cacheTime: 60_000, // serve cached reads for 60 seconds
});

Reads and searches share this cache automatically; you do not opt in per call.

Invalidate after actions

After an action or a write, cached lists are stale. Invalidate them so the next read fetches fresh data.

// Completing a task changes the task list: invalidate and re-read.
await palamond.tasks.complete(task.id, { questionnaireResponse: ref });
palamond.invalidateSearches('Task');
  • invalidateSearches(resourceType): drops cached searches for one type. Use it after any action that changes that type.
  • invalidateAll(): clears the whole cache. Rare; for example after sign-out and sign-in.

Workflow actions also have asynchronous effects: the platform may issue new resources moments after your call returns. When a screen depends on downstream state (a new task appearing after completing one), refetch when the screen shows, not only right after the action.

Using a data-fetching library

With React Query or similar, keep the client as the transport and let the library own cache keys, loading states, and refetching. The client method is the query function.

// Framework-agnostic shape: key + fetcher.
const key = ['tasks', 'open'];
const fetcher = () =>
  palamond.searchResources('Task', {
    status: 'requested,in-progress',
    _sort: '-_lastUpdated',
  });

After a mutation, invalidate the library's query key the same way you would invalidateSearches on the client, so one source of truth owns freshness.

On this page