55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import client from './client';
|
|
import { Medicine, MedicineWithStock, MedicineCreate, MedicineUpdate, MedicineListResponse } from '../types';
|
|
|
|
interface MedicineQueryParams {
|
|
categoryId?: number;
|
|
search?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}
|
|
|
|
export const medicineApi = {
|
|
list: (params?: MedicineQueryParams): Promise<MedicineListResponse> => {
|
|
return client.get('/v1/medicines', { params });
|
|
},
|
|
|
|
get: (id: number): Promise<Medicine> => {
|
|
return client.get(`/v1/medicines/${id}`);
|
|
},
|
|
|
|
create: (data: MedicineCreate): Promise<Medicine> => {
|
|
return client.post('/v1/medicines', data);
|
|
},
|
|
|
|
update: (id: number, data: MedicineUpdate): Promise<Medicine> => {
|
|
return client.put(`/v1/medicines/${id}`, data);
|
|
},
|
|
|
|
delete: (id: number): Promise<void> => {
|
|
return client.delete(`/v1/medicines/${id}`);
|
|
},
|
|
|
|
recognize: (file: File): Promise<{ genericName?: string; brandName?: string; manufacturer?: string; specification?: string }> => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
return client.post('/v1/ai/recognize-medicine', formData, {
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
});
|
|
},
|
|
|
|
recognizeDates: (file: File): Promise<{ productionDate?: string; expiryDate?: string }> => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
return client.post('/v1/ai/recognize-dates', formData, {
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
});
|
|
},
|
|
|
|
recognizeLeaflet: (file: File): Promise<{ indications: string; adultDose: string; childDose?: string; contraindications: string; notes?: string }> => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
return client.post('/v1/ai/recognize-leaflet', formData, {
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
});
|
|
}
|
|
}; |