| 1 | import { apiClient } from "@/api/client";
|
|---|
| 2 | import type { Therapy } from "@/api/therapy";
|
|---|
| 3 |
|
|---|
| 4 | export interface Consultation {
|
|---|
| 5 | idConsultation: number;
|
|---|
| 6 | patientId: number;
|
|---|
| 7 | patientName: string;
|
|---|
| 8 | therapistId: number;
|
|---|
| 9 | therapistName: string;
|
|---|
| 10 | date: string;
|
|---|
| 11 | dateOfPayment: string | null;
|
|---|
| 12 | price: number;
|
|---|
| 13 | advice: string;
|
|---|
| 14 | therapies: Therapy[];
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | export const isConsultationPaid = (consultation: Consultation): boolean =>
|
|---|
| 18 | consultation.dateOfPayment !== null;
|
|---|
| 19 |
|
|---|
| 20 | export interface CreateConsultationRequest {
|
|---|
| 21 | patientId: number;
|
|---|
| 22 | date: string;
|
|---|
| 23 | price: number;
|
|---|
| 24 | advice: string;
|
|---|
| 25 | dateOfPayment?: string | null;
|
|---|
| 26 | therapies?: Array<{
|
|---|
| 27 | name: string;
|
|---|
| 28 | dose: string;
|
|---|
| 29 | expDate: string;
|
|---|
| 30 | }>;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | export interface UpdateConsultationRequest {
|
|---|
| 34 | date?: string;
|
|---|
| 35 | price?: number;
|
|---|
| 36 | advice?: string;
|
|---|
| 37 | dateOfPayment?: string | null;
|
|---|
| 38 | therapies?: Array<{
|
|---|
| 39 | name: string;
|
|---|
| 40 | dose: string;
|
|---|
| 41 | expDate: string;
|
|---|
| 42 | }>;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | export const consultationApi = {
|
|---|
| 46 | getTherapistConsultations: async (
|
|---|
| 47 | therapistId: number,
|
|---|
| 48 | ): Promise<Consultation[]> =>
|
|---|
| 49 | apiClient.get<Consultation[]>(`/consultations/therapist/${therapistId}`),
|
|---|
| 50 |
|
|---|
| 51 | getPatientConsultations: async (patientId: number): Promise<Consultation[]> =>
|
|---|
| 52 | apiClient.get<Consultation[]>(`/consultations/patient/${patientId}`),
|
|---|
| 53 |
|
|---|
| 54 | createConsultation: async (
|
|---|
| 55 | data: CreateConsultationRequest,
|
|---|
| 56 | ): Promise<Consultation> =>
|
|---|
| 57 | apiClient.post<Consultation>("/consultations", data),
|
|---|
| 58 |
|
|---|
| 59 | updateConsultation: async (
|
|---|
| 60 | consultationId: number,
|
|---|
| 61 | data: UpdateConsultationRequest,
|
|---|
| 62 | ): Promise<Consultation> =>
|
|---|
| 63 | apiClient.put<Consultation>(`/consultations/${consultationId}`, data),
|
|---|
| 64 |
|
|---|
| 65 | deleteConsultation: async (consultationId: number): Promise<void> =>
|
|---|
| 66 | apiClient.delete<void>(`/consultations/${consultationId}`),
|
|---|
| 67 | };
|
|---|