diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index b2884120..075b973f 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -77,7 +77,9 @@ namespace BMA.EHR.Placement.Service.Controllers [HttpGet("exam/{year}")] public async Task> GetExam(int year) { - var data = await _context.Placements.Where(x => year > 0 ? (x.Year == year) : (x.Year > 0)).Select(x => new + var data = await _context.Placements.Where(x => year > 0 ? (x.Year == year) : (x.Year > 0)) + .OrderByDescending(x => x.CreatedAt) + .Select(x => new { Id = x.Id, ExamRound = x.Name, @@ -1115,5 +1117,62 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + [HttpGet("user/{personalId:length(36)}")] + public async Task> GetUserByOrganization(Guid personalId) + { + var profile = await _context.Profiles + .FirstOrDefaultAsync(x => x.Id == personalId); + if (profile == null) + return Error(GlobalMessages.DataNotFound, 404); + var organization = await _context.Organizations + .Include(x => x.Parent) + .FirstOrDefaultAsync(x => x.Id == profile.OcId); + if (organization == null) + return Error(GlobalMessages.OrganizationNotFound, 404); + var profilePosition = await _context.ProfilePositions + .Where(x => x.Profile != null) + .Where(x => x.OrganizationPosition != null) + .Where(x => x.OrganizationPosition.PositionMaster != null) + .Where(x => x.Profile != profile) + .Where(x => x.OrganizationPosition.Organization == organization) + .Select(x => new + { + Id = x.Profile.Id, + Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + FirstName = x.Profile.FirstName, + LastName = x.Profile.LastName, + CitizenId = x.Profile.CitizenId, + IsDirector = x.OrganizationPosition.PositionMaster.IsDirector, + }) + .ToListAsync(); + + var caregiver = profilePosition.Where(x => x.IsDirector == false).ToList(); + var commander = profilePosition.Where(x => x.IsDirector == true).ToList(); + + if (organization.Parent != null) + { + var profilePositionHigh = await _context.ProfilePositions + .Where(x => x.Profile != null) + .Where(x => x.OrganizationPosition != null) + .Where(x => x.OrganizationPosition.PositionMaster != null) + .Where(x => x.Profile != profile) + .Where(x => x.OrganizationPosition.Organization == organization.Parent) + .Select(x => new + { + Id = x.Profile.Id, + Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, + FirstName = x.Profile.FirstName, + LastName = x.Profile.LastName, + CitizenId = x.Profile.CitizenId, + IsDirector = x.OrganizationPosition.PositionMaster.IsDirector, + }) + .ToListAsync(); + var chairman = profilePositionHigh.Where(x => x.IsDirector == true).ToList(); + return Success(new { caregiver, commander, chairman }); + } + + return Success(new { caregiver, commander, chairman = new List() }); + } + } }