using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; /// /// Glasgow Coma Scale (GCS) scoring: latest computed score per encounter. /// [ApiController] [Route("api/v1/encounters/{encounterId:guid}/gcs")] [Produces("application/json")] [AuthorizePermission(ClinicalPermissions.EncountersRead)] public class GcsController : ControllerBase { private readonly IGcsService _gcs; public GcsController(IGcsService gcs) => _gcs = gcs; /// /// Returns the latest GCS score for an encounter, or null data when no score has been computed. /// /// Encounter id. /// The GCS component scores and total, or null. [HttpGet] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public async Task Current(Guid encounterId) { var score = await _gcs.GetCurrentAsync(encounterId); if (score is null) return Ok(ApiResponse.Ok(null)); return Ok(ApiResponse.Ok(MapResponse(score))); } /// /// Returns cursor-paginated GCS score history for an encounter. /// /// Encounter id. /// Maximum items per page. /// Opaque cursor from a previous page. /// A page of GCS scores with an optional next cursor. [HttpGet("history")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public async Task History( Guid encounterId, [FromQuery] int limit = 20, [FromQuery] string? cursor = null) { var page = await _gcs.GetHistoryAsync(encounterId, limit, cursor); return Ok(ApiResponse.Ok(new { items = page.Items.Select(MapResponse), nextCursor = page.NextCursor, hasMore = page.HasMore })); } private static GcsScoreResponse MapResponse(GcsScore score) => new(score.EyeScore, score.VerbalScore, score.MotorScore, score.TotalScore, score.Classification, score.CalculatedAt); }