122 lines
3.5 KiB
Plaintext
122 lines
3.5 KiB
Plaintext
@page "/doctor/dashboard"
|
|
@attribute [Authorize(Roles = UserRoles.Doctor)]
|
|
@layout DoctorLayout
|
|
@inject IAuthenticationService AuthenticationService
|
|
@inject IDoctorManagementService DoctorManagementService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<h3>Dashboard</h3>
|
|
|
|
@if (!string.IsNullOrEmpty(errorMessage))
|
|
{
|
|
<div class="alert alert-danger" role="alert">
|
|
@errorMessage
|
|
</div>
|
|
}
|
|
|
|
@if (!string.IsNullOrEmpty(username))
|
|
{
|
|
<p>Welcome, Dr. @username!</p>
|
|
<p>Here you have listed your active appointments with patients.</p>
|
|
}
|
|
|
|
@if (appointments != null && appointments.Count > 0)
|
|
{
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Patient</th>
|
|
<th>Time</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var appointment in appointments)
|
|
{
|
|
foreach (var appointmentTime in appointment.AppointmentsList)
|
|
{
|
|
<tr>
|
|
<td>@patients[Guid.Parse(appointment.PatientId)]</td>
|
|
<td>@appointmentTime.ToString("g")</td>
|
|
<td>
|
|
<button class="btn btn-danger" @onclick="() => DeleteAppointment(appointment, appointmentTime)">Delete</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}
|
|
else if (string.IsNullOrEmpty(errorMessage))
|
|
{
|
|
<p>No appointments exist.</p>
|
|
}
|
|
|
|
@code {
|
|
private string username;
|
|
private List<Appointment> appointments = new();
|
|
private Dictionary<Guid, string> patients = new();
|
|
private string errorMessage = string.Empty;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
var userInfo = await AuthenticationService.GetUserInformation();
|
|
username = userInfo.Name;
|
|
appointments = await DoctorManagementService.GetAppointmentsAsync(userInfo.Id);
|
|
var allPatients = await DoctorManagementService.GetAllPatientsAsync();
|
|
patients = allPatients.ToDictionary(pat => pat.Id, pat => pat.Name);
|
|
|
|
if (!appointments.Any())
|
|
{
|
|
errorMessage = "No appointments exist.";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = $"Failed to load data: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
private async Task DeleteAppointment(Appointment appointment, DateTime appointmentTime)
|
|
{
|
|
try
|
|
{
|
|
var success = await DoctorManagementService.CancelAppointmentAsync(
|
|
Guid.Parse(appointment.DoctorId),
|
|
Guid.Parse(appointment.PatientId),
|
|
appointmentTime
|
|
);
|
|
|
|
if (success)
|
|
{
|
|
var appList = appointments.FirstOrDefault(a => a.Id == appointment.Id)?.AppointmentsList;
|
|
if (appList != null)
|
|
{
|
|
appList.Remove(appointmentTime);
|
|
if (!appList.Any())
|
|
{
|
|
appointments.Remove(appointment);
|
|
}
|
|
}
|
|
|
|
if (!appointments.Any())
|
|
{
|
|
errorMessage = "No appointments exist.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
errorMessage = "Failed to delete the appointment.";
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errorMessage = $"Error deleting appointment: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
} |