Skip to content

Commit 3c642a0

Browse files
authored
Merge pull request #88 from ModusCreateOrg/ADE-66
[ADE-66] refactor and improve uploading a report & processing it
2 parents c365fc1 + 48103f4 commit 3c642a0

39 files changed

+1515
-490
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,10 @@ export class DocumentProcessorController {
201201
// Extract lab values
202202
report.labValues = result.analysis.labValues || [];
203203

204+
report.confidence = result.analysis.metadata.confidence || 0;
205+
204206
// Create summary from simplified explanation or diagnoses
205-
report.summary =
206-
result.simplifiedExplanation ||
207-
result.analysis.diagnoses.map(d => d.condition).join(', ') ||
208-
'No summary available';
207+
report.summary = result.simplifiedExplanation!;
209208

210209
report.updatedAt = new Date().toISOString();
211210

backend/src/reports/models/report.model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export class Report {
5050
@ApiProperty({ description: 'Summary of the report' })
5151
summary: string;
5252

53+
@ApiProperty({ description: 'Confidence score of the analysis (0-100)' })
54+
confidence: number;
55+
5356
@ApiProperty({
5457
description: 'Status of the report',
5558
enum: ReportStatus,
@@ -60,6 +63,12 @@ export class Report {
6063
@ApiProperty({ description: 'File path of the report' })
6164
filePath: string;
6265

66+
@ApiProperty({ description: 'Original filename of the uploaded file' })
67+
originalFilename: string;
68+
69+
@ApiProperty({ description: 'File size in bytes' })
70+
fileSize: number;
71+
6372
@ApiProperty({ description: 'Creation timestamp' })
6473
createdAt: string;
6574

backend/src/reports/reports.controller.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,28 @@ export class ReportsController {
157157
type: 'string',
158158
description: 'S3 file path for the report',
159159
},
160+
originalFilename: {
161+
type: 'string',
162+
description: 'Original filename of the uploaded file',
163+
},
164+
fileSize: {
165+
type: 'number',
166+
description: 'Size of the file in bytes',
167+
},
160168
},
161169
required: ['filePath'],
162170
},
163-
description: 'S3 file path for the report',
171+
description: 'S3 file path and metadata for the report',
164172
})
165173
@Post()
166174
async createReport(
167175
@Body('filePath') filePath: string,
176+
@Body('originalFilename') originalFilename: string,
177+
@Body('fileSize') fileSize: number,
168178
@Req() request: RequestWithUser,
169179
): Promise<Report> {
170180
const userId = this.extractUserId(request);
171-
return this.reportsService.saveReport(filePath, userId);
181+
return this.reportsService.saveReport(filePath, userId, originalFilename, fileSize);
172182
}
173183

174184
private extractUserId(request: RequestWithUser): string {

backend/src/reports/reports.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,20 @@ export class ReportsService {
282282
}
283283
}
284284

285-
async saveReport(filePath: string, userId: string): Promise<Report> {
285+
/**
286+
* Save a new report to DynamoDB
287+
* @param filePath S3 object path of the uploaded file
288+
* @param userId User ID of the report owner
289+
* @param originalFilename Original filename of the uploaded file
290+
* @param fileSize Size of the file in bytes
291+
* @returns The saved report
292+
*/
293+
async saveReport(
294+
filePath: string,
295+
userId: string,
296+
originalFilename: string = 'Unknown filename',
297+
fileSize: number = 0,
298+
): Promise<Report> {
286299
if (!filePath) {
287300
throw new NotFoundException('File URL is required');
288301
}
@@ -296,12 +309,15 @@ export class ReportsService {
296309
id: uuidv4(),
297310
userId,
298311
filePath,
312+
originalFilename,
313+
fileSize,
299314
title: 'New Report',
300315
bookmarked: false,
301316
category: '',
302317
processingStatus: ProcessingStatus.UNPROCESSED,
303318
labValues: [],
304319
summary: '',
320+
confidence: 0,
305321
status: ReportStatus.UNREAD,
306322
createdAt: new Date().toISOString(),
307323
updatedAt: new Date().toISOString(),

frontend/src/common/api/reportService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export const uploadReport = async (
7575
`${API_URL}/api/reports`,
7676
{
7777
filePath: s3Key,
78+
originalFilename: file.name,
79+
fileSize: file.size,
7880
},
7981
config,
8082
);

frontend/src/common/components/Icon/Icon.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
faArrowUpFromBracket,
2727
faHome,
2828
faFileLines as faSolidFileLines,
29+
faFileAlt as faFileText,
30+
faFilePdf,
2931
faUpload,
3032
faComment,
3133
faUserCircle,
@@ -36,12 +38,14 @@ import {
3638
faChevronUp,
3739
faChevronDown,
3840
faVial,
41+
faLightbulb as faSolidLightbulb,
3942
} from '@fortawesome/free-solid-svg-icons';
4043
import {
4144
faFileLines as faRegularFileLines,
4245
faComment as faRegularComment,
4346
faUser as faRegularUser,
4447
faBookmark as faRegularBookmark,
48+
faLightbulb as faRegularLightbulb,
4549
} from '@fortawesome/free-regular-svg-icons';
4650
import classNames from 'classnames';
4751

@@ -63,6 +67,8 @@ export type IconName =
6367
| 'comment'
6468
| 'envelope'
6569
| 'fileLines'
70+
| 'fileText'
71+
| 'filePdf'
6672
| 'home'
6773
| 'house'
6874
| 'link'
@@ -86,7 +92,8 @@ export type IconName =
8692
| 'flask'
8793
| 'chevronUp'
8894
| 'chevronDown'
89-
| 'vial';
95+
| 'vial'
96+
| 'lightbulb';
9097

9198
/**
9299
* Properties for the `Icon` component.
@@ -114,6 +121,8 @@ const solidIcons: Record<IconName, IconProp> = {
114121
comment: faComment,
115122
envelope: faEnvelope,
116123
fileLines: faSolidFileLines,
124+
fileText: faFileText,
125+
filePdf: faFilePdf,
117126
home: faHome,
118127
house: faHouse,
119128
link: faLink,
@@ -138,6 +147,7 @@ const solidIcons: Record<IconName, IconProp> = {
138147
chevronUp: faChevronUp,
139148
chevronDown: faChevronDown,
140149
vial: faVial,
150+
lightbulb: faSolidLightbulb,
141151
};
142152

143153
/**
@@ -150,6 +160,7 @@ const regularIcons: Partial<Record<IconName, IconProp>> = {
150160
user: faRegularUser,
151161
bookmark: faRegularBookmark,
152162
circleXmark: faCircleXmark,
163+
lightbulb: faRegularLightbulb,
153164
};
154165

155166
/**

frontend/src/common/components/Router/TabNavigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import ChatPage from 'pages/Chat/ChatPage';
1818
import UploadPage from 'pages/Upload/UploadPage';
1919
import ReportsListPage from 'pages/Reports/ReportsListPage';
2020
import ReportDetailPage from 'pages/Reports/ReportDetailPage';
21-
import Processing from 'pages/Processing/Processing';
21+
import ProcessingPage from 'pages/Processing/ProcessingPage';
2222

2323
/**
2424
* The `TabNavigation` component provides a router outlet for all of the
@@ -92,7 +92,7 @@ const TabNavigation = (): JSX.Element => {
9292
<ReportDetailPage />
9393
</Route>
9494
<Route exact path="/tabs/processing">
95-
<Processing />
95+
<ProcessingPage />
9696
</Route>
9797
<Route exact path="/">
9898
<Redirect to="/tabs/home" />

frontend/src/common/models/medicalReport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum ProcessingStatus {
2222
PROCESSED = 'processed',
2323
UNPROCESSED = 'unprocessed',
2424
IN_PROGRESS = 'in_progress',
25+
FAILED = 'failed',
2526
}
2627

2728
/**
@@ -50,8 +51,11 @@ export interface MedicalReport {
5051
processingStatus: ProcessingStatus;
5152
labValues: LabValue[];
5253
summary: string;
54+
confidence: number;
5355
status: ReportStatus;
5456
filePath: string;
57+
originalFilename: string;
58+
fileSize: number;
5559
createdAt: string; // ISO date string
5660
updatedAt: string; // ISO date string
5761
}

frontend/src/common/utils/i18n/resources/en/common.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
"required-path": "{{path}} is required. ",
7171
"url": "Must be a URL. "
7272
},
73+
"loading": {
74+
"report": "Loading report..."
75+
},
7376
"no": "no",
7477
"updated": "updated",
7578
"welcome": "Welcome",
@@ -79,4 +82,4 @@
7982
"title": "AI Assistant"
8083
}
8184
}
82-
}
85+
}

frontend/src/common/utils/i18n/resources/en/errors.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
},
55
"ai": {
66
"content_filtered": "I couldn't find an answer. Please try rephrasing your question or consult your healthcare provider."
7-
}
8-
}
7+
},
8+
"loading": {
9+
"report": "Error loading the report. Please try again."
10+
},
11+
"no-report-data": "No report data available."
12+
}

0 commit comments

Comments
 (0)