using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; /// /// Patient registry search and digitization history. /// [ApiController] [Route("api/v1/patients")] [Produces("application/json")] [Authorize] public class PatientsController : ControllerBase { private readonly IDigitizationHistoryService _history; private readonly IPatientRegistryService _patients; public PatientsController( IDigitizationHistoryService history, IPatientRegistryService patients) { _history = history; _patients = patients; } /// /// Searches live patients by MRN or full name (minimum 2 characters). /// [HttpGet("search")] [Authorize(Roles = "INTAKE_CLERK,CLINICIAN,ADMINISTRATOR")] [ProducesResponseType(typeof(ApiResponse>), StatusCodes.Status200OK)] public async Task Search([FromQuery] string q) { var results = await _patients.SearchAsync(q ?? string.Empty); return Ok(ApiResponse>.Ok(results)); } /// /// Returns the complete digitization history for a patient, including all /// batches, their promotion status, correction chains, and per-batch audit trails. /// Superseded observations are included with their supersession metadata. /// [HttpGet("{patientId:guid}/digitization-history")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task GetDigitizationHistory(Guid patientId) { var history = await _history.GetPatientHistoryAsync(patientId); return Ok(ApiResponse.Ok(history)); } }