Skip to content

Commit 5768f6e

Browse files
committed
Refactor MedicalDocumentAnalysis to replace 'isAbnormal' with 'isNormal' field and update related tests and documentation
1 parent b13a0cc commit 5768f6e

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

backend/src/document-processor/services/aws-bedrock.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ vi.mock('@aws-sdk/client-bedrock-runtime', () => {
7777
value: '14.2',
7878
unit: 'g/dL',
7979
normalRange: '13.5-17.5',
80-
isAbnormal: false,
80+
isNormal: 'normal',
8181
},
8282
],
8383
diagnoses: [],
@@ -140,7 +140,7 @@ describe('AwsBedrockService', () => {
140140
value: '14.2',
141141
unit: 'g/dL',
142142
normalRange: '13.5-17.5',
143-
isAbnormal: false,
143+
isNormal: 'normal',
144144
},
145145
],
146146
diagnoses: [],

backend/src/document-processor/services/aws-bedrock.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface MedicalDocumentAnalysis {
2020
value: string;
2121
unit: string;
2222
normalRange: string;
23-
isAbnormal: boolean;
23+
isNormal: 'normal' | 'high' | 'low';
2424
}>;
2525
diagnoses: Array<{ condition: string; details: string; recommendations: string }>;
2626
metadata: {
@@ -49,7 +49,7 @@ Look for and extract the following information:
4949
1. Document title or main subject based on content
5050
2. Document category based on organ system focus
5151
3. Key medical terms visible in the document with their definitions
52-
4. Lab test values with their normal ranges and whether they are abnormal (particularly important for blood work, metabolic panels, etc.)
52+
4. Lab test values with their normal ranges and whether they are normal, high, or low (particularly important for blood work, metabolic panels, etc.)
5353
5. Any diagnoses, findings, or medical observations with details and recommendations
5454
6. Analyze if this is a medical document (lab report, test result, medical chart, prescription, etc.) and provide confidence level
5555
@@ -60,7 +60,7 @@ Format the response as a JSON object with the following structure:
6060
"title": string,
6161
"category": string,
6262
"keyMedicalTerms": [{"term": string, "definition": string}],
63-
"labValues": [{"name": string, "value": string, "unit": string, "normalRange": string, "isAbnormal": boolean}],
63+
"labValues": [{"name": string, "value": string, "unit": string, "normalRange": string, "isNormal": "normal" | "high" | "low"}],
6464
"diagnoses": [{"condition": string, "details": string, "recommendations": string}],
6565
"metadata": {
6666
"isMedicalReport": boolean,
@@ -84,6 +84,7 @@ This is extremely important: If you see ANY lab values, numbers with units, or m
8484
When extracting lab values:
8585
1. Look for tables with numeric values and reference ranges
8686
2. Include any values even if you're not sure of the meaning
87+
3. For each lab value, use "isNormal" field with values "normal", "high", or "low" based on whether the value falls within, above, or below the normal range
8788
8889
EXTREMELY IMPORTANT FORMATTING INSTRUCTIONS:
8990
1. ABSOLUTELY DO NOT START YOUR RESPONSE WITH ANY TEXT. Begin immediately with the JSON object.

backend/src/iac/backend-stack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ export class BackendStack extends cdk.Stack {
8585
removalPolicy: isProd ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY,
8686
});
8787

88-
// Add GSI for querying by date
88+
// Add GSI for querying by createdAt
8989
reportsTable.addGlobalSecondaryIndex({
9090
indexName: 'userIdDateIndex',
9191
partitionKey: {
9292
name: 'userId',
9393
type: AttributeType.STRING,
9494
},
9595
sortKey: {
96-
name: 'date',
96+
name: 'createdAt',
9797
type: AttributeType.STRING,
9898
},
9999
});

backend/src/services/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface MedicalDocumentAnalysis {
6565
value: string;
6666
unit: string;
6767
normalRange: string;
68-
isAbnormal: boolean;
68+
isNormal: 'normal' | 'high' | 'low';
6969
}>;
7070
diagnoses: Array<{ condition: string; details: string; recommendations: string }>;
7171
metadata: {
@@ -120,7 +120,7 @@ curl -X POST \
120120
"value": "14.2",
121121
"unit": "g/dL",
122122
"normalRange": "13.5-17.5",
123-
"isAbnormal": false
123+
"isNormal": "normal"
124124
}
125125
],
126126
"diagnoses": [],
@@ -153,7 +153,7 @@ async processReport(fileBuffer: Buffer, userId: string) {
153153

154154
// Use the structured medical data
155155
const labValues = result.analysis.labValues;
156-
const abnormalValues = labValues.filter(lab => lab.isAbnormal);
156+
const abnormalValues = labValues.filter(lab => lab.isNormal !== 'normal');
157157

158158
return result;
159159
} catch (error) {
@@ -211,4 +211,4 @@ Planned future enhancements:
211211
- Support for multi-page PDF processing using async APIs
212212
- Enhanced lab report detection and categorization
213213
- Integration with medical terminology databases
214-
- OCR preprocessing for low-quality images
214+
- OCR preprocessing for low-quality images

0 commit comments

Comments
 (0)