Insurance Coverage
Use the b.well Kotlin SDK to read a user's insurance plans — insurer, plan name, group and member numbers.
New to the SDK? See Initialize and Authenticate before making your first call.
What can you do?
- Get all coverage plans for the current user
- Read insurer, plan name, group #, and member # from a plan
- Handle users with more than one active plan
- Paginate results
Need the full schema or error reference? Jump to Reference or Troubleshooting.
📘 Related Documents
- Working with claims for a specific plan? See Insurance Claims —
getClaimsForPlanthere takes the id you get back here.
Get all coverage plans for the current user
Method Signature :
suspend fun getCoverages(request: CoverageRequest?): BWellResult<Coverage>Example Code :
val coverageRequest = CoverageRequest.Builder()
.page(0)
.pageSize(20)
.build()
viewLifecycleOwner.lifecycleScope.launch {
when (val result = BWellSdk.financials.getCoverages(coverageRequest)) {
is BWellResult.ResourceCollection -> {
val coverages = result.data ?: emptyList()
println("Found ${coverages.size} coverage(s)")
}
else -> {
println("getCoverages failed: ${result.error}")
}
}
}📘 Notes
getCoveragesreturns a sealedBWellResult<Coverage>— pattern-match withwhen. There is no.data()method call.CoverageRequestis optional — passnullto fetch every availableCoveragewith default paging.- When the user has no coverage on file,
result.dataisnullor empty. This is a valid state, not an error — see Troubleshooting.
Read insurer, plan name, group #, and member # from a plan
None of these live on a single top-level field — insurer is a reference display, and Plan Name / Group # both live in the same class list, distinguished only by a type code.
val coverage: Coverage = /* one entry from the ResourceCollection above */
val insurer = coverage.payor?.firstOrNull()?.display
val planName = coverage.`class`
?.firstOrNull { it.type?.coding?.any { c -> c.code == "plan" } == true }?.name
val groupNumber = coverage.`class`
?.firstOrNull { it.type?.coding?.any { c -> c.code == "group" } == true }?.value
// Member # prefers the MB-typed identifier; subscriberId is the documented fallback
val memberNumber = coverage.identifier
?.firstOrNull { it.type?.coding?.any { c -> c.code == "MB" } == true }?.value
?: coverage.subscriberId📘 Notes
classis a Kotlin reserved word — access it with backticks:coverage.`class`.- Filter class entries by
type.coding[].code("plan" vs "group"), never by position in the list — a payor can omit either entry. - Always use
firstOrNull { ... }, never.first(). Calling.first()throws when no entry matches, which happens whenever a payor hasn't populated that class.
Handle users with more than one active plan
Coverage results are always a list — a user can hold multiple plans simultaneously. Iterate; don't assume a single result.
val activePlans = coverages.filter { coverage ->
coverage.status == FinancialResourceStatusCodes.ACTIVE &&
(coverage.period?.end == null || coverage.period.end > today)
}📘 Notes
status == ACTIVEalone is not sufficient — combine it withperiod.end(null or in the future) to decide what counts as "active" for display purposes.
Paginate results
val coverageRequest = CoverageRequest.Builder()
.page(1) // zero-based — page 1 is the second page
.pageSize(20)
.build()📘 Notes
pageis zero-based.pageSizedefaults to the SDK's standard page size if omitted.
Reference
Result type cheat sheet
| Method | Returns | How to read it |
|---|---|---|
BWellSdk.financials.getCoverages(...) | BWellResult<Coverage> | Pattern-match with when or as?. is BWellResult.ResourceCollection → .data: List<Coverage>?. Any other branch → .error: OperationOutcome. |
CoverageRequest fields
| Builder method | Required? | Notes |
|---|---|---|
.patient(patientId) | Optional | Scope to a single patient. Omit to fetch all coverages the authenticated user can see. |
.page(n) | Optional | Zero-indexed page number. Defaults to 0. |
.pageSize(n) | Optional | Results per page. Defaults to the SDK's standard page size. |
Coverage response shape
| Field | Type | Required | Notes |
|---|---|---|---|
| id | String | Required | Unique identifier |
| resourceType | String | Required | Always "Coverage" |
| status | FinancialResourceStatusCodes | Required | ACTIVE, CANCELLED, DRAFT, ENTERED_IN_ERROR |
| identifier | List<Identifier> | Optional | Member # is the entry where type.coding[].code == "MB" |
| type | CodeableConcept | Optional | Plan type; read type.text, fall back to type.coding[0].display |
| subscriberId | String | Optional | Fallback Member # when the MB identifier is absent |
| period | Period | Optional | start / end — Effective Start/End Date |
| payor | List<CoveragePayorReference> | Optional | Insurer name is payor[0].display |
| class | List<CoverageClass> | Optional | Carries Plan Name ("plan") and Group # ("group") |
CoveragePayorReference fields
| Field | Type | Required | Notes |
|---|---|---|---|
| reference | String | Optional | Reference to the payor resource |
| type | String | Optional | Expected type of the reference target |
| display | String | Optional | Plain-text Insurer display name — this is the field read as payor[0].display |
CoverageClass fields
| Field | Type | Required | Notes |
|---|---|---|---|
| id | String | Optional | Unique identifier for this class entry |
| type | CodeableConcept | Optional | Filter by type.coding[].code: "plan" → name is the Plan Name; "group" → value is the Group # |
| value | String | Optional | Alphanumeric insurer-issued label (populated for the "group" entry) |
| name | String | Optional | Short description for the class (populated for the "plan" entry) |
Annotated shape:
{
"id": "coverage-8841",
"resourceType": "Coverage",
"status": "active",
"type": { "text": "Medicare Advantage PPO" },
"subscriberId": "SUB-99213456",
"identifier": [
{ "type": { "coding": [{ "code": "MB" }] }, "value": "MB-2201938" }
],
"period": { "start": "2026-01-01", "end": "2026-12-31" },
"payor": [ { "display": "Acme Health Plans" } ],
"class": [
{ "type": { "coding": [{ "code": "plan" }] }, "name": "PPO Gold" },
{ "type": { "coding": [{ "code": "group" }] }, "value": "GRP-4471" }
]
}Troubleshooting
Each heading below is the symptom or error you may encounter. Search this section for the closest match to what you're hitting.
Issue : Does not compile: data is not a member of BWellResult<Coverage> You accessed .data directly on the BWellResult value instead of narrowing to BWellResult.ResourceCollection first.
Fix : (result as? BWellResult.ResourceCollection)?.data ?: emptyList(), or pattern-match with when.
Issue : getCoverages returns an error result where it used to succeed The session is missing or expired — getCoverages doesn't throw on an auth failure, it returns the non-ResourceCollection branch.
Fix : Check result.error for an OperationOutcome before treating this as a data problem. Re-run SDK initialization/authentication and retry.
Issue : data is null or an empty list Either the authenticated user has no Coverage records, or the current page/pageSize window has no results.
Fix Treat this as a valid "no coverages" state, not an error. Don't assume page(0) always has results.
Issue : Member # comes back null Code read only the MB-typed identifier and didn't fall back.
Fix : identifier.firstOrNull { ... "MB" ... }?.value ?: coverage.subscriberId.
Issue : Plan Name or Group # returns null class entries were filtered by the wrong type.coding[].code, or the payor hasn't populated that class entry.
Fix : Confirm the filter code matches exactly ("plan" / "group") and treat a missing entry as "not provided by this payor," not a bug.
If your issue isn't listed here, reach out to support and include: the SDK version, the exact CoverageRequest builder calls used, and the full OperationOutcome from result.error if the failure branch was hit.
Updated about 14 hours ago
