fix: restore lab import review in on-device fallback path - #33
Conversation
|
@claude review this PR |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fe542bcac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| documentText: result.extractedText, | ||
| extractedItems: [], // We'll use only the text | ||
| extractedItems: healthDataItems, // Use structured items as fallback if mapping fails | ||
| document: document |
There was a problem hiding this comment.
Avoid feeding generic structured items into lab fallback
Passing healthDataItems here changes the failure path for text mapping: if mapDocumentToBloodTest(documentText) throws, createBloodTestResultFromText now falls back to createBloodTestResultFromItems, which can end in createLegacyBloodTestResult that converts every item into a BloodTestItem. Because ProcessedDocumentResult.healthDataItems includes non-lab fields (e.g., vitals/medications), AI outages can now import incorrect lab results instead of the previous safe placeholder behavior. Please filter to lab-only items (or keep this fallback input empty) before calling this path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 67bcf8a. Added a labOnlyItems filter that excludes known non-lab item types ("Personal Information", "Demographics", "Vital Signs", "Imaging", "Radiology") before passing to createBloodTestResultFromText. If AI mapping fails and the code falls through to createBloodTestResultFromItems → createLegacyBloodTestResult, only lab-specific items will be converted to BloodTestItem entries. The full healthDataItems set is still passed to the structured fallback blocks that handle vitals, demographics, and imaging separately.
Address P1 review comment: passing all healthDataItems (which includes
vitals, demographics, and imaging entries) into createBloodTestResultFromText
meant an AI outage could cause those non-lab items to be silently imported as
blood test results via the legacy fallback.
Filter to labOnlyItems by excluding known non-lab type groups
("Personal Information", "Demographics", "Vital Signs", "Imaging", "Radiology")
before handing off to the text-based extraction path. The structured fallback
for non-lab types still receives the full healthDataItems set unchanged.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Review — PR #33: restore lab import review in on-device fallback pathOverviewThis PR fixes a real and important bug: the item-based (on-device) document processing path was silently swallowing the review flow by never setting IssuesCode duplication — medium priority The pending-review block (create private func applyPendingReview(
_ mappingResult: BloodTestMappingResult,
document: MedicalDocument,
to bloodTest: inout BloodTestResult
) async {
guard mappingResult.needsReview else { return }
let pendingReview = PendingImportReview(
documentId: document.id,
documentName: document.fileName,
importGroups: mappingResult.importGroups,
bloodTestResult: bloodTest
)
await MainActor.run { self.pendingImportReview = pendingReview }
var meta = bloodTest.metadata ?? [:]
meta["needs_review"] = "true"
meta["import_groups_count"] = String(mappingResult.importGroups.count)
meta["pending_review"] = "true"
bloodTest.metadata = meta
}Redundant metadata keys — low priority
Hardcoded type-name strings — low priority let nonLabTypes: Set<String> = ["Personal Information", "Demographics", "Vital Signs", "Imaging", "Radiology"]These strings must match whatever
Previously Correctness
Test CoverageThe PR description acknowledges no automated tests were added. Given that this is a UI-observable state change, a unit test verifying that SummaryThe fix is correct and addresses a genuine user-facing bug. The main ask before merging is extracting the duplicated pending-review block into a shared helper to prevent future drift. The hardcoded type strings and redundant metadata key are lower priority but worth a follow-up. |
Motivation
Description
healthDataItemsearly fromProcessedDocumentResultand pass them intocreateBloodTestResultFromTextso the item-based fallback mapping has real context instead of an empty list (file:Services/DocumentProcessor.swift).PendingImportReviewand assign it topendingImportReviewon theMainActorwhenmappingResult.needsReviewso the UI review sheet is triggered the same way as the full-text path.needs_review,import_groups_count,pending_review) onto theBloodTestResultmetadata and unify creation of the enhanced blood test result so downstream UI/DB logic can detect pending reviews.Testing
xcodebuildunless explicitly requested).Services/DocumentProcessor.swiftand align with the full-text mapping behavior; CI should run the full build and XCTest to verify runtime integration.Codex Task