Android only, iOS may be added in the future.

  • DataObserver

    The DataObserver is the primary interface between the DexCare SDK and your app. If you have experience with RxJava, you will likely find the concepts about to be discussed already familiar. Also, if you are already using RxJava in your app, we’ve provided an extension function DataObserver.convertToRxJava() to convert DataObservers back into RxJava.

    The vast majority of API calls contained in the DexCare SDK are asynchronous. This means that data will not be returned immediately, rather it will be returned at some point in the future. The DataObserver is the DexCare SDK’s means of returning that data to your app, asynchronously.

    The DataObserver is essentially a minimal, bare-bones equivalent of RxJava’s Single. As in, only one value or error will be returned per subscription (not a constant stream of data).

    DataObservers are typed to the return type of each API call. Examples:

    • PatientService.getPatient() returns a DataObserver<DexCarePatient>
    • VirtualService.getRegions() returns a DataObserver<List<Region>>

    Every call to one of the SDK’s service methods will return a DataObserver. Your implementing app then needs to call.subscribe() on the returned DataObserver, in order to listen for the result.

    The .subscribe() method has three parameters:

    • onSuccess: (T) -> Unit - A lambda method that will be run when the SDK is returning data to the app. T is typed to the return type of the API call.
    • onError: (Throwable) -> Unit = {} - An optional (but highly recommended to override) lambda that will be called when something went wrong. The exception is returned in this lambda for your app to handle appropriately.
    • thread: Thread = Thread.Main - An optional enum to change the Thread upon which data is returned to. In most cases, you’ll want to update your app’s UI when a DexCare SDK call completes, and updating the UI is required to be done on the Main thread. In the case where Main is not required, this parameter can be overridden to Thread.IO.

    DataObserver lifecycle management

    The DataObserver interface implements the androidx.lifecycle LifecycleObserver. Your app can simply register each DataObserver as an observer of your Fragment or Activity’s lifecycle, and the DataObserver will handle disposal of ongoing API calls as necessary. This should be done to ensure your app does not try to update a UI that no longer exists or is visible, which would result in an immediate crash.

            DexCareSDK.virtualService.startVirtualVisit(
                    this,
                    registerPushNotification,
                    paymentMethod,
                    virtualVisitInformation
            ).subscribe({
                val visitId = it.first
                val intent = it.second
    
                startActivityForResult(intent, VISIT_REQUEST_CODE)
            }, {
                // handle the error
            }).also { 
                // lifecycle is a member variable present in Fragments and Activities
                lifecycle.addObserver(it)
            }
    

    DataObserver disposal

    Once a DataObserver has been disposed, your app will no longer receive any success/error callbacks if the API calls are still processing.

    In some specific cases, it may be necessary for your app to know exactly when a DataObserver gets disposed. The DataObserver contains a property onDisposed: (() -> Unit)? = null, which, when set, will be invoked when a DataObserver gets disposed.

    Additionally, the DataObserver contains a method isDisposed(): Boolean, allowing you to check if a DataObserver has already been disposed or not.