finalizare 1.0
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
@page "/doctor/patients_medical_history"
|
||||
@attribute [Authorize(Roles = UserRoles.Doctor)]
|
||||
@layout DoctorLayout
|
||||
@inject IDoctorManagementService DoctorManagementService
|
||||
@inject IAuthenticationService AuthenticationService
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<script src="fileHelper.js"></script>
|
||||
<script src="downloadFile.js"></script>
|
||||
|
||||
<h3>Patient Medical Histories</h3>
|
||||
|
||||
|
||||
@if (!string.IsNullOrEmpty(statusMessage))
|
||||
{
|
||||
<div class="alert @(isSuccess ? "alert-success" : "alert-danger")" role="alert">
|
||||
@statusMessage
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="row mt-4">
|
||||
@foreach (var patient in patients)
|
||||
{
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<div>
|
||||
<strong>Status: </strong>
|
||||
@if (patientHasAccess(patient.Id))
|
||||
{
|
||||
<span class="text-success">Granted</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-danger">Revoked</span>
|
||||
}
|
||||
</div>
|
||||
<img src="user.png" style="width: 70px" alt="Patient" class="img-fluid mt-3"/>
|
||||
<h5 class="mt-3">@patient.Name</h5>
|
||||
<button class="btn btn-info mt-2" @onclick="() => DownloadMedicalHistory(patient.Id)" disabled="@(patientHasAccess(patient.Id) ? false : true)">Download Medical History</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string statusMessage;
|
||||
private bool isSuccess;
|
||||
private List<Patient> patients = new();
|
||||
private List<Guid> grantedAccessPatients = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadPatientsAndAccessStatus();
|
||||
}
|
||||
|
||||
private async Task LoadPatientsAndAccessStatus()
|
||||
{
|
||||
var userInfo = await AuthenticationService.GetUserInformation();
|
||||
patients = await DoctorManagementService.GetAllPatientsAsync();
|
||||
await UpdatePatientAccessStatuses(userInfo.Id);
|
||||
}
|
||||
|
||||
private async Task UpdatePatientAccessStatuses(Guid doctorId)
|
||||
{
|
||||
foreach (var patient in patients)
|
||||
{
|
||||
var medicalHistory = await DoctorManagementService.GetMedicalHistoryAsync(patient.Id);
|
||||
if (medicalHistory == null) continue;
|
||||
if (await DoctorManagementService.CheckForAccessAsync(medicalHistory.Id, doctorId))
|
||||
{
|
||||
grantedAccessPatients.Add(patient.Id);
|
||||
}
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private bool patientHasAccess(Guid patientId)
|
||||
{
|
||||
return grantedAccessPatients.Contains(patientId);
|
||||
}
|
||||
|
||||
private async Task DownloadMedicalHistory(Guid patientId)
|
||||
{
|
||||
var medicalHistory = await DoctorManagementService.DownloadMedicalHistoryAsync(patientId);
|
||||
if (medicalHistory != null)
|
||||
{
|
||||
var base64 = Convert.ToBase64String(medicalHistory);
|
||||
var href = $"data:application/octet-stream;base64,{base64}";
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", "MedicalHistory.pdf", href);
|
||||
}
|
||||
else
|
||||
{
|
||||
statusMessage = "Failed to download medical history.";
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user