PredictSpecialty
The PredictSpecialty interface represents specialties predicted based on the analysis of a consultation using a machine learning model. It includes a specialty_id and its related subCategories.
Interface Definition
interface PredictSpecialty {
specialty_id: number;
subCategories: SubCategory[];
}
Fields
| Field | Type | Required | Description |
|---|---|---|---|
specialty_id | number | Yes | The ID of the predicted specialty. |
subCategories | SubCategory[] | Yes | A list of related subcategories for the predicted specialty. |
SubCategory Interface
Each SubCategory contains the following fields:
interface SubCategory {
sub_category_id: number;
name_en: string;
name_ar: string;
}
| Field | Type | Required | Description |
|---|---|---|---|
sub_category_id | number | Yes | The unique identifier for the subcategory. |
name_en | string | Yes | The subcategory name in English. |
name_ar | string | Yes | The subcategory name in Arabic. |
Fetching Predicted Specialties
Use the getPredictSpecialty function to retrieve predicted specialties for a given consultation:
import { getPredictSpecialty } from 'altibbi-react-native';
const response = await getPredictSpecialty(consultationId);
// response.data is of type PredictSpecialty[]
Function Signature
getPredictSpecialty(consultation_id: number): Promise<ResponseType<PredictSpecialty[]>>
| Parameter | Type | Required | Description |
|---|---|---|---|
consultation_id | number | Yes | The ID of the consultation to analyze. |
Return Type
Returns a Promise<ResponseType<PredictSpecialty[]>> — an array of predicted specialties wrapped in a standard response object.
interface ResponseType<T> {
status: number;
data: T;
}
Example Usage
Using Predicted Specialty to Retrieve Related Articles
Once specialties have been predicted from a consultation analysis, the sub_category_id values from the subCategories array can be passed to getArticlesList to fetch related articles.
Note: The
getArticlesListfunction accepts an array of subcategory IDs (as strings), not specialty IDs. Use thesub_category_idfrom the predictedsubCategoriesto fetch relevant articles.
import { getPredictSpecialty, getArticlesList } from 'altibbi-react-native';
import type { PredictSpecialty, Article, ResponseType } from 'altibbi-react-native';
// Step 1: Get predicted specialties for a consultation
async function handleConsultationPrediction(consultationId: number) {
try {
const response: ResponseType<PredictSpecialty[]> = await getPredictSpecialty(consultationId);
const predictions = response.data;
if (predictions.length > 0) {
const firstPrediction = predictions[0];
console.log('Predicted Specialty ID:', firstPrediction.specialty_id);
// Step 2: Extract subcategory IDs from the prediction
if (firstPrediction.subCategories.length > 0) {
const subcategoryIds = firstPrediction.subCategories.map(
(sub) => sub.sub_category_id.toString()
);
// Step 3: Fetch articles for the predicted subcategories
await fetchArticlesForSubcategories(subcategoryIds);
} else {
console.log('No subcategories found for the predicted specialty');
}
} else {
console.log('No specialty predicted for this consultation');
}
} catch (error) {
console.error('Error predicting specialty:', error);
}
}
// Fetch and display articles based on subcategory IDs
async function fetchArticlesForSubcategories(subcategoryIds: string[]) {
try {
const articlesResponse: ResponseType<Article[]> = await getArticlesList(subcategoryIds);
const articles = articlesResponse.data;
if (articles && articles.length > 0) {
const firstArticle = articles[0];
console.log('Title:', firstArticle.title);
console.log('Body:', firstArticle.body);
console.log('URL:', firstArticle.url);
} else {
console.log('No articles found for the given subcategories');
}
} catch (error) {
console.error('Error fetching articles:', error);
}
}
// Usage
handleConsultationPrediction(12345);
Displaying All Predicted Specialties with Their Subcategories
import { getPredictSpecialty } from 'altibbi-react-native';
async function displayPredictions(consultationId: number) {
try {
const response = await getPredictSpecialty(consultationId);
response.data.forEach((prediction, index) => {
console.log(`\nPrediction #${index + 1}:`);
console.log(` Specialty ID: ${prediction.specialty_id}`);
console.log(` Subcategories:`);
prediction.subCategories.forEach((sub) => {
console.log(` - [${sub.sub_category_id}] ${sub.name_en} / ${sub.name_ar}`);
});
});
} catch (error) {
console.error('Error:', error);
}
}