-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.java
More file actions
53 lines (42 loc) · 1.7 KB
/
Database.java
File metadata and controls
53 lines (42 loc) · 1.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
import java.util.HashMap;
class Database {
private HashMap<Integer, HashMap<String, HashMap<Integer, Patient>>> database;
private HashMap<String, Patient> ICNumbers;
Database() {
this.database = new HashMap<>();
}
Database(int numberOfFloors, int numberOfWards, int numberOfBeds) {
this.database = new HashMap<>();
this.ICNumbers = new HashMap<>();
HashMap<Integer, Patient> beds;
HashMap<String, HashMap<Integer, Patient>> wards;
for (int i = 0; i < numberOfFloors; i++) {
wards = new HashMap<>();
for (int j = 0; j < numberOfWards; j++) {
beds = new HashMap<>();
for (int k = 0; k < numberOfBeds; k++) {
beds.put(k + 1, null);
}
wards.put(Character.toString((char) j + 65), beds);
}
this.database.put(i + 1, wards); //assuming floor starts from 1
}
}
public void addPatient(Patient patient) {
int floor = patient.getFloor();
String ward = patient.getWard();
int bedNumber = patient.getBedNumber();
String patientICNumber = patient.getICNumber();
this.database.get(floor).get(ward).put(bedNumber, patient);
this.ICNumbers.put(patientICNumber, patient);
}
public Patient searchByICNumber(String ICNumber) {
return this.ICNumbers.get(ICNumber);
}
public void addVisitor(Visitor visitor, Patient patient) {
int floor = patient.getFloor();
String ward = patient.getWard();
int bedNumber = patient.getBedNumber();
this.database.get(floor).get(ward).get(bedNumber).addVisitor(visitor);
}
}