Skip to content

Commit 48103f4

Browse files
committed
feat: Add confidence score to report and display low confidence notice in AI analysis tab
1 parent df0fd92 commit 48103f4

File tree

7 files changed

+77
-0
lines changed

7 files changed

+77
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ 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
205207
report.summary = result.simplifiedExplanation!;
206208

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

Lines changed: 3 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,

backend/src/reports/reports.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export class ReportsService {
317317
processingStatus: ProcessingStatus.UNPROCESSED,
318318
labValues: [],
319319
summary: '',
320+
confidence: 0,
320321
status: ReportStatus.UNREAD,
321322
createdAt: new Date().toISOString(),
322323
updatedAt: new Date().toISOString(),

frontend/src/common/models/medicalReport.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface MedicalReport {
5151
processingStatus: ProcessingStatus;
5252
labValues: LabValue[];
5353
summary: string;
54+
confidence: number;
5455
status: ReportStatus;
5556
filePath: string;
5657
originalFilename: string;

frontend/src/pages/Reports/ReportDetailPage.scss

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,34 @@
653653
background-color: #435ff0;
654654
border-radius: 100px;
655655
}
656+
657+
// Low Confidence Notice styles
658+
.low-confidence-notice {
659+
margin: 0 16px 20px;
660+
padding: 14px 16px;
661+
display: flex;
662+
align-items: flex-start;
663+
border: 1px solid #dce0e9;
664+
border-radius: 16px;
665+
background-color: #fff;
666+
}
667+
668+
.notice-icon {
669+
color: #667091;
670+
margin-right: 12px;
671+
font-size: 24px;
672+
display: flex;
673+
align-items: center;
674+
min-width: 24px;
675+
}
676+
677+
.notice-text {
678+
color: #313E4C;
679+
font-size: 14px;
680+
line-height: 20px;
681+
font-family: 'Inter', sans-serif;
682+
font-weight: 400;
683+
}
656684
}
657685

658686
// Media Queries for responsiveness
@@ -683,5 +711,11 @@
683711
margin: 20px auto 32px;
684712
padding: 0 16px 16px;
685713
}
714+
715+
.low-confidence-notice {
716+
max-width: 600px;
717+
margin-left: auto;
718+
margin-right: auto;
719+
}
686720
}
687721
}

frontend/src/pages/Reports/components/AiAnalysisTab.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MedicalReport, LabValue } from '../../../common/models/medicalReport';
33
import EmergencyAlert from './EmergencyAlert';
44
import FlaggedValuesSection from './FlaggedValuesSection';
55
import NormalValuesSection from './NormalValuesSection';
6+
import LowConfidenceNotice from './LowConfidenceNotice';
67

78
interface AiAnalysisTabProps {
89
reportData: MedicalReport;
@@ -30,11 +31,19 @@ const AiAnalysisTab: React.FC<AiAnalysisTabProps> = ({
3031
(value) => value.status === 'normal',
3132
);
3233

34+
// Format confidence score for display
35+
const confidenceScore = reportData.confidence;
36+
37+
const isLowConfidence = confidenceScore < 0.75;
38+
3339
return (
3440
<div className="ai-analysis-tab">
3541
{/* Emergency alert if needed */}
3642
{isEmergencyAlertVisible && hasEmergency && <EmergencyAlert />}
3743

44+
{/* Low confidence notice */}
45+
{isLowConfidence && <LowConfidenceNotice />}
46+
3847
{/* Flagged values section */}
3948
<FlaggedValuesSection
4049
flaggedValues={flaggedValues}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { IonIcon } from '@ionic/react';
4+
import { informationCircleOutline } from 'ionicons/icons';
5+
6+
/**
7+
* Component to display a notice when the confidence level is low
8+
*/
9+
const LowConfidenceNotice: React.FC = () => {
10+
const { t } = useTranslation();
11+
12+
return (
13+
<div className="low-confidence-notice">
14+
<div className="notice-icon">
15+
<IonIcon icon={informationCircleOutline} />
16+
</div>
17+
<div className="notice-text">
18+
{t('reports.lowConfidence.message', {
19+
defaultValue:
20+
'Please note that this diagnosis is uncertain due to an incomplete report. For a more accurate interpretation, we recommend uploading another report for processing.',
21+
})}
22+
</div>
23+
</div>
24+
);
25+
};
26+
27+
export default LowConfidenceNotice;

0 commit comments

Comments
 (0)