|
@@ -1,9 +1,522 @@
|
1
|
1
|
package service
|
2
|
2
|
|
3
|
|
-import "XT_New/models"
|
|
3
|
+import (
|
|
4
|
+ "XT_New/models"
|
|
5
|
+ "fmt"
|
|
6
|
+ "github.com/jinzhu/gorm"
|
|
7
|
+ "strconv"
|
|
8
|
+ "strings"
|
|
9
|
+ "time"
|
|
10
|
+)
|
4
|
11
|
|
5
|
|
-func GetBloodDialysisPatient(orgid int64) (paitents []*models.Patients, err error) {
|
|
12
|
+func GetIllnessListTwo() (ills []*models.Illness, err error) {
|
|
13
|
+ err = readUserDb.Where("status=1").Find(&ills).Error
|
|
14
|
+ return
|
|
15
|
+}
|
|
16
|
+
|
|
17
|
+func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
|
|
18
|
+ db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
|
|
19
|
+ if orgid > 0 {
|
|
20
|
+ db = db.Where("x.user_org_id = ?", orgid)
|
|
21
|
+ }
|
|
22
|
+ offset := (page - 1) * limit
|
|
23
|
+ err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
|
|
24
|
+ Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
|
|
25
|
+ fmt.Println("err是什么", err)
|
|
26
|
+ return
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+func GetAllBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
|
|
30
|
+ db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
|
|
31
|
+ if orgid > 0 {
|
|
32
|
+ db = db.Where("x.user_org_id = ? and x.blood_patients = 1", orgid)
|
|
33
|
+ }
|
|
34
|
+ offset := (page - 1) * limit
|
|
35
|
+ err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
|
|
36
|
+ Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
|
|
37
|
+ fmt.Println("err是什么", err)
|
|
38
|
+ return
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+func GetAllSlowPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
|
|
42
|
+ db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
|
|
43
|
+ if orgid > 0 {
|
|
44
|
+ db = db.Where("x.user_org_id = ? and x.slow_patients = 1", orgid)
|
|
45
|
+ }
|
|
46
|
+ offset := (page - 1) * limit
|
|
47
|
+ err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
|
|
48
|
+ Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
|
|
49
|
+ fmt.Println("err是什么", err)
|
|
50
|
+ return
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+func GetAllMemberPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
|
|
54
|
+ db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
|
|
55
|
+ if orgid > 0 {
|
|
56
|
+ db = db.Where("x.user_org_id = ? and x.member_patients = 1", orgid)
|
|
57
|
+ }
|
|
58
|
+ offset := (page - 1) * limit
|
|
59
|
+ err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
|
|
60
|
+ Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
|
|
61
|
+ fmt.Println("err是什么", err)
|
|
62
|
+ return
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+func GetAllPatient(orgid int64) (patients []*models.PatientsNew, err error) {
|
|
66
|
+ db := XTReadDB().Table("xt_patients_new as x")
|
|
67
|
+
|
|
68
|
+ err = db.Raw("select id,name from xt_patients_new where user_org_id = ? and status =1", orgid).Scan(&patients).Error
|
|
69
|
+ return
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+func ChechLastDialysisNoTwo(orgID int64) (dialysisNo int64) {
|
|
73
|
+ var patient models.Patients
|
|
74
|
+ err := readDb.Model(&models.Patients{}).Where("user_org_id=? and status = 1", orgID).Order("dialysis_no desc").First(&patient).Error
|
|
75
|
+ if err != nil {
|
|
76
|
+ return
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ if patient.ID == 0 {
|
|
80
|
+ return
|
|
81
|
+ }
|
|
82
|
+ dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
|
|
83
|
+ return
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+func GetBloodPatientInfo(orgid int64, phone string) (*models.Patients, error) {
|
|
87
|
+ patients := models.Patients{}
|
|
88
|
+ var err error
|
|
89
|
+ err = XTReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
|
|
90
|
+ if err == gorm.ErrRecordNotFound {
|
|
91
|
+ return nil, err
|
|
92
|
+ }
|
|
93
|
+ if err != nil {
|
|
94
|
+ return nil, err
|
|
95
|
+ }
|
|
96
|
+ return &patients, nil
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+func GetSlowPatientInfo(orgid int64, phone string) (*models.CdmPatients, error) {
|
|
100
|
+ patients := models.CdmPatients{}
|
|
101
|
+ var err error
|
|
102
|
+ err = PatientReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
|
|
103
|
+ if err == gorm.ErrRecordNotFound {
|
|
104
|
+ return nil, err
|
|
105
|
+ }
|
|
106
|
+ if err != nil {
|
|
107
|
+ return nil, err
|
|
108
|
+ }
|
|
109
|
+ return &patients, nil
|
|
110
|
+}
|
|
111
|
+
|
|
112
|
+func GetMemberPatientInfo(orgid int64, phone string) (*models.SgjUserCustomer, error) {
|
|
113
|
+ customer := models.SgjUserCustomer{}
|
|
114
|
+ err := UserReadDB().Model(&customer).Where("user_org_id = ? and mobile = ? and status =1", orgid, phone).Find(&customer).Error
|
|
115
|
+ if err == gorm.ErrRecordNotFound {
|
|
116
|
+ return nil, err
|
|
117
|
+ }
|
|
118
|
+ if err != nil {
|
|
119
|
+ return nil, err
|
|
120
|
+ }
|
|
121
|
+ return &customer, nil
|
|
122
|
+}
|
|
123
|
+
|
|
124
|
+func CreateOldPatient(patients *models.Patients) error {
|
|
125
|
+
|
|
126
|
+ err := XTWriteDB().Create(&patients).Error
|
|
127
|
+ return err
|
|
128
|
+}
|
|
129
|
+
|
|
130
|
+func GetLastOldPatient(orgid int64) (models.Patients, error) {
|
|
131
|
+ patients := models.Patients{}
|
|
132
|
+ err := XTReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
|
|
133
|
+ return patients, err
|
|
134
|
+}
|
|
135
|
+
|
|
136
|
+func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
|
|
137
|
+ utx := writeDb.Begin()
|
|
138
|
+ if len(contagions) > 0 {
|
|
139
|
+ thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
|
|
140
|
+ insertParams := make([]string, 0)
|
|
141
|
+ insertData := make([]interface{}, 0)
|
|
142
|
+ for _, contagion := range contagions {
|
|
143
|
+ insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
|
|
144
|
+ insertData = append(insertData, patienid)
|
|
145
|
+ insertData = append(insertData, contagion)
|
|
146
|
+ insertData = append(insertData, 1)
|
|
147
|
+ insertData = append(insertData, createdtime)
|
|
148
|
+ insertData = append(insertData, updatedtime)
|
|
149
|
+ }
|
|
150
|
+ thisSQL += strings.Join(insertParams, ",")
|
|
151
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
152
|
+ fmt.Println("这个错误err", err)
|
|
153
|
+ }
|
|
154
|
+ utx.Commit()
|
|
155
|
+ return
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+func AddSlowContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64, orgid int64) (err error) {
|
|
159
|
+ utx := PatientWriteDB().Begin()
|
|
160
|
+ if len(contagions) > 0 {
|
|
161
|
+ thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
|
|
162
|
+ insertParams := make([]string, 0)
|
|
163
|
+ insertData := make([]interface{}, 0)
|
|
164
|
+ for _, contagion := range contagions {
|
|
165
|
+ insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
|
|
166
|
+ insertData = append(insertData, patienid)
|
|
167
|
+ insertData = append(insertData, contagion)
|
|
168
|
+ insertData = append(insertData, 1)
|
|
169
|
+ insertData = append(insertData, createdtime)
|
|
170
|
+ insertData = append(insertData, updatedtime)
|
|
171
|
+ insertData = append(insertData, orgid)
|
|
172
|
+ }
|
|
173
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
174
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
175
|
+ if err != nil {
|
|
176
|
+ utx.Rollback()
|
|
177
|
+ utx.Rollback()
|
|
178
|
+ return
|
|
179
|
+ }
|
|
180
|
+ }
|
|
181
|
+ utx.Commit()
|
|
182
|
+ return
|
|
183
|
+}
|
|
184
|
+
|
|
185
|
+func AddSlowDiseases(patienid int64, createdtime int64, updatedtime int64, diseases []int64, orgid int64) (err error) {
|
|
186
|
+ utx := PatientWriteDB().Begin()
|
|
187
|
+ if len(diseases) > 0 {
|
|
188
|
+ thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
|
|
189
|
+ insertParams := make([]string, 0)
|
|
190
|
+ insertData := make([]interface{}, 0)
|
|
191
|
+ for _, disease := range diseases {
|
|
192
|
+ insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
|
|
193
|
+ insertData = append(insertData, patienid)
|
|
194
|
+ insertData = append(insertData, disease)
|
|
195
|
+ insertData = append(insertData, 1)
|
|
196
|
+ insertData = append(insertData, createdtime)
|
|
197
|
+ insertData = append(insertData, updatedtime)
|
|
198
|
+ insertData = append(insertData, orgid)
|
|
199
|
+ }
|
|
200
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
201
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
202
|
+ if err != nil {
|
|
203
|
+ utx.Rollback()
|
|
204
|
+ return
|
|
205
|
+ }
|
|
206
|
+ }
|
|
207
|
+ utx.Commit()
|
|
208
|
+ return
|
|
209
|
+}
|
|
210
|
+
|
|
211
|
+func CreateNewPatient(patientsNew *models.XtPatientsNew) error {
|
|
212
|
+ err := XTWriteDB().Create(&patientsNew).Error
|
|
213
|
+ return err
|
|
214
|
+}
|
|
215
|
+
|
|
216
|
+func CreateCdmPatient(cdmpatient *models.CdmPatients) error {
|
|
217
|
+ err := PatientWriteDB().Create(&cdmpatient).Error
|
|
218
|
+ return err
|
|
219
|
+}
|
|
220
|
+
|
|
221
|
+func CreateMemberPatient(customer *models.SgjUserCustomer) error {
|
|
222
|
+
|
|
223
|
+ err := UserWriteDB().Create(&customer).Error
|
|
224
|
+ return err
|
|
225
|
+}
|
|
226
|
+
|
|
227
|
+func GetOldCdmPatient(orgid int64) (models.CdmPatients, error) {
|
|
228
|
+ patients := models.CdmPatients{}
|
|
229
|
+ err := XTReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
|
|
230
|
+ return patients, err
|
|
231
|
+}
|
|
232
|
+
|
|
233
|
+func GetPatientDetailTwo(id int64) (models.XtPatientsNew, error) {
|
|
234
|
+ patients := models.XtPatientsNew{}
|
|
235
|
+ err := XTReadDB().Where("id=? and status = 1", id).Find(&patients).Error
|
|
236
|
+ return patients, err
|
|
237
|
+}
|
|
238
|
+
|
|
239
|
+func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
|
|
240
|
+
|
|
241
|
+ user, _ := GetSgjUserByMobild(patient.Phone)
|
|
242
|
+ customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
|
|
243
|
+
|
|
244
|
+ utx := writeDb.Begin()
|
|
245
|
+ btx := writeUserDb.Begin()
|
|
246
|
+
|
|
247
|
+ if user.ID == 0 {
|
|
248
|
+
|
|
249
|
+ user.Mobile = patient.Phone
|
|
250
|
+ user.Avatar = patient.Avatar
|
|
251
|
+ user.AvatarThumb = patient.Avatar
|
|
252
|
+ user.Birthday = patient.Birthday
|
|
253
|
+ user.Username = patient.Name
|
|
254
|
+ user.Gender = patient.Gender
|
|
255
|
+ user.Sources = 11
|
|
256
|
+ user.Introduce = patient.Remark
|
|
257
|
+ user.Status = 1
|
|
258
|
+ user.UpdatedTime = patient.UpdatedTime
|
|
259
|
+ user.CreatedTime = patient.CreatedTime
|
|
260
|
+ err = btx.Create(&user).Error
|
|
261
|
+ if err != nil {
|
|
262
|
+ utx.Rollback()
|
|
263
|
+ btx.Rollback()
|
|
264
|
+ return
|
|
265
|
+ }
|
|
266
|
+ }
|
|
267
|
+ patient.UserId = user.ID
|
|
268
|
+
|
|
269
|
+ if customer == nil {
|
|
270
|
+ err = btx.Create(&models.SgjCustomer{
|
|
271
|
+ UserOrgId: patient.UserOrgId,
|
|
272
|
+ UserId: user.ID,
|
|
273
|
+ Mobile: patient.Phone,
|
|
274
|
+ Name: patient.Name,
|
|
275
|
+ Gender: patient.Gender,
|
|
276
|
+ Birthday: patient.Birthday,
|
|
277
|
+ Sources: 11,
|
|
278
|
+ Status: 1,
|
|
279
|
+ CreatedTime: patient.CreatedTime,
|
|
280
|
+ UpdatedTime: patient.UpdatedTime,
|
|
281
|
+ Avatar: patient.Avatar,
|
|
282
|
+ Remark: patient.Remark,
|
|
283
|
+ }).Error
|
|
284
|
+ if err != nil {
|
|
285
|
+ utx.Rollback()
|
|
286
|
+ btx.Rollback()
|
|
287
|
+ return
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ err = utx.Create(patient).Error
|
|
292
|
+ if err != nil {
|
|
293
|
+ utx.Rollback()
|
|
294
|
+ btx.Rollback()
|
|
295
|
+ return
|
|
296
|
+ }
|
|
297
|
+
|
|
298
|
+ var lapseto models.PatientLapseto
|
|
299
|
+ lapseto.PatientId = patient.ID
|
|
300
|
+ lapseto.LapsetoType = patient.Lapseto
|
|
301
|
+ lapseto.CreatedTime = patient.CreatedTime
|
|
302
|
+ lapseto.UpdatedTime = patient.CreatedTime
|
|
303
|
+ lapseto.Status = 1
|
|
304
|
+ lapseto.LapsetoTime = patient.CreatedTime
|
|
305
|
+
|
|
306
|
+ err = utx.Create(&lapseto).Error
|
|
307
|
+ if err != nil {
|
|
308
|
+ utx.Rollback()
|
|
309
|
+ btx.Rollback()
|
|
310
|
+ return
|
|
311
|
+ }
|
|
312
|
+
|
|
313
|
+ if len(contagions) > 0 {
|
|
314
|
+ thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
|
|
315
|
+ insertParams := make([]string, 0)
|
|
316
|
+ insertData := make([]interface{}, 0)
|
|
317
|
+ for _, contagion := range contagions {
|
|
318
|
+ insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
|
|
319
|
+ insertData = append(insertData, patient.ID)
|
|
320
|
+ insertData = append(insertData, contagion)
|
|
321
|
+ insertData = append(insertData, 1)
|
|
322
|
+ insertData = append(insertData, patient.CreatedTime)
|
|
323
|
+ insertData = append(insertData, patient.UpdatedTime)
|
|
324
|
+ }
|
|
325
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
326
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
327
|
+ if err != nil {
|
|
328
|
+ utx.Rollback()
|
|
329
|
+ btx.Rollback()
|
|
330
|
+ return
|
|
331
|
+ }
|
|
332
|
+ }
|
|
333
|
+ if len(diseases) > 0 {
|
|
334
|
+ thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
|
|
335
|
+ insertParams := make([]string, 0)
|
|
336
|
+ insertData := make([]interface{}, 0)
|
|
337
|
+ for _, disease := range diseases {
|
|
338
|
+ insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
|
|
339
|
+ insertData = append(insertData, patient.ID)
|
|
340
|
+ insertData = append(insertData, disease)
|
|
341
|
+ insertData = append(insertData, 1)
|
|
342
|
+ insertData = append(insertData, patient.CreatedTime)
|
|
343
|
+ insertData = append(insertData, patient.UpdatedTime)
|
|
344
|
+ }
|
|
345
|
+ thisSQL += strings.Join(insertParams, ", ")
|
|
346
|
+ err = utx.Exec(thisSQL, insertData...).Error
|
|
347
|
+ if err != nil {
|
|
348
|
+ utx.Rollback()
|
|
349
|
+ btx.Rollback()
|
|
350
|
+ return
|
|
351
|
+ }
|
|
352
|
+ }
|
|
353
|
+ utx.Commit()
|
|
354
|
+ btx.Commit()
|
|
355
|
+
|
|
356
|
+ return
|
|
357
|
+}
|
|
358
|
+
|
|
359
|
+func GetPatientData(phone string, orgid int64) (*models.XtPatientsNew, error) {
|
|
360
|
+ var patientnew models.XtPatientsNew
|
|
361
|
+ var err error
|
|
362
|
+ err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status =? and blood_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
|
|
363
|
+ if err == gorm.ErrRecordNotFound {
|
|
364
|
+ return nil, err
|
|
365
|
+ }
|
|
366
|
+ if err != nil {
|
|
367
|
+ return nil, err
|
|
368
|
+ }
|
|
369
|
+ return &patientnew, nil
|
|
370
|
+}
|
|
371
|
+
|
|
372
|
+func GetSlowPatientData(phone string, orgid int64) (*models.CdmPatients, error) {
|
|
373
|
+ var patientnew models.CdmPatients
|
|
374
|
+ err = PatientReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ?", orgid, phone, 1).Find(&patientnew).Error
|
|
375
|
+ if err == gorm.ErrRecordNotFound {
|
|
376
|
+ return nil, err
|
|
377
|
+ }
|
|
378
|
+ if err != nil {
|
|
379
|
+ return nil, err
|
|
380
|
+ }
|
|
381
|
+ return &patientnew, nil
|
|
382
|
+}
|
|
383
|
+
|
|
384
|
+func GetMemberNewPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
|
|
385
|
+ var patientnew models.XtPatientsNew
|
|
386
|
+ err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and member_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
|
|
387
|
+ if err == gorm.ErrRecordNotFound {
|
|
388
|
+ return nil, err
|
|
389
|
+ }
|
|
390
|
+ if err != nil {
|
|
391
|
+ return nil, err
|
|
392
|
+ }
|
|
393
|
+ return &patientnew, nil
|
|
394
|
+}
|
|
395
|
+
|
|
396
|
+func GetLastNewSlowPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
|
|
397
|
+ var patientnew models.XtPatientsNew
|
|
398
|
+ err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and slow_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
|
|
399
|
+ if err == gorm.ErrRecordNotFound {
|
|
400
|
+ return nil, err
|
|
401
|
+ }
|
|
402
|
+ if err != nil {
|
|
403
|
+ return nil, err
|
|
404
|
+ }
|
|
405
|
+ return &patientnew, nil
|
|
406
|
+}
|
|
407
|
+
|
|
408
|
+func GetNewDoctorAdvice(patientid int64, doctype int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
|
|
409
|
+ db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1")
|
|
410
|
+ if orgId > 0 {
|
|
411
|
+ db = db.Where("x.user_org_id = ?", orgId)
|
|
412
|
+ }
|
|
413
|
+
|
|
414
|
+ if patientid > 0 {
|
|
415
|
+ db = db.Where("x.patient_id = ?", patientid)
|
|
416
|
+ }
|
|
417
|
+ if startime != 0 {
|
|
418
|
+ db = db.Where("x.record_date>= ?", startime)
|
|
419
|
+ }
|
|
420
|
+ if endtime != 0 {
|
|
421
|
+ db = db.Where("x.record_date<=?", endtime)
|
|
422
|
+ }
|
|
423
|
+
|
|
424
|
+ if doctype > 0 {
|
|
425
|
+ db = db.Where("x.advice_type = ?", doctype)
|
|
426
|
+ }
|
|
427
|
+ offset := (page - 1) * limit
|
|
428
|
+ err = db.Count(&total).Order("x.record_date desc").Offset(offset).Limit(limit).Group("x.id").Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&doctoradvice).Error
|
|
429
|
+ return
|
|
430
|
+}
|
|
431
|
+
|
|
432
|
+func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
|
|
433
|
+ db := XTReadDB().Table("xt_patient_dryweight as x").Where("x.status = 1")
|
|
434
|
+ if orgId > 0 {
|
|
435
|
+ db = db.Where("x.user_org_id = ?", orgId)
|
|
436
|
+ }
|
|
437
|
+ if patientid > 0 {
|
|
438
|
+ db = db.Where("x.patient_id = ?", patientid)
|
|
439
|
+ }
|
|
440
|
+ if startime > 0 {
|
|
441
|
+ db = db.Where("x.ctime >= ?", startime)
|
|
442
|
+ }
|
|
443
|
+ if endtime > 0 {
|
|
444
|
+ db = db.Where("x.ctime <=?", endtime)
|
|
445
|
+ }
|
|
446
|
+ offset := (page - 1) * limit
|
|
447
|
+ err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
|
|
448
|
+ Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.ctime,x.adjusted_value,x.user_id,x.user_org_id,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creator").Scan(&dryWeight).Error
|
|
449
|
+ return dryWeight, total, err
|
|
450
|
+}
|
|
451
|
+
|
|
452
|
+func ToSearch(orgId int64, name string) (patient []*models.XtPatientsNew, err error) {
|
|
453
|
+ likeKey := "%" + name + "%"
|
|
454
|
+ err = XTReadDB().Where("name like ? and user_org_id = ?", likeKey, orgId).Find(&patient).Error
|
|
455
|
+ return patient, err
|
|
456
|
+}
|
|
457
|
+
|
|
458
|
+func GetCourseManagement(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (patientCourse []*models.PatientCourseOfDiseases, total int64, err error) {
|
|
459
|
+ db := XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
|
|
460
|
+ if patientid > 0 {
|
|
461
|
+ db = db.Where("x.patient_id = ?", patientid)
|
|
462
|
+ }
|
|
463
|
+ if orgid > 0 {
|
|
464
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
465
|
+ }
|
|
466
|
+ if startime > 0 {
|
|
467
|
+ db = db.Where("x.record_time >=?", startime)
|
|
468
|
+ }
|
|
469
|
+ if endtime > 0 {
|
|
470
|
+ db = db.Where("x.record_time <= ?", endtime)
|
|
471
|
+ }
|
|
472
|
+ offset := (page - 1) * limit
|
|
473
|
+ err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
|
|
474
|
+ Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Scan(&patientCourse).Error
|
|
475
|
+ return patientCourse, total, err
|
|
476
|
+}
|
|
477
|
+
|
|
478
|
+func DeleteCouseManagement(patientid int64) error {
|
|
479
|
+
|
|
480
|
+ err := XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ?", patientid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
481
|
+ return err
|
|
482
|
+}
|
|
483
|
+
|
|
484
|
+func GetCouseManagentDetail(id int64) (models.PatientCourseOfDiseasess, error) {
|
|
485
|
+ disease := models.PatientCourseOfDiseasess{}
|
|
486
|
+ db := XTReadDB().Table("xt_patient_course_of_disease as x")
|
|
487
|
+ err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id ").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Where("x.id = ?", id).Scan(&disease).Error
|
|
488
|
+ return disease, err
|
|
489
|
+}
|
|
490
|
+
|
|
491
|
+func DeleteDryWeight(id int64) error {
|
|
492
|
+ err := XTWriteDB().Model(models.SgjPatientDryweight{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
493
|
+ return err
|
|
494
|
+}
|
|
495
|
+
|
|
496
|
+func GetDryWeightDetail(id int64) (models.SgjPatientDryweights, error) {
|
|
497
|
+ dryweight := models.SgjPatientDryweights{}
|
|
498
|
+ db := XTReadDB().Table("xt_patient_dryweight as x")
|
|
499
|
+ err := db.Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.adjusted_value,x.user_org_id,x.user_id,x.ctime,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.user_id").Where("x.id = ?", id).Scan(&dryweight).Error
|
|
500
|
+ return dryweight, err
|
|
501
|
+}
|
|
502
|
+
|
|
503
|
+func GetlongDialysisrecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (prescription []*models.XtDialysisSolution, total int64, err error) {
|
|
504
|
+ db := XTReadDB().Table("xt_dialysis_solution as x").Where("x.status = 1")
|
|
505
|
+ if patientid > 0 {
|
|
506
|
+ db = db.Where("x.patient_id = ?", patientid)
|
|
507
|
+ }
|
|
508
|
+ if orgid > 0 {
|
|
509
|
+ db = db.Where("x.user_org_id = ?", orgid)
|
|
510
|
+ }
|
|
511
|
+ if startime > 0 {
|
|
512
|
+ db = db.Where("x.created_time >=?", startime)
|
|
513
|
+ }
|
|
514
|
+ if endtime > 0 {
|
|
515
|
+ db = db.Where("x.created_time <= ?", endtime)
|
|
516
|
+ }
|
|
517
|
+ offset := (page - 1) * limit
|
|
518
|
+ err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).Group("x.id").
|
|
519
|
+ Select("x.id,x.name,x.sub_name,x.user_org_id,x.patient_id,x.parent_id,x.type,x.period,x.times,x.anticoagulant,x.anticoagulant_shouji,x.anticoagulant_weichi,x.anticoagulant_zongliang,x.anticoagulant_gaimingcheng,x.anticoagulant_gaijiliang,x.mode_name,x.mode_id,x.dialysis_duration,x.replacement_way,x.hemodialysis_machine,x.blood_filter,x.perfusion_apparatus,x.blood_flow_volume,x.dewater,x.displace_liqui,x.glucose,x.dry_weight,x.dialysate_flow,x.kalium,x.sodium,x.calcium,x.bicarbonate,x.doctor,x.first_dialysis,x.remark,x.initiate_mode,x.affirm_state,x.use_state,x.status,x.registrars_id,x.created_time,x.updated_time,x.solution_type,x.dialysate_temperature,x.conductivity,x.dialysis_duration_hour,x.dialysis_duration_minute,x.target_ultrafiltration,x.dialysate_formulation,x.dialyzer,x.replacement_total,x.dialyzer_perfusion_apparatus,x.body_fluid,x.special_medicine,x.special_medicine_other,x.displace_liqui_part,x.displace_liqui_value,x.blood_access,x.ultrafiltration,x.body_fluid_other,x.target_ktv").Find(&prescription).Error
|
6
|
520
|
|
7
|
|
- err = XTReadDB().Model(&paitents).Where("user_org_id = ? and status =1", orgid).Find(&paitents).Error
|
8
|
|
- return paitents, err
|
|
521
|
+ return
|
9
|
522
|
}
|