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,137 @@
@page "/patient/doctor_access"
@attribute [Authorize(Roles = UserRoles.Patient)]
@layout PatientLayout
@inject IPatientManagementService PatientManagementService
@inject IAuthenticationService AuthenticationService
@inject NavigationManager NavigationManager
<h3>Manage Access to Medical History</h3>
@if (!string.IsNullOrEmpty(statusMessage))
{
<div class="alert @(isSuccess ? "alert-success" : "alert-danger")" role="alert">
@statusMessage
</div>
}
<div class="row mt-4">
@foreach (var doctor in doctors)
{
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body text-center">
<div>
<strong>Status: </strong>
@if (doctorHasAccess(doctor.Id))
{
<span class="text-success">Granted</span>
}
else
{
<span class="text-danger">Revoked</span>
}
</div>
<img src="user.png" style="width: 70px" alt="Doctor" class="img-fluid mt-3"/>
<h5 class="mt-3">Dr. @doctor.Name</h5>
<button class="btn btn-success mt-2" @onclick="() => GrantAccess(doctor.Id)">Grant Access</button>
<button class="btn btn-warning mt-2" @onclick="() => RevokeAccess(doctor.Id)">Revoke Access</button>
</div>
</div>
</div>
}
</div>
@code {
private string statusMessage;
private bool isSuccess;
private List<Doctor> doctors = new();
private List<Guid> grantedAccessDoctors = new();
private Guid medicalRecordId;
protected override async Task OnInitializedAsync()
{
await LoadDoctorsAndAccessStatus();
}
private async Task LoadDoctorsAndAccessStatus()
{
var userInfo = await AuthenticationService.GetUserInformation();
var medicalHistory = await PatientManagementService.GetMedicalHistoryAsync(userInfo.Id);
if (medicalHistory != null)
{
medicalRecordId = medicalHistory.Id;
doctors = await PatientManagementService.GetAllDoctorsAsync();
await UpdateDoctorAccessStatuses(userInfo.Id);
}
else
{
statusMessage = "Failed to load medical history.";
isSuccess = false;
}
}
private async Task UpdateDoctorAccessStatuses(Guid patientId)
{
if (medicalRecordId != Guid.Empty)
{
foreach (var doctor in doctors)
{
if (await PatientManagementService.CheckForAccessAsync(medicalRecordId, doctor.Id))
{
grantedAccessDoctors.Add(doctor.Id);
}
}
StateHasChanged();
}
}
private bool doctorHasAccess(Guid doctorId)
{
return grantedAccessDoctors.Contains(doctorId);
}
private async Task GrantAccess(Guid doctorId)
{
if (medicalRecordId != Guid.Empty)
{
var success = await PatientManagementService.GrantAccessAsync(medicalRecordId, doctorId);
if (success)
{
grantedAccessDoctors.Add(doctorId);
statusMessage = "Access granted successfully.";
isSuccess = true;
}
else
{
statusMessage = "Failed to grant access.";
isSuccess = false;
}
StateHasChanged();
}
}
private async Task RevokeAccess(Guid doctorId)
{
if (medicalRecordId != Guid.Empty)
{
var success = await PatientManagementService.RevokeAccessAsync(medicalRecordId, doctorId);
if (success)
{
grantedAccessDoctors.Remove(doctorId);
statusMessage = "Access revoked successfully.";
isSuccess = true;
}
else
{
statusMessage = "Failed to revoke access.";
isSuccess = false;
}
StateHasChanged();
}
}
}