mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix(documents): keep an incomplete extraction on the document
A long document read in parts can end with a part cut at the provider's output limit, a part never read, or more facts than one review takes. That was told once, as a notice when the run finished; a review opened later looked complete. InboundDocument.extractionIncomplete (migration 0483) is written with the facts by both stagings, the extract route or run and lab auto-staging. The document detail publishes it and the review shows the same note whenever it is opened. The disaster-recovery backup carries it; an older file restores it as false. Refs #1257
This commit is contained in:
1 parent
5cfaf4869d
commit
958d230b9f
15 files changed
+233
-44
No files matched your search
@@ -173,6 +173,19 @@ describe("maybeAutoStageLabFacts", () => {
|
||||
expect(created.data.every((f) => f.status === "PENDING")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps on the document whether the staged facts may be missing a part", async () => {
|
||||
await maybeAutoStageLabFacts("u1", "d1");
|
||||
expect(updateMany.mock.calls[0]![0]).toMatchObject({
|
||||
data: { extractionIncomplete: false },
|
||||
});
|
||||
const whole = await mockExtract.mock.results[0]!.value;
|
||||
mockExtract.mockResolvedValueOnce({ ...whole, incomplete: true });
|
||||
await maybeAutoStageLabFacts("u1", "d1");
|
||||
expect(updateMany.mock.calls[1]![0]).toMatchObject({
|
||||
data: { extractionIncomplete: true },
|
||||
});
|
||||
});
|
||||
|
||||
it("plans a long report's reads against the run's deadline (#1274)", async () => {
|
||||
// Four hundred lines of a panel, many reads of text.
|
||||
const longReport = Array.from(
|
||||
|
||||
@@ -106,6 +106,7 @@ async function stageExtraction(
|
||||
documentId: string,
|
||||
userId: string,
|
||||
result: InboundExtractionResult,
|
||||
incomplete: boolean,
|
||||
) {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const locked = await tx.$queryRaw<{ status: string }[]>`
|
||||
@@ -151,6 +152,9 @@ async function stageExtraction(
|
||||
data: {
|
||||
status: "EXTRACTED",
|
||||
providerType: result.providerType,
|
||||
// Kept with the facts it describes, so a review opened later says
|
||||
// what the notice at the end of the run said.
|
||||
extractionIncomplete: incomplete,
|
||||
reportDate: result.reportDate
|
||||
? dateOnlyAtNoonUtc(result.reportDate)
|
||||
: null,
|
||||
@@ -320,10 +324,11 @@ export async function executeDocumentExtract(args: {
|
||||
return unreadableDocument(false);
|
||||
}
|
||||
await settle(true);
|
||||
const incomplete = result.incomplete || plan.partial;
|
||||
|
||||
let staged: StagedDocument;
|
||||
try {
|
||||
staged = await stageExtraction(document.id, userId, result);
|
||||
staged = await stageExtraction(document.id, userId, result, incomplete);
|
||||
} catch (err) {
|
||||
if (!(err instanceof StagingRefused)) {
|
||||
// The reservation is already settled for the call that was made; a
|
||||
@@ -356,6 +361,6 @@ export async function executeDocumentExtract(args: {
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
data: { document: staged, incomplete: result.incomplete || plan.partial },
|
||||
data: { document: staged, incomplete },
|
||||
};
|
||||
}
|
||||
@@ -221,6 +221,7 @@ async function stageFactsIfStored(
|
||||
userId: string,
|
||||
documentId: string,
|
||||
result: InboundExtractionResult,
|
||||
incomplete: boolean,
|
||||
): Promise<number | null> {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const moved = await tx.inboundDocument.updateMany({
|
||||
@@ -228,6 +229,7 @@ async function stageFactsIfStored(
|
||||
data: {
|
||||
status: "EXTRACTED",
|
||||
providerType: result.providerType,
|
||||
extractionIncomplete: incomplete,
|
||||
reportDate: result.reportDate
|
||||
? dateOnlyAtNoonUtc(result.reportDate)
|
||||
: null,
|
||||
@@ -359,7 +361,15 @@ export async function maybeAutoStageLabFacts(
|
||||
return { staged: false, reason: "extract-failed" };
|
||||
}
|
||||
|
||||
const staged = await stageFactsIfStored(userId, documentId, result);
|
||||
// Part of the document may be missing from the staged facts. Kept on the
|
||||
// document, so the review says so whenever it is opened.
|
||||
const incomplete = result.incomplete || plan.partial;
|
||||
const staged = await stageFactsIfStored(
|
||||
userId,
|
||||
documentId,
|
||||
result,
|
||||
incomplete,
|
||||
);
|
||||
if (staged === null) return { staged: false, reason: "raced" };
|
||||
|
||||
annotate({
|
||||
@@ -369,9 +379,7 @@ export async function maybeAutoStageLabFacts(
|
||||
facts: staged,
|
||||
provider: provider.pick.providerType,
|
||||
byKind: doc.kind === "LAB_RESULT",
|
||||
// Part of the document may be missing from the staged facts; the
|
||||
// manual extract says so to the person, this records it.
|
||||
incomplete: result.incomplete || plan.partial,
|
||||
incomplete,
|
||||
},
|
||||
});
|
||||
return { staged: true, facts: staged };
|
||||
|
||||
@@ -377,5 +377,6 @@ export function serialiseDocumentDetail(
|
||||
? doc.summaryGeneratedAt.toISOString()
|
||||
: null,
|
||||
summaryState,
|
||||
extractionIncomplete: doc.extractionIncomplete,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user