Browse Source

Merge remote-tracking branch 'origin/20211122' into 20211122

mainqaq 2 years ago
parent
commit
7d3aa4f02e

+ 35 - 3
controllers/dialysis_api_controller.go View File

64
 	beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
64
 	beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
65
 
65
 
66
 	beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
66
 	beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
67
+
68
+	beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
67
 }
69
 }
68
 
70
 
69
 func (c *DialysisApiController) GetQueueCall() {
71
 func (c *DialysisApiController) GetQueueCall() {
3749
 
3751
 
3750
 	patient_id, _ := c.GetInt64("patient_id")
3752
 	patient_id, _ := c.GetInt64("patient_id")
3751
 
3753
 
3754
+	good_type, _ := c.GetInt64("good_type")
3755
+
3752
 	date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
3756
 	date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
3753
 	if parseDateErr != nil && len(schedualDate) != 0 {
3757
 	if parseDateErr != nil && len(schedualDate) != 0 {
3754
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3758
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3771
 	goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
3775
 	goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
3772
 
3776
 
3773
 	if err == gorm.ErrRecordNotFound {
3777
 	if err == gorm.ErrRecordNotFound {
3778
+		list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
3779
+		var ids []int64
3780
+		for _, item := range list {
3781
+			ids = append(ids, item.PatientId)
3782
+		}
3774
 
3783
 
3775
-		dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
3784
+		dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
3776
 		for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
3785
 		for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
3777
-
3778
 			goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3786
 			goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3779
 			lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3787
 			lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3780
 			item.LastAutomaticReduceDetail = goodUser
3788
 			item.LastAutomaticReduceDetail = goodUser
3789
 
3797
 
3790
 	} else if err == nil {
3798
 	} else if err == nil {
3791
 		//获取当天排班的每个患者的库存使用情况
3799
 		//获取当天排班的每个患者的库存使用情况
3792
-		dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
3800
+		list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
3801
+		var ids []int64
3802
+		for _, item := range list {
3803
+			ids = append(ids, item.PatientId)
3804
+		}
3805
+
3806
+		dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
3793
 		for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
3807
 		for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
3794
 			goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3808
 			goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3795
 			lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3809
 			lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
3873
 		return
3887
 		return
3874
 	}
3888
 	}
3875
 }
3889
 }
3890
+
3891
+func (c *DialysisApiController) GetInitPrintData() {
3892
+
3893
+	patient_id, _ := c.GetInt64("patient_id")
3894
+	record_date, _ := c.GetInt64("record_date")
3895
+	orgId := c.GetAdminUserInfo().CurrentOrgId
3896
+	list, err := service.GetInitPrintData(patient_id, record_date, orgId)
3897
+	if err == nil {
3898
+		c.ServeSuccessJSON(map[string]interface{}{
3899
+			"list": list,
3900
+		})
3901
+		return
3902
+
3903
+	} else {
3904
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3905
+		return
3906
+	}
3907
+}

+ 0 - 1
controllers/dialysis_parameter_api_controller.go View File

37
 	adminUserInfo := this.GetAdminUserInfo()
37
 	adminUserInfo := this.GetAdminUserInfo()
38
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
38
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
39
 
39
 
40
-	fmt.Println("scheduletype", schedulType, start_time, partitionType, keywords, theTime.Unix())
41
 	if len(keywords) > 0 {
40
 	if len(keywords) > 0 {
42
 		dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
41
 		dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
43
 		patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit, keywords, schedulType, partitionType)
42
 		patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit, keywords, schedulType, partitionType)

+ 4 - 3
controllers/doctors_api_controller.go View File

69
 	schedule_type, _ := c.GetInt64("schedule_type")
69
 	schedule_type, _ := c.GetInt64("schedule_type")
70
 	partition_type, _ := c.GetInt64("partition_type")
70
 	partition_type, _ := c.GetInt64("partition_type")
71
 	patient_id, _ := c.GetInt64("patient_id")
71
 	patient_id, _ := c.GetInt64("patient_id")
72
+	excution_way, _ := c.GetInt64("excution_way")
72
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
73
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
73
 		adviceType = 0
74
 		adviceType = 0
74
 	}
75
 	}
87
 	adminUserInfo := c.GetAdminUserInfo()
88
 	adminUserInfo := c.GetAdminUserInfo()
88
 	orgID := adminUserInfo.CurrentOrgId
89
 	orgID := adminUserInfo.CurrentOrgId
89
 
90
 
90
-	scheduals, err := service.MobileGetScheduleDoctorAdvicesOne(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way, schedule_type, partition_type, patient_id)
91
-	hisAdvices, _ := service.GetHisDoctorAdvicesOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id)
91
+	scheduals, err := service.MobileGetScheduleDoctorAdvicesOne(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way, schedule_type, partition_type, patient_id, excution_way)
92
+	hisAdvices, _ := service.GetHisDoctorAdvicesOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way)
92
 
93
 
93
-	project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id)
94
+	project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
94
 	//project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id)
95
 	//project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id)
95
 	for _, item := range project {
96
 	for _, item := range project {
96
 		index := 0
97
 		index := 0

+ 1 - 0
controllers/his_api_controller.go View File

1115
 												c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1115
 												c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1116
 												return
1116
 												return
1117
 											}
1117
 											}
1118
+
1118
 										}
1119
 										}
1119
 
1120
 
1120
 									}
1121
 									}

+ 467 - 140
service/mobile_dialysis_service.go View File

2801
 	return
2801
 	return
2802
 }
2802
 }
2803
 
2803
 
2804
-func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
2804
+func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64, good_type int64, ids []int64) ([]*MDialysisGoodsVM, error, int64) {
2805
 	var vms []*MDialysisGoodsVM
2805
 	var vms []*MDialysisGoodsVM
2806
 	var total int64
2806
 	var total int64
2807
 
2807
 
2812
 		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2812
 		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2813
 		Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
2813
 		Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
2814
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?   ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
2814
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?   ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
2815
-		}).
2816
-		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2817
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=?  AND count > 0", orgID, scheduleDate, end_time)
2818
-		}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
2815
+		}).Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2816
+		return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=?  AND count > 0", orgID, scheduleDate, end_time)
2817
+	}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
2819
 
2818
 
2820
 	if scheduleDate != 0 {
2819
 	if scheduleDate != 0 {
2821
 		db = db.Where("schedule_date = ?", scheduleDate)
2820
 		db = db.Where("schedule_date = ?", scheduleDate)
2833
 		if partition_id != 0 {
2832
 		if partition_id != 0 {
2834
 			db = db.Where("partition_id = ?", partition_id)
2833
 			db = db.Where("partition_id = ?", partition_id)
2835
 		}
2834
 		}
2836
-
2835
+		if good_type == 1 {
2836
+			db = db.Where("patient_id in(?)", ids)
2837
+		}
2838
+		if good_type == 2 {
2839
+			db = db.Where("patient_id not in(?)", ids)
2840
+		}
2837
 		db = db.Count(&total)
2841
 		db = db.Count(&total)
2838
 		offset := (page - 1) * limit
2842
 		offset := (page - 1) * limit
2839
 
2843
 
3055
 	return advice, err
3059
 	return advice, err
3056
 }
3060
 }
3057
 
3061
 
3058
-func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
3062
+func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64) ([]*MScheduleDoctorAdviceVM, error) {
3059
 	var vms []*MScheduleDoctorAdviceVM
3063
 	var vms []*MScheduleDoctorAdviceVM
3060
 	adviceWhere := ""
3064
 	adviceWhere := ""
3061
 	adviceCondition := []interface{}{}
3065
 	adviceCondition := []interface{}{}
3062
 	if adviceType == 0 {
3066
 	if adviceType == 0 {
3063
 		if patientType == 0 {
3067
 		if patientType == 0 {
3064
 			if patient_id > 0 {
3068
 			if patient_id > 0 {
3065
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
3066
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3069
+				if execution_state > 0 {
3070
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
3071
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3072
+				} else {
3073
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
3074
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3075
+				}
3076
+
3067
 			} else {
3077
 			} else {
3068
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
3069
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3078
+				if execution_state > 0 {
3079
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and execution_state= ?"
3080
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3081
+				} else {
3082
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
3083
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3084
+				}
3085
+
3070
 			}
3086
 			}
3071
 
3087
 
3072
 		} else if patientType == 1 {
3088
 		} else if patientType == 1 {
3073
 			if patient_id > 0 {
3089
 			if patient_id > 0 {
3074
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
3075
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3090
+				if execution_state > 0 {
3091
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ? and execution_state= ?"
3092
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3093
+				} else {
3094
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
3095
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3096
+				}
3097
+
3076
 			} else {
3098
 			} else {
3077
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
3078
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3099
+				if execution_state > 0 {
3100
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
3101
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3102
+				} else {
3103
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
3104
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3105
+				}
3106
+
3079
 			}
3107
 			}
3080
 
3108
 
3081
 		} else if patientType == 2 {
3109
 		} else if patientType == 2 {
3082
 			if patient_id > 0 {
3110
 			if patient_id > 0 {
3083
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
3084
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3111
+				if execution_state > 0 {
3112
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?) and execution_state = ?"
3113
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3114
+				} else {
3115
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
3116
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3117
+				}
3118
+
3085
 			} else {
3119
 			} else {
3086
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
3087
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3120
+				if execution_state > 0 {
3121
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1) and execution_state = ?"
3122
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3123
+				} else {
3124
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
3125
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3126
+				}
3127
+
3088
 			}
3128
 			}
3089
 
3129
 
3090
 		}
3130
 		}
3092
 	} else if adviceType == 1 {
3132
 	} else if adviceType == 1 {
3093
 		if patientType == 0 {
3133
 		if patientType == 0 {
3094
 			if patient_id > 0 {
3134
 			if patient_id > 0 {
3095
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
3096
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3135
+				if execution_state > 0 {
3136
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? and execution_state = ?"
3137
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3138
+				} else {
3139
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
3140
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3141
+				}
3142
+
3097
 			} else {
3143
 			} else {
3098
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
3099
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3144
+				if execution_state > 0 {
3145
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and execution_state = ?"
3146
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3147
+				} else {
3148
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
3149
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3150
+				}
3151
+
3100
 			}
3152
 			}
3101
 
3153
 
3102
 		} else if patientType == 1 {
3154
 		} else if patientType == 1 {
3103
 			if patient_id > 0 {
3155
 			if patient_id > 0 {
3104
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
3105
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3156
+				if execution_state > 0 {
3157
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3158
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3159
+				} else {
3160
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
3161
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3162
+				}
3163
+
3106
 			} else {
3164
 			} else {
3107
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
3108
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3165
+				if execution_state > 0 {
3166
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and execution_state=?"
3167
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3168
+				} else {
3169
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
3170
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3171
+				}
3172
+
3109
 			}
3173
 			}
3110
 
3174
 
3111
 		} else if patientType == 2 {
3175
 		} else if patientType == 2 {
3112
 			if patient_id > 0 {
3176
 			if patient_id > 0 {
3113
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
3114
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3177
+				if execution_state > 0 {
3178
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3179
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3180
+				} else {
3181
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
3182
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3183
+				}
3184
+
3115
 			} else {
3185
 			} else {
3116
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
3117
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3186
+				if execution_state > 0 {
3187
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and execution_state = ?"
3188
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3189
+				} else {
3190
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
3191
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3192
+				}
3193
+
3118
 			}
3194
 			}
3119
 
3195
 
3120
 		}
3196
 		}
3122
 	} else if adviceType == 3 {
3198
 	} else if adviceType == 3 {
3123
 		if patientType == 0 {
3199
 		if patientType == 0 {
3124
 			if patient_id > 0 {
3200
 			if patient_id > 0 {
3125
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ?  "
3126
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3201
+				if execution_state > 0 {
3202
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? and  execution_state = ?"
3203
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3204
+				} else {
3205
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ?  "
3206
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3207
+				}
3208
+
3127
 			} else {
3209
 			} else {
3128
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
3129
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3210
+				if execution_state > 0 {
3211
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and execution_state =? "
3212
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3213
+				} else {
3214
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
3215
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3216
+				}
3217
+
3130
 			}
3218
 			}
3131
 
3219
 
3132
 		} else if patientType == 1 {
3220
 		} else if patientType == 1 {
3133
 			if patient_id > 0 {
3221
 			if patient_id > 0 {
3134
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
3135
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3222
+				if execution_state > 0 {
3223
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3224
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3225
+				} else {
3226
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
3227
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3228
+				}
3229
+
3136
 			} else {
3230
 			} else {
3137
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
3138
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3231
+				if execution_state > 0 {
3232
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and execution_state =? "
3233
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3234
+				} else {
3235
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
3236
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3237
+				}
3238
+
3139
 			}
3239
 			}
3140
 
3240
 
3141
 		} else if patientType == 2 {
3241
 		} else if patientType == 2 {
3142
 			if patient_id > 0 {
3242
 			if patient_id > 0 {
3143
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ?"
3144
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3243
+				if execution_state > 0 {
3244
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3245
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3246
+				} else {
3247
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ?"
3248
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3249
+				}
3250
+
3145
 			} else {
3251
 			} else {
3146
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
3147
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3252
+				if execution_state > 0 {
3253
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and execution_state= ?"
3254
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3255
+				} else {
3256
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
3257
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3258
+				}
3259
+
3148
 			}
3260
 			}
3149
 
3261
 
3150
 		}
3262
 		}
3152
 	} else if adviceType == 2 && len(deliverWay) > 0 {
3264
 	} else if adviceType == 2 && len(deliverWay) > 0 {
3153
 		if patientType == 0 {
3265
 		if patientType == 0 {
3154
 			if patient_id > 0 {
3266
 			if patient_id > 0 {
3155
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
3156
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3267
+				if execution_state > 0 {
3268
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ? and execution_state = ?"
3269
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
3270
+				} else {
3271
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
3272
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3273
+				}
3274
+
3157
 			} else {
3275
 			} else {
3158
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
3159
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3276
+				if execution_state > 0 {
3277
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and execution_state = ?"
3278
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
3279
+				} else {
3280
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
3281
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3282
+				}
3283
+
3160
 			}
3284
 			}
3161
 
3285
 
3162
 		} else if patientType == 1 {
3286
 		} else if patientType == 1 {
3163
 			if patient_id > 0 {
3287
 			if patient_id > 0 {
3164
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ?"
3165
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
3288
+				if execution_state > 0 {
3289
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ? and execution_state = ?"
3290
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id, execution_state)
3291
+				} else {
3292
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ?"
3293
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
3294
+				}
3295
+
3166
 			} else {
3296
 			} else {
3167
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
3168
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3297
+				if execution_state > 0 {
3298
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and execution_state = ?"
3299
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, execution_state)
3300
+				} else {
3301
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
3302
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3303
+				}
3304
+
3169
 			}
3305
 			}
3170
 
3306
 
3171
 		} else if patientType == 2 {
3307
 		} else if patientType == 2 {
3172
 			if patient_id > 0 {
3308
 			if patient_id > 0 {
3309
+				if execution_state > 0 {
3310
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and patient_id = ? and execution_state = ?"
3311
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id, execution_state)
3312
+				} else {
3313
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and patient_id = ?"
3314
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3315
+				}
3173
 
3316
 
3174
 			} else {
3317
 			} else {
3175
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
3176
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3318
+				if execution_state > 0 {
3319
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ? and execution_state = ?"
3320
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, execution_state)
3321
+				} else {
3322
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
3323
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3324
+				}
3325
+
3177
 			}
3326
 			}
3178
 
3327
 
3179
 		}
3328
 		}
3181
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
3330
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
3182
 		if patientType == 0 {
3331
 		if patientType == 0 {
3183
 			if patient_id > 0 {
3332
 			if patient_id > 0 {
3184
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
3185
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3333
+				if execution_state > 0 {
3334
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ? and execution_state = ?"
3335
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3336
+				} else {
3337
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
3338
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3339
+				}
3340
+
3186
 			} else {
3341
 			} else {
3187
-				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
3188
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3342
+				if execution_state > 0 {
3343
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_state = ?"
3344
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3345
+				} else {
3346
+					adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
3347
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3348
+				}
3349
+
3189
 			}
3350
 			}
3190
 
3351
 
3191
 		} else if patientType == 1 {
3352
 		} else if patientType == 1 {
3192
 			if patient_id > 0 {
3353
 			if patient_id > 0 {
3193
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
3194
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3354
+				if execution_state > 0 {
3355
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ? and execution_state = ?"
3356
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id, execution_state)
3357
+				} else {
3358
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
3359
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3360
+				}
3361
+
3195
 			} else {
3362
 			} else {
3196
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
3197
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3363
+				if execution_state > 0 {
3364
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and execution_state = ?"
3365
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, execution_state)
3366
+				} else {
3367
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
3368
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3369
+				}
3370
+
3198
 			}
3371
 			}
3199
 
3372
 
3200
 		} else if patientType == 2 {
3373
 		} else if patientType == 2 {
3201
 			if patient_id > 0 {
3374
 			if patient_id > 0 {
3202
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ?"
3203
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3375
+				if execution_state > 0 {
3376
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ? and execution_state = ?"
3377
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id, execution_state)
3378
+				} else {
3379
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ?"
3380
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3381
+				}
3382
+
3204
 			} else {
3383
 			} else {
3205
-				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
3206
-				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3384
+				if execution_state > 0 {
3385
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and execution_state = ?"
3386
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_state)
3387
+				} else {
3388
+					adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
3389
+					adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3390
+				}
3391
+
3207
 			}
3392
 			}
3208
 
3393
 
3209
 		}
3394
 		}
3235
 	return vms, err
3420
 	return vms, err
3236
 }
3421
 }
3237
 
3422
 
3238
-func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
3423
+func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64, execution_state int64) ([]*HisMScheduleDoctorAdviceVM, error) {
3239
 
3424
 
3240
 	var vms []*HisMScheduleDoctorAdviceVM
3425
 	var vms []*HisMScheduleDoctorAdviceVM
3241
 	if len(deliverWay) > 0 {
3426
 	if len(deliverWay) > 0 {
3247
 			db = db.Where("partition_id = ?", partitionType)
3432
 			db = db.Where("partition_id = ?", partitionType)
3248
 		}
3433
 		}
3249
 		if patient_id > 0 {
3434
 		if patient_id > 0 {
3250
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3251
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3252
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3253
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3254
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
3255
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3256
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3257
-				}).
3258
-				Where("status = 1 AND user_org_id = ?", orgID)
3259
-			if scheduleDate != 0 {
3260
-				db = db.Where("schedule_date = ?", scheduleDate)
3435
+			if execution_state > 0 {
3436
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3437
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3438
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3439
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3440
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?  and patient_id = ? and execution_state = ?", orgID, scheduleDate, deliverWay, patient_id, execution_state).
3441
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3442
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3443
+					}).
3444
+					Where("status = 1 AND user_org_id = ?", orgID)
3445
+				if scheduleDate != 0 {
3446
+					db = db.Where("schedule_date = ?", scheduleDate)
3447
+				}
3448
+				err = db.Find(&vms).Error
3449
+			} else {
3450
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3451
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3452
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3453
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3454
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
3455
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3456
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3457
+					}).
3458
+					Where("status = 1 AND user_org_id = ?", orgID)
3459
+				if scheduleDate != 0 {
3460
+					db = db.Where("schedule_date = ?", scheduleDate)
3461
+				}
3462
+				err = db.Find(&vms).Error
3261
 			}
3463
 			}
3262
-			err = db.Find(&vms).Error
3464
+
3263
 		} else {
3465
 		} else {
3264
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3265
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3266
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3267
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3268
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3269
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3270
-					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3271
-				}).
3272
-				Where("status = 1 AND user_org_id = ?", orgID)
3273
-			if scheduleDate != 0 {
3274
-				db = db.Where("schedule_date = ?", scheduleDate)
3466
+			if execution_state > 0 {
3467
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3468
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3469
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3470
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3471
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and execution_state = ?", orgID, scheduleDate, deliverWay, execution_state).
3472
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3473
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3474
+					}).
3475
+					Where("status = 1 AND user_org_id = ?", orgID)
3476
+				if scheduleDate != 0 {
3477
+					db = db.Where("schedule_date = ?", scheduleDate)
3478
+				}
3479
+				err = db.Find(&vms).Error
3480
+			} else {
3481
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3482
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3483
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3484
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3485
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3486
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3487
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3488
+					}).
3489
+					Where("status = 1 AND user_org_id = ?", orgID)
3490
+				if scheduleDate != 0 {
3491
+					db = db.Where("schedule_date = ?", scheduleDate)
3492
+				}
3493
+				err = db.Find(&vms).Error
3275
 			}
3494
 			}
3276
-			err = db.Find(&vms).Error
3495
+
3277
 		}
3496
 		}
3278
 
3497
 
3279
 	} else {
3498
 	} else {
3285
 			db = db.Where("partition_id = ?", partitionType)
3504
 			db = db.Where("partition_id = ?", partitionType)
3286
 		}
3505
 		}
3287
 		if patient_id > 0 {
3506
 		if patient_id > 0 {
3288
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3289
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3290
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3291
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3292
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3293
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3294
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3295
-				}).
3296
-				Where("status = 1 AND user_org_id = ?", orgID)
3297
-			if scheduleDate != 0 {
3298
-				db = db.Where("schedule_date = ?", scheduleDate)
3507
+			if execution_state > 0 {
3508
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3509
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3510
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3511
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3512
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ? and execution_state = ?", orgID, scheduleDate, patient_id, execution_state).
3513
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3514
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3515
+					}).
3516
+					Where("status = 1 AND user_org_id = ?", orgID)
3517
+				if scheduleDate != 0 {
3518
+					db = db.Where("schedule_date = ?", scheduleDate)
3519
+				}
3520
+				err = db.Find(&vms).Error
3521
+			} else {
3522
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3523
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3524
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3525
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3526
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3527
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3528
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3529
+					}).
3530
+					Where("status = 1 AND user_org_id = ?", orgID)
3531
+				if scheduleDate != 0 {
3532
+					db = db.Where("schedule_date = ?", scheduleDate)
3533
+				}
3534
+				err = db.Find(&vms).Error
3299
 			}
3535
 			}
3300
-			err = db.Find(&vms).Error
3536
+
3301
 		} else {
3537
 		} else {
3302
-			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3303
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3304
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3305
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3306
-				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3307
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3308
-					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3309
-				}).
3310
-				Where("status = 1 AND user_org_id = ?", orgID)
3311
-			if scheduleDate != 0 {
3312
-				db = db.Where("schedule_date = ?", scheduleDate)
3538
+			if execution_state > 0 {
3539
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3540
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3541
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3542
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3543
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and execution_state = ?", orgID, scheduleDate, execution_state).
3544
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3545
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3546
+					}).
3547
+					Where("status = 1 AND user_org_id = ?", orgID)
3548
+				if scheduleDate != 0 {
3549
+					db = db.Where("schedule_date = ?", scheduleDate)
3550
+				}
3551
+				err = db.Find(&vms).Error
3552
+			} else {
3553
+				db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3554
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3555
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3556
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3557
+					Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3558
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3559
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3560
+					}).
3561
+					Where("status = 1 AND user_org_id = ?", orgID)
3562
+				if scheduleDate != 0 {
3563
+					db = db.Where("schedule_date = ?", scheduleDate)
3564
+				}
3565
+				err = db.Find(&vms).Error
3313
 			}
3566
 			}
3314
-			err = db.Find(&vms).Error
3567
+
3315
 		}
3568
 		}
3316
 
3569
 
3317
 	}
3570
 	}
3443
 	return
3696
 	return
3444
 }
3697
 }
3445
 
3698
 
3446
-func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
3699
+func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
3447
 	var vms []*HisMScheduleProjectVM
3700
 	var vms []*HisMScheduleProjectVM
3448
 
3701
 
3449
 	if patientType == 0 {
3702
 	if patientType == 0 {
3450
 
3703
 
3451
 		if patient_id > 0 {
3704
 		if patient_id > 0 {
3452
-			db := readDb.
3453
-				Table("xt_schedule").
3454
-				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3455
-				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3456
-					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3457
-				}).
3458
-				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3459
-				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3460
-				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3461
-				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3462
-					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3463
-				}).
3464
-				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3465
-					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3466
-				}).Where("status = 1 AND user_org_id = ?", orgID)
3467
-			if scheduleDate != 0 {
3468
-				db = db.Where("schedule_date = ?", scheduleDate)
3469
-			}
3470
-			err = db.Find(&vms).Error
3471
-		} else {
3472
-			if patient_id > 0 {
3705
+			if execution_state > 0 {
3473
 				db := readDb.
3706
 				db := readDb.
3474
 					Table("xt_schedule").
3707
 					Table("xt_schedule").
3475
-					Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3708
+					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3476
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3709
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3477
 						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3710
 						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3478
 					}).
3711
 					}).
3480
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3713
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3481
 					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3714
 					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3482
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3715
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3483
-						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3716
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3484
 					}).
3717
 					}).
3485
 					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3718
 					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3486
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3719
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3494
 					Table("xt_schedule").
3727
 					Table("xt_schedule").
3495
 					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3728
 					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3496
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3729
 					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3497
-						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3730
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3498
 					}).
3731
 					}).
3499
 					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3732
 					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3500
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3733
 					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3501
-					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3734
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3502
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3735
 					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3503
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3736
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3504
 					}).
3737
 					}).
3510
 				}
3743
 				}
3511
 				err = db.Find(&vms).Error
3744
 				err = db.Find(&vms).Error
3512
 			}
3745
 			}
3746
+
3747
+		} else {
3748
+			if patient_id > 0 {
3749
+				if execution_state > 0 {
3750
+					db := readDb.
3751
+						Table("xt_schedule").
3752
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3753
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3754
+							return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3755
+						}).
3756
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3757
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3758
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3759
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3760
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3761
+						}).
3762
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3763
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3764
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3765
+					if scheduleDate != 0 {
3766
+						db = db.Where("schedule_date = ?", scheduleDate)
3767
+					}
3768
+					err = db.Find(&vms).Error
3769
+				} else {
3770
+					db := readDb.
3771
+						Table("xt_schedule").
3772
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3773
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3774
+							return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3775
+						}).
3776
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3777
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3778
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3779
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3780
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3781
+						}).
3782
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3783
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3784
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3785
+					if scheduleDate != 0 {
3786
+						db = db.Where("schedule_date = ?", scheduleDate)
3787
+					}
3788
+					err = db.Find(&vms).Error
3789
+				}
3790
+
3791
+			} else {
3792
+				if execution_state > 0 {
3793
+					db := readDb.
3794
+						Table("xt_schedule").
3795
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3796
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3797
+							return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3798
+						}).
3799
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3800
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3801
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3802
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3803
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3804
+						}).
3805
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3806
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3807
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3808
+					if scheduleDate != 0 {
3809
+						db = db.Where("schedule_date = ?", scheduleDate)
3810
+					}
3811
+					err = db.Find(&vms).Error
3812
+				} else {
3813
+					db := readDb.
3814
+						Table("xt_schedule").
3815
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3816
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3817
+							return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3818
+						}).
3819
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3820
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3821
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3822
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3823
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3824
+						}).
3825
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3826
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3827
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3828
+					if scheduleDate != 0 {
3829
+						db = db.Where("schedule_date = ?", scheduleDate)
3830
+					}
3831
+					err = db.Find(&vms).Error
3832
+				}
3833
+
3834
+			}
3513
 		}
3835
 		}
3514
 
3836
 
3515
 	}
3837
 	}
3627
 	err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
3949
 	err = readUserDb.Where("org_id = ? and admin_user_id = ? and status =1 ", orgid, admin_user_id).Find(&role).Error
3628
 	return role, err
3950
 	return role, err
3629
 }
3951
 }
3952
+
3953
+func GetDialysisGood(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
3954
+	err = readDb.Where("org_id = ? and status = 1 and record_time >= ?", orgID, scheduleDate).Group("patient_id").Find(&auto).Error
3955
+	return auto, err
3956
+}

+ 25 - 2
service/schedule_service.go View File

674
 
674
 
675
 func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
675
 func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
676
 
676
 
677
-	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
677
+	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
678
 	if orgid > 0 {
678
 	if orgid > 0 {
679
 		db = db.Where("x.user_org_id = ?", orgid)
679
 		db = db.Where("x.user_org_id = ?", orgid)
680
 	}
680
 	}
701
 
701
 
702
 func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
702
 func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
703
 
703
 
704
-	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
704
+	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
705
 	if orgid > 0 {
705
 	if orgid > 0 {
706
 		db = db.Where("x.user_org_id = ?", orgid)
706
 		db = db.Where("x.user_org_id = ?", orgid)
707
 	}
707
 	}
1160
 	err = XTReadDB().Where("user_org_id = ? and (lapseto = 2 || lapseto = 3) and status = 1", orgid).Find(&patient).Error
1160
 	err = XTReadDB().Where("user_org_id = ? and (lapseto = 2 || lapseto = 3) and status = 1", orgid).Find(&patient).Error
1161
 	return patient, err
1161
 	return patient, err
1162
 }
1162
 }
1163
+
1164
+func GetInitPrintData(patient_id int64, scheduleDate int64, orgid int64) (list []*models.VmSchedulesRemind, err error) {
1165
+
1166
+	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
1167
+	if orgid > 0 {
1168
+		db = db.Where("x.user_org_id = ?", orgid)
1169
+	}
1170
+	if patient_id > 0 {
1171
+		db = db.Where("patient_id = ?", patient_id)
1172
+	}
1173
+	if scheduleDate > 0 {
1174
+		db = db.Where("x.schedule_date >=? and x.schedule_date<=?", scheduleDate, scheduleDate)
1175
+	}
1176
+	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date =?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
1177
+		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
1178
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date = ?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
1179
+		return db.Where("status =1").Order("id asc")
1180
+	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
1181
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
1182
+	}).Find(&list).Error
1183
+
1184
+	return list, err
1185
+}