Initialization

The DexCareSDK object is the primary access point for interacting with the SDK. All services can be accessed through this object.

  • To initialize the SDK, you will need to call DexcareSDK.init(configuration: DexcareConfiguration). It is recommended to keep the SDK alive for the entirety of your application’s lifecycle. It is best to initialize the SDK as early as possible in your application’s lifecycle, however it is not necessarily needed to be initialized on didFinishLaunchingWithOptions. After initialization, the SDK does not pre-load any data.

    The DexcareConfiguration object requires a few objects to be setup before the SDK can be initialized.

    VirtualVisitConfiguration

    A VirtualVisitConfiguration object will contain all the appropriate information that is required for virtual visits.

    • pushNotificationAppId - The AppId for push notifications set up by Apple.
    • pushNotificationPlatform - The platform for push notifications set up by Apple (usually ios or ios-sandbox).
    • virtualVisitUrl - The url that is provided by your DexCare contact.
    let virtualVisitConfig = VirtualVisitConfiguration (
        pushNotificationAppId: "App id",
        pushNotificationPlatform: "ios",
        virtualVisitUrl: URL(string: "https://www.virtualvisiturl.com/api/")!
    )
    

    Environment

    An Environment object will contain all the urls and keys needed to run the SDK. The required URLs and keys will be provided by your DexCare contact.

    let environment = Environment(
        fhirOrchUrl: URL(string:  "https://www.aurl.com/api/")!,
        virtualVisitConfiguration: virtualVisitConfig,
        dexcareAPIKey: "apikey"
    

    DexcareSDKLogger

    The DexcareSDKLogger is a protocol that you can use to see more information about what the SDK does. If an instance of DexcareSDKLogger is attached on initialization, the SDK will post results, errors, information to the logger, which can help you debug issues.

    The DexcareSDKLogger has one function you must implement: func log(_ message: String, level: DexcareSDKLogLevel, sender: String)

    // Example `DexcareSDKLogger` to pass into the SDK.
    // Pass ConsoleLogger() into the SDK init method to post NSLog's to the console.
    class ConsoleLogger: DexcareSDKLogger {
        static var shared: ConsoleLogger = ConsoleLogger()
        func log(_ message: String, level: DexcareSDKLogLevel, sender: String) {
            let emoji: String
            switch level {
                case .verbose: emoji = "➡️"
                case .debug: emoji = "✳️"
                case .info: emoji = "✏️"
                case .warning: emoji = "⚠️"
                case .error: emoji = "❌"
            }
            NSLog("\(emoji) \(sender): \(message)")
        }
    }
    
    

    As an example, if the above is implmented, and a function call fails to the server, it will print to the console:

    ❌ DexcareSDK: Response error in 1.58s for: https://dexcareurl.com/api/7/visits/providerbooking?product=healthconnect-iOS - Status: 500 - Correlation: AD5C5189-DC90-46CB-A5F8-2641A0886E2C
    

    Correlation

    :heavy_check_mark: By providing the Correlation GUID to your dexcare contact, we can easily tell what went wrong in the call. :tada:

    Without it, it is more difficult to search on a server log to try and find out what happened.

    DexcareConfiguration

    Finally the DexcareConfiguration object combines all the 2 config objects.

    • environment - an Environment object created above.
    • userAgent - any specific information you want to pass in the UserAgent header to the API call. xxxUserAgentxxx|6.0.0|iPhone|12.1|darwin as an example of what will be used.
    • domain - a string provided by your DexCare contact.
    • customStrings - an optional set of strings that can override the default display strings inside a Virtual Visit.
    • logger - an optional implementation of DexcareSDKLogger.
    return DexcareConfiguration(
        environment: environment,
        userAgent: "MyDexcareApp",
        domain: "com.myapp",
        customStrings: nil,
        logger: ConsoleLogger() // as an example
    )
    
  • Setting up configs

    Your app will need to define several configuration values in string resources. Most of these can be provided by your DexCare contact, and note that some may differ for debug vs. release builds.

    See the DexCareSDK Sample App repo for a list of config values required by the SDK.

    Initializing the SDK

    To initialize the SDK, you will need to call DexCareSDK.init as early as possible in your application’s lifecycle, optimally inside your Application’s onCreate() method. The SDK can only be initialized once.

    The init method takes the parameters: context: Context, environment: Environment, refreshTokenContract: RefreshTokenContract? = null.

    context should be your Application’s context.

    environment should be an implementation of the SDK’s Environment interface. The required base URLs will be provided by your DexCare contact.

    refreshTokenContract is an optional argument, which can be an implementation of the SDK’s RefreshTokenContract interface.

    As of SDK 4.0.0, the SDK’s Koin instance is internal to the SDK.

    Your app is not required to use Koin.

    Initialization of the SDK should look something like this:

    class MainApplication : Application() {
        override fun onCreate() {
            super.onCreate()
            DexCareSDK.init(this,
                object : Environment {
                    override val isProd: Boolean = BuildConfig.BUILD_TYPE.toLowerCase(Locale.ROOT) == "release"
                    override val fhirOrchUrl: String = getString(R.string.dexcare_fhirorch_url)
                    override val virtualVisitUrl: String = getString(R.string.dexcare_virtualvisit_url)
                }
            )
        }
    }
    

Authentication

In order to use the DexCare services, the SDK requires an access token.

Currently, Auth0 is the only supported authentication platform for DexCare services. Additional authentication platforms can potentially be supported in the future.

  • To set the access token for the DexCare SDK to use, you need to call DexCareSDK.signIn(accessToken: String) method.

    let dexcareSDK = DexcareSDK(configuration: ...)
    dexcareSDK.signIn(accessToken: "myAuth0AccessToken")
    

    The token can be revoked from the SDK by calling the DexCareSDK.signOut() method.

    let dexcareSDK = DexcareSDK(configuration: ...)
    dexcareSDK.signOut()
    
  • To set the access token for the DexCare SDK to use, you need to call DexCareSDK.signIn(accessToken: String).

    These calls are synchronous, so subscribing for results is not needed.

    DexCareSDK.signIn("myAuth0AccessToken")
    

    The token can be revoked from the SDK by calling the DexCareSDK.signOut() method.

    Note: calling signOut also will remove any cache that the SDK has.

    DexCareSDK.signOut()