@using System.Text.Json
@using HealthcareManagerUiWebAssem.Models
@using HealthcareManagerUiWebAssem.Services.Profile
@using HealthcareManagerUiWebAssem.Services.Appointment
@using HealthcareManagerUiWebAssem.Services.User
@inject UserService UserService
@inject IProfileService ProfileService
@inject IAppointmentService AppointmentService
@inject IJSRuntime JS
Patient Menu
Here you can manage appointments, review your medical history and chat with doctors.
| Doctor Name |
Appointment Time |
Delete |
@foreach (var appointment in appointments)
{
@foreach (var date in appointment.AppointmentsList)
{
| @GetDoctorName(new Guid(appointment.DoctorId)) |
@date.ToString("yyyy-MM-dd HH:mm") |
|
}
}
@if (doctors != null)
{
}
else
{
Loading doctors...
}
@code {
private List doctors;
private string selectedDoctorId;
private DateTime? selectedDate;
private List appointments;
private List medicalHistoryFiles;
[Parameter] public string Role { get; set; }
protected override async Task OnInitializedAsync()
{
await InitializeDoctors();
await LoadAppointments();
}
private async Task LoadAppointments()
{
var response = await AppointmentService.GetAppointmentsByPatient(UserService.UserId);
var jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
if (response.StatusCode == HttpStatusCodes.OK)
{
appointments = JsonSerializer.Deserialize>(response.Data, jsonOptions) ?? new List();
}
else
{
appointments = new List();
}
}
private async Task ShowAddAppointmentModal()
{
await JS.InvokeVoidAsync("eval", "new bootstrap.Modal(document.getElementById('addAppointmentModal')).show();");
}
private async Task InitializeDoctors()
{
var response = await ProfileService.GetDoctors();
var jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
if (response.StatusCode == HttpStatusCodes.OK)
{
doctors = JsonSerializer.Deserialize>(response.Data, jsonOptions);
}
else
{
// Handle error
}
}
private async Task CreateAppointment()
{
if (string.IsNullOrEmpty(selectedDoctorId) || !selectedDate.HasValue)
{
// Handle validation
return;
}
// Call AddAppointment method, which is not shown here
var createAppointmentModel = new AppointmentManagementModel
{
PatientId = UserService.UserId,
DoctorId = new Guid(selectedDoctorId),
Appointment = (DateTime)selectedDate
};
await AppointmentService.CreateAppointment(createAppointmentModel);
// You'll need to pass UserService.UserId, selectedDoctorId, and selectedDate.Value to it
// Close the modal after creation
await JS.InvokeVoidAsync("eval", "new bootstrap.Modal(document.getElementById('addAppointmentModal')).hide();");
// Optionally, refresh the appointments list
}
private void AddMedicalHistoryFile()
{
// Logic for adding a new appointment
}
private async Task DeleteAppointment(Appointment appointmentToDelete)
{
var appointmentModelToDelete = new AppointmentManagementModel
{
PatientId = new Guid(appointmentToDelete.PatientId),
DoctorId = new Guid(appointmentToDelete.DoctorId),
Appointment = appointmentToDelete.AppointmentsList.FirstOrDefault()
};
await AppointmentService.DeleteAppointment(appointmentModelToDelete);
appointments.Remove(appointmentToDelete);
}
private string GetDoctorName(Guid doctorId)
{
var doctor = doctors.Select(d => d).FirstOrDefault(d => d.Id == doctorId);
return doctor?.Name ?? string.Empty;
}
}