Skip to content

Commit 82ada7a

Browse files
committed
Remove old report service model
1 parent 1e4999c commit 82ada7a

File tree

6 files changed

+34
-52
lines changed

6 files changed

+34
-52
lines changed

frontend/src/common/api/__tests__/reportService.test.ts

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ vi.mock('axios', () => ({
1919
// Mock dynamic imports to handle the service functions
2020
vi.mock('../reportService', async (importOriginal) => {
2121
const actual = await importOriginal() as typeof ReportServiceModule;
22-
22+
2323
// Create a new object with the same properties as the original
2424
return {
2525
// Keep the ReportError class
2626
ReportError: actual.ReportError,
27-
27+
2828
// Mock the API functions
2929
uploadReport: async (file: File, onProgress?: (progress: number) => void) => {
3030
try {
@@ -38,36 +38,36 @@ vi.mock('../reportService', async (importOriginal) => {
3838
return response.data;
3939
} catch (error) {
4040
// Properly wrap the error in a ReportError
41-
throw new actual.ReportError(error instanceof Error
41+
throw new actual.ReportError(error instanceof Error
4242
? `Failed to upload report: ${error.message}`
4343
: 'Failed to upload report');
4444
}
4545
},
46-
46+
4747
// Mock fetchLatestReports
4848
fetchLatestReports: async (limit = 3) => {
4949
try {
5050
const response = await axios.get(`/api/reports/latest?limit=${limit}`);
5151
return response.data;
5252
} catch (error) {
53-
throw new actual.ReportError(error instanceof Error
53+
throw new actual.ReportError(error instanceof Error
5454
? `Failed to fetch latest reports: ${error.message}`
5555
: 'Failed to fetch latest reports');
5656
}
5757
},
58-
58+
5959
// Mock fetchAllReports
6060
fetchAllReports: async () => {
6161
try {
6262
const response = await axios.get(`/api/reports`);
6363
return response.data;
6464
} catch (error) {
65-
throw new actual.ReportError(error instanceof Error
65+
throw new actual.ReportError(error instanceof Error
6666
? `Failed to fetch all reports: ${error.message}`
6767
: 'Failed to fetch all reports');
6868
}
6969
},
70-
70+
7171
// Keep other functions as is
7272
markReportAsRead: actual.markReportAsRead,
7373
getAuthConfig: actual.getAuthConfig,
@@ -92,28 +92,26 @@ const mockReports = [
9292
title: 'heart-report',
9393
status: ReportStatus.UNREAD,
9494
category: ReportCategory.HEART,
95-
documentUrl: 'http://example.com/heart-report.pdf',
9695
date: '2024-03-24',
9796
},
9897
{
9998
id: '2',
10099
title: 'brain-scan',
101100
status: ReportStatus.UNREAD,
102101
category: ReportCategory.NEUROLOGICAL,
103-
documentUrl: 'http://example.com/brain-scan.pdf',
104102
date: '2024-03-24',
105103
}
106104
];
107105

108106
describe('reportService', () => {
109107
const mockFile = new File(['test content'], 'test-report.pdf', { type: 'application/pdf' });
110108
let progressCallback: (progress: number) => void;
111-
109+
112110
beforeEach(() => {
113111
vi.resetAllMocks();
114112
progressCallback = vi.fn();
115113
});
116-
114+
117115
describe('uploadReport', () => {
118116
beforeEach(() => {
119117
// Mock axios.post for successful response
@@ -124,23 +122,22 @@ describe('reportService', () => {
124122
status: ReportStatus.UNREAD,
125123
category: ReportCategory.GENERAL,
126124
date: '2024-05-10',
127-
documentUrl: 'http://example.com/test-report.pdf'
128125
}
129126
});
130127
});
131-
128+
132129
test('should upload file successfully', async () => {
133130
const report = await uploadReport(mockFile, progressCallback);
134-
131+
135132
// Check the returned data matches our expectations
136133
expect(report).toBeDefined();
137134
expect(report.title).toBe('test-report');
138135
expect(report.status).toBe(ReportStatus.UNREAD);
139-
136+
140137
// Check the progress callback was called
141138
expect(progressCallback).toHaveBeenCalled();
142139
});
143-
140+
144141
test('should determine category based on filename', async () => {
145142
// Mock response for heart file
146143
(axios.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
@@ -150,14 +147,13 @@ describe('reportService', () => {
150147
status: ReportStatus.UNREAD,
151148
category: ReportCategory.HEART,
152149
date: '2024-05-10',
153-
documentUrl: 'http://example.com/heart-report.pdf'
154150
}
155151
});
156-
152+
157153
const heartFile = new File(['test'], 'heart-report.pdf', { type: 'application/pdf' });
158154
const heartReport = await uploadReport(heartFile);
159155
expect(heartReport.category).toBe(ReportCategory.HEART);
160-
156+
161157
// Mock response for neurological file
162158
(axios.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
163159
data: {
@@ -166,27 +162,26 @@ describe('reportService', () => {
166162
status: ReportStatus.UNREAD,
167163
category: ReportCategory.NEUROLOGICAL,
168164
date: '2024-05-10',
169-
documentUrl: 'http://example.com/brain-scan.pdf'
170165
}
171166
});
172-
167+
173168
const neuroFile = new File(['test'], 'brain-scan.pdf', { type: 'application/pdf' });
174169
const neuroReport = await uploadReport(neuroFile);
175170
expect(neuroReport.category).toBe(ReportCategory.NEUROLOGICAL);
176171
});
177-
172+
178173
test('should handle upload without progress callback', async () => {
179174
const report = await uploadReport(mockFile);
180175
expect(report).toBeDefined();
181176
expect(report.title).toBe('test-report');
182177
});
183-
178+
184179
test('should throw ReportError on upload failure', async () => {
185180
// Mock axios.post to fail
186181
(axios.post as ReturnType<typeof vi.fn>).mockRejectedValueOnce(
187182
new Error('API request failed')
188183
);
189-
184+
190185
await expect(uploadReport(mockFile, progressCallback))
191186
.rejects
192187
.toThrow(ReportError);
@@ -203,30 +198,30 @@ describe('reportService', () => {
203198

204199
test('should fetch latest reports with default limit', async () => {
205200
const reports = await fetchLatestReports();
206-
201+
207202
expect(axios.get).toHaveBeenCalled();
208203
expect(reports).toHaveLength(2);
209204
expect(reports[0]).toEqual(expect.objectContaining({
210205
id: expect.any(String),
211206
title: expect.any(String)
212207
}));
213208
});
214-
209+
215210
test('should fetch latest reports with custom limit', async () => {
216211
const limit = 1;
217212
(axios.get as ReturnType<typeof vi.fn>).mockResolvedValue({
218213
data: mockReports.slice(0, 1)
219214
});
220-
215+
221216
const reports = await fetchLatestReports(limit);
222-
217+
223218
expect(axios.get).toHaveBeenCalled();
224219
expect(reports).toHaveLength(1);
225220
});
226-
221+
227222
test('should throw ReportError on fetch failure', async () => {
228223
(axios.get as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Network error'));
229-
224+
230225
await expect(fetchLatestReports())
231226
.rejects
232227
.toThrow(ReportError);
@@ -242,14 +237,14 @@ describe('reportService', () => {
242237

243238
test('should fetch all reports', async () => {
244239
const reports = await fetchAllReports();
245-
240+
246241
expect(axios.get).toHaveBeenCalled();
247242
expect(reports).toEqual(mockReports);
248243
});
249-
244+
250245
test('should throw ReportError on fetch failure', async () => {
251246
(axios.get as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Network error'));
252-
247+
253248
await expect(fetchAllReports())
254249
.rejects
255250
.toThrow(ReportError);
@@ -262,25 +257,25 @@ describe('reportService', () => {
262257
...mockReports[0],
263258
status: ReportStatus.READ
264259
};
265-
260+
266261
(axios.patch as ReturnType<typeof vi.fn>).mockResolvedValue({
267262
data: updatedReport
268263
});
269264
});
270265

271266
test('should mark a report as read', async () => {
272267
const updatedReport = await markReportAsRead('1');
273-
268+
274269
expect(axios.patch).toHaveBeenCalled();
275270
expect(updatedReport.status).toBe(ReportStatus.READ);
276271
});
277-
272+
278273
test('should throw error when report not found', async () => {
279274
(axios.patch as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Report not found'));
280-
275+
281276
await expect(markReportAsRead('non-existent-id'))
282277
.rejects
283278
.toThrow(ReportError);
284279
});
285280
});
286-
});
281+
});

frontend/src/common/models/medicalReport.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,4 @@ export interface MedicalReport {
4949
filePath: string;
5050
createdAt: string; // ISO date string
5151
updatedAt: string; // ISO date string
52-
53-
// Optional fields for backward compatibility
54-
documentUrl?: string;
55-
content?: string;
56-
doctor?: string;
57-
facility?: string;
5852
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"results": "Results",
99
"refRange": "Ref. Range",
1010
"reportDate": "Report Date",
11-
"doctor": "Doctor",
12-
"facility": "Facility",
1311
"medicalComments": "Medical Comments",
1412
"hemoglobin": "Hemoglobin",
1513
"ldl": "LDL Cholesterol",

frontend/src/common/utils/i18n/resources/es/report.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"results": "Resultados",
99
"refRange": "Rango Ref.",
1010
"reportDate": "Fecha del Informe",
11-
"doctor": "Médico",
12-
"facility": "Centro Médico",
1311
"medicalComments": "Comentarios Médicos",
1412
"hemoglobin": "Hemoglobina",
1513
"ldl": "Colesterol LDL",

frontend/src/common/utils/i18n/resources/fr/report.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"results": "Résultats",
99
"refRange": "Plage Réf.",
1010
"reportDate": "Date du Rapport",
11-
"doctor": "Médecin",
12-
"facility": "Établissement",
1311
"medicalComments": "Commentaires Médicaux",
1412
"hemoglobin": "Hémoglobine",
1513
"ldl": "Cholestérol LDL",

frontend/src/pages/Home/components/ReportItem/__tests__/ReportItem.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ describe('ReportItem', () => {
7878

7979
// ASSERT
8080
expect(screen.getByText('Blood Test')).toBeInTheDocument();
81-
expect(screen.getByText('general')).toBeInTheDocument();
8281
expect(screen.getByText(/Upload Date 01\/27\/2025/)).toBeInTheDocument();
8382
expect(screen.getByTestId('mocked-icon-user')).toBeInTheDocument();
8483

0 commit comments

Comments
 (0)