· 6 years ago · May 18, 2019, 11:26 AM
1package com.inwaiders.imcc.common.medcenter.users.doctor;
2
3import java.io.DataInputStream;
4import java.io.DataOutputStream;
5import java.io.IOException;
6import java.util.HashSet;
7import java.util.List;
8import java.util.Map;
9import java.util.Queue;
10import java.util.Set;
11
12import com.inwaiders.imcc.common.medcenter.MedicineCenter;
13import com.inwaiders.imcc.common.medcenter.users.MedicineCenterStaff;
14import com.inwaiders.imcc.common.utils.DataDriversUtils;
15import com.inwaiders.imcc.server.data.IData;
16import com.inwaiders.imcc.server.data.sql.InsertSql;
17
18public class Doctor extends MedicineCenterStaff{
19
20 private Set<DoctorType> types = null;
21
22 public Doctor() {
23 super();
24
25 this.types = new HashSet<DoctorType>();
26 }
27
28 public Doctor(MedicineCenter mc) {
29 super(mc);
30
31 this.types = new HashSet<DoctorType>();
32 }
33
34 public void setTypes(Set<DoctorType> i) {
35 this.types = i;
36 }
37
38 public Set<DoctorType> getTypes() {
39 return this.types;
40 }
41
42 public static class Driver extends MedicineCenterStaff.Driver{
43
44 @Override
45 public void writeToStream(IData data, DataOutputStream out, List<IData> dependencies) throws IOException {
46 super.writeToStream(data, out, dependencies);
47
48 Doctor doctor = (Doctor)data;
49
50 Set<DoctorType> types = doctor.getTypes();
51
52 out.writeInt(types.size());
53
54 for(DoctorType type : types) {
55 DataDriversUtils.writeIData(type, dependencies);
56 }
57 }
58
59 @Override
60 public void readFromStream(IData data, DataInputStream in, Queue<IData> dependencies) throws IOException {
61 super.readFromStream(data, in, dependencies);
62
63 Doctor doctor = (Doctor)data;
64
65 }
66
67 @Override
68 public Map<String, Object> saveToDataBase(IData data, List<IData> dependencies) {
69
70 Map<String, Object> result = super.saveToDataBase(data, dependencies);
71
72 Doctor doctor = (Doctor)data;
73
74 InsertSql is = new InsertSql();
75
76 ///
77
78 result.putAll(is.getData());
79
80 return result;
81 }
82
83 @Override
84 public void loadFromDataBase(IData data, Map<String, Object> rawData, Queue<IData> dependencies) {
85 super.loadFromDataBase(data, rawData, dependencies);
86
87 Doctor doctor = (Doctor)data;
88 }
89
90 @Override
91 public String getDefaultTableName() {
92
93 return "humans_doctors";
94 }
95
96 @Override
97 public String getSqlCreateTableRequest() {
98 return "CREATE TABLE IF NOT EXISTS `humans_doctors` ("
99 + "id BIGINT(20), PRIMARY KEY(id), "
100 + "first_name TEXT NULL, "
101 + "last_nam TEXT NULL, "
102 + "patronym TEXT NULL, "
103 + "male BIT, "
104 + "dob TEXT NULL, "
105 + "bpl TEXT NULL, "
106 + "main_telephone BIT, "
107 + "sub_telephone BIT, "
108 + "contacts_count SMALLINT, "
109 + "docs_count SMALLINT, "
110 + "roles BIGINT(20), "
111 + "access_level TINYINT, "
112 + "login TEXT, "
113 + "pass_hash_0 BIGINT(20), "
114 + "pass_hash_1 BIGINT(20), "
115 + "system_dependencies TEXT)";
116 }
117
118 @Override
119 public String getDefaultSectorName() {
120
121 return "/humans/staff/doctors";
122 }
123
124 @Override
125 public String getNewFileName(IData data, MedicineCenter mc) {
126
127 return "doctor_"+data.getId()+".dat";
128 }
129
130 @Override
131 public IData getInstance() {
132
133 return new Doctor();
134 }
135 }
136}