11import axios from 'axios' ;
2- import { MedicalReport , ReportStatus , ReportCategory } from '../models/medicalReport' ;
2+ import { MedicalReport , ReportStatus } from '../models/medicalReport' ;
33
4- // Base API URL - should be configured from environment variables in a real app
5- // Removed unused API_URL variable
4+ // Get the API URL from environment variables
5+ const API_URL = import . meta . env . VITE_BASE_URL_API || '' ;
66
77/**
88 * Error thrown when report operations fail.
@@ -21,12 +21,10 @@ export class ReportError extends Error {
2121 */
2222export const fetchLatestReports = async ( limit = 3 ) : Promise < MedicalReport [ ] > => {
2323 try {
24- // In a real app, this would be an actual API call
25- // const response = await axios.get(`/api/reports/latest?limit=${limit}`);
26- // return response.data;
27-
28- // For now, return mock data
29- return mockReports . slice ( 0 , limit ) ;
24+ const response = await axios . get ( `${ API_URL } /reports/latest?limit=${ limit } ` ) ;
25+ console . log ( 'response' , response . data ) ;
26+ console . log ( 'API_URL' , API_URL ) ;
27+ return response . data ;
3028 } catch ( error ) {
3129 if ( axios . isAxiosError ( error ) ) {
3230 throw new ReportError ( `Failed to fetch latest reports: ${ error . message } ` ) ;
@@ -41,12 +39,8 @@ export const fetchLatestReports = async (limit = 3): Promise<MedicalReport[]> =>
4139 */
4240export const fetchAllReports = async ( ) : Promise < MedicalReport [ ] > => {
4341 try {
44- // In a real app, this would be an actual API call
45- // const response = await axios.get(`/api/reports`);
46- // return response.data;
47-
48- // For now, return mock data
49- return mockReports ;
42+ const response = await axios . get ( `${ API_URL } /reports` ) ;
43+ return response . data ;
5044 } catch ( error ) {
5145 if ( axios . isAxiosError ( error ) ) {
5246 throw new ReportError ( `Failed to fetch all reports: ${ error . message } ` ) ;
@@ -62,18 +56,16 @@ export const fetchAllReports = async (): Promise<MedicalReport[]> => {
6256 */
6357export const markReportAsRead = async ( reportId : string ) : Promise < MedicalReport > => {
6458 try {
65- // In a real app, this would be an actual API call
66- // const response = await axios.patch(`/api/reports/${reportId}`, {
67- // status: ReportStatus.READ
68- // });
69- // return response.data;
70-
71- // For now, update mock data
72- const report = mockReports . find ( r => r . id === reportId ) ;
59+ const response = await axios . patch ( `${ API_URL } /reports/${ reportId } ` , {
60+ status : ReportStatus . READ
61+ } ) ;
62+
63+ const report = response . data ;
64+
7365 if ( ! report ) {
7466 throw new Error ( `Report with ID ${ reportId } not found` ) ;
7567 }
76-
68+
7769 report . status = ReportStatus . READ ;
7870 return { ...report } ;
7971 } catch ( error ) {
@@ -83,34 +75,3 @@ export const markReportAsRead = async (reportId: string): Promise<MedicalReport>
8375 throw new ReportError ( 'Failed to mark report as read' ) ;
8476 }
8577} ;
86-
87- // Mock data for development
88- const mockReports : MedicalReport [ ] = [
89- {
90- id : '1' ,
91- title : 'Blood Test' ,
92- category : ReportCategory . GENERAL ,
93- date : '2025-01-27' ,
94- status : ReportStatus . UNREAD ,
95- doctor : 'Dr. Smith' ,
96- facility : 'City Hospital'
97- } ,
98- {
99- id : '2' ,
100- title : 'Cranial Nerve Exam' ,
101- category : ReportCategory . NEUROLOGICAL ,
102- date : '2025-01-19' ,
103- status : ReportStatus . UNREAD ,
104- doctor : 'Dr. Johnson' ,
105- facility : 'Neurology Center'
106- } ,
107- {
108- id : '3' ,
109- title : 'Stress Test' ,
110- category : ReportCategory . HEART ,
111- date : '2024-12-26' ,
112- status : ReportStatus . READ ,
113- doctor : 'Dr. Williams' ,
114- facility : 'Heart Institute'
115- }
116- ] ;
0 commit comments