External Accounts
Participants frequently have accounts with services external to MyDataHelps, such as their provider’s EHR, their health plan, or their wearable device manufacturer. For more information see the data overview. MyDataHelpsKit provides tools for your app to allow participants to link MyDataHelps to their external account(s), and to manage that link once it’s been established.
In the MyDataHelpsKit SDK, ExternalAccountProvider
identifies a provider supported by MyDataHelps, while ExternalAccount
represents a specific connection a participant has established to a provider within MyDataHelps.
The topics below are for querying and managing external accounts and providers. Your can also use the SDK to implement a complete provider connection user experience within your app. See External Account Connections for a detailed guide.
Contents
Retrieve External Account Providers
Construct an ExternalAccountProvidersQuery
to specify filtering criteria, and execute the query using ParticipantSession.queryExternalAccountProviders
. This query returns an ExternalAccountProvidersResultPage
containing ExternalAccountProvider
values.
Your app can use this query to construct a keyword search interface or categorized list view. Consult the programming guide for best practices on working with queries, search, and and paged results in MyDataHelpsKit.
See External Account Connections for using ExternalAccountProvider
data to implement a full account connection user experience in your app.
SDK Reference
ExternalAccountProvidersQuery
ParticipantSession.queryExternalAccountProviders(_:)
ExternalAccountProvidersResultPage
ExternalAccountProvider
Examples
let criteria = ExternalAccountProvidersQuery(search: "CareEvolution", category: .provider)
let result = try await session.queryExternalAccountProviders(criteria)
for provider in result.externalAccountProviders {
print(provider.name)
}
In the MyDataHelpsKit example app, see:
- ProviderConnections/ProvidersListView.swift: ExternalAccountProviderPagedView, accessible from the Account tab if your project supports EHR connections, implements a search interface for providers in SwiftUI.
Retrieve Connected External Accounts
ParticipantSession.listExternalAccounts
fetches a list of all of the participant’s connected external accounts. This API is not paged: all of the available accounts are returned in a simple array.
SDK Reference
ParticipantSession.listExternalAccounts()
ExternalAccount
ExternalAccountProvider
ExternalAccountStatus
Examples
let accounts = try await session.listExternalAccounts()
for account in accounts {
print("Account for \(account.provider.name): \(account.status)")
}
In the MyDataHelpsKit example app, see:
- ProviderConnections/ExternalAccountsListView.swift: ExternalAccountsListView, accessible from the Account tab, displays the participant's connected external accounts with refresh and delete buttons that use the related APIs described below.
Request the Refresh of Data from a Connected External Account
ParticipantSession.refreshExternalAccount
requests the refresh of data from a connected external account.
This API only begins the process of refreshing an account; the process may take additional time to complete. To track the status of a refresh, use ParticipantSession.listExternalAccounts
to poll the status value of an account, checking for fetchingData
or fetchComplete
status values.
SDK Reference
Examples
do {
// account is from the "Retrieving External Accounts" example above.
try await session.refreshExternalAccount(account)
print("Refresh initiated.")
} catch {
print("Error refreshing account: \(MyDataHelpsError(error))")
}
In the MyDataHelpsKit example app, see:
- ProviderConnections/ExternalAccountsListView.swift: ExternalAccountsListView, accessible from the Account tab, allows interactively refreshing connected accounts.
Delete an External Account Connection
ParticipantSession.deleteExternalAccount
deletes an external account.
SDK Reference
Examples
do {
// account is from the "Retrieving External Accounts" example above.
try await session.deleteExternalAccount(account)
print("Account connection deleted.")
} catch {
print("Error deleting account connection: \(MyDataHelpsError(error))")
}
In the MyDataHelpsKit example app, see:
- ProviderConnections/ExternalAccountsListView.swift: ExternalAccountsListView, accessible from the Account tab, allows interactively deleting connected accounts.