using System.Net.Http.Json; using HealthcareManagerUiWebAssem.Entities; using HealthcareManagerUiWebAssem.Models; using HealthcareManagerUiWebAssem.Services.RequestHttp; namespace HealthcareManagerUiWebAssem.Services.DoctorManagement; public class DoctorManagementService(IRequestHttpService requestHttpService) : IDoctorManagementService { public async Task GetDoctorProfileAsync(Guid doctorId) { var response = await requestHttpService.GetAsync($"/api/Doctors/{doctorId}"); if (!response.IsSuccessStatusCode) return null; var apiResponse = await response.Content.ReadFromJsonAsync>(); return apiResponse?.Data; } public async Task UpdateDoctorProfileAsync(Doctor doctor) { var response = await requestHttpService.PutAsync("/api/Doctors", doctor); return response.IsSuccessStatusCode; } public async Task DeleteDoctorProfileAsync(Guid doctorId) { var response = await requestHttpService.DeleteAsync($"/api/Doctors/{doctorId}"); return response.IsSuccessStatusCode; } public async Task GetMedicalHistoryAsync(Guid userId) { var response = await requestHttpService.GetAsync($"/api/MedicalHistory/user/{userId}"); if (!response.IsSuccessStatusCode) return null; var apiResponse = await response.Content.ReadFromJsonAsync>(); return apiResponse.Data; } public async Task> GetAllPatientsAsync() { var response = await requestHttpService.GetAsync("/api/Patients"); if (!response.IsSuccessStatusCode) return []; var apiResponse = await response.Content.ReadFromJsonAsync>>(); return apiResponse?.Data ?? []; } public async Task> GetAppointmentsAsync(Guid doctorId) { var response = await requestHttpService.GetAsync($"/api/Appointments/doctor/{doctorId}"); if (!response.IsSuccessStatusCode) return []; var apiResponse = await response.Content.ReadFromJsonAsync>>(); return apiResponse?.Data ?? []; } public async Task SendMessageAsync(Guid senderId, Guid receiverId, string message) { var requestBody = new { sender = senderId, receiver = receiverId, message }; var response = await requestHttpService.PostAsync("/api/Chat/send_message", requestBody); return response.IsSuccessStatusCode; } public async Task CancelAppointmentAsync(Guid doctorId, Guid patientId, DateTime appointmentDate) { var cancellationRequest = new AppointmentCancellationRequest { DoctorId = doctorId, PatientId = patientId, Appointment = appointmentDate }; var response = await requestHttpService.PutAsync("/api/Appointments", cancellationRequest); return response.IsSuccessStatusCode; } public async Task GetConversationAsync(Guid userId1, Guid userId2) { var requestBody = new { idUser1 = userId1, idUser2 = userId2 }; var response = await requestHttpService.PostAsync("/api/Chat/get_conversation", requestBody); if (!response.IsSuccessStatusCode) return null; var apiResponse = await response.Content.ReadFromJsonAsync>(); return apiResponse?.Data; } public async Task DownloadMedicalHistoryAsync(Guid patientId) { var response = await requestHttpService.GetAsync($"/api/MedicalHistory/user/{patientId}"); if (!response.IsSuccessStatusCode) return null; var apiResponse = await response.Content.ReadFromJsonAsync>(); return apiResponse.Data.Content; } public async Task CheckForAccessAsync(Guid medicalRecordId, Guid doctorId) { var requestBody = new { MedicalRecordId = medicalRecordId, DoctorId = doctorId }; var response = await requestHttpService.PostAsync("/api/MedicalHistory/check_access", requestBody); return response.IsSuccessStatusCode; } public async Task>> GetSicknessPrediction(string text) { var requestBody = new { text }; var response = await requestHttpService.PostAsync("/api/SicknessPrediction", requestBody); if (!response.IsSuccessStatusCode) return null; var apiResponse = await response.Content.ReadFromJsonAsync>>(); return apiResponse; } }