-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoname.txt
More file actions
403 lines (350 loc) · 15.7 KB
/
Copy pathnoname.txt
File metadata and controls
403 lines (350 loc) · 15.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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import React, { useState, useCallback, useEffect } from "react";
import {
Text, View, ScrollView, StyleSheet,
ActivityIndicator, Pressable, LayoutAnimation, Alert,
} from "react-native";
import axios from "axios";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useFocusEffect, useNavigation } from "@react-navigation/native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
const API = "https://medikidneysys.onrender.com";
const SelectPatient = ({ route }) => {
const navigation = useNavigation();
const alreadySelected = route?.params?.alreadySelected || [];
const [loading, setLoading] = useState(false);
const [shifts, setShifts] = useState([]);
const [activeShift, setActiveShift] = useState(1);
const [selectedIds, setSelectedIds] = useState(alreadySelected);
const [myId, setMyId] = useState(null);
const fetchData = async () => {
try {
setLoading(true);
const token = await AsyncStorage.getItem("token");
const userStr = await AsyncStorage.getItem("user"); // نفترض أن بيانات المستخدم مخزنة هنا
const user = JSON.parse(userStr);
setMyId(user?.id);
const { data } = await axios.get(`${API}/dialysis-scheduling/nurse/today`, {
headers: { Authorization: `Bearer ${token}` },
});
setShifts(data.shifts || []);
if (data.shifts?.length && !activeShift) setActiveShift(data.shifts[0].shiftNumber);
} catch {
Alert.alert("خطأ", "فشل جلب البيانات");
} finally {
setLoading(false);
}
};
useFocusEffect(useCallback(() => {
fetchData();
}, []));
const togglePatient = (patient) => {
// 1. المريض محجوز لممرض آخر
const isTakenByOthers = patient.assignedNurseId !== null && patient.assignedNurseId !== myId;
// 2. الجلسة مكتملة أو بدأت
const isCompleted = patient.sessionStatus === "COMPLETED";
if (isTakenByOthers) {
return Alert.alert("تنبيه", `هذا المريض محجوز للممرض: ${patient.assignedNurseName}`);
}
if (isCompleted) {
return Alert.alert("تنبيه", "هذا المريض أتم جلسته اليوم");
}
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setSelectedIds((prev) =>
prev.includes(patient.patientId)
? prev.filter((id) => id !== patient.patientId)
: [...prev, patient.patientId]
);
};
const handleProceed = () => {
if (!selectedIds.length) return Alert.alert("تنبيه", "اختر مريضاً واحداً على الأقل");
navigation.navigate("PatientState", { selectedPatientIds: selectedIds });
};
const currentShift = shifts.find((s) => s.shiftNumber === activeShift);
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerTitle}>اختيار مرضى الشفت</Text>
<View style={styles.shiftTabs}>
{shifts.map((s) => (
<Pressable
key={s.shiftNumber}
onPress={() => setActiveShift(s.shiftNumber)}
style={[styles.tab, activeShift === s.shiftNumber && styles.activeTab]}
>
<Text style={[styles.tabText, activeShift === s.shiftNumber && styles.activeTabText]}>
شفت {s.shiftNumber}
</Text>
</Pressable>
))}
</View>
</View>
<ScrollView contentContainerStyle={styles.scroll}>
{loading ? <ActivityIndicator size="large" color="#059669" /> :
currentShift?.patients?.map((patient) => {
const isSelected = selectedIds.includes(patient.patientId);
const isTakenByOthers = patient.assignedNurseId !== null && patient.assignedNurseId !== myId;
const isBusy = isTakenByOthers || patient.sessionStatus === "COMPLETED";
return (
<Pressable
key={patient.scheduleId}
onPress={() => togglePatient(patient)}
style={[
styles.card,
isSelected && styles.cardSelected,
isBusy && styles.cardBusy,
]}
>
<MaterialCommunityIcons
name={isTakenByOthers ? "lock-outline" : isSelected ? "checkbox-marked-circle" : "checkbox-blank-circle-outline"}
size={26}
color={isTakenByOthers ? "#ef4444" : isSelected ? "#059669" : "#D1D5DB"}
/>
<View style={styles.info}>
<Text style={[styles.name, isBusy && styles.busyName]}>
{patient.patientName}
</Text>
<Text style={styles.sub}>
{isTakenByOthers ? `مع الممرض: ${patient.assignedNurseName}` : `جهاز: ${patient.machineNumber}`}
</Text>
</View>
</Pressable>
);
})
}
</ScrollView>
{selectedIds.length > 0 && (
<View style={styles.footer}>
<Pressable style={styles.proceedBtn} onPress={handleProceed}>
<Text style={styles.proceedText}>متابعة ({selectedIds.length}) مرضى</Text>
</Pressable>
</View>
)}
</View>
);
};
export default SelectPatient;
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: "#F9FAFB" },
header: {
backgroundColor: "#065f46",
paddingTop: 55,
paddingBottom: 20,
paddingHorizontal: 20,
borderBottomLeftRadius: 28,
borderBottomRightRadius: 28,
},
headerTitle: {
fontSize: 20, fontWeight: "800", color: "#fff",
textAlign: "center", marginBottom: 16,
},
shiftTabs: {
flexDirection: "row-reverse", justifyContent: "center",
gap: 10, backgroundColor: "rgba(255,255,255,0.15)",
borderRadius: 14, padding: 5,
},
tab: { paddingVertical: 8, paddingHorizontal: 18, borderRadius: 10 },
activeTab: { backgroundColor: "#fff" },
tabText: { color: "#A7F3D0", fontWeight: "600" },
activeTabText: { color: "#065f46", fontWeight: "800" },
scroll: { padding: 16, paddingBottom: 110 },
card: {
backgroundColor: "#fff", borderRadius: 16, padding: 16,
marginBottom: 10, borderWidth: 1.5, borderColor: "#F3F4F6",
elevation: 2, flexDirection: "row-reverse", alignItems: "center", gap: 12,
},
cardSelected: { borderColor: "#059669", backgroundColor: "#F0FDF4" },
cardBusy: { backgroundColor: "#f8fafc", borderColor: "#e2e8f0", opacity: 0.65 },
info: { flex: 1 },
name: { fontSize: 16, fontWeight: "700", color: "#1F2937", textAlign: "right" },
busyName: { color: "#94a3b8" },
sub: { fontSize: 13, color: "#6B7280", textAlign: "right", marginTop: 3 },
checkBadge: {
width: 26, height: 26, borderRadius: 13,
backgroundColor: "#059669", alignItems: "center", justifyContent: "center",
},
checkText: { color: "#fff", fontWeight: "800", fontSize: 13 },
footer: {
position: "absolute", bottom: 0, left: 0, right: 0,
padding: 16, paddingBottom: 24, backgroundColor: "#fff",
borderTopLeftRadius: 20, borderTopRightRadius: 20,
shadowColor: "#000", shadowOffset: { width: 0, height: -3 },
shadowOpacity: 0.07, shadowRadius: 8, elevation: 10,
},
proceedBtn: {
backgroundColor: "#059669", padding: 16,
borderRadius: 14, alignItems: "center",
},
proceedText: { color: "#fff", fontWeight: "800", fontSize: 16 },
});
import React, { useState, useCallback } from "react";
import {
View, Text, StyleSheet, ScrollView, Pressable,
ActivityIndicator, RefreshControl, Alert
} from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import axios from "axios";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { useFocusEffect, useNavigation } from "@react-navigation/native";
const PatientState = ({ route }) => {
const navigation = useNavigation();
const { selectedPatientIds } = route.params || { selectedPatientIds: [] };
const [loading, setLoading] = useState(false);
const [myPatients, setMyPatients] = useState([]);
const [refreshing, setRefreshing] = useState(false);
// دالة جلب البيانات وتحديث حالة المرضى المتابعين
const fetchStatus = async () => {
try {
setLoading(true);
const token = await AsyncStorage.getItem("token");
const response = await axios.get(
"https://medikidneysys.onrender.com/dialysis-scheduling/nurse/today",
{ headers: { Authorization: `Bearer ${token}` } }
);
const allShifts = response.data.shifts || [];
// فلترة المرضى بناءً على الـ IDs التي اخترناها في الصفحة السابقة
const filtered = allShifts
.flatMap(shift => shift.patients)
.filter(p => selectedPatientIds.includes(p.patientId));
setMyPatients(filtered);
} catch (error) {
console.error("Fetch Error:", error);
} finally {
setLoading(false);
setRefreshing(false);
}
};
useFocusEffect(
useCallback(() => {
fetchStatus();
}, [selectedPatientIds])
);
// دالة لبدء الجلسة إذا كانت null (تحديث الحالة إلى IN_PROGRESS)
const handleStartSession = async (patient) => {
try {
setLoading(true);
const token = await AsyncStorage.getItem("token");
let sid = patient.sessionId;
// إذا كان الـ sessionId غير موجود (null)، ننشئ الجلسة بـ POST
if (!sid) {
const createRes = await axios.post(
"https://medikidneysys.onrender.com/dialysis-sessions",
{
patientId: patient.patientId,
scheduleId: patient.scheduleId,
date: new Date().toISOString(),
startTime: new Date().toISOString(),
status: "PENDING",
weightBefore: 0,
bloodPressureBefore: "0/0"
},
{ headers: { Authorization: `Bearer ${token}` } }
);
sid = createRes.data.sessionId || createRes.data.id;
}
// الآن نحدث الحالة إلى قيد العمل (IN_PROGRESS)
await axios.patch(
`https://medikidneysys.onrender.com/dialysis-sessions/${sid}/status`,
{ status: "IN_PROGRESS" },
{ headers: { Authorization: `Bearer ${token}` } }
);
Alert.alert("نجاح", "تم بدء الجلسة وتحويلها إلى قيد الغسيل");
fetchStatus();
} catch (error) {
console.log("Error Details:", error.response?.data);
Alert.alert("خطأ", "فشل بدء الجلسة");
} finally {
setLoading(false);
}
};
const getStatusInfo = (status) => {
switch (status) {
case "COMPLETED": return { label: "مكتمل", color: "#059669", icon: "check-circle" };
case "IN_PROGRESS": return { label: "قيد الغسيل", color: "#2563eb", icon: "sync" };
case "PENDING": return { label: "بانتظار البيانات", color: "#d97706", icon: "clock-outline" };
default: return { label: "لم تبدأ بعد", color: "#6b7280", icon: "play-circle-outline" };
}
};
return (
<View style={styles.container}>
{/* Header */}
<View style={styles.mainHeader}>
<View style={styles.headerTop}>
<Pressable onPress={() => navigation.navigate("NurseHome")} style={styles.headerIcon}>
<MaterialCommunityIcons name="home-variant-outline" size={26} color="#065f46" />
</Pressable>
<Text style={styles.mainTitle}>مرضاي ({myPatients.length})</Text>
<Pressable onPress={() => navigation.navigate("SelectPatient", { alreadySelected: selectedPatientIds })} style={styles.headerIcon}>
<MaterialCommunityIcons name="account-edit-outline" size={26} color="#065f46" />
</Pressable>
</View>
</View>
<ScrollView
contentContainerStyle={styles.scroll}
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={fetchStatus} />}
>
{loading && !refreshing ? (
<ActivityIndicator size="large" color="#059669" style={{ marginTop: 50 }} />
) : myPatients.map((patient) => {
const statusInfo = getStatusInfo(patient.sessionStatus);
const hasActiveSession = patient.sessionId !== null;
return (
<View key={patient.scheduleId} style={styles.patientCard}>
<View style={styles.cardHeader}>
<View style={[styles.statusBadge, { backgroundColor: statusInfo.color + '15' }]}>
<MaterialCommunityIcons name={statusInfo.icon} size={16} color={statusInfo.color} />
<Text style={[styles.statusText, { color: statusInfo.color }]}>{statusInfo.label}</Text>
</View>
<Text style={styles.machineText}>جهاز #{patient.machineNumber}</Text>
</View>
<Text style={styles.patientName}>{patient.patientName}</Text>
<View style={styles.cardFooter}>
{hasActiveSession ? (
<Pressable
style={styles.actionBtn}
onPress={() => navigation.navigate("SessionDetails", { patient: patient })}
>
<Text style={styles.actionBtnText}>إدخال البيانات الحيوية</Text>
<MaterialCommunityIcons name="chevron-left" size={20} color="#fff" />
</Pressable>
) : (
<Pressable
style={[styles.actionBtn, { backgroundColor: '#d97706' }]}
onPress={() => handleStartSession(patient)}
>
<Text style={styles.actionBtnText}>بدء جلسة غسيل الآن</Text>
<MaterialCommunityIcons name="play" size={20} color="#fff" />
</Pressable>
)}
</View>
</View>
);
})}
{myPatients.length === 0 && !loading && (
<View style={styles.empty}>
<MaterialCommunityIcons name="account-search-outline" size={60} color="#D1D5DB" />
<Text style={{color: '#9CA3AF', marginTop: 10}}>لم يتم اختيار مرضى للمتابعة</Text>
</View>
)}
</ScrollView>
</View>
);
};
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: "#F3F4F6" },
mainHeader: { backgroundColor: "#fff", paddingTop: 50, paddingBottom: 15, paddingHorizontal: 20, borderBottomWidth: 1, borderBottomColor: '#E5E7EB' },
headerTop: { flexDirection: 'row-reverse', justifyContent: 'space-between', alignItems: 'center' },
mainTitle: { fontSize: 18, fontWeight: 'bold', color: '#111827' },
headerIcon: { padding: 8, backgroundColor: '#ECFDF5', borderRadius: 12 },
scroll: { padding: 16 },
patientCard: { backgroundColor: "#fff", borderRadius: 15, padding: 16, marginBottom: 12, elevation: 2, borderRightWidth: 5, borderRightColor: '#059669' },
cardHeader: { flexDirection: 'row-reverse', justifyContent: 'space-between', marginBottom: 10 },
statusBadge: { flexDirection: 'row-reverse', alignItems: 'center', paddingHorizontal: 10, paddingVertical: 4, borderRadius: 20 },
statusText: { fontSize: 12, fontWeight: 'bold', marginRight: 5 },
machineText: { color: '#6B7280', fontSize: 12 },
patientName: { fontSize: 18, fontWeight: 'bold', color: '#1F2937', textAlign: 'right' },
cardFooter: { marginTop: 15, borderTopWidth: 1, borderTopColor: '#F3F4F6', paddingTop: 10 },
actionBtn: { backgroundColor: "#059669", flexDirection: 'row-reverse', justifyContent: 'center', alignItems: 'center', padding: 12, borderRadius: 10 },
actionBtnText: { color: "#fff", fontWeight: "bold", fontSize: 14, marginLeft: 8 },
empty: { alignItems: 'center', marginTop: 80 }
});
export default PatientState;