finalizare 1.0

This commit is contained in:
andrei-mihnea-cerbu
2024-05-21 12:10:53 +03:00
parent f7795f7519
commit 1cc1d34003
11268 changed files with 2102399 additions and 10909 deletions
@@ -0,0 +1,183 @@
@page "/patient/appointments"
@attribute [Authorize(Roles = UserRoles.Patient)]
@layout PatientLayout
@inject IPatientManagementService PatientManagementService;
@inject IAuthenticationService AuthenticationService;
<h3>Doctors</h3>
@if (!string.IsNullOrEmpty(_statusMessage))
{
<div class="alert @(_isError ? "alert-danger" : "alert-success")" role="alert">
@_statusMessage
</div>
}
<div class="card-deck">
@if (_doctors == null || !_doctors.Any())
{
<div class="alert alert-info center-content" style="width: 100%; height: 200px;">No doctors available.</div>
}
else
{
@foreach (var doctor in _doctors)
{
<div class="card doctor-card">
<div class="doctor-card-content">
<div class="user-icon"></div>
<div class="doctor-info">
<h5 class="card-title">Dr. @doctor.Name</h5>
<p class="card-text">@doctor.Email</p>
<button class="btn btn-primary" @onclick="() => ShowAppointmentOverlay(doctor)">Book Appointment</button>
</div>
</div>
</div>
}
}
</div>
@if (_showAppointmentOverlay)
{
<div class="overlay">
<div class="overlay-content">
<h5>Book Appointment with Dr. @_selectedDoctor.Name</h5>
<EditForm Model="@_dateAndTimeAppointment" OnValidSubmit="BookAppointment">
<div class="form-group">
<label for="date">Date</label>
<InputDate id="date" class="form-control" @bind-Value="_dateAndTimeAppointment.AppointmentDate" TValue="DateTime"/>
</div>
<div class="form-group">
<label for="time">Time</label>
<InputText id="time" class="form-control" @bind-Value="_dateAndTimeAppointment.FormattedAppointmentTime"/>
</div>
<button type="submit" class="btn btn-primary">Book</button>
<button type="button" class="btn btn-secondary" @onclick="HideAppointmentOverlay">Cancel</button>
</EditForm>
</div>
</div>
}
<style>
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.overlay-content {
background: white;
padding: 20px;
border-radius: 10px;
width: 400px;
text-align: center;
}
.doctor-card {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
margin-bottom: 20px;
}
.doctor-card-content {
display: flex;
align-items: center;
padding: 20px;
}
.user-icon {
background-image: url('user.png'); /* Ensure the path is correct */
background-size: cover;
width: 100px;
height: 100px;
border-radius: 50%;
margin-right: 20px;
}
.doctor-info {
display: flex;
flex-direction: column;
align-items: flex-start;
}
</style>
@code {
private List<Doctor> _doctors;
private Doctor _selectedDoctor;
private bool _showAppointmentOverlay = false;
private NewAppointmentModel _newAppointmentModel = new();
private DateAndTimeAppointment _dateAndTimeAppointment = new();
private string _statusMessage = string.Empty;
private bool _isError = false;
protected override async Task OnInitializedAsync()
{
await LoadDoctors();
}
private async Task LoadDoctors()
{
_doctors = await PatientManagementService.GetAllDoctorsAsync();
}
private void ShowAppointmentOverlay(Doctor doctor)
{
_selectedDoctor = doctor;
_newAppointmentModel = new NewAppointmentModel
{
DoctorId = doctor.Id
};
_showAppointmentOverlay = true;
}
private void HideAppointmentOverlay()
{
_showAppointmentOverlay = false;
}
private async Task BookAppointment()
{
var userInfo = await AuthenticationService.GetUserInformation();
_newAppointmentModel.PatientId = userInfo.Id;
_newAppointmentModel.Appointment = _dateAndTimeAppointment.GetAppointment();
var appointment = await PatientManagementService.BookAppointmentAsync(_newAppointmentModel);
_statusMessage = appointment.Message;
_isError = appointment.StatusCode != 201;
if (!_isError)
{
_showAppointmentOverlay = false;
}
}
class DateAndTimeAppointment
{
public DateTime AppointmentDate { get; set; } = DateTime.Now.Date;
public string FormattedAppointmentTime = DateTime.Now.ToString("HH:mm");
public DateTime GetAppointment()
{
// Parse FormattedAppointmentTime to a TimeSpan
if (TimeSpan.TryParse(FormattedAppointmentTime, out var appointmentTime))
{
// Combine AppointmentDate with appointmentTime
return AppointmentDate.Add(appointmentTime);
}
throw new FormatException("FormattedAppointmentTime is not in the correct format.");
}
}
}