diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 605c4db4..e4a73fb9 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; +using System.Reflection.Emit; using System.Security.Cryptography; namespace BMA.EHR.Application.Repositories @@ -510,6 +511,28 @@ namespace BMA.EHR.Application.Repositories } } + public async Task> GetActiveRootAsync(string? accessToken) + { + try + { + var apiPath = $"{_configuration["API"]}/org/active/root"; + + var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return null; + } + catch + { + throw; + } + } + #endregion } } diff --git a/BMA.EHR.Application/Responses/Organizations/GetActiveRootDto.cs b/BMA.EHR.Application/Responses/Organizations/GetActiveRootDto.cs new file mode 100644 index 00000000..99db4ba7 --- /dev/null +++ b/BMA.EHR.Application/Responses/Organizations/GetActiveRootDto.cs @@ -0,0 +1,15 @@ +namespace BMA.EHR.Application.Responses.Organizations +{ + public class GetActiveRootDto + { + public Guid Id { get; set; } + public DateTime CreatedAt { get; set; } + public Guid CreatedUserId { get; set; } + public DateTime LastUpdatedAt { get; set; } + public Guid LastUpdateUserId { get; set; } + public string CreatedFullName { get; set; } = string.Empty; + public string LastUpdateFullName { get; set; } = string.Empty; + + public string OrgRootName { get; set; } = string.Empty; + } +} diff --git a/BMA.EHR.Application/Responses/Organizations/GetActiveRootResultDto.cs b/BMA.EHR.Application/Responses/Organizations/GetActiveRootResultDto.cs new file mode 100644 index 00000000..8c7da985 --- /dev/null +++ b/BMA.EHR.Application/Responses/Organizations/GetActiveRootResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Organizations +{ + public class GetActiveRootResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public List Result { get; set; } = new(); + } +} diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs index 7de70823..b4dad631 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs @@ -604,10 +604,13 @@ namespace BMA.EHR.Insignia.Service.Controllers [HttpGet("{insigniaPeriodId:length(36)}")] public async Task> UpdateInsignaiRequestBkk(Guid insigniaPeriodId) { - var organizationType = await _context.OrganizationTypes.Where(x => x.Name == "หน่วยงาน").FirstOrDefaultAsync(); - if (organizationType == null) - return Error(GlobalMessages.OrganizationNotFound); - var organizations = await _context.Organizations.Where(x => x.OrganizationType == organizationType).ToListAsync(); + //var organizationType = await _context.OrganizationTypes.Where(x => x.Name == "หน่วยงาน").FirstOrDefaultAsync(); + //if (organizationType == null) + // return Error(GlobalMessages.OrganizationNotFound); + //var organizations = await _context.Organizations.Where(x => x.OrganizationType == organizationType).ToListAsync(); + + var organizations = await _userProfileRepository.GetActiveRootAsync(AccessToken); + foreach (var organization in organizations) { if (organization == null)