Skip to content

Commit 9e05244

Browse files
committed
Add title and category fields to MedicalDocumentAnalysis and update tests
1 parent 767cf99 commit 9e05244

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ vi.mock('@aws-sdk/client-bedrock-runtime', () => {
6565
{
6666
type: 'text',
6767
text: JSON.stringify({
68+
title: 'Blood Test Results',
69+
category: 'general',
6870
keyMedicalTerms: [
6971
{ term: 'RBC', definition: 'Red Blood Cells' },
7072
{ term: 'WBC', definition: 'White Blood Cells' },
@@ -126,6 +128,8 @@ describe('AwsBedrockService', () => {
126128
`;
127129

128130
const mockMedicalAnalysis: MedicalDocumentAnalysis = {
131+
title: 'Blood Test Results',
132+
category: 'general',
129133
keyMedicalTerms: [
130134
{ term: 'RBC', definition: 'Red Blood Cells' },
131135
{ term: 'WBC', definition: 'White Blood Cells' },
@@ -309,6 +313,8 @@ describe('AwsBedrockService', () => {
309313

310314
// Test a valid response
311315
const validResponse: MedicalDocumentAnalysis = {
316+
title: 'Test Report',
317+
category: 'general',
312318
keyMedicalTerms: [],
313319
labValues: [],
314320
diagnoses: [],

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { createHash } from 'crypto';
1212
* Interface for medical document analysis result
1313
*/
1414
export interface MedicalDocumentAnalysis {
15+
title: string;
16+
category: string;
1517
keyMedicalTerms: Array<{ term: string; definition: string }>;
1618
labValues: Array<{
1719
name: string;
@@ -44,15 +46,19 @@ export class AwsBedrockService {
4446
private readonly medicalAnalysisPrompt = `Please analyze this medical document carefully, with specific attention to medical lab reports.
4547
4648
Look for and extract the following information:
47-
1. Key medical terms visible in the document with their definitions
48-
2. Lab test values with their normal ranges and whether they are abnormal (particularly important for blood work, metabolic panels, etc.)
49-
3. Any diagnoses, findings, or medical observations with details and recommendations
50-
4. Analyze if this is a medical document (lab report, test result, medical chart, prescription, etc.) and provide confidence level
49+
1. Document title or main subject based on content
50+
2. Document category based on organ system focus
51+
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.)
53+
5. Any diagnoses, findings, or medical observations with details and recommendations
54+
6. Analyze if this is a medical document (lab report, test result, medical chart, prescription, etc.) and provide confidence level
5155
5256
This document may be a lab report showing blood work or other test results, so please pay special attention to tables, numeric values, reference ranges, and medical terminology.
5357
5458
Format the response as a JSON object with the following structure:
5559
{
60+
"title": string,
61+
"category": string,
5662
"keyMedicalTerms": [{"term": string, "definition": string}],
5763
"labValues": [{"name": string, "value": string, "unit": string, "normalRange": string, "isAbnormal": boolean}],
5864
"diagnoses": [{"condition": string, "details": string, "recommendations": string}],
@@ -63,6 +69,12 @@ Format the response as a JSON object with the following structure:
6369
}
6470
}
6571
72+
For the title field, create a concise title that summarizes what the document is about (e.g., "Complete Blood Count Results", "Liver Function Test", "MRI Report").
73+
For the category field, you MUST choose exactly one of these three values:
74+
- "heart" - if the document focuses primarily on cardiac/cardiovascular issues or tests
75+
- "brain" - if the document focuses primarily on neurological issues or brain-related tests
76+
- "general" - for all other medical documents, or when the focus spans multiple systems
77+
6678
Set isMedicalReport to true if you see ANY medical content such as lab values, medical terminology, doctor's notes, or prescription information.
6779
Set confidence between 0 and 1 based on document clarity and how confident you are about the medical nature of the document.
6880
@@ -115,6 +127,8 @@ INCORRECT RESPONSE FORMATS (DO NOT DO THESE):
115127
116128
CORRECT FORMAT (DO THIS):
117129
{
130+
"title": "Complete Blood Count Results",
131+
"category": "heart",
118132
"keyMedicalTerms": [
119133
{"term": "RBC", "definition": "Red blood cells"},
120134
{"term": "WBC", "definition": "White blood cells"}
@@ -401,6 +415,8 @@ Document text:
401415
// Check if response has all required properties
402416
if (
403417
!response ||
418+
typeof response.title !== 'string' ||
419+
typeof response.category !== 'string' ||
404420
!Array.isArray(response.keyMedicalTerms) ||
405421
!Array.isArray(response.labValues) ||
406422
!Array.isArray(response.diagnoses) ||

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ describe('DocumentProcessorService', () => {
3535
};
3636

3737
const medicalAnalysis = {
38+
title: 'Test Report',
39+
category: 'general',
3840
keyMedicalTerms: [],
3941
labValues: [],
4042
diagnoses: [],
@@ -147,6 +149,8 @@ describe('DocumentProcessorService', () => {
147149
keyValuePairs: [],
148150
},
149151
analysis: {
152+
title: 'Document 1 Report',
153+
category: 'general',
150154
keyMedicalTerms: [],
151155
labValues: [],
152156
diagnoses: [],
@@ -172,6 +176,8 @@ describe('DocumentProcessorService', () => {
172176
keyValuePairs: [],
173177
},
174178
analysis: {
179+
title: 'Document 2 Report',
180+
category: 'general',
175181
keyMedicalTerms: [],
176182
labValues: [],
177183
diagnoses: [],

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ export class DocumentProcessorService {
164164
keyValuePairs: [],
165165
},
166166
analysis: {
167+
title: 'Failed Document',
168+
category: 'general',
167169
keyMedicalTerms: [],
168170
labValues: [],
169171
diagnoses: [],

0 commit comments

Comments
 (0)