diff --git a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs index bf905cbc..807a2324 100644 --- a/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs +++ b/BMA.EHR.Insignia.Service/Controllers/InsigniaRequestController.cs @@ -1392,25 +1392,22 @@ namespace BMA.EHR.Insignia.Service.Controllers .FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); if (insigniaType == null) return Error(GlobalMessages.InsigniaTypeNotFound); - var insigniaNoteProfiles = await _context.InsigniaNoteProfiles + + var rawNoteProfiles = await _context.InsigniaNoteProfiles .Where(x => x.InsigniaNote == insigniaNote) .Where(x => x.RequestInsignia.InsigniaType == insigniaType) .Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId)) .Select(x => new { Id = x.Id, - Prefix = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Prefix, - Position = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Position, - ProfileType = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).ProfileType, - OcId = Guid.Empty, - CitizenId = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).CitizenId, - FullName = $"{_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).LastName}", + Profile = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken), + OcId = Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3"), // TODO: ต้องมาแก้ไข RequestInsignia = x.RequestInsignia.Name, RequestInsigniaId = x.RequestInsignia.Id, RequestInsigniaShortName = x.RequestInsignia.ShortName, DateReceive = x.DateReceive, - OrganizationOrganizationSend = x.OrganizationOrganizationSend, - OrganizationOrganizationReceive = x.OrganizationOrganizationReceive, + OrganizationOrganizationSend = _userProfileRepository.GetOc(Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3"), 0, AccessToken).Root, //hardcode + OrganizationOrganizationReceive = _userProfileRepository.GetOc(Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3"), 0, AccessToken).Root, //hardcode Status = x.Status, Issue = x.Issue, Date = x.Date, @@ -1425,11 +1422,89 @@ namespace BMA.EHR.Insignia.Service.Controllers Salary = x.Salary, DateReceiveInsignia = x.DateReceiveInsignia, DocReceiveInsignia = x.DocReceiveInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReceiveInsignia.Id, - OrgReceiveInsignia = x.OrgReceiveInsignia == null || x.OrgReceiveInsignia.OrganizationOrganization == null ? "-" : x.OrgReceiveInsignia.OrganizationOrganization.Name, + OrgReceiveInsignia = _userProfileRepository.GetOc(Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3"), 0, AccessToken).Root, //hardcode DateReturnInsignia = x.DateReturnInsignia, DocReturnInsignia = x.DocReturnInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReturnInsignia.Id, - OrgReturnInsignia = x.OrgReturnInsignia == null || x.OrgReturnInsignia.OrganizationOrganization == null ? "-" : x.OrgReturnInsignia.OrganizationOrganization.Name, - }).ToListAsync(); + OrgReturnInsignia = _userProfileRepository.GetOc(Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3"), 0, AccessToken).Root, //hardcode + }) + .ToListAsync(); + + var insigniaNoteProfiles = rawNoteProfiles + .Select(x => new + { + Id = x.Id, + Prefix = x.Profile == null ? "" : x.Profile.Prefix, + Position = x.Profile == null ? "" : x.Profile.Position, + ProfileType = x.Profile == null ? "" : x.Profile.ProfileType, + x.OcId, + CitizenId = x.Profile == null ? "" : x.Profile.CitizenId, + FullName = x.Profile == null ? "" : $"{x.Profile.Prefix}{x.Profile.FirstName} {x.Profile.LastName}", + RequestInsignia = x.RequestInsignia, + RequestInsigniaId = x.RequestInsigniaId, + RequestInsigniaShortName = x.RequestInsigniaShortName, + DateReceive = x.DateReceive, + OrganizationOrganizationSend = x.OrganizationOrganizationSend, + OrganizationOrganizationReceive = x.OrganizationOrganizationReceive, + Status = x.Status, + Issue = x.Issue, + Date = x.Date, + VolumeNo = x.VolumeNo, + Section = x.Section, + Page = x.Page, + No = x.No, + DatePayment = x.DatePayment, + TypePayment = x.TypePayment, + Address = x.Address, + Number = x.Number, + Salary = x.Salary, + DateReceiveInsignia = x.DateReceiveInsignia, + DocReceiveInsignia = x.DocReceiveInsignia, + OrgReceiveInsignia = x.OrgReceiveInsignia, + DateReturnInsignia = x.DateReturnInsignia, + DocReturnInsignia = x.DocReturnInsignia, + OrgReturnInsignia = x.OrgReturnInsignia, + }) + .ToList(); + + //var insigniaNoteProfiles = await _context.InsigniaNoteProfiles + // .Where(x => x.InsigniaNote == insigniaNote) + // .Where(x => x.RequestInsignia.InsigniaType == insigniaType) + // .Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId)) + // .Select(x => new + // { + // Id = x.Id, + // Prefix = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Prefix, + // Position = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Position, + // ProfileType = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).ProfileType, + // OcId = Guid.Empty, + // CitizenId = _userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).CitizenId, + // FullName = $"{_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(x.ProfileId.Value, AccessToken).LastName}", + // RequestInsignia = x.RequestInsignia.Name, + // RequestInsigniaId = x.RequestInsignia.Id, + // RequestInsigniaShortName = x.RequestInsignia.ShortName, + // DateReceive = x.DateReceive, + // OrganizationOrganizationSend = x.OrganizationOrganizationSend, + // OrganizationOrganizationReceive = x.OrganizationOrganizationReceive, + // Status = x.Status, + // Issue = x.Issue, + // Date = x.Date, + // VolumeNo = x.VolumeNo, + // Section = x.Section, + // Page = x.Page, + // No = x.No, + // DatePayment = x.DatePayment, + // TypePayment = x.TypePayment, + // Address = x.Address, + // Number = x.Number, + // Salary = x.Salary, + // DateReceiveInsignia = x.DateReceiveInsignia, + // DocReceiveInsignia = x.DocReceiveInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReceiveInsignia.Id, + // OrgReceiveInsignia = x.OrgReceiveInsignia == null || x.OrgReceiveInsignia.OrganizationOrganization == null ? "-" : x.OrgReceiveInsignia.OrganizationOrganization.Name, + // DateReturnInsignia = x.DateReturnInsignia, + // DocReturnInsignia = x.DocReturnInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReturnInsignia.Id, + // OrgReturnInsignia = x.OrgReturnInsignia == null || x.OrgReturnInsignia.OrganizationOrganization == null ? "-" : x.OrgReturnInsignia.OrganizationOrganization.Name, + // }).ToListAsync(); + var _insigniaNoteProfiles = new List(); foreach (var insigniaNoteProfile in insigniaNoteProfiles) { @@ -1447,7 +1522,7 @@ namespace BMA.EHR.Insignia.Service.Controllers insigniaNoteProfile.RequestInsigniaShortName, insigniaNoteProfile.DateReceive, insigniaNoteProfile.OrganizationOrganizationSend, - OrganizationOrganizationReceive = insigniaNoteProfile.OrganizationOrganizationReceive == null ? (insigniaNoteProfile.OcId == null ? null : FindOCFullPath(insigniaNoteProfile.OcId, true)) : insigniaNoteProfile.OrganizationOrganizationReceive, + insigniaNoteProfile.OrganizationOrganizationReceive, insigniaNoteProfile.Status, insigniaNoteProfile.Issue, insigniaNoteProfile.Date, @@ -1868,7 +1943,7 @@ namespace BMA.EHR.Insignia.Service.Controllers // continue; if (profile.Status != "DONE") { - + profile.Status = "DONE"; @@ -1894,7 +1969,7 @@ namespace BMA.EHR.Insignia.Service.Controllers }; await _userProfileRepository.PostProfileInsigniaAsync(profileInsignia, AccessToken); - + } } await _context.SaveChangesAsync();