-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
128 lines (109 loc) · 3.7 KB
/
types.ts
File metadata and controls
128 lines (109 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
export interface MedicineInfo {
brandName: string;
composition: string;
uses: string;
dosage: string;
sideEffects: string;
warnings: string;
otcOrPrescription: string;
manufacturer: string;
rawResponse: string;
imageUrl?: string;
}
export interface AgeBasedInfo {
age: number;
ageGroup: 'Child' | 'Adult' | 'Senior' | 'Unknown';
dosage: string;
timings: string;
sideEffects: string;
warnings: string;
}
export interface ComparisonItem extends AgeBasedInfo {
id: string;
}
export interface Language {
code: string;
name: string;
}
export type InputMode = 'image' | 'text';
export type NavigationView = 'input' | 'scan' | 'history' | 'ageGuide' | 'symptoms';
export interface HistoryItem extends MedicineInfo {
id: string;
timestamp: number;
}
export interface SymptomAnalysis {
urgency: 'Low' | 'Moderate' | 'High' | 'Emergency';
possibleConditions: string;
suggestedCare: string;
suggestedMedications: string;
rootCauses: string;
preventiveMeasures: string;
alternativePossibilities: string;
}
export interface SymptomHistoryItem extends SymptomAnalysis {
id: string;
timestamp: number;
inputSummary: string; // e.g., "Image Analysis" or the first 50 chars of text
}
// Medicine History
export const loadHistory = (): HistoryItem[] => {
try {
const historyJson = localStorage.getItem('mediscan_history');
if (!historyJson) return [];
const history = JSON.parse(historyJson) as HistoryItem[];
return history.sort((a, b) => b.timestamp - a.timestamp);
} catch (error) {
console.error("Failed to load medicine history from localStorage", error);
return [];
}
};
export const addHistoryItem = (item: HistoryItem): HistoryItem[] => {
const history = loadHistory();
const updatedHistory = [item, ...history];
localStorage.setItem('mediscan_history', JSON.stringify(updatedHistory));
return updatedHistory;
};
export const deleteHistoryItem = (id: string): HistoryItem[] => {
const history = loadHistory();
const updatedHistory = history.filter(item => item.id !== id);
localStorage.setItem('mediscan_history', JSON.stringify(updatedHistory));
return updatedHistory;
};
export const clearHistory = (): void => {
try {
localStorage.removeItem('mediscan_history');
} catch (error) {
console.error("Failed to clear medicine history from localStorage", error);
}
};
// Symptom History
export const loadSymptomHistory = (): SymptomHistoryItem[] => {
try {
const historyJson = localStorage.getItem('symptom_history');
if (!historyJson) return [];
const history = JSON.parse(historyJson) as SymptomHistoryItem[];
return history.sort((a, b) => b.timestamp - a.timestamp);
} catch (error) {
console.error("Failed to load symptom history from localStorage", error);
return [];
}
};
export const addSymptomHistoryItem = (item: SymptomHistoryItem): SymptomHistoryItem[] => {
const history = loadSymptomHistory();
const updatedHistory = [item, ...history];
localStorage.setItem('symptom_history', JSON.stringify(updatedHistory));
return updatedHistory;
};
export const deleteSymptomHistoryItem = (id: string): SymptomHistoryItem[] => {
const history = loadSymptomHistory();
const updatedHistory = history.filter(item => item.id !== id);
localStorage.setItem('symptom_history', JSON.stringify(updatedHistory));
return updatedHistory;
};
export const clearSymptomHistory = (): void => {
try {
localStorage.removeItem('symptom_history');
} catch (error) {
console.error("Failed to clear symptom history from localStorage", error);
}
};