using Microsoft.AspNetCore.Mvc; /// /// Encounter retrieval, status transitions, and clinical timeline. /// [ApiController] [Route("api/v1/encounters")] [Produces("application/json")] public class EncountersController : ControllerBase { private readonly IEncounterService _encounters; public EncountersController(IEncounterService encounters) => _encounters = encounters; /// /// Gets an encounter with patient, recent observations, and open alerts. /// /// Encounter id. /// The encounter with related data. [HttpGet("{id:guid}")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task Get(Guid id) { var encounter = await _encounters.GetByIdAsync(id); return Ok(ApiResponse.Ok(encounter)); } /// /// Transitions an encounter to a new status via the encounter state machine. /// /// Encounter id. /// Target status. /// The encounter id and new status. [HttpPatch("{id:guid}/status")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)] public async Task TransitionStatus(Guid id, [FromBody] TransitionStatusRequest req) { var result = await _encounters.TransitionStatusAsync(id, req.Status); return Ok(ApiResponse.Ok(new { encounterId = result.EncounterId, newStatus = result.NewStatus })); } /// /// Returns a merged chronological timeline of observations and alerts for an encounter. /// /// Encounter id. /// Ordered timeline events. [HttpGet("{id:guid}/timeline")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task Timeline(Guid id) { var timeline = await _encounters.GetTimelineAsync(id); return Ok(ApiResponse.Ok(timeline)); } }