|
|
@@ -5,7 +5,7 @@ import { Router, RouterModule } from '@angular/router';
|
|
|
import { ExtractionService } from '../../services/extraction.service';
|
|
|
import { SessionService, User } from '../../services/session.service';
|
|
|
import { ExtractionResponse, ClaimSubmission } from '../../services/extraction';
|
|
|
-import { LucideAngularModule, ShieldCheck, AlertCircle, CheckCircle, ArrowLeft, Eye, EyeOff, Wand2 } from 'lucide-angular';
|
|
|
+import { LucideAngularModule, ShieldCheck, AlertCircle, CheckCircle, ArrowLeft, Eye, EyeOff, Wand2, ClipboardList } from 'lucide-angular';
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
|
|
@Component({
|
|
|
@@ -35,8 +35,15 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
readonly Eye = Eye;
|
|
|
readonly EyeOff = EyeOff;
|
|
|
readonly Wand2 = Wand2;
|
|
|
+ readonly ClipboardList = ClipboardList;
|
|
|
errorMessage: string | null = null;
|
|
|
|
|
|
+ // Track which fields were auto-filled by AI
|
|
|
+ autoFilledFields: Set<string> = new Set();
|
|
|
+
|
|
|
+ categories = ['General', 'Dental', 'Optical', 'Specialist'];
|
|
|
+ treatmentTypes = ['Outpatient', 'Inpatient', 'Dental Care', 'Optical Care', 'Health Screening'];
|
|
|
+
|
|
|
constructor(
|
|
|
private fb: FormBuilder,
|
|
|
private extractionService: ExtractionService,
|
|
|
@@ -48,7 +55,16 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
visit_date: ['', Validators.required],
|
|
|
amount_spent: ['', [Validators.required, Validators.min(0.01)]],
|
|
|
amount_claimed: [{ value: 0, disabled: true }],
|
|
|
- currency: ['MYR']
|
|
|
+ currency: ['MYR'],
|
|
|
+ // AI-assisted fields
|
|
|
+ receipt_ref_no: ['', Validators.required],
|
|
|
+ clinic_reg_no: ['', Validators.required],
|
|
|
+ claim_category: ['', Validators.required],
|
|
|
+ diagnosis_brief: ['', Validators.required],
|
|
|
+ // Mandatory Manual fields
|
|
|
+ treatment_type: ['', Validators.required],
|
|
|
+ cost_center: ['', Validators.required],
|
|
|
+ declaration_signed: [false, Validators.requiredTrue]
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -114,8 +130,9 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
if (!this.currentUser) return;
|
|
|
this.selectedFile = file;
|
|
|
this.previewUrl = URL.createObjectURL(file);
|
|
|
- this.extractionResponse = null; // reset if existing
|
|
|
+ this.extractionResponse = null;
|
|
|
this.errorMessage = null;
|
|
|
+ this.autoFilledFields.clear();
|
|
|
}
|
|
|
|
|
|
autoFillWithAI(): void {
|
|
|
@@ -123,17 +140,40 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
this.isLoading = true;
|
|
|
this.errorMessage = null;
|
|
|
+ this.autoFilledFields.clear();
|
|
|
|
|
|
this.extractionService.extractData(this.selectedFile, this.currentUser.name, this.currentUser.department).subscribe({
|
|
|
next: (response) => {
|
|
|
this.extractionResponse = response;
|
|
|
- this.claimForm.patchValue({
|
|
|
+
|
|
|
+ const patchData: any = {
|
|
|
provider_name: response.provider_name,
|
|
|
visit_date: response.visit_date,
|
|
|
amount_spent: response.total_amount,
|
|
|
currency: response.currency || 'MYR'
|
|
|
- });
|
|
|
- // The valueChanges subscription will trigger calculateClaimable automatically
|
|
|
+ };
|
|
|
+
|
|
|
+ // Track auto-filled fields for UI cues
|
|
|
+ ['provider_name', 'visit_date', 'amount_spent'].forEach(f => this.autoFilledFields.add(f));
|
|
|
+
|
|
|
+ if (response.receipt_ref_no) {
|
|
|
+ patchData.receipt_ref_no = response.receipt_ref_no;
|
|
|
+ this.autoFilledFields.add('receipt_ref_no');
|
|
|
+ }
|
|
|
+ if (response.clinic_reg_no) {
|
|
|
+ patchData.clinic_reg_no = response.clinic_reg_no;
|
|
|
+ this.autoFilledFields.add('clinic_reg_no');
|
|
|
+ }
|
|
|
+ if (response.claim_category) {
|
|
|
+ patchData.claim_category = response.claim_category;
|
|
|
+ this.autoFilledFields.add('claim_category');
|
|
|
+ }
|
|
|
+ if (response.diagnosis_brief) {
|
|
|
+ patchData.diagnosis_brief = response.diagnosis_brief;
|
|
|
+ this.autoFilledFields.add('diagnosis_brief');
|
|
|
+ }
|
|
|
+
|
|
|
+ this.claimForm.patchValue(patchData);
|
|
|
this.isLoading = false;
|
|
|
},
|
|
|
error: (err: Error) => {
|
|
|
@@ -155,6 +195,9 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
visit_date: formData.visit_date,
|
|
|
amount_spent: Number(formData.amount_spent),
|
|
|
currency: formData.currency,
|
|
|
+ treatment_type: formData.treatment_type,
|
|
|
+ cost_center: formData.cost_center,
|
|
|
+ declaration_signed: formData.declaration_signed,
|
|
|
extraction_data: this.extractionResponse
|
|
|
};
|
|
|
|
|
|
@@ -171,6 +214,10 @@ export class ClaimFormComponent implements OnInit, OnDestroy {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ isAutoFilled(fieldName: string): boolean {
|
|
|
+ return this.autoFilledFields.has(fieldName);
|
|
|
+ }
|
|
|
+
|
|
|
get rawJson(): string {
|
|
|
return JSON.stringify(this.extractionResponse, null, 2);
|
|
|
}
|