Full SOFA Score: Data Layer + Scoring Engine

Glasgow Coma Scale: Data Layer + Scoring Engine
This commit is contained in:
voltsrage
2026-06-21 01:09:50 +08:00
parent 78c043e4d3
commit 93ea473d2b
62 changed files with 7133 additions and 72 deletions
@@ -0,0 +1,45 @@
using Microsoft.EntityFrameworkCore;
public class SofaService : ISofaService
{
private readonly AppDbContext _db;
public SofaService(AppDbContext db) => _db = db;
public async Task<SofaScore?> GetCurrentAsync(Guid encounterId)
{
return await _db.SofaScores
.AsNoTracking()
.Where(s => s.EncounterId == encounterId)
.OrderByDescending(s => s.CalculatedAt)
.FirstOrDefaultAsync();
}
public async Task<SofaScore?> GetBaselineAsync(Guid encounterId)
{
return await _db.SofaScores
.AsNoTracking()
.FirstOrDefaultAsync(s => s.EncounterId == encounterId && s.IsBaseline);
}
public async Task<CursorPage<SofaScore>> GetHistoryAsync(
Guid encounterId, int limit, string? cursorToken)
{
limit = Math.Clamp(limit, 1, 100);
var query = _db.SofaScores
.AsNoTracking()
.Where(s => s.EncounterId == encounterId);
var items = await query
.OrderByDescending(s => s.CalculatedAt)
.ThenByDescending(s => s.Id)
.Take(limit + 1)
.ToListAsync();
var hasMore = items.Count > limit;
if (hasMore) items.RemoveAt(limit);
return new CursorPage<SofaScore>(items, null, hasMore);
}
}