test_user 2 年之前
父節點
當前提交
e71cc237dc

+ 110 - 20
controllers/schedule_api_controller.go 查看文件

86
 
86
 
87
 	beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
87
 	beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
88
 	beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
88
 	beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
89
+	beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
89
 
90
 
90
 }
91
 }
91
 func (c *ScheduleApiController) CoverSch() {
92
 func (c *ScheduleApiController) CoverSch() {
103
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
104
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
104
 		return
105
 		return
105
 	}
106
 	}
106
-	count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch_two.PatientId)
107
-	if count > 1 {
108
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
109
-		return
110
-	}
111
-
112
-	count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
113
-	if count1 > 0 {
114
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
115
-		return
107
+	//替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
108
+	if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
109
+		count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
110
+		if count > 0 {
111
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
112
+			return
113
+		}
116
 	}
114
 	}
117
 
115
 
118
 	var new_sch models.Schedule
116
 	var new_sch models.Schedule
148
 		return
146
 		return
149
 	}
147
 	}
150
 
148
 
151
-	//count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId,sch.ScheduleDate,sch.PatientId)
152
-	//if count1 > 0 {
153
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
154
-	//	return
155
-	//}
156
-	//count2, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId,sch_two.ScheduleDate,sch_two.PatientId)
157
-	//if count2 > 0 {
158
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
159
-	//	return
160
-	//}
149
+	//替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
150
+	if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
151
+		count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
152
+		if count > 0 {
153
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
154
+			return
155
+		}
156
+
157
+		count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.ScheduleDate, sch_two.PatientId)
158
+		if count1 > 0 {
159
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
160
+			return
161
+		}
162
+	}
163
+
161
 	service.UpdateScheduleThree(sch, sch_two)
164
 	service.UpdateScheduleThree(sch, sch_two)
162
 	c.ServeSuccessJSON(map[string]interface{}{
165
 	c.ServeSuccessJSON(map[string]interface{}{
163
 		"msg": "交换成功",
166
 		"msg": "交换成功",
651
 				sch_id := int64(items["sch_id"].(float64))
654
 				sch_id := int64(items["sch_id"].(float64))
652
 				if sch_id > 0 { //修改排班信息
655
 				if sch_id > 0 { //修改排班信息
653
 					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
656
 					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
657
+
658
+					order, _ := service.GetDialysisOrderByPatientAndBed(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.BedId, schedule.PatientId)
659
+					if order.ID > 0 {
660
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
661
+						return
662
+					}
663
+
654
 					schedule.Status = 0
664
 					schedule.Status = 0
655
 					service.SaveSch(schedule)
665
 					service.SaveSch(schedule)
656
 				}
666
 				}
1001
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
1011
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
1002
 
1012
 
1003
 			}
1013
 			}
1014
+		} else {
1015
+			c.ServeSuccessJSON(map[string]interface{}{
1016
+				"msg": "保存成功",
1017
+			})
1004
 		}
1018
 		}
1005
 	}
1019
 	}
1006
 
1020
 
4497
 	}
4511
 	}
4498
 	return
4512
 	return
4499
 }
4513
 }
4514
+
4515
+func (c *ScheduleApiController) DeleteScheduleTwo() {
4516
+	id, _ := c.GetInt64("id", 0)
4517
+	if id <= 0 {
4518
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4519
+		return
4520
+	}
4521
+
4522
+	adminINfo := c.GetAdminUserInfo()
4523
+
4524
+	schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
4525
+	timeNow := time.Now().Format("2006-01-02")
4526
+	timeTemplate := "2006-01-02"
4527
+
4528
+	tm := time.Unix(int64(schedule.ScheduleDate), 0)
4529
+	timeStr := tm.Format(timeTemplate)
4530
+	if timeNow > timeStr {
4531
+		utils.ErrorLog(timeNow)
4532
+		utils.ErrorLog(timeStr)
4533
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
4534
+		return
4535
+	}
4536
+	if schedule == nil {
4537
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
4538
+		return
4539
+	}
4540
+
4541
+	order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
4542
+	if err != nil {
4543
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
4544
+		return
4545
+	}
4546
+
4547
+	if order != nil {
4548
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
4549
+		return
4550
+	}
4551
+
4552
+	schedule.Status = 0
4553
+	schedule.UpdatedTime = time.Now().Unix()
4554
+	err = service.UpdateSchedule(schedule)
4555
+	redis := service.RedisClient()
4556
+
4557
+	//处方
4558
+	keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
4559
+	redis.Set(keyOne, "", time.Second)
4560
+
4561
+	//医嘱
4562
+	keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
4563
+	redis.Set(keyTwo, "", time.Second)
4564
+
4565
+	keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
4566
+	redis.Set(keySix, "", time.Second)
4567
+	keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
4568
+	redis.Set(keyThree, "", time.Second)
4569
+
4570
+	keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
4571
+	redis.Set(keyFour, "", time.Second)
4572
+
4573
+	keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
4574
+	redis.Set(keyFive, "", time.Second)
4575
+
4576
+	keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
4577
+	redis.Set(keySeven, "", time.Second)
4578
+	fmt.Println(err)
4579
+	defer redis.Close()
4580
+	if err != nil {
4581
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
4582
+		return
4583
+	}
4584
+
4585
+	c.ServeSuccessJSON(map[string]interface{}{
4586
+		"msg":      "ok",
4587
+		"schedule": &schedule,
4588
+	})
4589
+}

+ 9 - 5
controllers/schedule_template_api_controller.go 查看文件

718
 		src_template, _ := service.GetScheduleTemplateItem(item.ID)
718
 		src_template, _ := service.GetScheduleTemplateItem(item.ID)
719
 		src_template.Status = 0
719
 		src_template.Status = 0
720
 		service.SaveSchTemplateItem(src_template)
720
 		service.SaveSchTemplateItem(src_template)
721
-
722
 	}
721
 	}
723
-
724
 	for _, item := range addOrEditSchedules {
722
 	for _, item := range addOrEditSchedules {
725
-
726
 		if item.ID > 0 { //已经存在的数据
723
 		if item.ID > 0 { //已经存在的数据
727
 			src_template, _ := service.GetScheduleTemplateItem(item.ID)
724
 			src_template, _ := service.GetScheduleTemplateItem(item.ID)
728
 			src_template.DeviceNumberID = item.DeviceNumberID
725
 			src_template.DeviceNumberID = item.DeviceNumberID
729
 			src_template.TimeType = int8(item.TimeType)
726
 			src_template.TimeType = int8(item.TimeType)
730
 			src_template.TreatMode = item.Mode
727
 			src_template.TreatMode = item.Mode
728
+			schItem, _ := service.GetScheduleTemplateThree(this.GetAdminUserInfo().CurrentOrgId, src_template.DeviceNumberID, src_template.TemplateID, int64(src_template.Weekday), int64(src_template.TimeType), src_template.PatientID)
729
+			if schItem.ID > 0 {
730
+				json := make(map[string]interface{})
731
+				json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班无法保存,可能存在重复排班"
732
+				json["state"] = 0
733
+				this.Data["json"] = json
734
+				this.ServeJSON()
735
+				break
736
+			}
731
 			service.SaveSchTemplateItem(src_template)
737
 			service.SaveSchTemplateItem(src_template)
732
-
733
 		} else {
738
 		} else {
734
 			schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
739
 			schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
735
 			fmt.Println("222222")
740
 			fmt.Println("222222")
736
-
737
 			if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
741
 			if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
738
 				fmt.Println("333333333")
742
 				fmt.Println("333333333")
739
 				src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
743
 				src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)

+ 8 - 6
enums/error_code.go 查看文件

269
 
269
 
270
 	ErrorCodeParamWrongForSchMode = 40000002
270
 	ErrorCodeParamWrongForSchMode = 40000002
271
 
271
 
272
-	ErrorCodePatientDialysisOrderOne = 60000000
273
-	ErrorCodePatientDialysisOrderTwo = 60000001
274
-	ErrorCodePatientScheduleRepeat   = 60000002
272
+	ErrorCodePatientDialysisOrderOne      = 60000000
273
+	ErrorCodePatientDialysisOrderTwo      = 60000001
274
+	ErrorCodePatientScheduleRepeat        = 60000002
275
+	ErrorCodeDelScheduleFailByDialysisTwo = 60000003
275
 )
276
 )
276
 
277
 
277
 var ErrCodeMsgs = map[int]string{
278
 var ErrCodeMsgs = map[int]string{
526
 	ErrorCodeSchedule:                 "该班次该床位已有患者",
527
 	ErrorCodeSchedule:                 "该班次该床位已有患者",
527
 	ErrorCodeParamWrongForSchMode:     "透析模式不能为空",
528
 	ErrorCodeParamWrongForSchMode:     "透析模式不能为空",
528
 
529
 
529
-	ErrorCodePatientDialysisOrderOne: "替换的患者已经上机,无法替换排班",
530
-	ErrorCodePatientDialysisOrderTwo: "被替换的患者已经上机,无法替换排班",
531
-	ErrorCodePatientScheduleRepeat:   "一天只能存在一次排班",
530
+	ErrorCodePatientDialysisOrderOne:      "替换的患者已经上机,无法替换排班",
531
+	ErrorCodePatientDialysisOrderTwo:      "被替换的患者已经上机,无法替换排班",
532
+	ErrorCodePatientScheduleRepeat:        "一天只能存在一次排班",
533
+	ErrorCodeDelScheduleFailByDialysisTwo: "已经上机透析,不能操作排班",
532
 }
534
 }
533
 
535
 
534
 type SGJError struct {
536
 type SGJError struct {

+ 7 - 0
service/device_service.go 查看文件

856
 	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", patient_id, orgID, template_id, week_type).First(&item).Error
856
 	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", patient_id, orgID, template_id, week_type).First(&item).Error
857
 	return item, err
857
 	return item, err
858
 }
858
 }
859
+
860
+//某模板下,某周几下,该床位是否有患者(不包括当前排班的人)
861
+func GetScheduleTemplateThree(orgID int64, deviceNumberID int64, template_id int64, week_type int64, time_type int64, patient_id int64) (models.PatientScheduleTemplateItem, error) {
862
+	var item models.PatientScheduleTemplateItem
863
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ? AND time_type = ? AND patient_id <> ?", deviceNumberID, orgID, template_id, week_type, time_type, patient_id).First(&item).Error
864
+	return item, err
865
+}

+ 5 - 0
service/schedule_service.go 查看文件

1457
 	err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
1457
 	err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
1458
 	return schedule, err
1458
 	return schedule, err
1459
 }
1459
 }
1460
+
1461
+func GetDialysisOrderByPatientAndBed(org_id int64, record_date int64, bed_id int64, patient_id int64) (order models.DialysisOrder, err error) {
1462
+	err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND status = 1 AND dialysis_date = ? AND bed_id = ? AND patient_id = ?", org_id, record_date, bed_id, patient_id).First(&order).Error
1463
+	return
1464
+}

+ 3 - 2
service/smart_sch.go 查看文件

48
 
48
 
49
 	for _, item := range sch {
49
 	for _, item := range sch {
50
 		var order models.SmSchDialysisOrder
50
 		var order models.SmSchDialysisOrder
51
-		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
51
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? ", orgID, item.PatientId, item.ScheduleDate).First(&order)
52
 		item.SmSchDialysisOrder = order
52
 		item.SmSchDialysisOrder = order
53
 	}
53
 	}
54
 
54
 
98
 		offset = -6
98
 		offset = -6
99
 	}
99
 	}
100
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
100
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
101
+
101
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
102
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
102
 		Preload("DeviceZone", "status = 1").
103
 		Preload("DeviceZone", "status = 1").
103
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
104
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
104
 
105
 
105
 	for _, item := range schs {
106
 	for _, item := range schs {
106
 		var order models.SmSchDialysisOrder
107
 		var order models.SmSchDialysisOrder
107
-		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
108
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? ", orgID, item.PatientId, item.ScheduleDate).First(&order)
108
 		item.SmSchDialysisOrder = order
109
 		item.SmSchDialysisOrder = order
109
 	}
110
 	}
110
 	return
111
 	return