Skip to main content

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 the Consultation class

class Consultation {
consultationId: Int,
userId: Int
question: String
medium: String
mediaIds: [String]?
parentConsultationId: Int?
forceWhiteLabelingPartnerName: String?
# ...
# Only these properties are needed for consultation creation from Consultation class
# Other properties are not needed
}

Consider that the required fields are question, medium and userId

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

The parentConsultationId field optional and used in case the consultation being created is related to a previous consultation, then you have to add the previous consultation id

The mediaIds field is optional and used in case of adding attachments to the consultation

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(
jsonFile: Data,
type: String,
completion: Void
)

In the example we are using the UIDocumentPickerViewController and UIImagePickerController along with the needed delegates UIDocumentPickerDelegate and UIImagePickerControllerDelegate

Check the code below:

import AltibbiTelehealth

// From documentPicker of UIDocumentPickerDelegate we can get the picked file this way
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let fileURL = urls.first else { return }
if fileURL.pathExtension.lowercased() == "pdf" {
do {
let pdfData = try Data(contentsOf: fileURL)
handleFileUpload(data: pdfData, type: "pdf")
} catch {
print("Error converting PDF to Data: \(error)")
}
}
}

// From the imagePickerController of UIImagePickerControllerDelegate we can get the pciked image this way
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true, completion: nil)

if let pickedImage = info[.originalImage] as? UIImage {
if let imageData = pickedImage.jpegData(compressionQuality: 0.5) {
handleFileUpload(data: imageData, type: "img")
}
}
}

// Handle File Upload
func handleFileUpload(data: Data, type: String) -> Void {
ApiService.uploadMedia(jsonFile: data, type: type, completion: {media, failure, error in
if let error = error {
print("Data Error: \(String(describing: error))")
} else if let failure = failure {
ResponseFailure.printJsonData(failure)
} else {
if let media = media {
// For creating consultation you could have an array of String and append the id from the media object
self.mediaIds.append(media.id!)
}
}
})
}

We have the struct Media to decode the response of the uploadMedia method

struct Media {
var id: String?
type: String?
name: String?
path: String?
ext: String?
size: Int?
createdAt: String?
url: String?
}

In the code snippet above we just added the id of the uploaded file directly to the mediaIds but in case of showing the uploaded files consider using the Media struct and use the url to show the file

Creating the consultation

Check the example

import AltibbiTelehealth

var mediaIds: [String] = []

/**
/ ... /
* Consider the upload functionality is done here and appended some ids
/ ... /
**/

let consultation = Consultation(
userId: 999999999,
question: "I want to consult a doctor on ...",
medium: "chat",
mediaIds: mediaIds
)

ApiService.createConsultation(consultation: consultation, completion: {createdConsultation, failure, error in
// Handle createdConsultation as a Consultation object
// You can start the socket now
})

Responses

Status 201

Success

{
consultationId: 123,
userId: 999999999,
question: "I want to consult a doctor on ...",
medium: "chat",
mediaIds: [String]?,
status: "new",
# ... Other Consultation 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"
}
]