Skip to main content

Create Consultation

createConsultation

For creating a consultation you have to use createConsultation and provide the data needed in consultation creation. We use ConsultationObject interface:

interface ConsultationObject {
question: string;
medium: string;
user_id: number;
mediaIds?: string[];
parent_consultation_id?: number | null;
forceWhiteLabelingPartnerName?: string | null;
consultation_category_id?: number | null;
scheduled_to?: string | null;
}

Consider that the required fields are question, medium and user_id

The accepted values for medium are: chat, gsm, voip, video

The parent_consultation_id field is not required and used in case the consultation being created is related to a previous consultation, then you have to add the previous consultation ID

The consultation_category_id field is optional and used to categorize the consultation

forceWhiteLabelingPartnerName is used to notify doctors to use a specific partner name in communication with patients

scheduled_to is used for scheduling a follow-up consultation. It should be a string representing the scheduled time (usually obtained from shiftValue).

Scheduled Follow-up Consultations

To create a scheduled follow-up consultation, you first need to fetch available shifts for the parent consultation, then pick a shift and use its value for the scheduled_to field.

Fetching Available Shifts

You can use getConsultationAvailableShifts to get the list of available time slots for a specific parent consultation and date.

getConsultationAvailableShifts(
parent_consultation_id: string,
date: string // format: yyyy-MM-dd, leave empty for today
): Promise<ResponseType<{ shifts: ShiftType[] }>>

ShiftValue Helper

The shiftValue helper function extracts the necessary string from a shift object to be used in the scheduled_to field.

import { shiftValue } from 'react-native-altibbi';

const scheduledTo = shiftValue(shift);

Scheduled Follow-up Example

Here is how you can use these methods together:

import { 
getConsultationAvailableShifts,
shiftValue,
createConsultation
} from 'react-native-altibbi';

// 1. Fetch available shifts
const response = await getConsultationAvailableShifts(parent_id, '2026-03-24');
const shifts = response?.data?.shifts || [];

// 2. Find an available shift (not booked)
const shift = shifts.find((s) => s?.booked === false) || shifts.find((s) => s?.booked == null);

if (shift) {
// 3. Get the shift value
const scheduledTo = shiftValue(shift);

// 4. Create the scheduled follow-up consultation
await createConsultation({
question: "Follow-up question...",
medium: 'chat',
user_id: 12345,
parent_consultation_id: parent_id,
scheduled_to: scheduledTo,
});
}

Before the consultation example, let us explain the use of mediaIds field

In some cases the consultation might include some media files (Images or PDFs), so there is a flow of uploading these files and attaching their IDs to the createConsultation method.

We have the uploadMedia method that can be used to upload the files. Here is a quick view for this method:

uploadMedia(
path: string,
type: string,
fileName: string
): Promise<ResponseType<MediaType>>

Where the data required for this method should be from the file reader of the device. Check the following code snippet:

import React, { useState } from 'react';
import { Platform } from 'react-native';
import { uploadMedia } from 'react-native-altibbi';
import { ImageLibraryOptions, ImagePickerResponse, launchImageLibrary } from 'react-native-image-picker';
// We used react-native-image-picker here to be able to use the file selection functionality from the device
const [idsList, setIdsList] = useState<string[]>([]);

// This function could be used in some CTA to open the image selector and select an image to upload
const openImagePicker = () => {
const options: ImageLibraryOptions = {
mediaType: 'photo',
includeBase64: false,
maxHeight: 2000,
maxWidth: 2000,
};

launchImageLibrary(options, (response: ImagePickerResponse) => {
const source =
Platform.OS === 'android'
? response?.assets?.[0].uri
: response?.assets?.[0].uri?.replace('file://', '');
const fileName = encodeURI(source.replace(/^.*[\\\/]/, ''));
const type = response?.assets?.[0]?.type || '';
uploadMedia(source, type, fileName).then((res) => {
setIdsList([...idsList, res?.data?.id]);
});
}).then();
};

We have the MediaType interface to decode the response of the uploadMedia method:

interface MediaType {
id?: string;
type?: string;
name?: string;
path?: string;
extension?: string;
url?: string;
size?: number;
}

In the code snippet above we just added the ID of the uploaded file directly to the idsList state, but in case of showing the uploaded files consider using the MediaType interface.

Creating the Consultation

Check the example:

import React, { useState } from 'react';
import { uploadMedia, createConsultation } from 'react-native-altibbi';

const [idsList, setIdsList] = useState<string[]>([]);

/**
* ...
* Consider the upload functionality is done here
* ...
*/

const data = {
question: 'I want to consult a doctor on ...',
medium: 'chat',
user_id: 999999999,
mediaIds: idsList,
};

const response = await createConsultation(data);

Responses

Status 201

Success

{
"id": 123,
"user_id": 999999999,
"question": "I want to consult a doctor on ...",
"medium": "chat",
"parent_consultation_id": null,
"status": "new"
}

Status 401

UnauthorizedHttpException represents an Unauthorized HTTP exception with status code 401.

{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials",
"code": "0",
"status": "401",
"type": "yii\\web\\UnauthorizedHttpException"
}

Status 403

Duplicate request.

{
"name": "Forbidden",
"message": "duplicate request OR Current user cant access this page",
"code": "0",
"status": "403",
"type": "yii\\web\\ForbiddenHttpException"
}

Status 422

Data Validation Failed.

[
{
"field": "string",
"message": "string"
}
]