Finding Member ID

Goal

After having a Patient go through the <FlexpaLogin /> flow, we can fetch Coverage information by using our out-of-the-box React Component, or by constructing the FHIR query ourselves.

This guide will focus on making the FHIR query ourselves allowing us to inspect the result and do what we want with it.

What is Coverage?

Coverage describes an insurance plan policy belonging to a Patient or RelatedPerson that is used to provision health care products and services.

Some examples of Coverage are:

  • Life Insurance Policies
  • Automobile Policies
  • Healthcare Spending Accounts
  • or even Paying for a good or service directly.

Flexpa has made it easy to fetch this information and to simply display it inside of your React app.

How to search for Patient Coverage

To search a Patient's Coverage, we use a React hook to actually make this query. The hook itself useFHIRSearch allows you to Search for FHIR resources that belong to the currently logged in Patient. The hook expects two parameters, and a type variable to strongly type its response.

  1. fhirResource: The Resource we are searching for (as a string)
  2. options: A Javascript object representing the options for the request (URL, headers, etc).

The response will be an object with two properties.

  1. data: The parsed JSON response strongly typed to the type variable<T> originally passed into the hook (if exists).
  2. error: A Javascript Error object representing the Error of the request (if any).

Here is some sample code to search Coverage belonging to Patient/A000123:

// note: both of these properties are set for you
// when rendeirng inside of a `<FlexpaLogin />`.
const options = {
  baseURL: 'https://api.sandbox.flexpa.com/fhir/'
  authorization: 'fake-jwt',
  query: { patient: 'Patient/123' },
};
const { data, error } = useFHIRSearch<Coverage>('Coverage', options);

// data: Coverage[] is now a list of Coverages
// we can easily pluck out all Member IDs
const memberIds = data.map(coverage => coverage.identifier);

You can import this hook and use it however you want in your own application, you'll just need to make sure you are configuring the variables similar to above.

Putting it all together

To complete this task we will need to use:

  • FlexpaLogin - to prompt the Patient to login to their health plan system & grant API access
  • useFlexpaConfig - React hook to give us access to the Flexpa config
  • useFHIRSearch - React hook to search the FHIR API on behalf of the Patient

Code:

import { FlexpaLogin, useFlexpaConfig, useFHIRSearch } from '@flexpa/login';

const SearchCoverageComponent = () => {
  const { state: { flexpaJwt, gatewayUrl, patient } } = useFlexpaConfig();
  const options = {
    baseURL: gatewayUrl,
    authorization: flexpaJwt,
    patient
  };
  const { data, error } = useFHIRSearch<Coverage>('Coverage', options);
  return (
    <ul>
      {data.map(coverage => (
        <li key={coverage.identifier}>{coverage.identifier}</li>
      ))}
    </ul>
  );
};

// App.jsx
<FlexpaLogin sandbox>
  <SearchCoverageComponent />
</FlexpaLogin>

How the query works

The simplest implementation of fetching a Patient's coverage is querying a FHIR API directly. This is what the useFHIRSearch hook is doing when it runs. Using all of these variables (same as above):

  • baseURL: https://api.sandbox.flexpa.com/fhir/
  • authorization: fake-jwt
  • fhirResource: Coverage
  • Patient ID: Patient/A000123

We can put these together to make a request with curl like this:

GATEWAY=https://api.sandbox.flexpa.com/fhir/
JWT=fake-jwt
PATIENT_ID=Patient/A000123

curl "$GATEWAY/Coverage?patient=$PATIENT_ID" \
  -H "Authorization: $JWT"

See also