Procházet zdrojové kódy

Merge branch 'master' of http://git.shengws.com/csx/XT_New

XMLWAN před 4 roky
rodič
revize
a7d3b61172

+ 60 - 59
controllers/base_api_controller.go Zobrazit soubor

@@ -2,6 +2,7 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
5 6
 	"XT_New/service"
6 7
 	"fmt"
7 8
 	"strconv"
@@ -64,36 +65,36 @@ type BaseAuthAPIController struct {
64 65
 func (this *BaseAuthAPIController) Prepare() {
65 66
 	this.BaseAPIController.Prepare()
66 67
 	if this.GetAdminUserInfo() == nil {
67
-		//var userAdmin models.AdminUser
68
-		//userAdmin.Id = 400
69
-		//userAdmin.Mobile = "13535547901"
70
-		//
71
-		////userAdmin.Id = 597
72
-		////userAdmin.Mobile = "19874122664"
73
-		//userAdmin.IsSuperAdmin = false
74
-		//userAdmin.Status = 1
75
-		//userAdmin.CreateTime = 1530786071
76
-		//userAdmin.ModifyTime = 1530786071
77
-		//var subscibe models.ServeSubscibe
78
-		//subscibe.ID = 1
79
-		//subscibe.OrgId = 12
80
-		//subscibe.PeriodStart = 1538035409
81
-		//subscibe.PeriodEnd = 1569571409
82
-		//subscibe.State = 1
83
-		//subscibe.Status = 1
84
-		//subscibe.CreatedTime = 1538035409
85
-		//subscibe.UpdatedTime = 1538035409
86
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
87
-		//subscibes[4] = &subscibe
88
-		//var adminUserInfo service.AdminUserInfo
89
-		//adminUserInfo.CurrentOrgId = 12
90
-		//adminUserInfo.CurrentAppId = 18
91
-		//adminUserInfo.AdminUser = &userAdmin
92
-		//adminUserInfo.Subscibes = subscibes
93
-		//this.SetSession("admin_user_info", &adminUserInfo)
94
-
95
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
96
-		this.StopRun()
68
+		var userAdmin models.AdminUser
69
+		userAdmin.Id = 400
70
+		userAdmin.Mobile = "13535547901"
71
+
72
+		//userAdmin.Id = 597
73
+		//userAdmin.Mobile = "19874122664"
74
+		userAdmin.IsSuperAdmin = false
75
+		userAdmin.Status = 1
76
+		userAdmin.CreateTime = 1530786071
77
+		userAdmin.ModifyTime = 1530786071
78
+		var subscibe models.ServeSubscibe
79
+		subscibe.ID = 1
80
+		subscibe.OrgId = 12
81
+		subscibe.PeriodStart = 1538035409
82
+		subscibe.PeriodEnd = 1569571409
83
+		subscibe.State = 1
84
+		subscibe.Status = 1
85
+		subscibe.CreatedTime = 1538035409
86
+		subscibe.UpdatedTime = 1538035409
87
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
88
+		subscibes[4] = &subscibe
89
+		var adminUserInfo service.AdminUserInfo
90
+		adminUserInfo.CurrentOrgId = 12
91
+		adminUserInfo.CurrentAppId = 18
92
+		adminUserInfo.AdminUser = &userAdmin
93
+		adminUserInfo.Subscibes = subscibes
94
+		this.SetSession("admin_user_info", &adminUserInfo)
95
+
96
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
97
+		//this.StopRun()
97 98
 	}
98 99
 
99 100
 	adminUserInfo := this.GetAdminUserInfo()
@@ -315,35 +316,35 @@ type BaseServeAPIController struct {
315 316
 func (this *BaseServeAPIController) Prepare() {
316 317
 	this.BaseAPIController.Prepare()
317 318
 	if this.GetAdminUserInfo() == nil {
318
-		//var userAdmin models.AdminUser
319
-		//userAdmin.Id = 400
320
-		//userAdmin.Mobile = "13535547901"
321
-		////userAdmin.Id = 597
322
-		////userAdmin.Mobile = "19874122664"
323
-		//userAdmin.IsSuperAdmin = false
324
-		//userAdmin.Status = 1
325
-		//userAdmin.CreateTime = 1530786071
326
-		//userAdmin.ModifyTime = 1530786071
327
-		//var subscibe models.ServeSubscibe
328
-		//subscibe.ID = 1
329
-		//subscibe.OrgId = 12
330
-		//subscibe.PeriodStart = 1538035409
331
-		//subscibe.PeriodEnd = 1569571409
332
-		//subscibe.State = 1
333
-		//subscibe.Status = 1
334
-		//subscibe.CreatedTime = 1538035409
335
-		//subscibe.UpdatedTime = 1538035409
336
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
337
-		//subscibes[4] = &subscibe
338
-		//var adminUserInfo service.AdminUserInfo
339
-		//adminUserInfo.CurrentOrgId = 12
340
-		//adminUserInfo.CurrentAppId = 18
341
-		//adminUserInfo.AdminUser = &userAdmin
342
-		//adminUserInfo.Subscibes = subscibes
343
-		//this.SetSession("admin_user_info", &adminUserInfo)
344
-
345
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
346
-		this.StopRun()
319
+		var userAdmin models.AdminUser
320
+		userAdmin.Id = 400
321
+		userAdmin.Mobile = "13535547901"
322
+		//userAdmin.Id = 597
323
+		//userAdmin.Mobile = "19874122664"
324
+		userAdmin.IsSuperAdmin = false
325
+		userAdmin.Status = 1
326
+		userAdmin.CreateTime = 1530786071
327
+		userAdmin.ModifyTime = 1530786071
328
+		var subscibe models.ServeSubscibe
329
+		subscibe.ID = 1
330
+		subscibe.OrgId = 12
331
+		subscibe.PeriodStart = 1538035409
332
+		subscibe.PeriodEnd = 1569571409
333
+		subscibe.State = 1
334
+		subscibe.Status = 1
335
+		subscibe.CreatedTime = 1538035409
336
+		subscibe.UpdatedTime = 1538035409
337
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
+		subscibes[4] = &subscibe
339
+		var adminUserInfo service.AdminUserInfo
340
+		adminUserInfo.CurrentOrgId = 12
341
+		adminUserInfo.CurrentAppId = 18
342
+		adminUserInfo.AdminUser = &userAdmin
343
+		adminUserInfo.Subscibes = subscibes
344
+		this.SetSession("admin_user_info", &adminUserInfo)
345
+
346
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
347
+		//this.StopRun()
347 348
 	}
348 349
 
349 350
 	//if adminUserInfo.AppRole != nil {

+ 1 - 1
controllers/schedule_api_controller.go Zobrazit soubor

@@ -683,7 +683,7 @@ func (this *ScheduleApiController) GetWeekDaySchedule() {
683 683
 	}
684 684
 
685 685
 	adminUserInfo := this.GetAdminUserInfo()
686
-	list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix())
686
+	list, _ := service.GetWeekDaySchedule(adminUserInfo.CurrentOrgId, targetDay.Unix(), targetDay)
687 687
 
688 688
 	this.ServeSuccessJSON(map[string]interface{}{
689 689
 		"schdules": list,

+ 1 - 0
models/dialysis.go Zobrazit soubor

@@ -385,6 +385,7 @@ type DoctorAdvice struct {
385 385
 	ChildDoctorAdvice     []*DoctorAdvice `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
386 386
 	TemplateId            string          `gorm:"column:template_id" json:"template_id"`
387 387
 	Modifier              int64           `gorm:"column:modifier" json:"modifier" form:"modifier"`
388
+	IsCheck               int64           `gorm:"-" json:"is_check" form:"is_check"`
388 389
 }
389 390
 
390 391
 func (DoctorAdvice) TableName() string {

+ 1 - 1
models/schedule_models.go Zobrazit soubor

@@ -83,7 +83,7 @@ type WeekSchedule struct {
83 83
 	DeviceZone           DeviceZone       `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
84 84
 	DeviceNumber         DeviceNumber     `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
85 85
 	DialysisPrescription DialysisSolution `json:"prescription" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
86
-	DoctorAdvice         []*DoctorAdvice  `json:"doctor_advice" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId"`
86
+	DoctorAdvice         []*DoctorAdvice  `json:"doctor_advice" gorm:"-"`
87 87
 }
88 88
 
89 89
 func (WeekSchedule) TableName() string {

+ 106 - 4
service/schedule_service.go Zobrazit soubor

@@ -2,6 +2,10 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
6
+	"strconv"
7
+	"strings"
8
+	"time"
5 9
 
6 10
 	"github.com/jinzhu/gorm"
7 11
 )
@@ -227,15 +231,12 @@ func GetSchedualPatientsByKeywords(keywords string, org_id int64) (schedule []*m
227 231
 
228 232
 }
229 233
 
230
-func GetWeekDaySchedule(orgID int64, scheduleDate int64) (schedules []*models.WeekSchedule, err error) {
234
+func GetWeekDaySchedule(orgID int64, scheduleDate int64, scheduleDates *time.Time) (schedules []*models.WeekSchedule, err error) {
231 235
 
232 236
 	err = readDb.
233 237
 		Table("xt_schedule as s").
234 238
 		Preload("DeviceZone", "status = 1 ").
235 239
 		Preload("DeviceNumber", "status = 1 ").
236
-		Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
237
-			return db.Where("status = 1 AND advice_type = 1").Preload("ChildDoctorAdvice", "status = 1")
238
-		}).
239 240
 		Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
240 241
 			return db.Where("status = 1").Order("id desc")
241 242
 		}).
@@ -244,5 +245,106 @@ func GetWeekDaySchedule(orgID int64, scheduleDate int64) (schedules []*models.We
244 245
 		Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
245 246
 		Order("schedule_type").
246 247
 		Find(&schedules).Error
248
+
249
+	for _, item := range schedules {
250
+		_, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
251
+		if config.IsOpenRemind > 0 {
252
+			//开启推送提醒逻辑    提交长期处方的时候,弹起长期医嘱推送
253
+			var advice_three []*models.DoctorAdvice
254
+			advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
255
+			advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
256
+			for _, advice := range advices {
257
+				advice.IsCheck = 1
258
+				if advice.FrequencyType == 3 {
259
+					week := int(scheduleDates.Weekday())
260
+					fmt.Println(advice.WeekDay)
261
+					switch week {
262
+					case 1:
263
+						if strings.Index(advice.WeekDay, "周一") > -1 {
264
+							advice_three = append(advice_three, advice)
265
+						}
266
+						break
267
+					case 2:
268
+						if strings.Index(advice.WeekDay, "周二") > -1 {
269
+							advice_three = append(advice_three, advice)
270
+						}
271
+						break
272
+					case 3:
273
+						if strings.Index(advice.WeekDay, "周三") > -1 {
274
+							advice_three = append(advice_three, advice)
275
+						}
276
+						break
277
+					case 4:
278
+						if strings.Index(advice.WeekDay, "周四") > -1 {
279
+							advice_three = append(advice_three, advice)
280
+						}
281
+						break
282
+					case 5:
283
+						if strings.Index(advice.WeekDay, "周五") > -1 {
284
+							advice_three = append(advice_three, advice)
285
+						}
286
+						break
287
+					case 6:
288
+						if strings.Index(advice.WeekDay, "周六") > -1 {
289
+							advice_three = append(advice_three, advice)
290
+						}
291
+						break
292
+					case 0:
293
+						if strings.Index(advice.WeekDay, "周日") > -1 {
294
+							advice_three = append(advice_three, advice)
295
+						}
296
+						break
297
+					}
298
+				} else if advice.FrequencyType == 1 {
299
+					advice_three = append(advice_three, advice)
300
+				}
301
+			}
302
+
303
+			for _, advice := range advices_two {
304
+				now := scheduleDates.Unix()
305
+				dayStr := strconv.FormatInt(advice.DayCount, 10)
306
+				dayStr2 := "-" + dayStr
307
+				count, _ := strconv.ParseInt(dayStr2, 10, 64)
308
+				oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
309
+				advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
310
+				if len(advices) == 0 {
311
+					advice_three = append(advice_three)
312
+				}
313
+			}
314
+			item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
315
+		}
316
+	}
317
+	return
318
+}
319
+
320
+func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
321
+	newArr = make([]*models.DoctorAdvice, 0)
322
+	for i := 0; i < len(arr); i++ {
323
+		repeat := false
324
+		for j := i + 1; j < len(arr); j++ {
325
+			if arr[i].ID == arr[j].ID {
326
+				repeat = true
327
+				break
328
+			}
329
+		}
330
+		if !repeat {
331
+			newArr = append(newArr, arr[i])
332
+		}
333
+	}
334
+	return
335
+}
336
+
337
+func GetLastLongAdviceByGroupNoOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
338
+	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1  AND stop_state = 2 AND parent_id = 0", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
339
+	return
340
+}
341
+
342
+func GetLastLongAdviceByGroupNoThreeOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
343
+	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ?  AND  advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 ", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
344
+	return
345
+}
346
+
347
+func FindAllDoctorAdviceByTimeOther(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
348
+	err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2   AND frequency_type = 2 AND advice_date > ? AND advice_date < ? AND template_id = ?  ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
247 349
 	return
248 350
 }