using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; /// /// NEWS2 composite scoring: current score and paginated history per encounter. /// [ApiController] [Route("api/v1/encounters/{encounterId:guid}/news2")] [Produces("application/json")] [AuthorizePermission(ClinicalPermissions.EncountersRead)] public class News2Controller : ControllerBase { private readonly INews2Service _news2; public News2Controller(INews2Service news2) => _news2 = news2; /// /// Returns the latest NEWS2 score for an encounter, or 404 if no score has been computed. /// [HttpGet("current")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public async Task Current(Guid encounterId) { var score = await _news2.GetCurrentAsync(encounterId); if (score is null) return Ok(ApiResponse.Ok(null)); return Ok(ApiResponse.Ok(score)); } /// /// Returns cursor-paginated NEWS2 score history for an encounter. /// [HttpGet("history")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public async Task History( Guid encounterId, [FromQuery] int limit = 20, [FromQuery] string? cursor = null) { var page = await _news2.GetHistoryAsync(encounterId, limit, cursor); return Ok(ApiResponse.Ok(new { items = page.Items, nextCursor = page.NextCursor, hasMore = page.HasMore })); } }