feature: Optional OCR-Assisted Draft Pre-Fill

This commit is contained in:
voltsrage
2026-06-28 01:28:54 +08:00
parent 5039dbb979
commit c160c5f912
42 changed files with 3592 additions and 33 deletions
@@ -31,11 +31,29 @@ public class DraftService : IDraftService
if (batch is null)
throw new NotFoundException("Batch not found.", "BATCH_NOT_FOUND");
var ocrResult = await _db.OcrResults
.AsNoTracking()
.FirstOrDefaultAsync(o => o.BatchId == batchId);
OcrConfidenceMap? ocrConfidence = null;
if (ocrResult is not null)
{
var fieldConfidences = JsonSerializer.Deserialize<Dictionary<string, double>>(
ocrResult.FieldConfidencesJson) ?? new Dictionary<string, double>();
ocrConfidence = new OcrConfidenceMap(
ocrResult.Provider,
ocrResult.ProcessedAt,
ocrResult.DurationMs,
fieldConfidences);
}
return new DraftPayloadResponse(
batch.Id,
batch.Status.ToDbString(),
batch.BatchType.ToDbString(),
BatchTypeFieldRequirements.ForBatchType(batch.BatchType),
ocrConfidence,
batch.DraftPatient is not null ? MapPatient(batch.DraftPatient) : null,
batch.DraftEncounter is not null ? MapEncounter(batch.DraftEncounter) : null,
batch.DraftObservations.Select(MapObservation).OrderBy(o => o.RecordedAt).ToList()