-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctor.cpp
129 lines (107 loc) · 3.5 KB
/
doctor.cpp
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
#include "base.h"
#include "doctor.h"
void createNewListDoctor(ListDoctor &L) {
first(L) = nil;
}
doctorAddress allocateDoctor(doctorInfo Elm) {
doctorAddress newElm = new ElmDoctor;
info(newElm) = Elm;
next(newElm) = nil;
relation(newElm) = nil;
return newElm;
}
void insertDoctorLast(ListDoctor &L, doctorAddress P) {
doctorAddress x;
if (isDoctorEmpty(L)) {
first(L) = P;
} else {
x = first(L);
while (next(x) != nil){
x = next(x);
}
next(x) = P;
}
}
void deleteDoctorLast(ListDoctor &L, doctorAddress &P) {
if (isDoctorEmpty(L)) {
cout << "List dokter kosong, tidak ada yang bisa dihapus." << endl;
return;
}
if (next(first(L)) == nil){
P = first(L);
first(L) = nil;
} else {
doctorAddress q;
P = first(L);
while (next(P) != nil){
q = P;
P = next(P);
}
next(q) = nil;
}
}
doctorAddress findDoctor(ListDoctor &L, string doctorName) {
doctorAddress current = first(L);
while (current != nil) {
if (info(current).name == doctorName) {
return current;
}
current = next(current);
}
return nil;
}
bool isDoctorEmpty(ListDoctor L) {
return first(L) == nil;
}
void printListDoctor(ListDoctor L) {
doctorAddress current = first(L);
while (current != nil) {
cout << info(current).name << " " << info(current).speciality << " " << info(current).age << endl;
current = next(current);
}
}
void printListDoctorByPatient(ListDoctor L, string patientName) {
doctorAddress current = first(L);
while (current != nil) {
if (relation(current) != nil) {
if (info(relation(current)).name == patientName) {
cout << info(current).name << " " << info(current).speciality << " " << info(current).age << endl;
}
}
current = next(current);
}
}
void printTotalPatientByDoctor(ListDoctor L, string doctorName) {
doctorAddress currentDoctor = first(L);
int totalPatients = 0;
while (currentDoctor != nil) {
// Periksa apakah nama dokter sesuai
if (info(currentDoctor).name == doctorName) {
// Telusuri daftar perawatan
treatmentAddress currentTreatment = relation(currentDoctor);
// Hitung pasien yang berbeda
while (currentTreatment != nil) {
totalPatients++;
currentTreatment = next(currentTreatment);
}
// Tampilkan total pasien yang ditangani dokter
cout << "Total pasien yang ditangani Dr. " << doctorName << ": " << totalPatients << endl;
return;
}
currentDoctor = next(currentDoctor);
}
// Jika dokter tidak ditemukan
cout << "Dokter " << doctorName << " tidak ditemukan." << endl;
}
void printListDoctorNoPatient(ListDoctor L) {
doctorAddress currentDoctor = first(L);
while (currentDoctor != nil) {
// Periksa apakah dokter tidak memiliki relasi perawatan (pasien)
if (relation(currentDoctor) == nil) {
cout << info(currentDoctor).name << " "
<< info(currentDoctor).speciality << " "
<< info(currentDoctor).age << endl;
}
currentDoctor = next(currentDoctor);
}
}