feature:
Full SOFA Score: Data Layer + Scoring Engine Glasgow Coma Scale: Data Layer + Scoring Engine
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/encounters/{encounterId:guid}/gcs")]
|
||||
[Produces("application/json")]
|
||||
public class GcsController : ControllerBase
|
||||
{
|
||||
private readonly IGcsService _gcs;
|
||||
|
||||
public GcsController(IGcsService gcs) => _gcs = gcs;
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(ApiResponse<GcsScoreResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Current(Guid encounterId)
|
||||
{
|
||||
var score = await _gcs.GetCurrentAsync(encounterId);
|
||||
if (score is null)
|
||||
return NotFound(ApiResponse<object>.Fail(
|
||||
404, "No GCS score computed for this encounter.", "NO_GCS_SCORE"));
|
||||
|
||||
return Ok(ApiResponse<GcsScoreResponse>.Ok(new GcsScoreResponse(
|
||||
score.EyeScore, score.VerbalScore, score.MotorScore,
|
||||
score.TotalScore, score.Classification, score.CalculatedAt)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/encounters/{encounterId:guid}/sofa")]
|
||||
[Produces("application/json")]
|
||||
public class SofaController : ControllerBase
|
||||
{
|
||||
private readonly ISofaService _sofa;
|
||||
|
||||
public SofaController(ISofaService sofa) => _sofa = sofa;
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(ApiResponse<SofaScoreResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Current(Guid encounterId)
|
||||
{
|
||||
var score = await _sofa.GetCurrentAsync(encounterId);
|
||||
if (score is null)
|
||||
return NotFound(ApiResponse<object>.Fail(
|
||||
404, "No SOFA score computed for this encounter.", "NO_SOFA_SCORE"));
|
||||
|
||||
return Ok(ApiResponse<SofaScoreResponse>.Ok(MapResponse(score)));
|
||||
}
|
||||
|
||||
[HttpGet("history")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> History(
|
||||
Guid encounterId,
|
||||
[FromQuery] int limit = 20,
|
||||
[FromQuery] string? cursor = null)
|
||||
{
|
||||
var page = await _sofa.GetHistoryAsync(encounterId, limit, cursor);
|
||||
return Ok(ApiResponse<object>.Ok(new
|
||||
{
|
||||
items = page.Items.Select(MapResponse),
|
||||
nextCursor = page.NextCursor,
|
||||
hasMore = page.HasMore
|
||||
}));
|
||||
}
|
||||
|
||||
private static SofaScoreResponse MapResponse(SofaScore score)
|
||||
{
|
||||
SofaStalenessInfo? staleness = null;
|
||||
if (!string.IsNullOrEmpty(score.StalenessFlags))
|
||||
{
|
||||
var flags = JsonSerializer.Deserialize<SofaStalenessFlags>(
|
||||
score.StalenessFlags,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
if (flags is not null)
|
||||
{
|
||||
staleness = new SofaStalenessInfo(
|
||||
flags.StaleComponents, flags.MissingComponents, flags.UsedSpO2Fallback);
|
||||
}
|
||||
}
|
||||
|
||||
return new SofaScoreResponse(
|
||||
score.TotalScore,
|
||||
score.RespiratoryScore, score.CoagulationScore, score.LiverScore,
|
||||
score.CardiovascularScore, score.CnsScore, score.RenalScore,
|
||||
score.IsBaseline, score.DeltaFromBaseline,
|
||||
staleness, score.CalculatedAt);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user