|
@@ -495,7 +495,7 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
|
495
|
495
|
db = db.Where("x.start_time>=?", start)
|
496
|
496
|
}
|
497
|
497
|
if end > 0 {
|
498
|
|
- db = db.Where("start_time<=?", end)
|
|
498
|
+ db = db.Where("x.start_time<=?", end)
|
499
|
499
|
}
|
500
|
500
|
//offset := (page - 1) * limit
|
501
|
501
|
err = db.Group("x.id").Count(&total).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.status, 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,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
|
|
@@ -504,39 +504,32 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
|
504
|
504
|
|
505
|
505
|
}
|
506
|
506
|
|
507
|
|
-func GetNewDoctorAdviceOne(patientID int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, date int64, err error) {
|
508
|
|
-
|
509
|
|
- var advicesCount models.UserDoctorAdvicesCount
|
510
|
|
-
|
511
|
|
- err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status =1", patientID, orgID).Select("count(distinct record_date) as count,patient_id").Scan(&advicesCount).Error
|
512
|
|
-
|
513
|
|
- if err != nil {
|
514
|
|
- return
|
|
507
|
+func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
|
|
508
|
+ fmt.Println("advicetype------------------------------", advice_type)
|
|
509
|
+ db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
|
|
510
|
+ table := UserReadDB().Table("sgj_user_admin_role as r")
|
|
511
|
+ fmt.Println("table", table)
|
|
512
|
+ if orgID > 0 {
|
|
513
|
+ db = db.Where("x.user_org_id=?", orgID)
|
515
|
514
|
}
|
516
|
|
- total = advicesCount.Count
|
517
|
|
- if total == 0 || page > total {
|
518
|
|
- return
|
|
515
|
+ if patientID > 0 {
|
|
516
|
+ db = db.Where("x.patient_id = ?", patientID)
|
519
|
517
|
}
|
520
|
|
-
|
521
|
|
- var Id models.AdviceDate
|
522
|
|
-
|
523
|
|
- err = XTReadDB().Model(models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Select("record_date").Group("record_date").Order("created_time desc").Offset(page - 1).Limit(10).Scan(&Id).Error
|
524
|
|
- if err != nil {
|
525
|
|
- return
|
|
518
|
+ if advice_type > 0 {
|
|
519
|
+ db = db.Where("x.advice_type = ?", advice_type)
|
|
520
|
+ } else if advice_type == 0 {
|
|
521
|
+ db = db.Where("x.advice_type in (?)", []int{1, 3})
|
526
|
522
|
}
|
527
|
|
-
|
528
|
|
- if Id.RecordDate == 0 {
|
529
|
|
- return
|
|
523
|
+ if start > 0 {
|
|
524
|
+ db = db.Where("x.start_time>=?", start)
|
530
|
525
|
}
|
531
|
|
-
|
532
|
|
- date = Id.RecordDate
|
533
|
|
- fmt.Println("结构是==============", Id.RecordDate)
|
534
|
|
- doctoradvice, err = GetAdvices(orgID, patientID, Id.RecordDate)
|
535
|
|
- if err != nil {
|
536
|
|
- return
|
|
526
|
+ if end > 0 {
|
|
527
|
+ db = db.Where("x.start_time<=?", end)
|
537
|
528
|
}
|
|
529
|
+ offset := (page - 1) * limit
|
|
530
|
+ err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).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.status, 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,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&doctoradvice).Error
|
|
531
|
+ fmt.Print("错误是什么", err)
|
538
|
532
|
return
|
539
|
|
-
|
540
|
533
|
}
|
541
|
534
|
|
542
|
535
|
func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
|
|
@@ -889,14 +882,14 @@ func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.SgjUserAdminRo
|
889
|
882
|
func GetDoctorAdviceDetail(id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
|
890
|
883
|
|
891
|
884
|
db := XTReadDB().Table("xt_doctor_advice as x")
|
892
|
|
- err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,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.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.groupno = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
|
|
885
|
+ err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,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.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.start_time = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
|
893
|
886
|
|
894
|
887
|
return advices, err
|
895
|
888
|
}
|
896
|
889
|
|
897
|
890
|
func DeleteManagement(groupid int64, orgid int64) error {
|
898
|
891
|
|
899
|
|
- err := XTWriteDB().Model(models.DoctorAdvice{}).Where("groupno=? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
892
|
+ err := XTWriteDB().Model(models.DoctorAdvice{}).Where("start_time =? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
900
|
893
|
return err
|
901
|
894
|
}
|
902
|
895
|
|
|
@@ -908,7 +901,7 @@ func DeleteChild(id int64) error {
|
908
|
901
|
|
909
|
902
|
func DeletePatient(id int64) error {
|
910
|
903
|
|
911
|
|
- err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? and parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
904
|
+ err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? or parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
912
|
905
|
return err
|
913
|
906
|
}
|
914
|
907
|
|
|
@@ -1064,7 +1057,7 @@ func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZone
|
1064
|
1057
|
db = db.Where("x.org_id = ?", orgid)
|
1065
|
1058
|
}
|
1066
|
1059
|
offset := (page - 1) * limit
|
1067
|
|
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id").Scan(&zone).Error
|
|
1060
|
+ err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id AND n.status = 1").Scan(&zone).Error
|
1068
|
1061
|
return zone, total, err
|
1069
|
1062
|
}
|
1070
|
1063
|
|
|
@@ -1087,7 +1080,7 @@ func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGr
|
1087
|
1080
|
db = db.Where("x.org_id = ?", orgid)
|
1088
|
1081
|
}
|
1089
|
1082
|
offset := (page - 1) * limit
|
1090
|
|
- err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id").Scan(&group).Error
|
|
1083
|
+ err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id And n.status = 1").Scan(&group).Error
|
1091
|
1084
|
return group, total, err
|
1092
|
1085
|
}
|
1093
|
1086
|
|
|
@@ -1121,11 +1114,24 @@ func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.Device
|
1121
|
1114
|
db = db.Where("x.org_id = ?", orgid)
|
1122
|
1115
|
}
|
1123
|
1116
|
offset := (page - 1) * limit
|
1124
|
|
- err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
|
|
1117
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime asc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
|
1125
|
1118
|
|
1126
|
1119
|
return number, total, err
|
1127
|
1120
|
}
|
1128
|
1121
|
|
|
1122
|
+func GetSchedu(bedid int64, thetime int64, orgid int64) (*models.XtSchedule, error) {
|
|
1123
|
+ schedule := models.XtSchedule{}
|
|
1124
|
+ err := XTReadDB().Model(&schedule).Where("bed_id = ? and schedule_date = ? and user_org_id = ? and status = 1", bedid, thetime, orgid).Find(&schedule).Error
|
|
1125
|
+ if err == gorm.ErrRecordNotFound {
|
|
1126
|
+ return nil, err
|
|
1127
|
+ }
|
|
1128
|
+ if err != nil {
|
|
1129
|
+ return nil, err
|
|
1130
|
+ }
|
|
1131
|
+ return &schedule, nil
|
|
1132
|
+
|
|
1133
|
+}
|
|
1134
|
+
|
1129
|
1135
|
func DeleteBed(id int64) error {
|
1130
|
1136
|
err := XTWriteDB().Model(models.DeviceNumber{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "ctime": time.Now().Unix()}).Error
|
1131
|
1137
|
return err
|
|
@@ -1178,3 +1184,90 @@ func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
|
1178
|
1184
|
err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
|
1179
|
1185
|
return org, err
|
1180
|
1186
|
}
|
|
1187
|
+
|
|
1188
|
+func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
|
|
1189
|
+
|
|
1190
|
+ orgType := models.SgjUserOrgType{}
|
|
1191
|
+ err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
|
|
1192
|
+ return orgType, err
|
|
1193
|
+}
|
|
1194
|
+
|
|
1195
|
+func GetTypeName(id int64) (models.SgjUserOrgType, error) {
|
|
1196
|
+ orgType := models.SgjUserOrgType{}
|
|
1197
|
+ err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
|
|
1198
|
+ return orgType, err
|
|
1199
|
+}
|
|
1200
|
+
|
|
1201
|
+func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
|
|
1202
|
+
|
|
1203
|
+ district := models.SgjUserDistrict{}
|
|
1204
|
+ err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
|
|
1205
|
+ return district, err
|
|
1206
|
+}
|
|
1207
|
+
|
|
1208
|
+func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
|
|
1209
|
+
|
|
1210
|
+ err = UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Find(&orgType).Error
|
|
1211
|
+ return
|
|
1212
|
+}
|
|
1213
|
+
|
|
1214
|
+func UpdateOrg(id int64, org models.SgjUserOrg) error {
|
|
1215
|
+
|
|
1216
|
+ err := UserWriteDB().Model(&org).Where("id = ?", id).Update(map[string]interface{}{"org_name": org.OrgName, "org_short_name": org.OrgShortName, "province": org.Province, "city": org.City, "district": org.District, "address": org.Address, "org_type": org.OrgType, "telephone": org.Telephone, "contact_name": org.ContactName, "mtime": time.Now().Unix()}).Error
|
|
1217
|
+ return err
|
|
1218
|
+}
|
|
1219
|
+
|
|
1220
|
+func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
|
|
1221
|
+ role := models.SgjUserAdminRole{}
|
|
1222
|
+ err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
|
|
1223
|
+ return role, err
|
|
1224
|
+}
|
|
1225
|
+
|
|
1226
|
+func GetAdminName(id int64) (models.AdminUser, error) {
|
|
1227
|
+ user := models.AdminUser{}
|
|
1228
|
+ err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
|
|
1229
|
+ return user, err
|
|
1230
|
+}
|
|
1231
|
+
|
|
1232
|
+func GetPartionDetail(id int64) (models.DeviceZone, error) {
|
|
1233
|
+
|
|
1234
|
+ zone := models.DeviceZone{}
|
|
1235
|
+ err := XTReadDB().Model(&zone).Where("id=? and status = 1", id).Find(&zone).Error
|
|
1236
|
+ return zone, err
|
|
1237
|
+}
|
|
1238
|
+
|
|
1239
|
+func UpdatePartition(id int64, zone *models.DeviceZone) error {
|
|
1240
|
+
|
|
1241
|
+ err := XTWriteDB().Model(&zone).Where("id=?", id).Update(map[string]interface{}{"name": zone.Name, "type": zone.Type, "mtime": time.Now().Unix()}).Error
|
|
1242
|
+ return err
|
|
1243
|
+}
|
|
1244
|
+
|
|
1245
|
+func GetGroupDetail(id int64) (models.DeviceGroup, error) {
|
|
1246
|
+ group := models.DeviceGroup{}
|
|
1247
|
+ err := XTReadDB().Model(&group).Where("id=? and status = 1", id).Find(&group).Error
|
|
1248
|
+ return group, err
|
|
1249
|
+}
|
|
1250
|
+
|
|
1251
|
+func UpdateGroup(id int64, group *models.DeviceGroup) error {
|
|
1252
|
+
|
|
1253
|
+ err := XTWriteDB().Model(&group).Where("id=?", id).Update(map[string]interface{}{"name": group.Name, "mtime": time.Now().Unix()}).Error
|
|
1254
|
+ return err
|
|
1255
|
+}
|
|
1256
|
+
|
|
1257
|
+func GetBedDetail(id int64) (models.DeviceNumber, error) {
|
|
1258
|
+ number := models.DeviceNumber{}
|
|
1259
|
+ err := XTReadDB().Model(&number).Where("id=? and status =1", id).Find(&number).Error
|
|
1260
|
+ return number, err
|
|
1261
|
+}
|
|
1262
|
+
|
|
1263
|
+func UpdatedBed(id int64, number *models.DeviceNumber) error {
|
|
1264
|
+
|
|
1265
|
+ err = XTWriteDB().Model(&number).Where("id=?", id).Update(map[string]interface{}{"number": number.Number, "zone_id": number.ZoneID, "group_id": number.GroupID, "mtime": time.Now().Unix()}).Error
|
|
1266
|
+ return err
|
|
1267
|
+}
|
|
1268
|
+
|
|
1269
|
+func CreateLoginLod(log *models.SgjUserAdminLoginLog) error {
|
|
1270
|
+
|
|
1271
|
+ err := UserWriteDB().Model(&log).Create(&log).Error
|
|
1272
|
+ return err
|
|
1273
|
+}
|