-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
329 lines (303 loc) · 11.3 KB
/
Copy pathApp.js
File metadata and controls
329 lines (303 loc) · 11.3 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import React, { useState, useEffect } from 'react';
import { View, TextInput, Button, Text, ScrollView, Alert, Platform, StyleSheet } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Picker } from '@react-native-picker/picker';
import DateTimePicker from '@react-native-community/datetimepicker';
import axios from 'axios'; // Import axios for API calls
const App = () => {
const [patients, setPatients] = useState([]);
const [mobileNumber, setMobileNumber] = useState('');
const [email, setEmail] = useState(''); // Email state
const [otp, setOtp] = useState(''); // OTP state
const [otpSent, setOtpSent] = useState(false); // OTP sent status
const [name, setName] = useState('');
const [gender, setGender] = useState('');
const [dob, setDob] = useState(new Date());
const [showDobPicker, setShowDobPicker] = useState(false);
const [age, setAge] = useState('');
const [relationship, setRelationship] = useState('');
const [notes, setNotes] = useState('');
const [useDOB, setUseDOB] = useState(true);
useEffect(() => {
const fetchPatients = async () => {
const storedPatients = await AsyncStorage.getItem('patients');
if (storedPatients) {
setPatients(JSON.parse(storedPatients));
}
};
fetchPatients();
}, []);
const handleRegister = async () => {
const chartCode = generateChartCode();
const formattedDob = dob.toISOString().split('T')[0];
const newPatient = {
chartCode,
name,
mobileNumber,
email, // Include email in patient data
gender,
dob: formattedDob,
age,
relationship,
notes,
};
const updatedPatients = [...patients, newPatient];
setPatients(updatedPatients);
await AsyncStorage.setItem('patients', JSON.stringify(updatedPatients));
Alert.alert('Patient registered successfully!');
resetForm();
};
const resetForm = () => {
setMobileNumber('');
setEmail(''); // Reset email
setOtp(''); // Reset OTP
setName('');
setGender('');
setDob(new Date());
setAge('');
setRelationship('');
setNotes('');
setOtpSent(false); // Reset OTP sent status
};
const generateChartCode = () => {
return Math.random().toString(36).substring(2, 8).toUpperCase();
};
const onDobChange = (event, selectedDate) => {
const currentDate = selectedDate || dob;
setShowDobPicker(Platform.OS === 'ios');
setDob(currentDate);
};
const handleRequestOtp = async () => {
if (!email) {
Alert.alert('Please enter a valid email address.');
return;
}
try {
console.log('Sending OTP to:', email);
const response = await axios.post('http://192.168.29.32:3000/send-otp', { email });
console.log('Response:', response.data);
if (response.data.success) {
setOtpSent(true);
Alert.alert('OTP sent to your email.');
} else {
Alert.alert('Failed to send OTP. Please try again.');
}
} catch (error) {
console.error('Error sending OTP:', error);
Alert.alert('An error occurred. Please try again.');
}
};
const handleVerifyOtp = async () => {
try {
console.log('Verifying OTP for:', email);
const response = await axios.post('http://192.168.29.32:3000/verify-otp', { email, otp });
console.log('Response:', response.data);
if (response.data.success) {
Alert.alert('OTP verified successfully.');
} else {
Alert.alert('Invalid OTP. Please try again.');
}
} catch (error) {
console.error('Error verifying OTP:', error);
Alert.alert('An error occurred. Please try again.');
}
};
const RadioButton = ({ selected, onPress }) => (
<Text style={{ marginLeft: 10, marginRight: 10 }} onPress={onPress}>
{selected ? '◉' : '◯'}
</Text>
);
return (
<ScrollView style={styles.container}>
<Text style={styles.header}>Patient Registration</Text>
<Text style={styles.label}>Patient Mobile Number</Text>
<TextInput
style={styles.input}
keyboardType="numeric"
maxLength={10}
value={mobileNumber}
onChangeText={setMobileNumber}
/>
<Text style={styles.label}>Patient Email</Text>
<TextInput
style={styles.input}
keyboardType="email-address"
value={email}
onChangeText={setEmail}
/>
{!otpSent && (
<View style={styles.buttonContainer}>
<Button title="Request OTP" onPress={handleRequestOtp} color="#FF6F30" />
</View>
)}
{otpSent && (
<>
<Text style={styles.label}>Enter OTP</Text>
<TextInput
style={styles.input}
keyboardType="numeric"
value={otp}
onChangeText={setOtp}
/>
<View style={styles.buttonContainer}>
<Button title="Verify OTP" onPress={handleVerifyOtp} color="#FF6F30" />
</View>
</>
)}
<Text style={styles.label}>Patient Name</Text>
<TextInput
style={styles.input}
value={name}
onChangeText={setName}
/>
<Text style={styles.label}>Patient Gender</Text>
<Picker selectedValue={gender} onValueChange={setGender} style={styles.picker}>
<Picker.Item label="Male" value="male" />
<Picker.Item label="Female" value="female" />
<Picker.Item label="Other" value="other" />
</Picker>
<Text style={styles.label}>Date of Birth or Age</Text>
<View style={styles.radioContainer}>
<Text onPress={() => setUseDOB(true)}>DOB</Text>
<RadioButton selected={useDOB} onPress={() => setUseDOB(true)} />
<Text onPress={() => setUseDOB(false)}>Age</Text>
<RadioButton selected={!useDOB} onPress={() => setUseDOB(false)} />
</View>
{useDOB ? (
<View>
<Text style={styles.label}>Patient DOB</Text>
<Button onPress={() => setShowDobPicker(true)} title="Select Date" />
{showDobPicker && (
<DateTimePicker
value={dob}
mode="date"
display="default"
onChange={onDobChange}
/>
)}
<Text style={styles.dateText}>{dob.toDateString()}</Text>
</View>
) : (
<View>
<Text style={styles.label}>Patient Age</Text>
<TextInput
style={styles.input}
keyboardType="numeric"
maxLength={3}
value={age}
onChangeText={setAge}
/>
</View>
)}
<Text style={styles.label}>Patient Relationship</Text>
<Picker selectedValue={relationship} onValueChange={setRelationship} style={styles.picker}>
<Picker.Item label="Father" value="father" />
<Picker.Item label="Mother" value="mother" />
<Picker.Item label="Brother" value="brother" />
<Picker.Item label="Sister" value="sister" />
<Picker.Item label="Son" value="son" />
<Picker.Item label="Daughter" value="daughter" />
<Picker.Item label="Friend" value="friend" />
</Picker>
<Text style={styles.label}>Notes</Text>
<TextInput
style={styles.input}
multiline
value={notes}
onChangeText={setNotes}
/>
<View style={styles.buttonContainer}>
<Button title="Register" onPress={handleRegister} color="#FF6F30" />
</View>
<View>
{patients.map((patient, index) => (
<View key={index} style={styles.patientCard}>
<Text style={styles.patientText}>Chart Code: {patient.chartCode}</Text>
<Text style={styles.patientText}>Name: {patient.name}</Text>
<Text style={styles.patientText}>Mobile: {patient.mobileNumber}</Text>
<Text style={styles.patientText}>Email: {patient.email}</Text>
<Text style={styles.patientText}>Gender: {patient.gender}</Text>
<Text style={styles.patientText}>DOB: {patient.dob}</Text>
<Text style={styles.patientText}>Age: {patient.age}</Text>
<Text style={styles.patientText}>Relationship: {patient.relationship}</Text>
<Text style={styles.patientText}>Notes: {patient.notes}</Text>
</View>
))}
</View>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 50,
paddingBottom: 50,
paddingLeft: 20,
paddingRight: 20,
backgroundColor: '#FAF3E0',
},
header: {
fontSize: 28,
fontWeight: 'bold',
marginBottom: 20,
textAlign: 'center',
color: '#FF6F30',
},
label: {
fontSize: 15,
marginBottom: 5,
color: '#333',
fontWeight: '600',
},
input: {
borderBottomWidth: 1,
borderBottomColor: '#FF6F30',
marginBottom: 20,
padding: 12,
borderRadius: 8,
backgroundColor: '#FFFFFF',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 2,
elevation: 3,
},
picker: {
marginBottom: 15,
borderColor: '#FF6F30',
borderWidth: 1,
borderRadius: 8,
backgroundColor: '#FFFFFF',
},
radioContainer: {
flexDirection: 'row',
marginBottom: 25,
alignItems: 'center',
},
dateText: {
marginTop: 15,
fontWeight: 'bold',
color: '#333',
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 20,
},
patientCard: {
marginTop: 10,
padding: 15,
borderRadius: 8,
backgroundColor: '#FFE4B5',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.2,
shadowRadius: 1,
elevation: 3,
},
patientText: {
fontSize: 16,
color: '#333',
},
});
export default App;