
Couchbase x Medblocks - Building a NoSQL FHIR Server
We walk you through building a FHIR server on top of Couchbase's NoSQL database, covering challenges, technical decisions, architecture, and local setup.
February 20, 2025
Your health app reminds you about medications, syncs with your lab results, and even pulls records from different hospitals. It feels effortless, but what’s really happening behind the scenes?
The secret is SMART on FHIR.
This game-changing framework is revolutionizing healthcare app development, yet few truly understand how it works. In this guide, we’ll break it down step by step and show you how to build your own SMART-powered health app. When we’re done, you’ll have the foundation to build your own SMART healthcare app.
Substitutable Medical Applications and Reusable Technologies or SMART is a framework that provides functionalities to build healthcare apps to function on top of EHRs in a secure and standardized way without the need to reconfigure it for individual EHRs. It is a one-size-fits-all solution. When using SMART on FHIR it combines the authentication layer of SMART with the data standardization of FHIR to create a secure, interoperable way for applications to interact with EHRs, thereby proving the best of both worlds.
The core security features of SMART are that it uses oAuth2 and OpenID Connect to securely access the EHR and provide user credentials back to the SMART application.
SMART provides the following advantages:
SMART uses a few core components such as oAuth, OpenID Connect, well-known discovery endpoints, scope and launch context. Let’s understand each of these in the simplest way possible.
Let’s say application ‘A’ wants to access the resources of application ‘B’ for its own use. Now here’s where oAuth2 comes into play, through which ‘B’ can provide ‘A’ access to its resources, effectively providing authorization.
Here’s an oAuth2 playground to follow along.

Breaking down the parts of the URL:
This step tells the oAuth2 app that it needs an authorization code.

As you can see from the screenshot the code is being sent along the POST request.

OpenID Connect (OIDC) is an authentication protocol that works on top of OAuth 2.0, allowing apps to verify a user’s identity and get their profile information securely. To put it simply:
Now let’s explore the OpenID connect playground




This is the sole purpose of OpenID Connect, it gives the details of the authorizing user.
Discovery Endpoints are used by client apps to dynamically discover authentication The ‘.well-known’ directory defines a location where publicly accessible metadata can be stored in a predictable format. In SMART it is used for auto-discovery of an authorization server’s capabilities.
Let’s use the R4 endpoint https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4/ and append .well-known/smart-configurations and use it in POSTMAN to see the response.

Let’s break down the response:
Why use discovery endpoints?
How does this work? When the SMART app starts, it fetches all endpoints available at the .well-known endpoint and now the app has the endpoints to query for different purposes. Hence based on the response breakdown we saw earlier, it sends requests to the respective endpoint.
In SMART on FHIR, scopes control access to healthcare data and identity information. Scopes can be simplified in explanation as to what the SMART app needs for it to perform its functions, e.g. requesting user details or patient information.
Some common scopes seen in the R4 endpoint are:

Let’s look at fhirUser scope in depth as that is very important, and we advise you to go through the link for a comprehensive understanding as scopes are a vast topic, whereas launch will be discussed in the next section.

fhirUser scope is divided into:
Patient-specific scopes: Patient-level scopes in SMART on FHIR define what data a healthcare app can access for a specific patient after authentication. They restrict access to only the authorized patient’s data, rather than system-wide or practitioner-wide data.
User-level scopes: User-level scopes allow an app to access multiple data based on the permissions of the logged-in user
System-level scopes: System-level scopes allow server-to-server communication without a user logging in. Used for background tasks, data synchronization, population health analytics, and reporting.
The launch context is an important concept that refers to additional information passed along with the authorization request. It is required by the SMART app to contextually know what data it will be working on.
Eg: A vitals app needs to know which patient is being read and the patient’s observation, hence the launch context here would ask for ‘launch/patient’ to get the patient detail and to read it will raise a scope as user/Observation.read. This is how scope and launch context work together
Use of Launch Context: When your app is launched, especially in clinical settings, the launch context allows the app to be aware of:

patient/Observation.read allows the app to read patient observations.launch/patient gives the app the active patient ID.patient/Observation.read allows reading observations, but without launch/patient, the app wouldn’t know which patient to request data for.patient/Observation.read but no launch/patient, it cannot automatically get patient data without user input.Now that we’ve covered the fundamentals—authorization with OAuth and authentication using OpenID Connect—it’s time to dive into the code. Here’s the step-by-step guide to get started.
If you still have questions, feel free to revisit the earlier sections. These core concepts are crucial for understanding and successfully implementing the next steps.

We walk you through building a FHIR server on top of Couchbase's NoSQL database, covering challenges, technical decisions, architecture, and local setup.

Breaking down the Top 10 FHIR tools every developer should know in 2025, from building and hosting servers to validating, profiling, and testing data.

Deploy your patient-facing FHIR app across Epic hospitals in just 48 hours. We demystify Epic's Automatic Client Record Distribution process easily.
No comments yet. Be the first to comment!