Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions frontend/src/app/api/medical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,19 @@ export async function analyzeMedicalOcr(
return parseEnvelope<MedicalOcrResult>(res);
}

export async function uploadMedicalRecord(body: MedicalUploadBody): Promise<MedicalRecordApi> {
export async function uploadMedicalRecord(body: MedicalUploadBody): Promise<MedicalRecordApi | null> {
const petId = Number(getPetId());
const res = await safeFetch(`${API_BASE}/api/upload/medical`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders() },
body: JSON.stringify({ ...body, petId }),
});
return parseEnvelope<MedicalRecordApi>(res);
if (!res.ok) return parseEnvelope<MedicalRecordApi>(res);
try {
return await parseEnvelope<MedicalRecordApi>(res);
} catch {
return null;
}
}

export async function getLatestMedicalSummary(): Promise<MedicalLatestSummary> {
Expand All @@ -174,3 +179,4 @@ export async function getLatestMedicalSummary(): Promise<MedicalLatestSummary> {
});
return parseEnvelope<MedicalLatestSummary>(res);
}

3 changes: 2 additions & 1 deletion frontend/src/app/components/HealthLogScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const symptomChips = [
{ id: 'itch', label: '가려움', emoji: '🐾' },
{ id: 'appetite', label: '식욕부진', emoji: '🍽️' },
{ id: 'lethargy', label: '기력저하', emoji: '😴' },
{ id: 'limp', label: '跛行', emoji: '🦵' },
{ id: 'limp', label: '파행', emoji: '🦵' },
{ id: 'eye', label: '눈 분비물', emoji: '👁️' },
{ id: 'ear', label: '귀 긁음', emoji: '👂' },
];
Expand Down Expand Up @@ -601,3 +601,4 @@ export default function HealthLogScreen() {
</MobileFrame>
);
}

1 change: 1 addition & 0 deletions frontend/src/app/components/MedicalRecordsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default function MedicalRecordsScreen() {
<p style={{ fontSize: '11px', color: '#6A9FD4' }}>처방 내역이 없어요</p>
)}
</div>

</div>
</div>
)}
Expand Down
20 changes: 6 additions & 14 deletions frontend/src/app/components/MedicalUploadScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function MedicalUploadScreen() {
const [analyzeStep, setAnalyzeStep] = useState(0);
const [ocrData, setOcrData] = useState<OcrData>({ hospital: '', date: '', items: '', diagnosis: '', amount: '' });
const [showTypePicker, setShowTypePicker] = useState(false);
const [ocrImageUrls, setOcrImageUrls] = useState<string[]>([]);
const [ocrError, setOcrError] = useState<string | null>(null);
const [saving, setSaving] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
Expand Down Expand Up @@ -80,13 +81,6 @@ export default function MedicalUploadScreen() {
});
};

const readAsDataUrl = (file: File): Promise<string> => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(String(reader.result ?? ''));
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});

const handleAnalyze = async () => {
setScreenState('analyzing');
setAnalyzeStep(0);
Expand All @@ -103,7 +97,8 @@ export default function MedicalUploadScreen() {

clearInterval(interval);

const { extracted } = result;
const { extracted, imageUrls } = result;
setOcrImageUrls(imageUrls ?? []);
setOcrData({
hospital: extracted.clinicName ?? '',
date: extracted.visitDate || selectedDate,
Expand All @@ -113,6 +108,7 @@ export default function MedicalUploadScreen() {
});
} catch (e) {
clearInterval(interval);
setOcrImageUrls([]);
setOcrData({ hospital: '', date: selectedDate, items: '', diagnosis: '', amount: '' });
setOcrError(e instanceof Error ? e.message : 'OCR 분석에 실패했습니다. 직접 입력해주세요.');
}
Expand All @@ -125,19 +121,14 @@ export default function MedicalUploadScreen() {
setSaving(true);
setSaveError(null);
try {
const base64List = await Promise.all(receiptFiles.map(readAsDataUrl));
const imageBase64 = base64List.map(b => {
const idx = b.indexOf(',');
return idx >= 0 ? b.substring(idx + 1) : b;
});
await uploadMedicalRecord({
type: TYPE_MAP[medType],
clinicName: ocrData.hospital,
visitDate: ocrData.date,
content: ocrData.items,
diagnosis: ocrData.diagnosis,
totalCost: ocrData.amount,
image: imageBase64,
image: ocrImageUrls,
});
navigate('/medical-records', { replace: true });
} catch (e) {
Expand Down Expand Up @@ -417,3 +408,4 @@ export default function MedicalUploadScreen() {
</MobileFrame>
);
}

Loading