@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Thirdparty.Patient @using Indotalent.Features.Thirdparty.Patient.Cqrs @using Indotalent.Features.Thirdparty.Patient.Components @using Indotalent.Shared.Utils @using MudBlazor @inject PatientService PatientService @inject ISnackbar Snackbar
@(ReadOnly ? "Patient Profile" : "Edit Patient") @(ReadOnly ? "Viewing detailed patient records." : "Update patient account information.")
@if (_isDataLoading) {
} else { General Information Patient Name Patient Group @foreach (var item in _lookupData.PatientGroups) { @item.Name } Patient Category @foreach (var item in _lookupData.PatientCategories) { @item.Name } Description <_PatientContactDataTable Contacts="_model.Contacts" PatientId="@(_model.Id ?? string.Empty)" ReadOnly="ReadOnly" OnChanged="RefreshData" /> Address Information Street City State / Province Zip Code Country Contact & Online Phone Number Fax Number WhatsApp Email Address Website Social Media LinkedIn Facebook Instagram Twitter (X) TikTok Audit History Created At @DateTimeExtensions.ToString(_model.CreatedAt) Created By @(!string.IsNullOrEmpty(_model.CreatedBy) ? _model.CreatedBy : "System") Last Updated At @DateTimeExtensions.ToString(_model.UpdatedAt) Last Updated By @(!string.IsNullOrEmpty(_model.UpdatedBy) ? _model.UpdatedBy : "System")
@(ReadOnly ? "Back to List" : "Cancel") @if (!ReadOnly) { @if (_processing) { Updating... } else { Save Changes } }
}
@code { [Parameter] public UpdatePatientRequest Data { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnCancel { get; set; } [Parameter] public EventCallback OnSuccess { get; set; } private MudForm _form = default!; private UpdatePatientValidator _validator = new(); private GetPatientByIdResponse _model = new(); private LookupPatientResponse _lookupData = new(); private bool _processing = false; private bool _isDataLoading = true; protected override async Task OnInitializedAsync() { await RefreshData(); } private async Task RefreshData() { _isDataLoading = true; try { var response = await PatientService.GetPatientLookupAsync(); if (response != null && response.IsSuccess) { _lookupData = response.Value!; } var patient = await PatientService.GetPatientByIdAsync(Data.Id!); if (patient != null && patient.IsSuccess) { _model = patient.Value!; } } finally { _isDataLoading = false; } } private async Task Submit() { if (ReadOnly) return; await _form.Validate(); if (!_form.IsValid) return; _processing = true; try { var updateRequest = new UpdatePatientRequest { Id = _model.Id, Name = _model.Name, Description = _model.Description, Street = _model.Street, City = _model.City, State = _model.State, ZipCode = _model.ZipCode, Country = _model.Country, PhoneNumber = _model.PhoneNumber, FaxNumber = _model.FaxNumber, EmailAddress = _model.EmailAddress, Website = _model.Website, WhatsApp = _model.WhatsApp, LinkedIn = _model.LinkedIn, Facebook = _model.Facebook, Instagram = _model.Instagram, TwitterX = _model.TwitterX, TikTok = _model.TikTok, PatientGroupId = _model.PatientGroupId, PatientCategoryId = _model.PatientCategoryId }; var response = await PatientService.UpdatePatientAsync(updateRequest); await Task.Delay(500); if (response != null && response.IsSuccess) { Snackbar.Add("Patient updated successfully", Severity.Success); await OnSuccess.InvokeAsync(); } } finally { _processing = false; } } }