# Schedule Appointment Flow URL: https://developers.vsee.com/guides/clinickit/android-schedule-appointment 1. [Authentication](#1-authentication) 2. [Create intake](#2-create-intake) 3. [Select a consultation](#3-select-a-consultation) 4. [Select appointment time](#4-select-appointment-time) 5. [Start or cancel an appointment](#5-start-or-cancel-an-appointment) ![Schedule appointment flow](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/flow.png) Before scheduling an appointment with a provider, the user must log in to their patient account. For the same flow on iOS, see [Schedule Appointment Flow](https://developers.vsee.com/guides/clinickit/schedule-appointment) under Mobile flows. #### 1. Authentication ```kotlin val res = VseeApi.auth.loginAsPatient(username = username, password = password) when (res) { is Resource.Success -> {} is Resource.Error -> {} } ``` 1. **Initiate login:** - The app calls `VseeApi.auth.loginAsPatient`, passing the username and password. 2. **Handle the response:** - The function returns a `Resource` that indicates success or failure: - **Success:** if authentication succeeds, the code in the `Resource.Success` block runs. - **Error:** if authentication fails, the code in the `Resource.Error` block handles the error. This ensures that only authorized patients can access and schedule appointments with providers. For details of the authentication process, see [Authentication](https://developers.vsee.com/guides/clinickit/android-enter-waiting-room#1-authentication) in the Enter Waiting Room Flow. #### 2. Create intake The intake form, opened with the **Schedule an appointment** button, lets patients update information about their visit, such as the reason for the visit and the consultation type. ![Intake access](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/home-screen.png) Update the reason for the visit: ![Update reason for visit](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/create-intake.png) #### 3. Select a consultation After entering the reason for the appointment, the user chooses a consultation type. ```kotlin val res = VseeApi.visitApi.updateConsultation(intakeId, consultationId) res.doIfSuccess { _updatedIntake.postValue(it) } res.doIfFailure { Timber.e("Unable to update consultation: $it") } ``` ![Select a consultation](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/select-consultation.png) Use this API to get the available consultations, including their types, slots, and price. ```kotlin val res = VseeApi.roomApi.getRoom(roomCode = it, timeZone = TimeZone.getDefault().id) res.doIfSuccess { room -> if (room.payment?.consultations?.isEmpty() == true) { error.postValue("No consultation types are available in this room currently.") } else { _consultations.postValue(room.payment!!) } } res.doIfFailure { Timber.e("Unable to get room: $it") } ``` #### 4. Select appointment time After choosing a consultation type, the user selects an available time slot. > **Note:** Providers manage the available appointment slots. If no slot is convenient, contact the provider for more options. ![Select appointment time](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/select-time.png) To book the selected time: 1. **Call the API:** - The app calls the `createVisit` API with the details needed to create the visit: - Intake ID: the ID of the intake form. - Member ID: the ID of the patient scheduling the appointment. - Slot start: the start time of the selected slot. - Slot end: the end time of the selected slot. - Room code: the code of the virtual consultation room. 2. **Handle the response:** - The API returns success or failure: - **Success:** the app updates the UI to show the appointment was created. - **Failure:** the app tells the user it failed and asks them to retry or get help. ```kotlin val res = VseeApi.visitApi.createVisit( CreateVisitRequest( intakeId = intakeId, memberId = VseeApi.session.getUserId()!!, slotStart = slot.start, slotEnd = slot.end, roomCode = VseeApi.session.getRoomCode() ) ) res.doIfSuccess { Timber.d("Create visit success: $it") _visitCreatedSuccessfully.postValue(slot) } res.doIfFailure { Timber.e("Create visit error: ${res.message}") } ``` ![Appointment confirmation](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/confirmed.png) #### 5. Start or cancel an appointment To get the list of upcoming appointments, call the `getVisits` API with the `filter` parameter set to `'upcoming'`. ```kotlin val request = GetVisitsRequest( roomCode = VseeApi.session.getRoomCode(), accountCode = VseeApi.session.getAccountCode(), filter = "upcoming", extended = true, order = "desc" ) viewModelScope.launch { isLoading.postValue(true) val res = VseeApi.visitApi.getVisits(request) isLoading.postValue(false) when (res) { is Resource.Success -> res.data?.let { data -> _visits.value = data } is Resource.Error -> { Timber.d("Get visits error: ${res.message}") } } } ``` When the scheduled time arrives, the user can start the meeting with their provider or cancel the appointment. ![Start or cancel an appointment](https://developers.vsee.com/images/guides/clinickit/android-schedule-appointment/start-or-cancel.png) Start an appointment: ```kotlin startActivity(Actions.openPreWaitingRoom(this, visit)) ``` Cancel an appointment: ```kotlin viewModelScope.launch { val res = VseeApi.visitApi.closeVisit(visitId, "Close visit on the sample app.") res.doIfSuccess { _closeVisitResult.postValue(true) } res.doIfFailure { _closeVisitResult.postValue(false) } } ```