fix issues with phase-32
This commit is contained in:
@@ -58,7 +58,11 @@ public class GcsScoringService : BackgroundService
|
||||
evt.Value,
|
||||
stoppingToken);
|
||||
|
||||
if (outcome.Outcome == GcsOutcome.ScoreComputed)
|
||||
if (outcome.Outcome == GcsOutcome.EncounterNotFound)
|
||||
_logger.LogWarning(
|
||||
"Skipping stale observation.recorded event — encounter={Id} code={Code} offset={Offset}",
|
||||
evt.EncounterId, evt.ObservationCode, result.Offset.Value);
|
||||
else if (outcome.Outcome == GcsOutcome.ScoreComputed)
|
||||
_logger.LogInformation(
|
||||
"GCS scored via consumer — encounter={Id} total={Total} class={Class}",
|
||||
evt.EncounterId, outcome.TotalScore, outcome.Classification);
|
||||
|
||||
@@ -58,7 +58,11 @@ public class News2ScoringService : BackgroundService
|
||||
evt.Value,
|
||||
stoppingToken);
|
||||
|
||||
if (outcome.Outcome == News2Outcome.ScoreComputed)
|
||||
if (outcome.Outcome == News2Outcome.EncounterNotFound)
|
||||
_logger.LogWarning(
|
||||
"Skipping stale observation.recorded event — encounter={Id} code={Code} offset={Offset}",
|
||||
evt.EncounterId, evt.ObservationCode, result.Offset.Value);
|
||||
else if (outcome.Outcome == News2Outcome.ScoreComputed)
|
||||
_logger.LogInformation(
|
||||
"NEWS2 scored via consumer — encounter={Id} score={Score} risk={Risk}",
|
||||
evt.EncounterId, outcome.TotalScore, outcome.RiskLevel);
|
||||
|
||||
@@ -2,5 +2,6 @@ public enum GcsOutcome
|
||||
{
|
||||
NotGcsCode,
|
||||
IncompleteComponents,
|
||||
EncounterNotFound,
|
||||
ScoreComputed
|
||||
}
|
||||
@@ -2,5 +2,6 @@ public enum News2Outcome
|
||||
{
|
||||
NotNews2Code,
|
||||
IncompleteParameters,
|
||||
EncounterNotFound,
|
||||
ScoreComputed
|
||||
}
|
||||
@@ -60,6 +60,17 @@ public class GcsDetector
|
||||
var classification = GcsCalculator.ClassifyGcs(total);
|
||||
var calculatedAt = DateTimeOffset.UtcNow;
|
||||
|
||||
using (var checkScope = _services.CreateScope())
|
||||
{
|
||||
var db = checkScope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
if (!await db.Encounters.AnyAsync(e => e.Id == encounterId, ct))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Skipping GCS score for unknown encounter {EncounterId}", encounterId);
|
||||
return GcsResult.EncounterNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
await PersistScoreAsync(
|
||||
encounterId, patientId, (int)eye, (int)verbal, (int)motor,
|
||||
total, classification, calculatedAt, ct);
|
||||
|
||||
@@ -43,13 +43,8 @@ namespace VigilCareClinicalAPI.Migrations
|
||||
name: "name_search_token",
|
||||
table: "patients");
|
||||
|
||||
migrationBuilder.AlterColumn<DateOnly>(
|
||||
name: "date_of_birth",
|
||||
table: "patients",
|
||||
type: "date",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
migrationBuilder.Sql(
|
||||
"ALTER TABLE patients ALTER COLUMN date_of_birth TYPE date USING date_of_birth::date;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ public record GcsResult(
|
||||
int PresentComponents = 0)
|
||||
{
|
||||
public static readonly GcsResult NotGcsCode = new(GcsOutcome.NotGcsCode);
|
||||
public static readonly GcsResult EncounterNotFound = new(GcsOutcome.EncounterNotFound);
|
||||
|
||||
public static GcsResult IncompleteComponents(int presentCount) =>
|
||||
new(GcsOutcome.IncompleteComponents, PresentComponents: presentCount);
|
||||
|
||||
@@ -7,6 +7,7 @@ public record News2Result(
|
||||
bool HasSingleParamThree = false)
|
||||
{
|
||||
public static readonly News2Result NotNews2Code = new(News2Outcome.NotNews2Code);
|
||||
public static readonly News2Result EncounterNotFound = new(News2Outcome.EncounterNotFound);
|
||||
|
||||
public static News2Result IncompleteParameters(int presentCount) =>
|
||||
new(News2Outcome.IncompleteParameters, PresentParameters: presentCount);
|
||||
|
||||
@@ -103,6 +103,17 @@ public class News2Detector
|
||||
var hasSingleParamThree = paramScores.Any(s => s == 3);
|
||||
var riskLevel = News2Calculator.DetermineRiskLevel(totalScore, hasSingleParamThree);
|
||||
|
||||
using (var scope = _services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
if (!await db.Encounters.AnyAsync(e => e.Id == encounterId, ct))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Skipping NEWS2 score for unknown encounter {EncounterId}", encounterId);
|
||||
return News2Result.EncounterNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
await PersistScoreAsync(
|
||||
encounterId, patientId, totalScore, riskLevel,
|
||||
paramScores, hasSingleParamThree, ct);
|
||||
|
||||
Reference in New Issue
Block a user