108 lines
4.5 KiB
C#
108 lines
4.5 KiB
C#
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<Doctor> GetDoctorProfileAsync(Guid doctorId)
|
|
{
|
|
var response = await requestHttpService.GetAsync($"/api/Doctors/{doctorId}");
|
|
if (!response.IsSuccessStatusCode) return null;
|
|
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<Doctor>>();
|
|
return apiResponse?.Data;
|
|
}
|
|
|
|
public async Task<bool> UpdateDoctorProfileAsync(Doctor doctor)
|
|
{
|
|
var response = await requestHttpService.PutAsync("/api/Doctors", doctor);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<bool> DeleteDoctorProfileAsync(Guid doctorId)
|
|
{
|
|
var response = await requestHttpService.DeleteAsync($"/api/Doctors/{doctorId}");
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<MedicalHistory?> GetMedicalHistoryAsync(Guid userId)
|
|
{
|
|
var response = await requestHttpService.GetAsync($"/api/MedicalHistory/user/{userId}");
|
|
if (!response.IsSuccessStatusCode) return null;
|
|
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<MedicalHistory>>();
|
|
return apiResponse.Data;
|
|
}
|
|
|
|
public async Task<List<Patient>> GetAllPatientsAsync()
|
|
{
|
|
var response = await requestHttpService.GetAsync("/api/Patients");
|
|
if (!response.IsSuccessStatusCode) return [];
|
|
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<List<Patient>>>();
|
|
return apiResponse?.Data ?? [];
|
|
}
|
|
|
|
public async Task<List<Appointment>> GetAppointmentsAsync(Guid doctorId)
|
|
{
|
|
var response = await requestHttpService.GetAsync($"/api/Appointments/doctor/{doctorId}");
|
|
if (!response.IsSuccessStatusCode) return [];
|
|
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<List<Appointment>>>();
|
|
return apiResponse?.Data ?? [];
|
|
}
|
|
|
|
public async Task<bool> SendMessageAsync(Guid senderId, Guid receiverId, string message)
|
|
{
|
|
var requestBody = new { sender = senderId, receiver = receiverId, message = message };
|
|
var response = await requestHttpService.PostAsync("/api/Chat/send_message", requestBody);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<bool> 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<Chat> 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<ApiResponse<Chat>>();
|
|
return apiResponse?.Data;
|
|
}
|
|
|
|
|
|
public async Task<byte[]> DownloadMedicalHistoryAsync(Guid patientId)
|
|
{
|
|
var response = await requestHttpService.GetAsync($"/api/MedicalHistory/user/{patientId}");
|
|
if (!response.IsSuccessStatusCode) return null;
|
|
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<MedicalHistory>>();
|
|
return apiResponse.Data.Content;
|
|
}
|
|
|
|
public async Task<bool> 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<ApiResponse<List<PredictionResult>>> 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<ApiResponse<List<PredictionResult>>>();
|
|
return apiResponse;
|
|
}
|
|
} |