Create Consultation
Create Consultation Example
For creating a consultation you have to use the creatConsultation and provide the data needed in consultation creation, we use interface ConsultationObject
interface ConsultationObject {
question: string;
medium: string;
user_id: number;
mediaIds?: string[];
followUpId?: string;
forceWhiteLabelingPartnerName?: string;
}
Consider that the required fields are
question
,medium
anduser_id
The accepted values for
medium
are:chat
,gsm
,voip
,video
The
followUpId
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
forceWhiteLabelingPartnerName
is used to notify doctors to use specific partner name in communication with patients
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 add attach their IDs to the createConsultation method
We have the uploadMedia
method that could be used to upload the files, here is a quick view for this method
uploadMedia(
path: string,
type: string,
fileName: string
)
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 { 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([])
// This function could be used in some CTA to open the image selector and select and 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 interface MediaType
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';
import { ImageLibraryOptions, ImagePickerResponse, launchImageLibrary } from 'react-native-image-picker';
const [idsList, setIdsList] = useState([])
/**
/ ... /
* Consider the upload functionality is done here
/ ... /
**/
const data: ConsultationObject = {
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",
# ... Other ConsultationType properties
}
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"
}
]