feature: Optional OCR-Assisted Draft Pre-Fill
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user