-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataFunctions.c
133 lines (109 loc) · 4.42 KB
/
dataFunctions.c
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
#include "./include/dataFunctions.h"
int diseaseFrequency(char* country,char* virus,HashTable* diseaseHashtable,HashTable* countryHashtable,char* FirstDate,char* SecondDate,int entry,int exit){
BucketRecord* record;
int count=0;
if(!findData(diseaseHashtable,virus,&record)){ // find the virus
return -1;
}
if(!strcmp(country,"-")){ // if no country is given
countTreePatients(&count,record->root,FirstDate,SecondDate,entry,exit); // count all the tree of the virus
return count;
}else{
if(!findData(countryHashtable,country,&record)){ // find the country
return -1;
}
countFrequency(virus,&count,record->root,FirstDate,SecondDate,entry,exit);
return count;
}
}
void countTreePatients(int* count,Treenode * root,char* FirstDate,char* SecondDate,int entry,int exit){ // count the patients in the tree
Treenode *temp = root;
Patient* pat = (Patient*) temp->data;
if(exit){
if(temp==guard)
return;
if(strcmp(pat->exitDate,"-") && CompareDates(&(pat->exitDate),&FirstDate)>=0 && CompareDates(&(pat->exitDate),&SecondDate)<=0) // increase the counter between the two dates
(*count)++;
countTreePatients(count,temp->left,FirstDate,SecondDate,entry,exit);
countTreePatients(count,temp->right,FirstDate,SecondDate,entry,exit);
}else{
if(temp==guard)
return;
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0) // increase the counter between the two dates
(*count)++;
countTreePatients(count,temp->left,FirstDate,SecondDate,entry,exit);
countTreePatients(count,temp->right,FirstDate,SecondDate,entry,exit);
}
}
void countFrequency(char* virus,int* count,Treenode * root,char* FirstDate,char* SecondDate,int entry,int exit){ // count patients with this varius
Treenode *temp = root;
Patient* pat = (Patient*) temp->data;
if(exit){
if(temp==guard)
return;
if(strcmp(pat->exitDate,"-") && CompareDates(&(pat->exitDate),&FirstDate)>=0 && CompareDates(&(pat->exitDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,virus))
(*count)++;
}
countFrequency(virus,count,temp->left,FirstDate,SecondDate,entry,exit);
countFrequency(virus,count,temp->right,FirstDate,SecondDate,entry,exit);
}else{
if(temp==guard)
return;
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,virus))
(*count)++;
}
countFrequency(virus,count,temp->left,FirstDate,SecondDate,entry,exit);
countFrequency(virus,count,temp->right,FirstDate,SecondDate,entry,exit);
}
}
int findRange(char* country,char* disease,HashTable* diseaseHashtable,HashTable* countryHashtable,char* FirstDate,char* SecondDate,int range){
BucketRecord* record;
int count=0;
if(!findData(diseaseHashtable,disease,&record)){ // find the virus
return -1;
}
if(!findData(countryHashtable,country,&record)){ // find the country
return -1;
}
countRanges(disease,&count,record->root,FirstDate,SecondDate,range);
return count;
}
void countRanges(char* disease,int* count,Treenode * root,char* FirstDate,char* SecondDate,int range){
Treenode *temp = root;
Patient* pat = (Patient*) temp->data;
if(temp==guard)
return;
if(range == 0){
if(pat->age>=0 && pat->age<= 20){
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,disease))
(*count)++;
}
}
}else if(range == 1){
if(pat->age>=21 && pat->age<= 40){
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,disease))
(*count)++;
}
}
}else if(range == 2){
if(pat->age>=41 && pat->age<= 60){
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,disease))
(*count)++;
}
}
}else if(range == 3){
if(pat->age>=60){
if(CompareDates(&(pat->entryDate),&FirstDate)>=0 && CompareDates(&(pat->entryDate),&SecondDate)<=0){ // increase the counter between the two dates
if(!strcmp(pat->disease,disease))
(*count)++;
}
}
}
countRanges(disease,count,temp->left,FirstDate,SecondDate,range);
countRanges(disease,count,temp->right,FirstDate,SecondDate,range);
}