Browse Source

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

XMLWAN 1 year ago
parent
commit
64c42d6089

+ 1 - 0
.idea/XT_New.iml View File

@@ -1,5 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module type="WEB_MODULE" version="4">
3
+  <component name="Go" enabled="true" />
3 4
   <component name="NewModuleRootManager">
4 5
     <content url="file://$MODULE_DIR$" />
5 6
     <orderEntry type="inheritedJdk" />

+ 0 - 3
.idea/misc.xml View File

@@ -3,9 +3,6 @@
3 3
   <component name="JavaScriptSettings">
4 4
     <option name="languageLevel" value="ES6" />
5 5
   </component>
6
-  <component name="RustProjectSettings">
7
-    <option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
8
-  </component>
9 6
   <component name="SvnBranchConfigurationManager">
10 7
     <option name="myConfigurationMap">
11 8
       <map>

+ 2 - 2
conf/app.conf View File

@@ -1,6 +1,6 @@
1 1
 appname = 血透
2
-httpport = 9529
3
-runmode = dev
2
+httpport = 9531
3
+runmode =dev
4 4
 #dev/prod
5 5
 
6 6
 #

+ 5 - 0
controllers/his_api_controller.go View File

@@ -5995,6 +5995,8 @@ func (c *HisApiController) GetUploadInfo() {
5995 5995
 			PrivatePrice:          private_price,
5996 5996
 			SettleEndTime:         end_time,
5997 5997
 			SettleStartTime:       start_time,
5998
+			PsnPartAmt:            totals,
5999
+			PsnCashPay:            totals,
5998 6000
 			SettleType:            settle_accounts_type,
5999 6001
 			FaPiaoCode:            fapiao_code,
6000 6002
 			FaPiaoNumber:          fapiao_number,
@@ -6270,6 +6272,7 @@ func (c *HisApiController) GetUploadInfo() {
6270 6272
 			c.ServeSuccessJSON(map[string]interface{}{
6271 6273
 				"msg": "结算成功",
6272 6274
 			})
6275
+
6273 6276
 		}
6274 6277
 	} else {
6275 6278
 		if tempOrder.IsPre > 0 {
@@ -8842,6 +8845,8 @@ func (c *HisApiController) PreSettle() {
8842 8845
 		SettleEndTime:      end_time,
8843 8846
 		SettleStartTime:    start_time,
8844 8847
 		SettleType:         settle_accounts_type,
8848
+		PsnPartAmt:         totals,
8849
+		PsnCashPay:         totals,
8845 8850
 		PType:              2,
8846 8851
 		IsPre:              1,
8847 8852
 		MedType:            strconv.Itoa(int(reg_type)),

+ 173 - 39
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -2217,11 +2217,12 @@ func (this *DialysisAPIController) StartDialysis() {
2217 2217
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
2218 2218
 
2219 2219
 	//查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
2220
+	//sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
2220 2221
 
2221 2222
 	schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
2222 2223
 
2223 2224
 	//查询该床位是否有人用了
2224
-	order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
2225
+	order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
2225 2226
 
2226 2227
 	if err == gorm.ErrRecordNotFound { //空床位
2227 2228
 		// 修改了床位逻辑
@@ -2247,33 +2248,10 @@ func (this *DialysisAPIController) StartDialysis() {
2247 2248
 	} else if err == nil {
2248 2249
 		if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
2249 2250
 
2250
-			if order_err == nil {
2251
-				if order.ID > 0 { //该机位被其他人占用了
2252
-					this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
2253
-					return
2254
-
2255
-				} else {
2256
-					daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
2257
-					if daySchedule.ID > 0 {
2258
-						//daySchedule.PartitionId = deviceNumber.ZoneID
2259
-						//daySchedule.BedId = bedID
2260
-						//daySchedule.ScheduleType = schedual_type
2261
-						//daySchedule.UpdatedTime = time.Now().Unix()
2262
-						//err := service.UpdateSchedule(&daySchedule)
2263
-						xtSchedule := models.Schedule{
2264
-							PartitionId:  deviceNumber.ZoneID,
2265
-							BedId:        bedID,
2266
-							ScheduleType: schedual_type,
2267
-							UpdatedTime:  time.Now().Unix(),
2268
-						}
2269
-						err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
2270
-						if err != nil {
2271
-							this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2272
-							return
2273
-						}
2274
-					}
2275
-				}
2276
-			} else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
2251
+			if order.ID > 0 { //该机位被其他人占用了
2252
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
2253
+				return
2254
+			} else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
2277 2255
 				daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
2278 2256
 				if daySchedule.ID > 0 {
2279 2257
 					//daySchedule.PartitionId = deviceNumber.ZoneID
@@ -2281,23 +2259,44 @@ func (this *DialysisAPIController) StartDialysis() {
2281 2259
 					//daySchedule.ScheduleType = schedual_type
2282 2260
 					//daySchedule.UpdatedTime = time.Now().Unix()
2283 2261
 					//err := service.UpdateSchedule(&daySchedule)
2284
-					xtSchedule := models.Schedule{
2285
-						PartitionId:  deviceNumber.ZoneID,
2286
-						BedId:        bedID,
2287
-						ScheduleType: schedual_type,
2288
-						UpdatedTime:  time.Now().Unix(),
2289
-					}
2290
-					err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
2291
-					if err != nil {
2292
-						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2293
-						return
2294
-					}
2262
+					//xtSchedule := models.Schedule{
2263
+					//	PartitionId:  deviceNumber.ZoneID,
2264
+					//	BedId:        bedID,
2265
+					//	ScheduleType: schedual_type,
2266
+					//	UpdatedTime:  time.Now().Unix(),
2267
+					//}
2268
+					//err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
2269
+					service.UpdateScheduleTwo(daySchedule, schedule)
2270
+
2295 2271
 				}
2296 2272
 			}
2297 2273
 		} else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
2298 2274
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
2299 2275
 			return
2300 2276
 		}
2277
+		//else if order.ID == 0 { //该床位没被占用
2278
+		//	daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
2279
+		//	if daySchedule.ID > 0 {
2280
+		//		//daySchedule.PartitionId = deviceNumber.ZoneID
2281
+		//		//daySchedule.BedId = bedID
2282
+		//		//daySchedule.ScheduleType = schedual_type
2283
+		//		//daySchedule.UpdatedTime = time.Now().Unix()
2284
+		//		//err := service.UpdateSchedule(&daySchedule)
2285
+		//		xtSchedule := models.Schedule{
2286
+		//			PartitionId:  deviceNumber.ZoneID,
2287
+		//			BedId:        bedID,
2288
+		//			ScheduleType: schedual_type,
2289
+		//			UpdatedTime:  time.Now().Unix(),
2290
+		//		}
2291
+		//		err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
2292
+		//		if err != nil {
2293
+		//			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2294
+		//			return
2295
+		//		}
2296
+		//	}
2297
+		//}
2298
+		//}
2299
+
2301 2300
 	} else if err != nil {
2302 2301
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2303 2302
 		return
@@ -7534,3 +7533,138 @@ func (this *DialysisAPIController) GetCheckMobileAdvice() {
7534 7533
 	}
7535 7534
 
7536 7535
 }
7536
+
7537
+func (this *DialysisAPIController) CheckSchedule() {
7538
+
7539
+	patientID, _ := this.GetInt64("patient_id")
7540
+	recordDateStr := this.GetString("record_date")
7541
+	nurseID, _ := this.GetInt64("nurse")
7542
+	schedual_type, _ := this.GetInt64("schedual_type")
7543
+
7544
+	bedID, _ := this.GetInt64("bed")
7545
+	start_time := this.GetString("start_time")
7546
+
7547
+	if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
7548
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7549
+		return
7550
+	}
7551
+
7552
+	startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
7553
+	if parseStartDateErr != nil {
7554
+		this.ErrorLog("时间解析失败:%v", parseStartDateErr)
7555
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7556
+		return
7557
+	}
7558
+
7559
+	recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
7560
+	if parseErr != nil {
7561
+		this.ErrorLog("时间解析失败:%v", parseErr)
7562
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7563
+		return
7564
+	}
7565
+
7566
+	adminUserInfo := this.GetMobileAdminUserInfo()
7567
+	patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
7568
+	if getPatientErr != nil {
7569
+		this.ErrorLog("获取患者信息失败:%v", getPatientErr)
7570
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7571
+		return
7572
+	} else if patient == nil {
7573
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
7574
+		return
7575
+	}
7576
+
7577
+	nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
7578
+	if getNurseErr != nil {
7579
+		this.ErrorLog("获取护士失败:%v", getNurseErr)
7580
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7581
+		return
7582
+	} else if nurse == nil {
7583
+		this.ErrorLog("护士不存在")
7584
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7585
+		return
7586
+	}
7587
+
7588
+	deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
7589
+	if getDeviceNumberErr != nil {
7590
+		this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
7591
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7592
+		return
7593
+	} else if deviceNumber == nil {
7594
+		this.ErrorLog("床位号不存在")
7595
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7596
+		return
7597
+	}
7598
+
7599
+	dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
7600
+	if getRecordErr != nil {
7601
+		this.ErrorLog("获取透析记录失败:%v", getRecordErr)
7602
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
7603
+		return
7604
+	} else if dialysisRecord != nil {
7605
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
7606
+		return
7607
+	}
7608
+
7609
+	scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
7610
+	scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
7611
+	timeLayout := "2006-01-02 15:04:05"
7612
+	loc, _ := time.LoadLocation("Local")
7613
+	theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
7614
+	theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
7615
+	schedulestartTime := theStartTime.Unix()
7616
+	scheduleendTime := theEndTime.Unix()
7617
+
7618
+	//查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
7619
+	//sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
7620
+
7621
+	schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
7622
+
7623
+	//查询该床位是否有人用了
7624
+	order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
7625
+
7626
+	if err == nil {
7627
+		if schedule.ID == 0 {
7628
+			this.ServeSuccessJSON(map[string]interface{}{
7629
+				"status": 0,
7630
+			})
7631
+
7632
+		} else {
7633
+
7634
+			if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
7635
+				if order.ID > 0 { //该机位被其他人占用了
7636
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
7637
+					return
7638
+				} else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
7639
+					daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
7640
+					if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
7641
+
7642
+						this.ServeSuccessJSON(map[string]interface{}{
7643
+							"status": 1,
7644
+							"msg":    "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
7645
+						})
7646
+						return
7647
+					} else {
7648
+						this.ServeSuccessJSON(map[string]interface{}{
7649
+							"status": 0,
7650
+						})
7651
+					}
7652
+				}
7653
+			} else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
7654
+				this.ServeSuccessJSON(map[string]interface{}{
7655
+					"status": 2,
7656
+					"msg":    "当前机位已有患者在使用,请重新选择!",
7657
+				})
7658
+
7659
+			}
7660
+
7661
+		}
7662
+
7663
+	} else {
7664
+		this.ServeSuccessJSON(map[string]interface{}{
7665
+			"status": 0,
7666
+		})
7667
+
7668
+	}
7669
+
7670
+}

+ 5 - 0
controllers/mobile_api_controllers/mobile_api_router_register.go View File

@@ -174,6 +174,11 @@ func MobileAPIControllersRegisterRouters() {
174 174
 
175 175
 	beego.Router("/m/api/getdialysisrecordeorder", &DialysisAPIController{}, "Get:GetDialysisRecordOrder")
176 176
 
177
+	beego.Router("/m/api/getdialysisrecordeorder", &DialysisAPIController{}, "Get:GetDialysisRecordOrder")
178
+	beego.Router("/m/api/checksch/get", &DialysisAPIController{}, "Get:CheckSchedule")
179
+
180
+	//beego.Router("/m/api/getscheduletypebyidlist",&DialysisAPIController{},"Get:GetScheduleTypeByIdList")
181
+
177 182
 	beego.Router("/m/api/getscheduletypebyidlist", &DialysisAPIController{}, "Get:GetScheduleTypeByIdList")
178 183
 
179 184
 	beego.Router("/m/api/savepatientpicture", &DialysisAPIController{}, "Get:SavePatientPicture")

+ 36 - 0
controllers/patient_api_controller.go View File

@@ -841,6 +841,25 @@ func (c *PatientApiController) CreateDialysisSolution() {
841 841
 	solution.ParentId = 0
842 842
 	solution.SolutionStatus = 1
843 843
 
844
+	//records, _ := service.GetAllSchedules()
845
+
846
+	schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
847
+	for _, sch := range schs {
848
+		var DialysisMachineName string
849
+		if len(solution.DialysisDialyszers) > 0 {
850
+			DialysisMachineName = solution.DialysisDialyszers
851
+		}
852
+		if len(solution.DialyzerPerfusionApparatus) > 0 {
853
+			DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
854
+		}
855
+
856
+		if len(solution.DialysisIrrigation) > 0 {
857
+			DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
858
+		}
859
+		sch.DialysisMachineName = DialysisMachineName
860
+		service.UpdateSch(sch)
861
+	}
862
+
844 863
 	err := service.CreatePatientDialysisSolution(&solution)
845 864
 
846 865
 	//获取最新1条
@@ -923,6 +942,23 @@ func (c *PatientApiController) UpdateDialysisSolution() {
923 942
 		service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
924 943
 	}
925 944
 
945
+	schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
946
+	for _, sch := range schs {
947
+		var DialysisMachineName string
948
+		if len(solution.DialysisDialyszers) > 0 {
949
+			DialysisMachineName = solution.DialysisDialyszers
950
+		}
951
+		if len(solution.DialyzerPerfusionApparatus) > 0 {
952
+			DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
953
+		}
954
+
955
+		if len(solution.DialysisIrrigation) > 0 {
956
+			DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
957
+		}
958
+		sch.DialysisMachineName = DialysisMachineName
959
+		service.UpdateSch(sch)
960
+	}
961
+
926 962
 	if err != nil {
927 963
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
928 964
 		return

+ 246 - 0
controllers/public_api_controller.go View File

@@ -73,8 +73,208 @@ func PublicApiRegistRouters() {
73 73
 
74 74
 	beego.Router("/handelHis", &PublicApiController{}, "get:HandleHisTwo")
75 75
 
76
+	beego.Router("/handelProject", &PublicApiController{}, "get:HandleProject")
77
+
78
+	beego.Router("/handelsettledata", &PublicApiController{}, "get:HandleSettleData")
79
+
80
+	beego.Router("/handelhispatient", &PublicApiController{}, "get:HandleHisPatient")
81
+
76 82
 	//beego.Router("/handelOrder", &PublicApiController{}, "get:HandleOrder")
77 83
 
84
+	beego.Router("/handleExportData", &PublicApiController{}, "get:HandleExportAllData")
85
+
86
+	beego.Router("/handleExportData10138", &PublicApiController{}, "get:HandleExportData10138")
87
+
88
+	beego.Router("/handleData10265", &PublicApiController{}, "get:HandleData10265")
89
+
90
+	beego.Router("/handleData10106", &PublicApiController{}, "get:HandleData10106")
91
+
92
+	beego.Router("/handelschedule", &PublicApiController{}, "get:HandleSchedule")
93
+	beego.Router("/handelscheduleTwo", &PublicApiController{}, "get:HandleScheduleTwo")
94
+
95
+}
96
+
97
+type ResultFiveT struct {
98
+	Balc                   float64 `json:"balc"`
99
+	CvlservFlag            string  `json:"cvlserv_flag"`
100
+	EmpName                string  `json:"emp_name"`
101
+	InsuplcAdmdvs          string  `json:"insuplc_admdvs"`
102
+	Insutype               string  `json:"insutype"`
103
+	PausInsuDansuplcAdmdvs string  `json:"paus_insu_dansuplc_admdvs"`
104
+	PausInsuDate           string  `json:"paus_insu_date"`
105
+	PsnInsuDate            string  `json:"psn_insu_date"`
106
+	PsnInsuStas            string  `json:"psn_insu_stas"`
107
+	PsnType                string  `json:"psn_type"`
108
+}
109
+
110
+func (c *PublicApiController) HandleSchedule() {
111
+	//fmt.Println("~~~~~~")
112
+	service.GetLongSolution()
113
+
114
+}
115
+
116
+func (c *PublicApiController) HandleScheduleTwo() {
117
+	models, _ := service.GetAllSchMode()
118
+	for _, item := range models {
119
+		if item.Mode == 1 {
120
+			templates, _ := service.GetOrgPatientScheduleTemplateIDs(item.OrgID)
121
+			thisTime := time.Now()
122
+			_, theWeek := thisTime.ISOWeek()
123
+			templates[0].Week = theWeek
124
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
125
+		} else if item.Mode == 2 {
126
+			templates, _ := service.GetOrgPatientScheduleTemplateIDs(item.OrgID)
127
+			now := time.Now()
128
+			nextSecWeek := now.AddDate(0, 0, 14)
129
+			nextWeek := now.AddDate(0, 0, 7)
130
+			if item.ExecuteTimes%2 == 0 { //下第二周生成的是
131
+				templates[0].Week = service.GetWeeks(nextWeek.Format("2006-01-02 15:04:05"))
132
+				templates[1].Week = service.GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
133
+				service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
134
+				service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
135
+
136
+			} else if item.ExecuteTimes%2 == 1 {
137
+				templates[0].Week = service.GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
138
+				templates[1].Week = service.GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
139
+				service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
140
+				service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
141
+
142
+			}
143
+
144
+		}
145
+	}
146
+
147
+}
148
+
149
+func (c *PublicApiController) HandleHisPatient() {
150
+
151
+	ps, _ := service.GetHisPatient11111(10215)
152
+	for _, item := range ps {
153
+		var rf []*ResultFiveT
154
+		json.Unmarshal([]byte(item.Iinfo), &rf)
155
+		var insuplc_admdvs string
156
+		var insutype string
157
+		var is390 int = 0
158
+		var is310 int = 0
159
+		var insutypes []*ResultFiveT
160
+
161
+		for _, item := range rf {
162
+			if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
163
+				insutypes = append(insutypes, item)
164
+			}
165
+		}
166
+
167
+		fmt.Println(insutypes)
168
+		if len(insutypes) == 1 {
169
+			insutype = insutypes[0].Insutype
170
+			is390 = 1
171
+			fmt.Println("111111")
172
+			//insuplc_admdvs = insutypes[0].InsuplcAdmdvs
173
+		} else {
174
+			fmt.Println("222222")
175
+
176
+			for _, i := range insutypes {
177
+				if i.Insutype == "390" {
178
+					is390 = 1
179
+				}
180
+
181
+				if i.Insutype == "310" {
182
+					is310 = 1
183
+				}
184
+			}
185
+		}
186
+
187
+		if is390 == 1 {
188
+			insutype = "390"
189
+		}
190
+
191
+		if is310 == 1 {
192
+			insutype = "310"
193
+		}
194
+
195
+		if len(insutypes) == 0 {
196
+			insutype = "310"
197
+		}
198
+		for _, item := range rf {
199
+			if item.Insutype == insutype {
200
+				insuplc_admdvs = item.InsuplcAdmdvs
201
+			}
202
+		}
203
+		item.InsuplcAdmdvs = insuplc_admdvs
204
+
205
+		service.SaveHP(item)
206
+	}
207
+}
208
+
209
+func (c *PublicApiController) HandleSettleData() {
210
+	orders, _ := service.GetHisOrderDetailThree()
211
+	c.ServeSuccessJSON(map[string]interface{}{
212
+		"order": orders,
213
+	})
214
+}
215
+
216
+//func (c *PublicApiController) HandleData10106() {
217
+//	start_time := c.GetString("start_time")
218
+//	end_time := c.GetString("end_time")
219
+//
220
+//	timeLayout := "2006-01-02"
221
+//	loc, _ := time.LoadLocation("Local")
222
+//	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
223
+//	if err != nil {
224
+//
225
+//	}
226
+//	startRecordDateTime := startTime.Unix()
227
+//
228
+//	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
229
+//	if err != nil {
230
+//
231
+//	}
232
+//	endRecordDateTime := endTime.Unix()
233
+//	fmt.Println(startRecordDateTime)
234
+//	fmt.Println(endRecordDateTime)
235
+//
236
+//	orders, _ := service.GetHisOrderDetail10106(startRecordDateTime, endRecordDateTime)
237
+//	c.ServeSuccessJSON(map[string]interface{}{
238
+//		"order": orders,
239
+//	})
240
+//}
241
+
242
+func (c *PublicApiController) HandleData10106() {
243
+	start_time := c.GetString("start_time")
244
+	end_time := c.GetString("end_time")
245
+
246
+	start_time = "2022-11-01"
247
+	end_time = "2022-11-30"
248
+	timeLayout := "2006-01-02"
249
+	loc, _ := time.LoadLocation("Local")
250
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
251
+	if err != nil {
252
+
253
+	}
254
+	startRecordDateTime := startTime.Unix()
255
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
256
+	if err != nil {
257
+
258
+	}
259
+	endRecordDateTime := endTime.Unix()
260
+	fmt.Println(startRecordDateTime)
261
+	fmt.Println(endRecordDateTime)
262
+
263
+	orders, _ := service.GetHisOrderDetail10106(startRecordDateTime, endRecordDateTime)
264
+	c.ServeSuccessJSON(map[string]interface{}{
265
+		"order": orders,
266
+	})
267
+}
268
+
269
+func (c *PublicApiController) HandleProject() {
270
+	prescriptions := service.GetAllProjectPrescription()
271
+	for _, item := range prescriptions {
272
+		ps := service.GetAllProject(item.ID)
273
+		for _, subItem := range ps {
274
+			subItem.Status = 0
275
+			service.SaveHisProject(subItem)
276
+		}
277
+	}
78 278
 }
79 279
 
80 280
 func (c *PublicApiController) HandleHisTwo() {
@@ -2070,3 +2270,49 @@ func (c *PublicApiController) Handle10215() {
2070 2270
 	}
2071 2271
 
2072 2272
 }
2273
+
2274
+func (c *PublicApiController) HandleExportAllData() {
2275
+	orders, _ := service.GetHisOrderDetail9504()
2276
+	c.ServeSuccessJSON(map[string]interface{}{
2277
+		"order": orders,
2278
+	})
2279
+}
2280
+
2281
+func (c *PublicApiController) HandleExportData10138() {
2282
+	orders, _ := service.GetHisOrderDetail10138()
2283
+	c.ServeSuccessJSON(map[string]interface{}{
2284
+		"order": orders,
2285
+	})
2286
+}
2287
+
2288
+func (c *PublicApiController) HandleData10265() {
2289
+	orders, _ := service.GetHisOrder10265()
2290
+	for _, items := range orders {
2291
+		if items.AdviceId == 0 && items.ProjectId > 0 {
2292
+			p, _ := service.GetHisPrescriptionProjectByIDTwo(items.ProjectId)
2293
+			if p.Type == 2 {
2294
+				if p.HisProject.CostClassify == 3 {
2295
+					items.MedChrgitmType = "04"
2296
+				}
2297
+
2298
+				if p.HisProject.CostClassify == 2 {
2299
+					items.MedChrgitmType = "05"
2300
+				}
2301
+
2302
+				if p.HisProject.CostClassify == 8 {
2303
+					items.MedChrgitmType = "03"
2304
+				}
2305
+
2306
+				//p.HisProject.CostClassify == 8
2307
+
2308
+			} else {
2309
+
2310
+				items.MedChrgitmType = "08"
2311
+
2312
+			}
2313
+
2314
+		}
2315
+		service.SaveOrderInfo(items)
2316
+	}
2317
+
2318
+}

File diff suppressed because it is too large
+ 1154 - 29
controllers/schedule_api_controller.go


+ 311 - 62
controllers/schedule_template_api_controller.go View File

@@ -4,9 +4,9 @@ import (
4 4
 	"XT_New/enums"
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7
-	"XT_New/utils"
8 7
 	"encoding/json"
9 8
 	"fmt"
9
+	"strings"
10 10
 	"time"
11 11
 
12 12
 	"github.com/astaxie/beego"
@@ -17,6 +17,8 @@ func PatientScheduleTemplateAPIControllerRegistRouters() {
17 17
 	beego.Router("/api/schtemp/p/setmode", &PatientScheduleTemplateAPIController{}, "post:SetMode")
18 18
 	beego.Router("/api/schtemp/p/update_sch", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedules")
19 19
 
20
+	beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList")
21
+
20 22
 	// beego.Router("/api/test", &TestCtr{}, "get:Test")
21 23
 }
22 24
 
@@ -52,6 +54,12 @@ type PatientScheduleTemplateAPIController struct {
52 54
 func (this *PatientScheduleTemplateAPIController) InitData() {
53 55
 	adminUserInfo := this.GetAdminUserInfo()
54 56
 
57
+	patitionIdStr := this.GetString("patitionid")
58
+	var ids []string
59
+	if len(patitionIdStr) > 0 {
60
+		ids = strings.Split(patitionIdStr, ",")
61
+	}
62
+
55 63
 	mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
56 64
 	if getModeErr != nil {
57 65
 		this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr)
@@ -76,7 +84,7 @@ func (this *PatientScheduleTemplateAPIController) InitData() {
76 84
 		}
77 85
 	}
78 86
 
79
-	deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId)
87
+	deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId, ids)
80 88
 
81 89
 	fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers)
82 90
 	if getDeviceNumbersErr != nil {
@@ -92,18 +100,34 @@ func (this *PatientScheduleTemplateAPIController) InitData() {
92 100
 		return
93 101
 	}
94 102
 	if len(templates) == 0 {
95
-		firstTemp, secondTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId)
103
+		firstTemp, secondTemp, thirdTemp, fourTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId)
96 104
 		if createTempErr != nil {
97
-			this.ErrorLog("创建个排班模板失败:%v", createTempErr)
105
+			this.ErrorLog("创建4个排班模板失败:%v", createTempErr)
98 106
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99 107
 			return
100 108
 		}
101
-		templates = append(templates, firstTemp, secondTemp)
109
+		templates = append(templates, firstTemp, secondTemp, thirdTemp, fourTemp)
102 110
 
103 111
 	} else if len(templates) == 1 {
104
-		temp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId)
112
+		temp, thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId)
113
+		if createTempErr != nil {
114
+			this.ErrorLog("创建3个排班模板失败:%v", createTempErr)
115
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
116
+			return
117
+		}
118
+		templates = append(templates, temp, thirdTemp, fourTemp)
119
+	} else if len(templates) == 2 {
120
+		thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplateTwo(adminUserInfo.CurrentOrgId)
121
+		if createTempErr != nil {
122
+			this.ErrorLog("创建2个排班模板失败:%v", createTempErr)
123
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
124
+			return
125
+		}
126
+		templates = append(templates, thirdTemp, fourTemp)
127
+	} else if len(templates) == 3 {
128
+		temp, createTempErr := service.CreatePatientScheduleTemplateThree(adminUserInfo.CurrentOrgId)
105 129
 		if createTempErr != nil {
106
-			this.ErrorLog("创建两个排班模板失败:%v", createTempErr)
130
+			this.ErrorLog("创建1个排班模板失败:%v", createTempErr)
107 131
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
108 132
 			return
109 133
 		}
@@ -118,31 +142,39 @@ func (this *PatientScheduleTemplateAPIController) InitData() {
118 142
 	}
119 143
 
120 144
 	// 获取本周的排班
121
-	monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
122
-	schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
123
-	if getScheduleErr != nil {
124
-		this.ErrorLog("获取本周排班失败:%v", getScheduleErr)
125
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
126
-		return
127
-	}
145
+	//monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
146
+	//schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
147
+	//if getScheduleErr != nil {
148
+	//	this.ErrorLog("获取本周排班失败:%v", getScheduleErr)
149
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
150
+	//	return
151
+	//}
128 152
 
129 153
 	this.ServeSuccessJSON(map[string]interface{}{
130 154
 		"template_mode":  mode,
131 155
 		"device_numbers": deviceNumbers,
132 156
 		"templates":      templates,
133 157
 		"patients":       patients,
134
-		"schedules":      schedules,
158
+		//"schedules":      schedules,
135 159
 	})
136 160
 }
137 161
 
138 162
 // /api/schtemp/p/setmode [post]
139
-// @param mode:int 0.不启用模板 1.单周模板 2.双周模板
163
+// @param mode:int 0.不启用模板 1.单周模板 2.双周模板 3.三周模版   4.四周模版
140 164
 func (this *PatientScheduleTemplateAPIController) SetMode() {
141 165
 	mode, _ := this.GetInt8("mode")
166
+	week_time, _ := this.GetInt8("week_time")
167
+
142 168
 	if mode != 1 && mode != 2 && mode != 0 && mode != 3 && mode != 4 {
143 169
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
144 170
 		return
145 171
 	}
172
+	if mode > 0 {
173
+		if week_time == 0 {
174
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
175
+			return
176
+		}
177
+	}
146 178
 
147 179
 	adminUserInfo := this.GetAdminUserInfo()
148 180
 
@@ -156,9 +188,10 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
156 188
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
157 189
 		return
158 190
 	}
191
+	templateMode.Week = int64(week_time)
159 192
 
160 193
 	if mode != templateMode.Mode {
161
-		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下两周的排班
194
+		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2  则直接清除下四周的排班
162 195
 			templateMode.Mode = mode
163 196
 			templateMode.ExecuteTimes = 0
164 197
 			templateMode.ModifyTime = time.Now().Unix()
@@ -184,14 +217,36 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
184 217
 			templateMode.Mode = mode
185 218
 			templateMode.ExecuteTimes = 0
186 219
 			templateMode.ModifyTime = time.Now().Unix()
187
-			updateErr := service.SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode)
220
+			updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
188 221
 			if updateErr != nil {
189 222
 				this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
190 223
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
191 224
 				return
192 225
 			}
193 226
 
194
-		} else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班,将第一周的排班重复到第二周
227
+		} else if templateMode.Mode == 1 && mode == 3 {
228
+			templateMode.Mode = mode
229
+			templateMode.ExecuteTimes = 0
230
+			templateMode.ModifyTime = time.Now().Unix()
231
+			updateErr := service.SaveTemplateMode(templateMode)
232
+			if updateErr != nil {
233
+				this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
234
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
235
+				return
236
+			}
237
+
238
+		} else if templateMode.Mode == 1 && mode == 4 {
239
+			templateMode.Mode = mode
240
+			templateMode.ExecuteTimes = 0
241
+			templateMode.ModifyTime = time.Now().Unix()
242
+			updateErr := service.SaveTemplateMode(templateMode)
243
+			if updateErr != nil {
244
+				this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
245
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
246
+				return
247
+			}
248
+
249
+		} else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班
195 250
 			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
196 251
 			if getTemplateIDsErr != nil {
197 252
 				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
@@ -215,8 +270,160 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
215 270
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
216 271
 				return
217 272
 			}
273
+		} else if templateMode.Mode == 2 && mode == 3 { //
274
+			templateMode.Mode = mode
275
+			templateMode.ExecuteTimes = 0
276
+			templateMode.ModifyTime = time.Now().Unix()
277
+			updateErr := service.SaveTemplateMode(templateMode)
278
+			if updateErr != nil {
279
+				this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
280
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
281
+				return
282
+			}
283
+		} else if templateMode.Mode == 2 && mode == 4 { //
284
+			templateMode.Mode = mode
285
+			templateMode.ExecuteTimes = 0
286
+			templateMode.ModifyTime = time.Now().Unix()
287
+			updateErr := service.SaveTemplateMode(templateMode)
288
+			if updateErr != nil {
289
+				this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
290
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
291
+				return
292
+			}
293
+		} else if templateMode.Mode == 3 && mode == 1 { // 3 -> 1 清除第三,二周模板item,清除第三,二周排班
294
+			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
295
+			if getTemplateIDsErr != nil {
296
+				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
297
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
298
+				return
299
+			}
300
+
301
+			templateMode.Mode = mode
302
+			templateMode.ExecuteTimes = 0
303
+			templateMode.ModifyTime = time.Now().Unix()
304
+			updateErr := service.SavePatientScheduleTemplateMode3To1(templateMode, templateIDs[1].ID, templateIDs[2].ID)
305
+			if updateErr != nil {
306
+				this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
307
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
308
+				return
309
+			}
310
+		} else if templateMode.Mode == 3 && mode == 2 { // 3 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
311
+			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
312
+			if getTemplateIDsErr != nil {
313
+				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
314
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
315
+				return
316
+			}
317
+
318
+			templateMode.Mode = mode
319
+			templateMode.ExecuteTimes = 0
320
+			templateMode.ModifyTime = time.Now().Unix()
321
+			updateErr := service.SavePatientScheduleTemplateMode3To2(templateMode, templateIDs[2].ID)
322
+			if updateErr != nil {
323
+				this.ErrorLog("更新排班模板启用方式(2 -> 3)时失败:%v", updateErr)
324
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
325
+				return
326
+			}
327
+
328
+		} else if templateMode.Mode == 3 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班
329
+			templateMode.Mode = mode
330
+			templateMode.ExecuteTimes = 0
331
+			templateMode.ModifyTime = time.Now().Unix()
332
+			updateErr := service.SaveTemplateMode(templateMode)
333
+			if updateErr != nil {
334
+				this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
335
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
336
+				return
337
+			}
338
+		} else if templateMode.Mode == 4 && mode == 1 { // 4 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
339
+			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
340
+			if getTemplateIDsErr != nil {
341
+				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
342
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
343
+				return
344
+			}
345
+
346
+			templateMode.Mode = mode
347
+			templateMode.ExecuteTimes = 0
348
+			templateMode.ModifyTime = time.Now().Unix()
349
+			updateErr := service.SavePatientScheduleTemplateMode4To1(templateMode, templateIDs[1].ID, templateIDs[2].ID, templateIDs[3].ID)
350
+			if updateErr != nil {
351
+				this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
352
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
353
+				return
354
+			}
355
+
356
+		} else if templateMode.Mode == 4 && mode == 2 { // 4 -> 2
357
+			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
358
+			if getTemplateIDsErr != nil {
359
+				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
360
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
361
+				return
362
+			}
363
+
364
+			templateMode.Mode = mode
365
+			templateMode.ExecuteTimes = 0
366
+			templateMode.ModifyTime = time.Now().Unix()
367
+			updateErr := service.SavePatientScheduleTemplateMode4To2(templateMode, templateIDs[2].ID, templateIDs[3].ID)
368
+			if updateErr != nil {
369
+				this.ErrorLog("更新排班模板启用方式(2 -> 4)时失败:%v", updateErr)
370
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
371
+				return
372
+			}
373
+
374
+		} else if templateMode.Mode == 4 && mode == 3 { // 4 -> 3
375
+			templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
376
+			if getTemplateIDsErr != nil {
377
+				this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
378
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
379
+				return
380
+			}
381
+
382
+			templateMode.Mode = mode
383
+			templateMode.ExecuteTimes = 0
384
+			templateMode.ModifyTime = time.Now().Unix()
385
+			updateErr := service.SavePatientScheduleTemplateMode4To3(templateMode, templateIDs[3].ID)
386
+			if updateErr != nil {
387
+				this.ErrorLog("更新排班模板启用方式(3 -> 4)时失败:%v", updateErr)
388
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
389
+				return
390
+			}
218 391
 		}
392
+		templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
393
+		//处理第几周数问题
394
+		if mode == 0 {
395
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0)
396
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
397
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
398
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
399
+
400
+		} else if mode == 1 {
401
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
402
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
403
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
404
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
405
+
406
+		} else if mode == 2 {
407
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
408
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
409
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
410
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
411
+
412
+		} else if mode == 3 {
413
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
414
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
415
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
416
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
417
+
418
+		} else if mode == 4 {
419
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
420
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
421
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
422
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
423
+		}
424
+
219 425
 	}
426
+
220 427
 	this.ServeSuccessJSON(nil)
221 428
 }
222 429
 
@@ -230,7 +437,7 @@ func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
230 437
 	addSchedulesJSON := this.GetString("add_schs")
231 438
 	delSchedulesJSON := this.GetString("del_schs")
232 439
 	changeSchedulesJSON := this.GetString("change_schs")
233
-	if templateID <= 0 || len(addSchedulesJSON) == 0 || len(delSchedulesJSON) == 0 || len(changeSchedulesJSON) == 0 {
440
+	if len(addSchedulesJSON) == 0 || len(delSchedulesJSON) == 0 || len(changeSchedulesJSON) == 0 {
234 441
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
235 442
 		return
236 443
 	}
@@ -329,59 +536,90 @@ func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
329 536
 		return
330 537
 	}
331 538
 
332
-	shouldUpdateNextWeekSchedules := false
333
-	shouldUpdateNextSecondWeekSchedules := false
539
+	//shouldUpdateNextWeekSchedules := false
540
+	//shouldUpdateNextSecondWeekSchedules := false
541
+	//shouldUpdateNextThirdWeekSchedules := false
542
+	//shouldUpdateNextFourWeekSchedules := false
543
+	//
334 544
 	if templateMode.Mode == 0 {
335 545
 		this.ErrorLog("当前未开启排班模板,所以更新模板的操作将被无视")
336 546
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
337 547
 		return
338 548
 	}
339
-	templateIDIndex := 1
340
-	for index, templateIDObject := range templateIDs {
341
-		if templateIDObject.ID == templateID {
342
-			templateIDIndex = index + 1
343
-		}
344
-	}
345
-	if templateMode.Mode == 1 {
346
-		if templateIDIndex == 1 {
347
-			shouldUpdateNextWeekSchedules = true
348
-			shouldUpdateNextSecondWeekSchedules = true
349
-		} else {
350
-			this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板")
351
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
352
-			return
353
-		}
354
-
355
-	} else { // mode == 2 => 开启双周模板时,只需更新一周排班
356
-		if templateIDIndex == 1 {
357
-			if templateMode.ExecuteTimes%2 == 0 {
358
-				shouldUpdateNextWeekSchedules = true
359
-				shouldUpdateNextSecondWeekSchedules = false
360
-			} else {
361
-				shouldUpdateNextWeekSchedules = false
362
-				shouldUpdateNextSecondWeekSchedules = true
363
-			}
364
-
365
-		} else {
366
-			if templateMode.ExecuteTimes%2 == 0 {
367
-				shouldUpdateNextWeekSchedules = false
368
-				shouldUpdateNextSecondWeekSchedules = true
369
-			} else {
370
-				shouldUpdateNextWeekSchedules = true
371
-				shouldUpdateNextSecondWeekSchedules = false
372
-			}
373
-
374
-		}
375
-	}
376
-
377
-	updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, shouldUpdateNextWeekSchedules, shouldUpdateNextSecondWeekSchedules)
549
+	//判断当前用的是模版几
550
+	//templateIDIndex := 1
551
+	//for index, templateIDObject := range templateIDs {
552
+	//	if templateIDObject.ID == templateID {
553
+	//		//templateIDIndex = index + 1
554
+	//	}
555
+	//}
556
+	//if templateMode.Mode == 1 {
557
+	//	if templateIDIndex == 1 {
558
+	//		shouldUpdateNextWeekSchedules = true
559
+	//		shouldUpdateNextSecondWeekSchedules = true
560
+	//	} else {
561
+	//		this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板")
562
+	//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
563
+	//		return
564
+	//	}
565
+	//
566
+	//} else if templateMode.Mode == 2 { // mode == 2 => 开启双周模板时,只需更新一周排班
567
+	//	if templateIDIndex == 1 {
568
+	//		if templateMode.ExecuteTimes%2 == 0 {
569
+	//			shouldUpdateNextWeekSchedules = true
570
+	//			shouldUpdateNextSecondWeekSchedules = false
571
+	//		} else {
572
+	//			shouldUpdateNextWeekSchedules = false
573
+	//			shouldUpdateNextSecondWeekSchedules = true
574
+	//		}
575
+	//
576
+	//	} else {
577
+	//		if templateMode.ExecuteTimes%2 == 0 {
578
+	//			shouldUpdateNextWeekSchedules = false
579
+	//			shouldUpdateNextSecondWeekSchedules = true
580
+	//		} else {
581
+	//			shouldUpdateNextWeekSchedules = true
582
+	//			shouldUpdateNextSecondWeekSchedules = false
583
+	//		}
584
+	//
585
+	//	}
586
+	//} else if templateMode.Mode == 3 { // mode == 2 => 开启双周模板时,只需更新一周排班
587
+	//	if templateIDIndex == 1 { //当前修改的是第一个模版
588
+	//		if templateMode.ExecuteTimes%3 == 0 {
589
+	//			shouldUpdateNextWeekSchedules = true
590
+	//			shouldUpdateNextSecondWeekSchedules = false
591
+	//			shouldUpdateNextThirdWeekSchedules = false
592
+	//		} else if templateMode.ExecuteTimes%3 == 1 {
593
+	//			shouldUpdateNextWeekSchedules = false
594
+	//			shouldUpdateNextSecondWeekSchedules = true
595
+	//			shouldUpdateNextThirdWeekSchedules = false
596
+	//		} else {
597
+	//			shouldUpdateNextWeekSchedules = false
598
+	//			shouldUpdateNextSecondWeekSchedules = false
599
+	//			shouldUpdateNextThirdWeekSchedules = true
600
+	//		}
601
+	//	} else if templateIDIndex == 2 {
602
+	//		if templateMode.ExecuteTimes%2 == 0 {
603
+	//			shouldUpdateNextWeekSchedules = false
604
+	//			shouldUpdateNextSecondWeekSchedules = true
605
+	//		} else {
606
+	//			shouldUpdateNextWeekSchedules = true
607
+	//			shouldUpdateNextSecondWeekSchedules = false
608
+	//		}
609
+	//
610
+	//	} else {
611
+	//
612
+	//	}
613
+	//}
614
+
615
+	updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false)
378 616
 	if updateErr != nil {
379 617
 		this.ErrorLog("更新排班模板排班失败:%v", updateErr)
380 618
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
381 619
 		return
382 620
 	}
383 621
 
384
-	newItems, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItemsByTemplateID(adminUserInfo.CurrentOrgId, templateID)
622
+	newItems, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItemsByTemplateID(adminUserInfo.CurrentOrgId)
385 623
 	if getTemplateItemsErr != nil {
386 624
 		this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
387 625
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -399,3 +637,14 @@ type ParamModelSchedule struct {
399 637
 	Weekday        int8  `json:"weekday"`
400 638
 	TimeType       int8  `json:"time_type"`
401 639
 }
640
+
641
+func (this *PatientScheduleTemplateAPIController) GetPatientList() {
642
+	patients, err := service.GetSchTemplatePatientList(this.GetAdminUserInfo().CurrentOrgId)
643
+	if err != nil {
644
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
645
+	}
646
+	this.ServeSuccessJSON(map[string]interface{}{
647
+		"list": patients,
648
+	})
649
+
650
+}

+ 4 - 5
controllers/stock_in_api_controller.go View File

@@ -151,10 +151,10 @@ func StockManagerApiRegistRouters() {
151 151
 	beego.Router("/api/stock/getwarehouseinfolist", &StockManagerApiController{}, "Get:GetInvetoryWarehouseInfoList")
152 152
 
153 153
 	//结算成功后调用操作库存相关接口
154
-	//beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
155
-	//beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
156
-}
154
+	beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
155
+	beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
157 156
 
157
+}
158 158
 func (c *StockManagerApiController) HandleRefundStock() {
159 159
 	order_id, _ := c.GetInt64("order_id", 0)
160 160
 	order, _ := service.GetHisOrderByIDThree(order_id)
@@ -202,14 +202,12 @@ func (c *StockManagerApiController) HandleRefundStock() {
202 202
 
203 203
 }
204 204
 func (c *StockManagerApiController) HandleSettleStock() {
205
-
206 205
 	order_id, _ := c.GetInt64("order_id", 0)
207 206
 	order, _ := service.GetHisOrderByID(order_id)
208 207
 	if order.ID == 0 {
209 208
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
210 209
 		return
211 210
 	}
212
-
213 211
 	orders, _ := service.GetHisOrderDetailByNumberTwo(order.Number, order.UserOrgId)
214 212
 	houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
215 213
 	var goods []*models.DialysisBeforePrepareGoods
@@ -247,6 +245,7 @@ func (c *StockManagerApiController) HandleSettleStock() {
247 245
 		service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
248 246
 	}
249 247
 }
248
+
250 249
 func (c *StockManagerApiController) CreateWarehouse() {
251 250
 
252 251
 	warehousing_time := c.GetString("warehousing_time")

+ 7 - 1
enums/error_code.go View File

@@ -263,7 +263,11 @@ const ( // ErrorCode
263 263
 
264 264
 	ErrorCodeHisPatientNoRegException = 4000000
265 265
 
266
+	ErrorCodeCantDeleteScheduleBeforeNow = 40000001
267
+
266 268
 	ErrorCodeSchedule = 50000000
269
+
270
+	ErrorCodeParamWrongForSchMode = 40000002
267 271
 )
268 272
 
269 273
 var ErrCodeMsgs = map[int]string{
@@ -337,6 +341,7 @@ var ErrCodeMsgs = map[int]string{
337 341
 	ErrorCodeCreateScheduleFail:             "添加排班失败",
338 342
 	ErrorCodeCantSetScheduleAgainOneDay:     "同一天不可有两次排班",
339 343
 	ErrorCodeCantSetScheduleBeforeNow:       "不能给今天之前的日期排班",
344
+	ErrorCodeCantDeleteScheduleBeforeNow:    "不能删除今天之前的日期排班",
340 345
 	ErrorCodeScheduleNotExist:               "排班不存在",
341 346
 	ErrorCodePointScheduleExist:             "所先位置排班已经存在",
342 347
 	ErrorCodeDeleteScheduleFail:             "取消排班失败",
@@ -514,7 +519,8 @@ var ErrCodeMsgs = map[int]string{
514 519
 	ErrorCodeDeletePChargeWrongTwo: "该医嘱所属处方已经收费或已经上传的处方,无法删除",
515 520
 
516 521
 	ErrorCodeHisPatientNoRegException: "该患者尚未挂号,请先挂号",
517
-	ErrorCodeSchedule:                 "被调用床位已有患者上机",
522
+	ErrorCodeSchedule:                 "该班次该床位已有患者",
523
+	ErrorCodeParamWrongForSchMode:     "透析模式不能为空",
518 524
 }
519 525
 
520 526
 type SGJError struct {

+ 12 - 1
main.go View File

@@ -11,7 +11,8 @@ func init() {
11 11
 }
12 12
 
13 13
 func main() {
14
-	service.BeginAutoCreateWeekSchedulesJob()
14
+	//service.NewAutoCreateWeekSchedules()
15
+
15 16
 	//service.BeginAutoCreateWeekDisinfectionJob()
16 17
 	//service.BeginAutoCreatePlanJob()
17 18
 	//service.AutoClearSchedules()
@@ -21,5 +22,15 @@ func main() {
21 22
 
22 23
 	//beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 6000
23 24
 	//beego.BConfig.WebConfig.AutoRender = false
25
+	//
26
+	//fmt.Println(0 % 4)
27
+	//fmt.Println(1 % 4)
28
+	//fmt.Println(2 % 4)
29
+	//fmt.Println(3 % 4)
30
+	//fmt.Println(4 % 4)
31
+	//fmt.Println(5 % 4)
32
+	//fmt.Println(6 % 4)
33
+	//fmt.Println(7 % 4)
34
+
24 35
 	beego.Run()
25 36
 }

+ 107 - 14
models/device_models.go View File

@@ -116,6 +116,98 @@ func (DeviceZone) TableName() string {
116 116
 	return "xt_device_zone"
117 117
 }
118 118
 
119
+type DeviceZonePb struct {
120
+	ID         int64  `gorm:"column:id" json:"id"`
121
+	OrgID      int64  `gorm:"column:org_id" json:"-"`
122
+	Name       string `json:"name"`
123
+	Type       int    `json:"type"`
124
+	TotalBed   int	  `json:"total_bed"`
125
+	SwBed      int	  `json:"sw_bed"`
126
+	XwBed      int	  `json:"xw_bed"`
127
+	WsBed      int	  `json:"ws_bed"`
128
+	CreateTime int64  `gorm:"column:ctime" json:"-"`
129
+	ModifyTime int64  `gorm:"column:mtime" json:"-"`
130
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
131
+	DeviceNumber   []*DeviceNumberPb   `json:"device" gorm:"foreignkey:ZoneID;AssociationForeignKey:ID;"`
132
+}
133
+
134
+func (DeviceZonePb) TableName() string {
135
+	return "xt_device_zone"
136
+}
137
+
138
+type DialysisSolutionPb struct {
139
+	UserOrgId                  int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
140
+	PatientId                  int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
141
+	DialysisDialyszers         string                `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
142
+	DialysisIrrigation         string                `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
143
+	DialyzerPerfusionApparatus string                `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus"`
144
+	ModeName                   string                `gorm:"column:mode_name" json:"mode_name" form:"mode_name"`
145
+	ModeId                     int64                 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
146
+	Anticoagulant              int64                 `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
147
+}
148
+
149
+func (DialysisSolutionPb) TableName() string {
150
+	return "xt_dialysis_solution"
151
+}
152
+
153
+type DeviceNumberPb struct {
154
+	ID         int64      `gorm:"column:id" json:"id"`
155
+	OrgID      int64      `gorm:"column:org_id" json:"-"`
156
+	Number     string     `gorm:"column:number" json:"number"`
157
+	GroupID    int64      `gorm:"column:group_id" json:"group_id"`
158
+	ZoneID     int64      `gorm:"column:zone_id" json:"zone_id"`
159
+	Status     int64      `gorm:"column:status" json:"status" form:"status"`
160
+	CreateTime int64      `gorm:"column:ctime" json:"-"`
161
+	ModifyTime int64      `gorm:"column:mtime" json:"-"`
162
+	Sort       int64      `gorm:"column:sort" json:"sort" form:"sort"`
163
+	Schedule   []*BlodSchedulePb `json:"schedule" gorm:"foreignkey:BedId;AssociationForeignKey:ID;"`
164
+}
165
+
166
+func (DeviceNumberPb) TableName() string {
167
+	return "xt_device_number"
168
+}
169
+
170
+type BlodSchedulePb struct {
171
+	ID                        int64                     `gorm:"column:id" json:"id" form:"id"`
172
+	UserOrgId                 int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
173
+	PartitionId               int64                     `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
174
+	BedId                     int64                     `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
175
+	PatientId                 int64                     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
176
+	ScheduleDate              int64                     `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
177
+	ScheduleType              int64                     `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
178
+	ScheduleWeek              int64                     `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
179
+	ModeId                    int64                     `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
180
+	Status                    int64                     `gorm:"column:status" json:"status" form:"status"`
181
+	VmBloodPatients           VmBloodPatients           `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientId;"`
182
+	BloodDialysisOrder        BloodPatientDialysisOrder `json:"order" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
183
+	BloodDialysisPrescription BloodDialysisPrescriptionPb `json:"prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
184
+	DialysisSolution 		  DialysisSolutionPb `gorm:"ForeignKey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId" json:"vmsolution"`
185
+}
186
+
187
+func (BlodSchedulePb) TableName() string {
188
+	return "xt_schedule"
189
+}
190
+
191
+type BloodDialysisPrescriptionPb struct {
192
+	ID                         int64   `gorm:"column:id" json:"id" form:"id"`
193
+	UserOrgId                  int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
194
+	PatientId                  int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
195
+	Remark                     string  `gorm:"column:remark" json:"remark" form:"remark"`
196
+	ModeId                     int64   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
197
+	Anticoagulant              int64   `gorm:"column:anticoagulant" json:"anticoagulant" form:"anticoagulant"`
198
+	AnticoagulantShouji        float64 `gorm:"column:anticoagulant_shouji" json:"anticoagulant_shouji" form:"anticoagulant_shouji"`
199
+	AnticoagulantWeichi        float64 `gorm:"column:anticoagulant_weichi" json:"anticoagulant_weichi" form:"anticoagulant_weichi"`
200
+	AnticoagulantZongliang     float64 `gorm:"column:anticoagulant_zongliang" json:"anticoagulant_zongliang" form:"anticoagulant_zongliang"`
201
+	AnticoagulantGaimingcheng  string  `gorm:"column:anticoagulant_gaimingcheng" json:"anticoagulant_gaimingcheng" form:"anticoagulant_gaimingcheng"`
202
+	AnticoagulantGaijiliang    string  `gorm:"column:anticoagulant_gaijiliang" json:"anticoagulant_gaijiliang" form:"anticoagulant_gaijiliang"`
203
+	DialysisDialyszers         string  `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
204
+	DialysisIrrigation         string  `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
205
+}
206
+
207
+func (BloodDialysisPrescriptionPb) TableName() string {
208
+	return "xt_dialysis_prescription"
209
+}
210
+
119 211
 type DeviceGroups struct {
120 212
 	ID         int64  `gorm:"column:id" json:"id"`
121 213
 	OrgID      int64  `gorm:"column:org_id" json:"-"`
@@ -403,20 +495,21 @@ type Schedules struct {
403 495
 }
404 496
 
405 497
 type XtSchedule struct {
406
-	ID              int64                   `gorm:"column:id" json:"id" form:"id"`
407
-	UserOrgId       int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
408
-	PartitionId     int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
409
-	BedId           int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
410
-	PatientId       int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
411
-	ScheduleDate    int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
412
-	ScheduleType    int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
413
-	ScheduleWeek    int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
414
-	ModeId          int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
415
-	Status          int64                   `gorm:"column:status" json:"status" form:"status"`
416
-	CreatedTime     int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
417
-	UpdatedTime     int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
418
-	IsExport        int64                   `gorm:"column:is_export" json:"is_export" form:"is_export"`
419
-	LastAfterWeight AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
498
+	ID                  int64                   `gorm:"column:id" json:"id" form:"id"`
499
+	UserOrgId           int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
500
+	PartitionId         int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
501
+	BedId               int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
502
+	PatientId           int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
503
+	ScheduleDate        int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
504
+	ScheduleType        int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
505
+	ScheduleWeek        int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
506
+	ModeId              int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
507
+	Status              int64                   `gorm:"column:status" json:"status" form:"status"`
508
+	CreatedTime         int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
509
+	UpdatedTime         int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
510
+	IsExport            int64                   `gorm:"column:is_export" json:"is_export" form:"is_export"`
511
+	LastAfterWeight     AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
512
+	DialysisMachineName string                  `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
420 513
 }
421 514
 
422 515
 func (XtSchedule) TableName() string {

+ 5 - 5
models/patient_schedule_template_models.go View File

@@ -8,6 +8,7 @@ type PatientScheduleTemplateMode struct {
8 8
 	Status       int8  `gorm:"column:status" json:"-" form:"status"`
9 9
 	CreateTime   int64 `gorm:"column:ctime" json:"-" form:"ctime"`
10 10
 	ModifyTime   int64 `gorm:"column:mtime" json:"-" form:"mtime"`
11
+	Week         int64 `gorm:"column:week" json:"-" form:"week"`
11 12
 }
12 13
 
13 14
 func (PatientScheduleTemplateMode) TableName() string {
@@ -15,11 +16,10 @@ func (PatientScheduleTemplateMode) TableName() string {
15 16
 }
16 17
 
17 18
 type PatientScheduleTemplateId struct {
18
-	ID         int64 `gorm:"column:id" json:"id" form:"id"`
19
-	OrgID      int64 `gorm:"column:org_id" json:"-" form:"org_id"`
20
-	Status     int8  `gorm:"column:status" json:"-" form:"status"`
21
-	CreateTime int64 `gorm:"column:ctime" json:"-" form:"ctime"`
22
-	ModifyTime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
19
+	ID     int64 `gorm:"column:id" json:"id" form:"id"`
20
+	OrgID  int64 `gorm:"column:org_id" json:"-" form:"org_id"`
21
+	Status int8  `gorm:"column:status" json:"-" form:"status"`
22
+	Week   int   `gorm:"column:week" json:"week" form:"week"`
23 23
 }
24 24
 
25 25
 func (PatientScheduleTemplateId) TableName() string {

+ 5 - 3
models/schedule_models.go View File

@@ -44,13 +44,15 @@ type Schedule struct {
44 44
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
45 45
 	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
46 46
 
47
-	Patient                   string               `gorm:"-" json:"patient" form:"patient"`
48
-	DeviceZone                DeviceZone           `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
-	DeviceNumber              DeviceNumber         `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
47
+	Patient      string       `gorm:"-" json:"patient" form:"patient"`
48
+	DeviceZone   DeviceZone   `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
+	DeviceNumber DeviceNumber `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
50
+
50 51
 	TreatmentMode             TreatmentMode        `json:"mode" gorm:"foreignkey:ModeId"`
51 52
 	DialysisOrder             DialysisOrder        `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
52 53
 	DialysisPrescription      DialysisPrescription `json:"dialysis_prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
53 54
 	PatientInfectiousDiseases []InfectiousDiseases `json:"patient_contagions" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
55
+	DialysisMachineName       string               `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
54 56
 }
55 57
 
56 58
 func (Schedule) TableName() string {

+ 101 - 0
models/smart_sch.go View File

@@ -0,0 +1,101 @@
1
+package models
2
+
3
+type SmartSchPatient struct {
4
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	Name       string `gorm:"column:name" json:"name" form:"name"`
7
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8
+
9
+	SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
10
+}
11
+
12
+func (SmartSchPatient) TableName() string {
13
+	return "xt_patients"
14
+}
15
+
16
+type SmartSchTemplatePatient struct {
17
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
18
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
19
+	Name       string `gorm:"column:name" json:"name" form:"name"`
20
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
21
+
22
+	XtPatientScheduleTemplateId []*XtPatientScheduleTemplateId
23
+}
24
+
25
+func (SmartSchTemplatePatient) TableName() string {
26
+	return "xt_patients"
27
+}
28
+
29
+type SmartSchedule struct {
30
+	ID                 int64              `gorm:"column:id" json:"id" form:"id"`
31
+	UserOrgId          int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
+	PartitionId        int64              `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
33
+	BedId              int64              `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
34
+	PatientId          int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
35
+	ScheduleDate       int64              `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36
+	ScheduleType       int64              `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
37
+	ScheduleWeek       int64              `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
38
+	ModeId             int64              `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
39
+	Status             int64              `gorm:"column:status" json:"status" form:"status"`
40
+	CreatedTime        int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
41
+	UpdatedTime        int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
42
+	IsExport           int64              `gorm:"column:is_export" json:"is_export" form:"is_export"`
43
+	DeviceZone         DeviceZone         `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
44
+	DeviceNumber       DeviceNumber       `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
45
+	SmSchDialysisOrder SmSchDialysisOrder `json:"order" gorm:"foreignkey:BedId,PatientId,DialysisDate;AssociationForeignKey:BedId,PatientId,ScheduleDate;"`
46
+}
47
+
48
+func (SmartSchedule) TableName() string {
49
+	return "xt_schedule"
50
+}
51
+
52
+type XtPatientScheduleTemplateId struct {
53
+	ID                            int64                            `gorm:"column:id" json:"id" form:"id"`
54
+	OrgId                         int64                            `gorm:"column:org_id" json:"org_id" form:"org_id"`
55
+	Status                        int64                            `gorm:"column:status" json:"status" form:"status"`
56
+	Ctime                         int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
57
+	Mtime                         int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
58
+	Week                          int64                            `gorm:"column:week" json:"week" form:"week"`
59
+	XtPatientScheduleTemplateItem []*XtPatientScheduleTemplateItem `gorm:"foreignkey:TemplateId;AssociationForeignKey:ID;" json:"template" form:"template"`
60
+}
61
+
62
+func (XtPatientScheduleTemplateId) TableName() string {
63
+	return "xt_patient_schedule_template_id"
64
+}
65
+
66
+type XtPatientScheduleTemplateItem struct {
67
+	ID             int64 `gorm:"column:id" json:"id" form:"id"`
68
+	OrgId          int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
69
+	TemplateId     int64 `gorm:"column:template_id" json:"template_id" form:"template_id"`
70
+	DeviceNumberId int64 `gorm:"column:device_number_id" json:"device_number_id" form:"device_number_id"`
71
+	PatientId      int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
72
+	TreatMode      int64 `gorm:"column:treat_mode" json:"treat_mode" form:"treat_mode"`
73
+	Weekday        int64 `gorm:"column:weekday" json:"weekday" form:"weekday"`
74
+	TimeType       int64 `gorm:"column:time_type" json:"time_type" form:"time_type"`
75
+	Status         int64 `gorm:"column:status" json:"status" form:"status"`
76
+	Ctime          int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
77
+	Mtime          int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
78
+	IsExport       int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
79
+	ZoneId         int64 `gorm:"-" json:"zone_id" form:"zone_id"`
80
+}
81
+
82
+func (XtPatientScheduleTemplateItem) TableName() string {
83
+	return "xt_patient_schedule_template_item"
84
+}
85
+
86
+type SmSchDialysisOrder struct {
87
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
88
+	DialysisDate int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
89
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
90
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
91
+	Stage        int64  `gorm:"column:stage" json:"stage" form:"stage"`
92
+	Remark       string `gorm:"column:remark" json:"remark" form:"remark"`
93
+	BedId        int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
94
+	StartNurse   int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
95
+	FinishNurse  int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
96
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
97
+}
98
+
99
+func (SmSchDialysisOrder) TableName() string {
100
+	return "xt_dialysis_order"
101
+}

+ 1 - 0
models/vm_models.go View File

@@ -230,6 +230,7 @@ type VMPatientScheduleTemplateMode struct {
230 230
 	Status       int64 `gorm:"column:status" json:"status" form:"status"`
231 231
 	Ctime        int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
232 232
 	Mtime        int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
233
+	Week         int64 `gorm:"column:week" json:"-" form:"week"`
233 234
 }
234 235
 
235 236
 func (VMPatientScheduleTemplateMode) TableName() string {

+ 1 - 1
routers/router.go View File

@@ -14,7 +14,7 @@ func init() {
14 14
 		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
15 15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
16 16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
17
-		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission"},
17
+		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},
18 18
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
19 19
 		AllowCredentials: true,
20 20
 	}))

+ 566 - 0
service/app_version.go View File

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
6 7
 	"time"
7 8
 )
@@ -456,3 +457,568 @@ func SaveHis(his *models.HisPatient) {
456 457
 	writeDb.Save(his)
457 458
 	return
458 459
 }
460
+
461
+func GetAllProjectPrescription() (pre []*models.HisPrescription) {
462
+	readDb.Model(&models.HisPrescription{}).Where("user_org_id = 10215 AND status = 1 AND type = 2 AND order_status = 1 AND record_date >= 1659283200").Find(&pre)
463
+	return
464
+}
465
+
466
+func GetAllProject(id int64) (pre []*models.HisPrescriptionProject) {
467
+	readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = 10215 AND status = 1 AND project_id = 1735  AND prescription_id = ?", id).Find(&pre)
468
+	return
469
+}
470
+
471
+//func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
472
+//	readDb.Model(&models.Patients{})
473
+//
474
+//	err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
475
+//		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
476
+//	}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
477
+//		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
478
+//	}).Find(&order).Error
479
+//	return
480
+//}
481
+
482
+type HisOrderTen struct {
483
+	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
484
+	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
485
+	HisPatientId          int64                 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
486
+	SettleAccountsDate    int64                 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
487
+	Ctime                 int64                 `gorm:"column:ctime" json:"ctime" form:"ctime"`
488
+	Mtime                 int64                 `gorm:"column:mtime" json:"mtime" form:"mtime"`
489
+	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
490
+	Number                string                `gorm:"column:number" json:"number" form:"number"`
491
+	PatientId             int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
492
+	Infcode               int64                 `gorm:"column:infcode" json:"infcode" form:"infcode"`
493
+	WarnMsg               string                `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
494
+	Cainfo                string                `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
495
+	ErrMsg                string                `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
496
+	RespondTime           string                `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
497
+	InfRefmsgid           string                `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
498
+	OrderStatus           int64                 `gorm:"column:order_status" json:"order_status" form:"order_status"`
499
+	MdtrtId               string                `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
500
+	SetlId                string                `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
501
+	PsnNo                 string                `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
502
+	PsnName               string                `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
503
+	PsnCertType           string                `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
504
+	Certno                string                `gorm:"column:certno" json:"certno" form:"certno"`
505
+	Gend                  string                `gorm:"column:gend" json:"gend" form:"gend"`
506
+	Naty                  string                `gorm:"column:naty" json:"naty" form:"naty"`
507
+	Brdy                  time.Time             `gorm:"column:brdy" json:"brdy" form:"brdy"`
508
+	Age                   float64               `gorm:"column:age" json:"age" form:"age"`
509
+	Insutype              string                `gorm:"column:insutype" json:"insutype" form:"insutype"`
510
+	PsnType               string                `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
511
+	CvlservFlag           string                `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
512
+	SetlTime              string                `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
513
+	MdtrtCertType         string                `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
514
+	MedType               string                `gorm:"column:med_type" json:"med_type" form:"med_type"`
515
+	MedfeeSumamt          float64               `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
516
+	FulamtOwnpayAmt       float64               `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
517
+	OverlmtSelfPay        float64               `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
518
+	PreselfpayAmt         float64               `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
519
+	InscpScpAmt           float64               `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
520
+	ActPayDedc            float64               `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
521
+	HifpPay               float64               `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
522
+	CvlservPay            float64               `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
523
+	PoolPropSelfpay       float64               `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
524
+	HifesPay              float64               `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
525
+	HifmiPay              float64               `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
526
+	HifobPay              float64               `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
527
+	MafPay                float64               `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
528
+	OthPay                float64               `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
529
+	FundPaySumamt         float64               `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
530
+	PsnPartAmt            float64               `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
531
+	AcctPay               float64               `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
532
+	PsnCashPay            float64               `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
533
+	HospPartAmt           float64               `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
534
+	Balc                  float64               `gorm:"column:balc" json:"balc" form:"balc"`
535
+	AcctMulaidPay         float64               `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
536
+	MedinsSetlId          string                `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
537
+	ClrOptins             string                `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
538
+	ClrWay                string                `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
539
+	ClrType               string                `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
540
+	SetlDetail            string                `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
541
+	IsMedicineInsurance   int64                 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
542
+	PayWay                int64                 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
543
+	PayPrice              float64               `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
544
+	PayCardNo             string                `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
545
+	DiscountPrice         float64               `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
546
+	PreferentialPrice     float64               `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
547
+	RealityPrice          float64               `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
548
+	FoundPrice            float64               `gorm:"column:found_price" json:"found_price" form:"found_price"`
549
+	MedicalInsurancePrice float64               `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
550
+	PrivatePrice          float64               `gorm:"column:private_price" json:"private_price" form:"private_price"`
551
+	DepartmentName        string                `gorm:"-" json:"department_name" form:"department_name"`
552
+	DoctorName            string                `gorm:"-" json:"doctor_name" form:"doctor_name"`
553
+	Creator               int64                 `gorm:"column:creator" json:"creator" form:"creator"`
554
+	PType                 int64                 `gorm:"column:p_type" json:"p_type" form:"p_type"`
555
+	Decimal               float64               `gorm:"column:decimal" json:"decimal" form:"decimal"`
556
+	HisPrescriptionTen    []*HisPrescriptionTen `gorm:"ForeignKey:BatchNumber;AssociationForeignKey:Number" json:"info"`
557
+	Patients              Patients              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
558
+}
559
+
560
+func (HisOrderTen) TableName() string {
561
+	return "his_order"
562
+}
563
+
564
+type HisPrescriptionTen struct {
565
+	ID                        int64                        `gorm:"column:id" json:"id" form:"id"`
566
+	UserOrgId                 int64                        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
567
+	RecordDate                int64                        `gorm:"column:record_date" json:"record_date" form:"record_date"`
568
+	PatientId                 int64                        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
569
+	HisPatientId              int64                        `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
570
+	Status                    int64                        `gorm:"column:status" json:"status" form:"status"`
571
+	Ctime                     int64                        `gorm:"column:ctime" json:"ctime" form:"ctime"`
572
+	Mtime                     int64                        `gorm:"column:mtime" json:"mtime" form:"mtime"`
573
+	Number                    string                       `gorm:"column:number" json:"number" form:"number"`
574
+	Type                      int64                        `gorm:"column:type" json:"type" form:"type"`
575
+	Doctor                    string                       `gorm:"column:doctor" json:"doctor" form:"doctor"`
576
+	Creator                   int64                        `gorm:"column:creator" json:"creator" form:"creator"`
577
+	Modifier                  int64                        `gorm:"column:modifier" json:"modifier" form:"modifier"`
578
+	OrderStatus               int64                        `gorm:"column:order_status" json:"order_status" form:"order_status"`
579
+	PreTime                   int64                        `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
580
+	BatchNumber               string                       `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
581
+	PrescriptionNumber        string                       `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
582
+	Patients                  Patients                     `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
583
+	HisDoctorAdviceInfoTen    []*HisDoctorAdviceInfoTen    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
584
+	HisPrescriptionProjectTen []*HisPrescriptionProjectTen `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
585
+	Total                     string                       `gorm:"-" json:"total" form:"total"`
586
+	PType                     int64                        `gorm:"column:p_type" json:"p_type" form:"p_type"`
587
+	MedType                   string                       `gorm:"column:med_type" json:"med_type" form:"med_type"`
588
+	IsMedicine                int64                        `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
589
+}
590
+
591
+func (HisPrescriptionTen) TableName() string {
592
+	return "his_prescription"
593
+}
594
+
595
+func GetHisOrderDetailThree() (order []*HisOrderTen, err error) {
596
+	err = readDb.Model(&HisOrderTen{}).Preload("Patients", "status = 1").Preload("HisPrescriptionTen", func(db *gorm.DB) *gorm.DB {
597
+		return db.Where("status = 1").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
598
+			return db.Where("status = 1").Preload("VMHisProject", "status = 1").Preload("VMGoodInfo", "status = 1")
599
+		}).Preload("HisDoctorAdviceInfoTen", func(db *gorm.DB) *gorm.DB {
600
+			return db.Where("status = 1").Preload("Drug", "status = 1")
601
+		})
602
+	}).Where("settle_accounts_date >= 1659283200 AND settle_accounts_date <= 1661788800 AND status = 1 AND order_status =2 and p_type = 1 AND user_org_id = 10215").Find(&order).Order("patient_id").Error
603
+	return
604
+}
605
+
606
+type HisDoctorAdviceInfoTen struct {
607
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
608
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
609
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
610
+	AdviceDate            int64   `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
611
+	AdviceName            string  `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
612
+	AdviceDesc            string  `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
613
+	SingleDose            float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
614
+	SingleDoseUnit        string  `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
615
+	PrescribingNumber     float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
616
+	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
617
+	DeliveryWay           string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
618
+	ExecutionFrequency    string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
619
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
620
+	CreatedTime           int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
621
+	RecordDate            int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
622
+	DrugSpec              float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
623
+	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
624
+	PrescriptionId        int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
625
+
626
+	Price                float64 `gorm:"column:price" json:"price" form:"price"`
627
+	DrugId               int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
628
+	Drug                 Drug    `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
629
+	IsMedicine           int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
630
+	ExecutionFrequencyId int64   `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
631
+}
632
+
633
+func (HisDoctorAdviceInfoTen) TableName() string {
634
+	return "his_doctor_advice_info"
635
+}
636
+
637
+type HisPrescriptionProjectTen struct {
638
+	ID                 int64        `gorm:"column:id" json:"id" form:"id"`
639
+	ProjectId          int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
640
+	Price              float64      `gorm:"column:price" json:"price" form:"price"`
641
+	UserOrgId          int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
642
+	Status             int64        `gorm:"column:status" json:"status" form:"status"`
643
+	Ctime              int64        `gorm:"column:ctime" json:"ctime" form:"ctime"`
644
+	Mtime              int64        `gorm:"column:mtime" json:"mtime" form:"mtime"`
645
+	PatientId          int64        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
646
+	HisPatientId       int64        `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
647
+	RecordDate         int64        `gorm:"column:record_date" json:"record_date" form:"record_date"`
648
+	PrescriptionId     int64        `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
649
+	Count              string       `gorm:"column:count" json:"count" form:"count"`
650
+	FeedetlSn          string       `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
651
+	MedListCodg        string       `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
652
+	SingleDose         string       `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
653
+	DeliveryWay        string       `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
654
+	ExecutionFrequency string       `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
655
+	Day                string       `gorm:"column:day" json:"day" form:"day"`
656
+	VMHisProject       VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
657
+	VMGoodInfo         VMGoodInfo   `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
658
+	Remark             string       `gorm:"column:remark" json:"remark" form:"remark"`
659
+	Unit               string       `gorm:"column:unit" json:"unit" form:"unit"`
660
+	Type               int64        `gorm:"column:type" json:"type" form:"type"`
661
+	Doctor             int64        `gorm:"column:doctor" json:"doctor" form:"doctor"`
662
+	ExecutionTime      int64        `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
663
+	ExecutionStaff     int64        `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
664
+	ExecutionState     int64        `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
665
+	CheckTime          int64        `gorm:"column:check_time" json:"check_time" form:"check_time"`
666
+	CheckState         int64        `gorm:"column:check_state" json:"check_state" form:"check_state"`
667
+	Checker            int64        `gorm:"column:checker" json:"checker" form:"checker"`
668
+	StartTime          int64        `gorm:"column:start_time" json:"start_time" form:"start_time"`
669
+	TeamId             int64        `gorm:"column:team_id" json:"team_id" form:"team_id"`
670
+
671
+	FrequencyType        int64  `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
672
+	DayCount             int64  `gorm:"column:day_count" json:"day_count" form:"day_count"`
673
+	WeekDay              string `gorm:"column:week_day" json:"week_day" form:"week_day"`
674
+	ExecutionFrequencyId int64  `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
675
+}
676
+
677
+func (HisPrescriptionProjectTen) TableName() string {
678
+	return "his_prescription_project"
679
+}
680
+
681
+func GetHisPatient11111(orgid int64) (paitent []*models.HisHospitalCheckRecord, err error) {
682
+	err = XTReadDB().Model(&paitent).Where("user_org_id = ?  and status = 1 AND in_hosptial_time >= '2022-11-01 00:00:00' AND in_hosptial_time <= '2022-11-30 23:59:59'", orgid).Find(&paitent).Error
683
+	return paitent, err
684
+}
685
+
686
+func SaveHP(paitent *models.HisHospitalCheckRecord) {
687
+	writeDb.Save(&paitent)
688
+
689
+}
690
+
691
+type HisOrder9504 struct {
692
+	ID                    int64     `gorm:"column:id" json:"id" form:"id"`
693
+	UserOrgId             int64     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
694
+	HisPatientId          int64     `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
695
+	SettleAccountsDate    int64     `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
696
+	Ctime                 int64     `gorm:"column:ctime" json:"ctime" form:"ctime"`
697
+	Mtime                 int64     `gorm:"column:mtime" json:"mtime" form:"mtime"`
698
+	Status                int64     `gorm:"column:status" json:"status" form:"status"`
699
+	Number                string    `gorm:"column:number" json:"number" form:"number"`
700
+	PatientId             int64     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
701
+	Infcode               int64     `gorm:"column:infcode" json:"infcode" form:"infcode"`
702
+	WarnMsg               string    `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
703
+	Cainfo                string    `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
704
+	ErrMsg                string    `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
705
+	RespondTime           string    `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
706
+	InfRefmsgid           string    `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
707
+	OrderStatus           int64     `gorm:"column:order_status" json:"order_status" form:"order_status"`
708
+	MdtrtId               string    `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
709
+	SetlId                string    `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
710
+	PsnNo                 string    `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
711
+	PsnName               string    `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
712
+	PsnCertType           string    `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
713
+	Certno                string    `gorm:"column:certno" json:"certno" form:"certno"`
714
+	Gend                  string    `gorm:"column:gend" json:"gend" form:"gend"`
715
+	Naty                  string    `gorm:"column:naty" json:"naty" form:"naty"`
716
+	Brdy                  time.Time `gorm:"column:brdy" json:"brdy" form:"brdy"`
717
+	Age                   float64   `gorm:"column:age" json:"age" form:"age"`
718
+	Insutype              string    `gorm:"column:insutype" json:"insutype" form:"insutype"`
719
+	PsnType               string    `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
720
+	CvlservFlag           string    `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
721
+	SetlTime              string    `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
722
+	MdtrtCertType         string    `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
723
+	MedType               string    `gorm:"column:med_type" json:"med_type" form:"med_type"`
724
+	MedfeeSumamt          float64   `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
725
+	FulamtOwnpayAmt       float64   `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
726
+	OverlmtSelfPay        float64   `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
727
+	PreselfpayAmt         float64   `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
728
+	InscpScpAmt           float64   `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
729
+	ActPayDedc            float64   `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
730
+	HifpPay               float64   `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
731
+	CvlservPay            float64   `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
732
+	PoolPropSelfpay       float64   `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
733
+	HifesPay              float64   `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
734
+	HifmiPay              float64   `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
735
+	HifobPay              float64   `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
736
+	MafPay                float64   `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
737
+	OthPay                float64   `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
738
+	FundPaySumamt         float64   `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
739
+	PsnPartAmt            float64   `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
740
+	AcctPay               float64   `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
741
+	PsnCashPay            float64   `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
742
+	HospPartAmt           float64   `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
743
+	Balc                  float64   `gorm:"column:balc" json:"balc" form:"balc"`
744
+	AcctMulaidPay         float64   `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
745
+	MedinsSetlId          string    `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
746
+	ClrOptins             string    `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
747
+	ClrWay                string    `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
748
+	ClrType               string    `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
749
+	SetlDetail            string    `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
750
+	IsMedicineInsurance   int64     `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
751
+	PayWay                int64     `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
752
+	PayPrice              float64   `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
753
+	PayCardNo             string    `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
754
+	DiscountPrice         float64   `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
755
+	PreferentialPrice     float64   `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
756
+	RealityPrice          float64   `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
757
+	FoundPrice            float64   `gorm:"column:found_price" json:"found_price" form:"found_price"`
758
+	MedicalInsurancePrice float64   `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
759
+	PrivatePrice          float64   `gorm:"column:private_price" json:"private_price" form:"private_price"`
760
+	DepartmentName        string    `gorm:"-" json:"department_name" form:"department_name"`
761
+	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
762
+	SettleStartTime       int64     `gorm:"settle_start_time" json:"settle_start_time" form:"settle_start_time"`
763
+
764
+	Creator            int64                 `gorm:"column:creator" json:"creator" form:"creator"`
765
+	PType              int64                 `gorm:"column:p_type" json:"p_type" form:"p_type"`
766
+	Decimal            float64               `gorm:"column:decimal" json:"decimal" form:"decimal"`
767
+	VmHisOrderInfo9504 []*VmHisOrderInfo9504 `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"info"`
768
+	Patients           Patients              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
769
+}
770
+
771
+func (HisOrder9504) TableName() string {
772
+	return "his_order"
773
+}
774
+
775
+type VmHisOrderInfo9504 struct {
776
+	ID                        int64                     `gorm:"column:id" json:"id" form:"id"`
777
+	OrderNumber               string                    `gorm:"column:order_number" json:"order_number" form:"order_number"`
778
+	UploadDate                int64                     `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
779
+	AdviceId                  int64                     `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
780
+	DetItemFeeSumamt          float64                   `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
781
+	Cnt                       float64                   `gorm:"column:cnt" json:"cnt" form:"cnt"`
782
+	Pric                      float64                   `gorm:"column:pric" json:"pric" form:"pric"`
783
+	PatientId                 int64                     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
784
+	PricUplmtAmt              float64                   `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
785
+	SelfpayProp               float64                   `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
786
+	FulamtOwnpayAmt           float64                   `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
787
+	OverlmtAmt                float64                   `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
788
+	PreselfpayAmt             float64                   `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
789
+	BasMednFlag               string                    `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
790
+	MedChrgitmType            string                    `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
791
+	HiNegoDrugFlag            string                    `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
792
+	Status                    int64                     `gorm:"column:status" json:"status" form:"status"`
793
+	Memo                      string                    `gorm:"column:memo" json:"memo" form:"memo"`
794
+	FeedetlSn                 string                    `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
795
+	Mtime                     int64                     `gorm:"column:mtime" json:"mtime" form:"mtime"`
796
+	InscpScpAmt               float64                   `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
797
+	DrtReimFlag               string                    `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
798
+	Ctime                     int64                     `gorm:"column:ctime" json:"ctime" form:"ctime"`
799
+	ListSpItemFlag            string                    `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
800
+	ChldMedcFlag              string                    `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
801
+	LmtUsedFlag               string                    `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
802
+	ChrgitmLv                 string                    `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
803
+	UserOrgId                 int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
804
+	HisPatientId              int64                     `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
805
+	OrderId                   int64                     `gorm:"column:order_id" json:"order_id" form:"order_id"`
806
+	ProjectId                 int64                     `gorm:"column:project_id" json:"project_id" form:"project_id"`
807
+	Type                      int64                     `gorm:"column:type" json:"type" form:"type"`
808
+	ItemId                    int64                     `gorm:"column:item_id" json:"item_id" form:"item_id"`
809
+	SettleType                int64                     `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
810
+	HisPrescriptionProjectTen HisPrescriptionProjectTen `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
811
+	HisDoctorAdviceInfoTen    HisDoctorAdviceInfoTen    `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advices"`
812
+}
813
+
814
+func (VmHisOrderInfo9504) TableName() string {
815
+	return "his_order_info"
816
+}
817
+
818
+type VmHisOrderInfo95042 struct {
819
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
820
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
821
+	UploadDate       int64   `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
822
+	AdviceId         int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
823
+	DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
824
+	Cnt              float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
825
+	Pric             float64 `gorm:"column:pric" json:"pric" form:"pric"`
826
+	PatientId        int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
827
+	PricUplmtAmt     float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
828
+	SelfpayProp      float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
829
+	FulamtOwnpayAmt  float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
830
+	OverlmtAmt       float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
831
+	PreselfpayAmt    float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
832
+	BasMednFlag      string  `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
833
+	MedChrgitmType   string  `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
834
+	HiNegoDrugFlag   string  `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
835
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
836
+	Memo             string  `gorm:"column:memo" json:"memo" form:"memo"`
837
+	FeedetlSn        string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
838
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
839
+	InscpScpAmt      float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
840
+	DrtReimFlag      string  `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
841
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
842
+	ListSpItemFlag   string  `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
843
+	ChldMedcFlag     string  `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
844
+	LmtUsedFlag      string  `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
845
+	ChrgitmLv        string  `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
846
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
847
+	HisPatientId     int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
848
+	OrderId          int64   `gorm:"column:order_id" json:"order_id" form:"order_id"`
849
+	ProjectId        int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
850
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
851
+	ItemId           int64   `gorm:"column:item_id" json:"item_id" form:"item_id"`
852
+	SettleType       int64   `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
853
+}
854
+
855
+func (VmHisOrderInfo95042) TableName() string {
856
+	return "his_order_info"
857
+}
858
+
859
+func GetHisOrderDetail9504() (order []*HisOrder9504, err error) {
860
+	err = readDb.Model(&HisOrder9504{}).Preload("Patients", "status = 1").Preload("VmHisOrderInfo9504", func(db *gorm.DB) *gorm.DB {
861
+		return db.Where("status = 1").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
862
+			return db.Where("status = 1").Preload("VMHisProject", "status = 1").Preload("VMGoodInfo", "status = 1")
863
+		}).Preload("HisDoctorAdviceInfoTen", func(db *gorm.DB) *gorm.DB {
864
+			return db.Where("status = 1").Preload("Drug", "status = 1")
865
+		})
866
+	}).Where("settle_accounts_date >= 1640966400 AND settle_accounts_date <= 1661875200 AND status = 1 AND order_status =2  AND user_org_id = 9504").Find(&order).Order("setl_time").Error
867
+	return
868
+}
869
+
870
+func GetHisOrderDetail10188() (order []*HisOrder9504, err error) {
871
+	err = readDb.Model(&HisOrder9504{}).Preload("Patients", "status = 1").Preload("VmHisOrderInfo9504", func(db *gorm.DB) *gorm.DB {
872
+		return db.Where("status = 1").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
873
+			return db.Where("status = 1").Preload("VMHisProject", "status = 1").Preload("VMGoodInfo", "status = 1")
874
+		})
875
+	}).Where("settle_accounts_date >= 1654012800 AND settle_accounts_date <= 1661875200 AND status = 1 AND order_status =2  AND user_org_id = 10188").Find(&order).Order("setl_time").Error
876
+	return
877
+}
878
+
879
+//func GetHisOrderDetail10138() (order []*HisOrder9504, err error) {
880
+//	err = readDb.Model(&HisOrder9504{}).Preload("Patients", "status = 1").Preload("VmHisOrderInfo9504", func(db *gorm.DB) *gorm.DB {
881
+//		return db.Where("status = 1").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
882
+//			return db.Where("status = 1").Preload("VMHisProject", "status = 1")
883
+//		})
884
+//	}).Where("settle_accounts_date >= 1640966400 AND settle_accounts_date <= 1648656000 AND status = 1 AND order_status =2  AND user_org_id = 10138").Find(&order).Order("setl_time").Error
885
+//	return
886
+//}
887
+
888
+func GetHisOrderDetail10138() (order []*HisOrderTen, err error) {
889
+	err = readDb.Model(&HisOrderTen{}).Preload("HisPrescriptionTen", func(db *gorm.DB) *gorm.DB {
890
+		return db.Where("status = 1 AND order_status = 2").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
891
+			return db.Where("status = 1").Preload("VMHisProject")
892
+		})
893
+	}).Where("settle_accounts_date >= 1656604800 AND settle_accounts_date <= 1664553599 AND status = 1 AND order_status =2  AND user_org_id = 10138").Find(&order).Error
894
+	return
895
+}
896
+
897
+func GetHisOrderDetail10265() (order_infos []*VmHisOrderInfo9504, err error) {
898
+	err = readDb.Model(&VmHisOrderInfo9504{}).Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
899
+		return db.Preload("VMHisProject").Preload("VMGoodInfo", "status = 1")
900
+	}).Preload("HisDoctorAdviceInfoTen", func(db *gorm.DB) *gorm.DB {
901
+		return db.Where("status = 1").Preload("Drug", "status = 1")
902
+	}).Where(" status = 1  AND user_org_id = 10265 AND order_number = '2022090814370516482'").Find(&order_infos).Error
903
+	return
904
+}
905
+
906
+func GetHisOrder10265() (order_infos []*VmHisOrderInfo9504, err error) {
907
+	err = readDb.Model(&VmHisOrderInfo95042{}).Where(" status = 1  AND user_org_id = 10265 AND order_number = '2022092912130116192' AND project_id > 0").Find(&order_infos).Error
908
+	return
909
+}
910
+
911
+func SaveOrderInfo(info *VmHisOrderInfo9504) {
912
+	writeDb.Save(&info)
913
+}
914
+
915
+func GetHisOrderDetail10106(start_time int64, end_time int64) (order []*HisOrder9504, err error) {
916
+	err = readDb.Model(&HisOrder9504{}).Preload("VmHisOrderInfo9504", func(db *gorm.DB) *gorm.DB {
917
+		return db.Where("status = 1").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
918
+			return db.Where("status = 1").Preload("VMHisProject").Preload("VMGoodInfo")
919
+		}).Preload("HisDoctorAdviceInfoTen", func(db *gorm.DB) *gorm.DB {
920
+			return db.Where("status = 1").Preload("Drug")
921
+		})
922
+	}).Where("settle_accounts_date >= ? AND settle_accounts_date <= ? AND status = 1 AND order_status =2  AND user_org_id = 10106", start_time, end_time).Find(&order).Order("setl_time").Error
923
+	return
924
+}
925
+
926
+func GetLongSolution() {
927
+	records, _ := GetAllSchedules()
928
+	fmt.Println(records)
929
+	for _, item := range records {
930
+		//1.透析器   2.灌流器     3.透析器/灌流器
931
+		so, _ := GetDialysisSolutionTwo(item.UserOrgId, item.PatientId, item.ModeId)
932
+		filedRecordOne, _ := FindFiledBy(item.UserOrgId, "透析器")
933
+		filedRecordTwo, _ := FindFiledBy(item.UserOrgId, "灌流器")
934
+		filedRecordThree, _ := FindFiledBy(item.UserOrgId, "透析器/灌流器")
935
+		if filedRecordOne.IsShow == 1 {
936
+			item.DialysisMachineName = so.DialysisDialyszers
937
+		}
938
+		if filedRecordThree.IsShow == 1 {
939
+			if len(item.DialysisMachineName) > 0 {
940
+				item.DialysisMachineName = item.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
941
+
942
+			} else {
943
+				item.DialysisMachineName = so.DialyzerPerfusionApparatus
944
+
945
+			}
946
+		}
947
+		if filedRecordTwo.IsShow == 1 {
948
+			if len(item.DialysisMachineName) > 0 {
949
+				item.DialysisMachineName = item.DialysisMachineName + "," + so.DialysisIrrigation
950
+
951
+			} else {
952
+				item.DialysisMachineName = so.DialysisIrrigation
953
+
954
+			}
955
+		}
956
+
957
+		UpdateSch(item)
958
+
959
+	}
960
+}
961
+
962
+func GetAllSchMode() (modes []*models.PatientScheduleTemplateMode, getModesErr error) {
963
+	getModesErr = readDb.Model(&models.PatientScheduleTemplateMode{}).Where("mode <> 0 AND status = 1 ").Find(&modes).Error
964
+	return
965
+}
966
+
967
+type DialysisSolutionTwo struct {
968
+	ID        int64 `gorm:"column:id" json:"id" form:"id"`
969
+	UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
970
+}
971
+
972
+func (DialysisSolutionTwo) TableName() string {
973
+	return "xt_dialysis_solution"
974
+}
975
+
976
+type Schedule struct {
977
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
978
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
979
+	PatientId           int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
980
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`
981
+	ScheduleDate        int64  `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
982
+	ModeId              int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
983
+	DialysisMachineName string `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
984
+}
985
+
986
+func (Schedule) TableName() string {
987
+	return "xt_schedule"
988
+}
989
+
990
+func GetAllSchedules() ([]Schedule, error) {
991
+	var record []Schedule
992
+
993
+	err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date > 1670774400").Find(&record).Error
994
+	if err != nil {
995
+		if err == gorm.ErrRecordNotFound {
996
+			return nil, nil
997
+		} else {
998
+			return nil, err
999
+		}
1000
+	}
1001
+	return record, nil
1002
+}
1003
+
1004
+func FindFiledBy(org_id int64, name string) (filedConfig models.FiledConfig, err error) {
1005
+	err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND  module = 1 AND filed_name_cn= ?", org_id, name).First(&filedConfig).Error
1006
+	return
1007
+}
1008
+
1009
+// 透析方案
1010
+func GetDialysisSolutionTwo(orgID int64, patientID int64, mode_id int64) (models.DialysisSolution, error) {
1011
+	var record models.DialysisSolution
1012
+	err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
1013
+	return record, err
1014
+}
1015
+
1016
+func UpdateSch(sch Schedule) (err error) {
1017
+	err = writeDb.Model(&Schedule{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"dialysis_machine_name": sch.DialysisMachineName}).Error
1018
+	return
1019
+}
1020
+
1021
+func SaveSch(sch models.Schedule) (err error) {
1022
+	err = writeDb.Save(&sch).Error
1023
+	return
1024
+}

+ 814 - 46
service/auto_create_week_schedules_service.go View File

@@ -2,7 +2,6 @@ package service
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"strings"
6 5
 	"time"
7 6
 
8 7
 	"XT_New/models"
@@ -21,7 +20,8 @@ func init() {
21 20
 	spec := "0 0 0 ? * MON" // 每周一凌晨0点生成排班
22 21
 	//spec := "0 */1 * * * ?"
23 22
 	createWeekSchedulesCronJob.AddFunc(spec, func() {
24
-		AutoCreateWeekSchedules()
23
+		//AutoCreateWeekSchedules()
24
+		NewAutoCreateWeekSchedules()
25 25
 	})
26 26
 }
27 27
 
@@ -29,6 +29,669 @@ func BeginAutoCreateWeekSchedulesJob() {
29 29
 	createWeekSchedulesCronJob.Start()
30 30
 }
31 31
 
32
+func NewAutoCreateWeekSchedules() {
33
+	utils.TraceLog("自动排班任务开始执行")
34
+	var modes []*models.PatientScheduleTemplateMode
35
+	getModesErr := readDb.Model(&models.PatientScheduleTemplateMode{}).Where("mode <> 0 AND status = 1 ").Find(&modes).Error
36
+	if getModesErr != nil {
37
+		utils.ErrorLog("自动排班-获取启用模板模式列表失败:%v", getModesErr)
38
+		CreateDBErrorRecord(0, "自动排班-获取启用模板模式列表失败:%v", getModesErr)
39
+		return
40
+	}
41
+
42
+	for _, mode := range modes {
43
+		templates, getTemplatesErr := GetOrgPatientScheduleTemplateIDs(mode.OrgID)
44
+		if getTemplatesErr != nil {
45
+			utils.ErrorLog("自动排班-org_id: %v :获取模板 ID 失败:%v", mode.OrgID, getTemplatesErr)
46
+			CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取模板 ID 失败:%v", mode.OrgID, getTemplatesErr)
47
+			continue
48
+		} else if len(templates) == 0 {
49
+			utils.WarningLog("自动排班-org_id: %v :没有模板", mode.OrgID)
50
+			continue
51
+		}
52
+
53
+		now := time.Now()
54
+		nextSecWeek := now.AddDate(0, 0, 14)
55
+		//nextThridWeek := now.AddDate(0, 0, 21)
56
+		//nextFourWeek := now.AddDate(0, 0, 28)
57
+		curWeek := now.AddDate(0, 0, 0)
58
+		nextWeek := now.AddDate(0, 0, 7)
59
+
60
+		tx := writeDb.Begin()
61
+		thisTime := time.Now()
62
+		_, theWeek := thisTime.ISOWeek()
63
+		fmt.Println(theWeek)
64
+
65
+		//mode.Week == 0 为了兼容开发新功能前的老数据
66
+		//新功能加了,预约排班生成的,int64(theWeek) >= mode.Week 当判断当前周数是否小大于或者等于模版预约第几周生成的周数
67
+		if mode.Week == 0 || int64(theWeek) >= mode.Week {
68
+			if mode.Week > 0 { //新机构或者重新设置模版的机构需要帮他们根据选择的模版模式,来生成本周,下周,下下周数据
69
+				if mode.Mode == 1 {
70
+					items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
71
+					if getItemsErr != nil {
72
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
73
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
74
+						continue
75
+
76
+					}
77
+					insertErr, count := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, curWeek, items, nil)
78
+					if insertErr != "" {
79
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
80
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
81
+						tx.Rollback()
82
+						continue
83
+
84
+					} else {
85
+						//更新周次
86
+						templates[0].Week = count
87
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
88
+
89
+					}
90
+
91
+					items2, getItemsErr2 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
92
+					if getItemsErr2 != nil {
93
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr2)
94
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr2)
95
+						continue
96
+
97
+					}
98
+					insertErr2, count2 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextWeek, items2, nil)
99
+					if insertErr2 != "" {
100
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr2)
101
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr2)
102
+						tx.Rollback()
103
+						continue
104
+
105
+					} else {
106
+						//更新周次
107
+						templates[0].Week = count2
108
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
109
+
110
+					}
111
+
112
+					items3, getItemsErr3 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
113
+					if getItemsErr3 != nil {
114
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
115
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
116
+						continue
117
+
118
+					}
119
+					insertErr3, count3 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items3, nil)
120
+					if insertErr != "" {
121
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
122
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
123
+						tx.Rollback()
124
+						continue
125
+
126
+					} else {
127
+						//更新周次
128
+						templates[0].Week = count3
129
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
130
+
131
+					}
132
+
133
+					mode.Week = 0
134
+					mode.ExecuteTimes += 3
135
+					mode.ModifyTime = now.Unix()
136
+					updateModeErr := tx.Save(mode).Error
137
+					if updateModeErr != nil {
138
+						utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
139
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
140
+						tx.Rollback()
141
+						continue
142
+
143
+					}
144
+					tx.Commit()
145
+					utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
146
+					time.Sleep(time.Second * 30)
147
+
148
+				} else if mode.Mode == 2 {
149
+
150
+					items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
151
+					if getItemsErr != nil {
152
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
153
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
154
+						continue
155
+
156
+					}
157
+					insertErr, count := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, curWeek, items, nil)
158
+					if insertErr != "" {
159
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
160
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
161
+						tx.Rollback()
162
+						continue
163
+
164
+					} else {
165
+						//更新周次
166
+						templates[0].Week = count
167
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
168
+					}
169
+
170
+					items2, getItemsErr2 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[1].ID)
171
+					if getItemsErr2 != nil {
172
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr2)
173
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr2)
174
+						continue
175
+
176
+					}
177
+					insertErr2, count2 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextWeek, items2, nil)
178
+					if insertErr2 != "" {
179
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr2)
180
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr2)
181
+						tx.Rollback()
182
+						continue
183
+
184
+					} else {
185
+						//更新周次
186
+						templates[1].Week = count2
187
+						UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
188
+
189
+					}
190
+
191
+					items3, getItemsErr3 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
192
+					if getItemsErr3 != nil {
193
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
194
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
195
+						continue
196
+
197
+					}
198
+					insertErr3, count3 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items3, nil)
199
+					if insertErr != "" {
200
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
201
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
202
+						tx.Rollback()
203
+						continue
204
+
205
+					} else {
206
+						//更新周次
207
+						templates[0].Week = count3
208
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
209
+
210
+					}
211
+
212
+					mode.Week = 0
213
+					mode.ExecuteTimes += 3
214
+					mode.ModifyTime = now.Unix()
215
+					updateModeErr := tx.Save(mode).Error
216
+					if updateModeErr != nil {
217
+						utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
218
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
219
+						tx.Rollback()
220
+						continue
221
+
222
+					}
223
+					tx.Commit()
224
+					utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
225
+					time.Sleep(time.Second * 30)
226
+
227
+				} else if mode.Mode == 3 || mode.Mode == 4 {
228
+					fmt.Println("---------")
229
+					items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
230
+					if getItemsErr != nil {
231
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
232
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
233
+						continue
234
+
235
+					}
236
+					insertErr, count := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, curWeek, items, nil)
237
+					if insertErr != "" {
238
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
239
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr)
240
+						tx.Rollback()
241
+						continue
242
+
243
+					} else {
244
+						//更新周次
245
+						templates[0].Week = count
246
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
247
+
248
+					}
249
+
250
+					items12, getItemsErr12 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[1].ID)
251
+					fmt.Println("------22222")
252
+					if getItemsErr12 != nil {
253
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr12)
254
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr12)
255
+						continue
256
+
257
+					}
258
+					insertErr12, count12 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextWeek, items12, nil)
259
+					if insertErr12 != "" {
260
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr12)
261
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr12)
262
+						tx.Rollback()
263
+						continue
264
+
265
+					} else {
266
+						//更新周次
267
+						templates[1].Week = count12
268
+						UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
269
+
270
+					}
271
+
272
+					items3, getItemsErr3 := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[2].ID)
273
+					if getItemsErr3 != nil {
274
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
275
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr3)
276
+						continue
277
+
278
+					}
279
+					insertErr3, count3 := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items3, nil)
280
+					if insertErr != "" {
281
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
282
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入本周排班失败:%v", mode.OrgID, insertErr3)
283
+						tx.Rollback()
284
+						continue
285
+
286
+					} else {
287
+						//更新周次
288
+						templates[2].Week = count3
289
+						UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, int8(templates[2].Week))
290
+
291
+					}
292
+
293
+					mode.Week = 0
294
+					mode.ExecuteTimes += 3
295
+					mode.ModifyTime = now.Unix()
296
+					updateModeErr := tx.Save(mode).Error
297
+					if updateModeErr != nil {
298
+						utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
299
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
300
+						tx.Rollback()
301
+						continue
302
+
303
+					}
304
+					tx.Commit()
305
+					utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
306
+					time.Sleep(time.Second * 30)
307
+				}
308
+			} else {
309
+				if mode.Mode == 1 { // 用第一周模板生成下第二周的排班
310
+					items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
311
+					if getItemsErr != nil {
312
+						utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
313
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
314
+						continue
315
+					}
316
+					insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
317
+					if insertErr != "" {
318
+						utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
319
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
320
+						tx.Rollback()
321
+						continue
322
+					} else {
323
+						//thisTime := time.Now()
324
+						//_, theWeek := thisTime.ISOWeek()
325
+
326
+						//更新周次
327
+						templates[0].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
328
+						UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
329
+					}
330
+
331
+					mode.Week = 0
332
+					mode.ExecuteTimes += 1
333
+					mode.ModifyTime = now.Unix()
334
+					updateModeErr := tx.Save(mode).Error
335
+					if updateModeErr != nil {
336
+						utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
337
+						CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
338
+						tx.Rollback()
339
+						continue
340
+					}
341
+					tx.Commit()
342
+					utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
343
+					time.Sleep(time.Second * 30)
344
+
345
+				} else if mode.Mode == 2 { // mode.ExecuteTimes % 2 的结果,如果为0,用第一周模板生成下第二周的排班,否则用第二周的模板生成排班
346
+					if mode.ExecuteTimes%2 == 0 {
347
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
348
+						if getItemsErr != nil {
349
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
350
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
351
+							continue
352
+						}
353
+
354
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
355
+						if insertErr != "" {
356
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
357
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
358
+							tx.Rollback()
359
+							continue
360
+						} else {
361
+
362
+							templates[0].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
363
+
364
+							UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
365
+
366
+						}
367
+
368
+						mode.Week = 0
369
+						mode.ExecuteTimes += 1
370
+						mode.ModifyTime = now.Unix()
371
+						updateModeErr := tx.Save(mode).Error
372
+						if updateModeErr != nil {
373
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
374
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
375
+							tx.Rollback()
376
+							continue
377
+						}
378
+						tx.Commit()
379
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
380
+						time.Sleep(time.Second * 30)
381
+
382
+					} else {
383
+						if len(templates) < 2 {
384
+							utils.WarningLog("自动排班-org_id: %v :没有第二周的模板")
385
+							continue
386
+						}
387
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[1].ID)
388
+						if getItemsErr != nil {
389
+							utils.ErrorLog("自动排班-org_id: %v :获取第二周模板Item失败:%v", mode.OrgID, getItemsErr)
390
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第二周模板Item失败:%v", mode.OrgID, getItemsErr)
391
+							continue
392
+						}
393
+
394
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
395
+						if insertErr != "" {
396
+							utils.ErrorLog("自动排班-org_id: %v :使用第二周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
397
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第二周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
398
+							tx.Rollback()
399
+							continue
400
+						} else {
401
+
402
+							//thisTime := time.Now()
403
+							//_, week := thisTime.ISOWeek()
404
+
405
+							//更新周次
406
+							templates[1].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
407
+
408
+							//templates[1].Week = week + 2
409
+							UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
410
+
411
+						}
412
+
413
+						mode.Week = 0
414
+						mode.ExecuteTimes += 1
415
+						mode.ModifyTime = now.Unix()
416
+						updateModeErr := tx.Save(mode).Error
417
+						if updateModeErr != nil {
418
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
419
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
420
+							tx.Rollback()
421
+							continue
422
+						}
423
+						tx.Commit()
424
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
425
+						time.Sleep(time.Second * 30)
426
+
427
+					}
428
+				} else if mode.Mode == 3 { // mode.ExecuteTimes % 2 的结果,如果为0,用第一周模板生成下第二周的排班,否则用第二周的模板生成排班
429
+					if mode.ExecuteTimes%3 == 0 {
430
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
431
+						if getItemsErr != nil {
432
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
433
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
434
+							continue
435
+						}
436
+
437
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
438
+						if insertErr != "" {
439
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第三周排班失败:%v", mode.OrgID, insertErr)
440
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第三周排班失败:%v", mode.OrgID, insertErr)
441
+							tx.Rollback()
442
+							continue
443
+						} else {
444
+							templates[0].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
445
+
446
+							UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
447
+						}
448
+						mode.Week = 0
449
+						mode.ExecuteTimes += 1
450
+						mode.ModifyTime = now.Unix()
451
+						updateModeErr := tx.Save(mode).Error
452
+						if updateModeErr != nil {
453
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
454
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
455
+							tx.Rollback()
456
+							continue
457
+						}
458
+						tx.Commit()
459
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
460
+						time.Sleep(time.Second * 30)
461
+
462
+					} else if mode.ExecuteTimes%3 == 1 {
463
+						if len(templates) < 2 {
464
+							utils.WarningLog("自动排班-org_id: %v :没有第二周的模板")
465
+							continue
466
+						}
467
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[1].ID)
468
+						if getItemsErr != nil {
469
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
470
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
471
+							continue
472
+						}
473
+
474
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
475
+						if insertErr != "" {
476
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
477
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
478
+							tx.Rollback()
479
+							continue
480
+						} else {
481
+							templates[1].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
482
+
483
+							UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
484
+
485
+						}
486
+						mode.Week = 0
487
+						mode.ExecuteTimes += 1
488
+						mode.ModifyTime = now.Unix()
489
+						updateModeErr := tx.Save(mode).Error
490
+						if updateModeErr != nil {
491
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
492
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
493
+							tx.Rollback()
494
+							continue
495
+						}
496
+						tx.Commit()
497
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
498
+						time.Sleep(time.Second * 30)
499
+
500
+					} else {
501
+						if len(templates) < 3 {
502
+							utils.WarningLog("自动排班-org_id: %v :没有第三周的模板")
503
+							continue
504
+						}
505
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[2].ID)
506
+						if getItemsErr != nil {
507
+							utils.ErrorLog("自动排班-org_id: %v :获取第三周模板Item失败:%v", mode.OrgID, getItemsErr)
508
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第三周模板Item失败:%v", mode.OrgID, getItemsErr)
509
+							continue
510
+						}
511
+
512
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
513
+						if insertErr != "" {
514
+							utils.ErrorLog("自动排班-org_id: %v :使用第三周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
515
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第三周模板插入下第三周排班失败:%v", mode.OrgID, insertErr)
516
+							tx.Rollback()
517
+							continue
518
+						} else {
519
+							templates[2].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
520
+
521
+							UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, int8(templates[2].Week))
522
+
523
+						}
524
+						mode.Week = 0
525
+						mode.ExecuteTimes += 1
526
+						mode.ModifyTime = now.Unix()
527
+						updateModeErr := tx.Save(mode).Error
528
+						if updateModeErr != nil {
529
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
530
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
531
+							tx.Rollback()
532
+							continue
533
+						}
534
+						tx.Commit()
535
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
536
+						time.Sleep(time.Second * 30)
537
+
538
+					}
539
+				} else if mode.Mode == 4 { // mode.ExecuteTimes % 2 的结果,如果为0,用第一周模板生成下第二周的排班,否则用第二周的模板生成排班
540
+					if mode.ExecuteTimes%4 == 0 {
541
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[0].ID)
542
+						if getItemsErr != nil {
543
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
544
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
545
+							continue
546
+						}
547
+
548
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
549
+						if insertErr != "" {
550
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
551
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
552
+							tx.Rollback()
553
+							continue
554
+						} else {
555
+							templates[0].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
556
+
557
+							UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, int8(templates[0].Week))
558
+
559
+						}
560
+						mode.Week = 0
561
+						mode.ExecuteTimes += 1
562
+						mode.ModifyTime = now.Unix()
563
+						updateModeErr := tx.Save(mode).Error
564
+						if updateModeErr != nil {
565
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
566
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
567
+							tx.Rollback()
568
+							continue
569
+						}
570
+						tx.Commit()
571
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
572
+						time.Sleep(time.Second * 30)
573
+
574
+					} else if mode.ExecuteTimes%4 == 1 {
575
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[1].ID)
576
+						if getItemsErr != nil {
577
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
578
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
579
+							continue
580
+						}
581
+
582
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
583
+						if insertErr != "" {
584
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
585
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
586
+							tx.Rollback()
587
+							continue
588
+						} else {
589
+							templates[1].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
590
+
591
+							UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, int8(templates[1].Week))
592
+
593
+						}
594
+						mode.Week = 0
595
+						mode.ExecuteTimes += 1
596
+						mode.ModifyTime = now.Unix()
597
+						updateModeErr := tx.Save(mode).Error
598
+						if updateModeErr != nil {
599
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
600
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
601
+							tx.Rollback()
602
+							continue
603
+						}
604
+						tx.Commit()
605
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
606
+						time.Sleep(time.Second * 30)
607
+
608
+					} else if mode.ExecuteTimes%4 == 2 {
609
+						if len(templates) < 2 {
610
+							utils.WarningLog("自动排班-org_id: %v :没有第二周的模板")
611
+							continue
612
+						}
613
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[2].ID)
614
+						if getItemsErr != nil {
615
+							utils.ErrorLog("自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
616
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
617
+							continue
618
+						}
619
+
620
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
621
+						if insertErr != "" {
622
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
623
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
624
+							tx.Rollback()
625
+							continue
626
+						} else {
627
+							templates[2].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
628
+
629
+							UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, int8(templates[2].Week))
630
+
631
+						}
632
+						mode.Week = 0
633
+						mode.ExecuteTimes += 1
634
+						mode.ModifyTime = now.Unix()
635
+						updateModeErr := tx.Save(mode).Error
636
+						if updateModeErr != nil {
637
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
638
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
639
+							tx.Rollback()
640
+							continue
641
+						}
642
+						tx.Commit()
643
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
644
+						time.Sleep(time.Second * 30)
645
+
646
+					} else if mode.ExecuteTimes%4 == 3 {
647
+						if len(templates) < 3 {
648
+							utils.WarningLog("自动排班-org_id: %v :没有第三周的模板")
649
+							continue
650
+						}
651
+						items, getItemsErr := GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(mode.OrgID, templates[3].ID)
652
+						if getItemsErr != nil {
653
+							utils.ErrorLog("自动排班-org_id: %v :获取第三周模板Item失败:%v", mode.OrgID, getItemsErr)
654
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第三周模板Item失败:%v", mode.OrgID, getItemsErr)
655
+							continue
656
+						}
657
+
658
+						insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
659
+						if insertErr != "" {
660
+							utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第四周排班失败:%v", mode.OrgID, insertErr)
661
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第三周排班失败:%v", mode.OrgID, insertErr)
662
+							tx.Rollback()
663
+							continue
664
+						} else {
665
+							templates[3].Week = GetWeeks(nextSecWeek.Format("2006-01-02 15:04:05"))
666
+
667
+							UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, int8(templates[3].Week))
668
+
669
+						}
670
+
671
+						mode.Week = 0
672
+						mode.ExecuteTimes += 1
673
+						mode.ModifyTime = now.Unix()
674
+						updateModeErr := tx.Save(mode).Error
675
+						if updateModeErr != nil {
676
+							utils.ErrorLog("自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
677
+							CreateDBErrorRecord(mode.OrgID, "自动排班-org_id:%v :更新启用模板模式的执行次数失败:%v", mode.OrgID, updateModeErr)
678
+							tx.Rollback()
679
+							continue
680
+						}
681
+						tx.Commit()
682
+						utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
683
+						time.Sleep(time.Second * 30)
684
+
685
+					}
686
+				}
687
+
688
+			}
689
+			utils.SuccessLog("自动排班任务完成")
690
+		}
691
+	}
692
+
693
+}
694
+
32 695
 func AutoCreateWeekSchedules() {
33 696
 	utils.TraceLog("自动排班任务开始执行")
34 697
 	var modes []*models.PatientScheduleTemplateMode
@@ -61,8 +724,8 @@ func AutoCreateWeekSchedules() {
61 724
 				CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :获取第一周模板Item失败:%v", mode.OrgID, getItemsErr)
62 725
 				continue
63 726
 			}
64
-			insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
65
-			if insertErr != nil {
727
+			insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
728
+			if insertErr != "" {
66 729
 				utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
67 730
 				CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
68 731
 				tx.Rollback()
@@ -78,8 +741,8 @@ func AutoCreateWeekSchedules() {
78 741
 					continue
79 742
 				}
80 743
 
81
-				insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
82
-				if insertErr != nil {
744
+				insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
745
+				if insertErr != "" {
83 746
 					utils.ErrorLog("自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
84 747
 					CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
85 748
 					tx.Rollback()
@@ -98,16 +761,17 @@ func AutoCreateWeekSchedules() {
98 761
 					continue
99 762
 				}
100 763
 
101
-				insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
102
-				if insertErr != nil {
764
+				insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, nextSecWeek, items, nil)
765
+				if insertErr != "" {
103 766
 					utils.ErrorLog("自动排班-org_id: %v :使用第二周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
104 767
 					CreateDBErrorRecord(mode.OrgID, "自动排班-org_id: %v :使用第二周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
105 768
 					tx.Rollback()
106 769
 					continue
770
+				} else {
771
+
107 772
 				}
108 773
 			}
109 774
 		}
110
-
111 775
 		mode.ExecuteTimes += 1
112 776
 		mode.ModifyTime = now.Unix()
113 777
 		updateModeErr := tx.Save(mode).Error
@@ -117,22 +781,20 @@ func AutoCreateWeekSchedules() {
117 781
 			tx.Rollback()
118 782
 			continue
119 783
 		}
120
-
121 784
 		tx.Commit()
122 785
 		utils.SuccessLog("自动排班-插入排班成功:org_id: %v", mode.OrgID)
123
-
124 786
 		time.Sleep(time.Second * 30)
125 787
 	}
126 788
 
127 789
 	utils.SuccessLog("自动排班任务完成")
128 790
 }
129 791
 
130
-func _refreshWeekSchedulesWithTemplateItems(tx *gorm.DB, orgID int64, week time.Time, templateItems []*models.PatientScheduleTemplateItem, deviceNumberMap map[int64]*DeviceNumberViewModel) error {
792
+func _refreshWeekSchedulesWithTemplateItems(tx *gorm.DB, orgID int64, week time.Time, templateItems []*models.PatientScheduleTemplateItem, deviceNumberMap map[int64]*DeviceNumberViewModel) (string, int) {
131 793
 	if deviceNumberMap == nil {
132 794
 		deviceNumbers, getDeviceNumbersErr := GetAllValidDeviceNumbers(orgID)
133 795
 		//fmt.Println("getDeviceNumbersErr3232322332323232323323223232323",getDeviceNumbersErr)
134 796
 		if getDeviceNumbersErr != nil {
135
-			return getDeviceNumbersErr
797
+			return getDeviceNumbersErr.Error(), 0
136 798
 		}
137 799
 		deviceNumberMap = make(map[int64]*DeviceNumberViewModel, 0)
138 800
 		for _, deviceNumber := range deviceNumbers {
@@ -145,42 +807,107 @@ func _refreshWeekSchedulesWithTemplateItems(tx *gorm.DB, orgID int64, week time.
145 807
 	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", orgID, monday.Unix(), sunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
146 808
 	//fmt.Println("disableErr323232332323232233222332232332",disableErr)
147 809
 	if disableErr != nil {
148
-		return disableErr
810
+		return disableErr.Error(), 0
149 811
 	}
150 812
 
813
+	var week_count int
151 814
 	// 批量插入排班
152 815
 	if len(templateItems) > 0 {
153 816
 
154
-		valueStrs := make([]string, 0, len(templateItems))
155
-		values := make([]interface{}, 0, len(templateItems)*11)
817
+		timeLayout := "2006-01-02"
818
+		loc, _ := time.LoadLocation("Local")
819
+		tmp, _ := time.ParseInLocation(timeLayout, time.Unix(monday.Unix(), 0).Format("2006-01-02"), loc)
820
+		_, weeks := tmp.ISOWeek()
821
+		week_count = weeks
156 822
 
823
+		//valueStrs := make([]string, 0, len(templateItems))
824
+		//values := make([]interface{}, 0, len(templateItems)*11)
825
+		var errs string
157 826
 		for _, item := range templateItems {
158 827
 			deviceNumber := deviceNumberMap[item.DeviceNumberID]
159 828
 			if deviceNumber == nil {
160 829
 				continue
161 830
 			}
162 831
 
163
-			valueStrs = append(valueStrs, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
164
-			values = append(values, orgID)
165
-			values = append(values, deviceNumber.ZoneID)
166
-			values = append(values, item.DeviceNumberID)
167
-			values = append(values, item.PatientID)
168
-			values = append(values, monday.AddDate(0, 0, int(item.Weekday-1)).Unix())
169
-			values = append(values, item.Weekday)
170
-			values = append(values, item.TimeType)
171
-			values = append(values, item.TreatMode)
172
-			values = append(values, 1)
173
-			values = append(values, now.Unix())
174
-			values = append(values, now.Unix())
175
-		}
832
+			so, _ := GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
833
+			filedRecordOne, _ := FindFiledBy(item.OrgID, "透析器")
834
+			filedRecordTwo, _ := FindFiledBy(item.OrgID, "灌流器")
835
+			filedRecordThree, _ := FindFiledBy(item.OrgID, "透析器/灌流器")
836
+			var DialysisMachineName string
837
+			if filedRecordOne.IsShow == 1 {
838
+				DialysisMachineName = so.DialysisDialyszers
839
+			}
840
+			if filedRecordThree.IsShow == 1 {
841
+				if len(DialysisMachineName) > 0 {
842
+					DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
843
+
844
+				} else {
845
+					DialysisMachineName = so.DialyzerPerfusionApparatus
846
+
847
+				}
848
+			}
849
+			if filedRecordTwo.IsShow == 1 {
850
+				if len(DialysisMachineName) > 0 {
851
+					DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
176 852
 
177
-		sql := fmt.Sprintf("INSERT INTO xt_schedule (user_org_id, partition_id, bed_id, patient_id, schedule_date, schedule_week, schedule_type, mode_id, status, created_time, updated_time) VALUES %v;", strings.Join(valueStrs, ", "))
178
-		if insertErr := tx.Exec(sql, values...).Error; insertErr != nil {
179
-			//fmt.Println("insertErr232332233223332232323222222www",insertErr)
180
-			return insertErr
853
+				} else {
854
+					DialysisMachineName = so.DialysisIrrigation
855
+
856
+				}
857
+			}
858
+
859
+			var sch models.Schedule
860
+			sch.UserOrgId = orgID
861
+			sch.PartitionId = deviceNumber.ZoneID
862
+			sch.BedId = item.DeviceNumberID
863
+			sch.PatientId = item.PatientID
864
+			sch.ScheduleDate = monday.AddDate(0, 0, int(item.Weekday-1)).Unix()
865
+			sch.ScheduleWeek = int64(item.Weekday)
866
+			sch.ScheduleType = int64(item.TimeType)
867
+			sch.ModeId = int64(item.TreatMode)
868
+			sch.Status = 1
869
+			sch.CreatedTime = now.Unix()
870
+			sch.UpdatedTime = now.Unix()
871
+			sch.IsExport = 0
872
+			sch.DialysisMachineName = DialysisMachineName
873
+
874
+			//为了防止数据重复,先查询有无记录
875
+			//var othSch []*models.Schedule
876
+			//readDb.Model(&models.Schedule{}).Where("status = 1 AND schedule_date = ? AND user_org_id = ? AND patient_id = ?", sch.ScheduleDate, sch.UserOrgId, sch.PatientId).Find(&othSch)
877
+			//for _, items := range othSch {
878
+			//	items.Status = 0
879
+			//	writeDb.Save(&items)
880
+			//}
881
+			err := writeDb.Create(&sch).Error
882
+			if err != nil {
883
+				errs = errs + err.Error()
884
+			}
885
+
886
+			//valueStrs = append(valueStrs, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
887
+			//values = append(values, orgID)
888
+			//values = append(values, deviceNumber.ZoneID)
889
+			//values = append(values, item.DeviceNumberID)
890
+			//values = append(values, item.PatientID)
891
+			//values = append(values, monday.AddDate(0, 0, int(item.Weekday-1)).Unix())
892
+			//values = append(values, item.Weekday)
893
+			//values = append(values, item.TimeType)
894
+			//values = append(values, item.TreatMode)
895
+			//values = append(values, 1)
896
+			//values = append(values, now.Unix())
897
+			//values = append(values, now.Unix())
898
+			//values = append(values, 0)
899
+			//values = append(values, DialysisMachineName)
900
+		}
901
+		//sql := fmt.Sprintf("INSERT INTO xt_schedule (user_org_id, partition_id, bed_id, patient_id, schedule_date, schedule_week, schedule_type, mode_id, status, created_time, updated_time,is_export,dialysis_machine_name) VALUES %v;", strings.Join(valueStrs, ", "))
902
+		//if insertErr := tx.Exec(sql, values...).Error; insertErr != nil {
903
+		//	fmt.Println("insertErr232332233223332232323222222www", insertErr)
904
+		//}
905
+		if len(errs) != 0 {
906
+			return errs, 0
181 907
 		}
182 908
 	}
183
-	return nil
909
+
910
+	return "", week_count
184 911
 }
185 912
 
186 913
 func FakeAutoCreateNextTwoWeekSchedules(orgID int64) {
@@ -218,14 +945,14 @@ func FakeAutoCreateNextTwoWeekSchedules(orgID int64) {
218 945
 			utils.ErrorLog("获取第一周模板Item失败:%v", getItemsErr)
219 946
 			return
220 947
 		}
221
-		insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), items, deviceNumberMap)
222
-		if insertErr != nil {
948
+		insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), items, deviceNumberMap)
949
+		if insertErr != "" {
223 950
 			utils.ErrorLog("使用第一周模板插入下第一周排班失败:%v", insertErr)
224 951
 			tx.Rollback()
225 952
 			return
226 953
 		}
227
-		insertErr = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), items, deviceNumberMap)
228
-		if insertErr != nil {
954
+		insertErr, _ = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), items, deviceNumberMap)
955
+		if insertErr != "" {
229 956
 			utils.ErrorLog("使用第一周模板插入下第二周排班失败:%v", insertErr)
230 957
 			tx.Rollback()
231 958
 			return
@@ -244,28 +971,28 @@ func FakeAutoCreateNextTwoWeekSchedules(orgID int64) {
244 971
 		}
245 972
 
246 973
 		if mode.ExecuteTimes%2 == 0 {
247
-			insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), firstItems, deviceNumberMap)
248
-			if insertErr != nil {
974
+			insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), firstItems, deviceNumberMap)
975
+			if insertErr != "" {
249 976
 				utils.ErrorLog("使用第一周模板插入下第一周排班失败:%v", insertErr)
250 977
 				tx.Rollback()
251 978
 				return
252 979
 			}
253
-			insertErr = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), secItems, deviceNumberMap)
254
-			if insertErr != nil {
980
+			insertErr, _ = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), secItems, deviceNumberMap)
981
+			if insertErr != "" {
255 982
 				utils.ErrorLog("使用第二周模板插入下第二周排班失败:%v", insertErr)
256 983
 				tx.Rollback()
257 984
 				return
258 985
 			}
259 986
 
260 987
 		} else { // mode.ExecuteTimes%2 == 1
261
-			insertErr := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), secItems, deviceNumberMap)
262
-			if insertErr != nil {
988
+			insertErr, _ := _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 7), secItems, deviceNumberMap)
989
+			if insertErr != "" {
263 990
 				utils.ErrorLog("使用第二周模板插入下第一周排班失败:%v", mode.OrgID, insertErr)
264 991
 				tx.Rollback()
265 992
 				return
266 993
 			}
267
-			insertErr = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), firstItems, deviceNumberMap)
268
-			if insertErr != nil {
994
+			insertErr, _ = _refreshWeekSchedulesWithTemplateItems(tx, mode.OrgID, now.AddDate(0, 0, 14), firstItems, deviceNumberMap)
995
+			if insertErr != "" {
269 996
 				utils.ErrorLog("使用第一周模板插入下第二周排班失败:%v", mode.OrgID, insertErr)
270 997
 				tx.Rollback()
271 998
 				return
@@ -285,3 +1012,44 @@ func FakeAutoCreateNextTwoWeekSchedules(orgID int64) {
285 1012
 	tx.Commit()
286 1013
 	utils.SuccessLog("模拟自动更新下两周排班成功")
287 1014
 }
1015
+
1016
+func GetWeeks(oneTimeStr string) int {
1017
+	fmt.Println(oneTimeStr)
1018
+
1019
+	//某个时间
1020
+	//oneTimeStr := "2018-01-08 00:00:00"
1021
+	//oneTimeStr := "2021-04-05 00:00:00"
1022
+	//时间转换成time.Time格式
1023
+	t, err := time.ParseInLocation("2006-01-02 15:04:05", oneTimeStr, time.Local)
1024
+	if err != nil {
1025
+		fmt.Println(err)
1026
+	}
1027
+	//获取这个时间的基于这一年有多少天了
1028
+	yearDay := t.YearDay()
1029
+	//获取上一年的最后一天
1030
+	yesterdayYearEndDay := t.AddDate(0, 0, -yearDay)
1031
+	//获取上一年最后一天是星期几
1032
+	dayInWeek := int(yesterdayYearEndDay.Weekday())
1033
+	//第一周的总天数,默认是7天
1034
+	firstWeekDays := 7
1035
+	//如果上一年最后一天不是星期天,则第一周总天数是7-dayInWeek
1036
+	if dayInWeek != 0 {
1037
+		firstWeekDays = 7 - dayInWeek
1038
+	}
1039
+	week := 0
1040
+	//如果这一年的总天数小于第一周总天数,则是第一周,否则按照这一年多少天减去第一周的天数除以7+1 但是要考虑这一天减去第一周天数除以7会取整型,
1041
+	//所以需要处理两个数取余之后是否大于0,如果大于0 则多加一天,这样自然周就算出来了。
1042
+	if yearDay <= firstWeekDays {
1043
+		week = 1
1044
+	} else {
1045
+		plusDay := 0
1046
+		if (yearDay-firstWeekDays)%7 > 0 {
1047
+			plusDay = 1
1048
+		}
1049
+		week = (yearDay-firstWeekDays)/7 + 1 + plusDay
1050
+	}
1051
+	fmt.Println(week)
1052
+
1053
+	return week - 1
1054
+
1055
+}

+ 16 - 3
service/device_service.go View File

@@ -390,10 +390,23 @@ func UpdateDeviceGroup(group *models.DeviceGroup) error {
390 390
 
391 391
 //////// 机号 Number
392 392
 
393
+type DeviceNumberVM struct {
394
+	ID     int64  `gorm:"column:id" json:"id"`
395
+	OrgID  int64  `gorm:"column:org_id" json:"-"`
396
+	Number string `gorm:"column:number" json:"number"`
397
+	ZoneID int64  `gorm:"column:zone_id" json:"zone_id"`
398
+	Status int64  `gorm:"column:status" json:"status" form:"status"`
399
+}
400
+
401
+func (DeviceNumberVM) TableName() string {
402
+	return "xt_device_number"
403
+}
404
+
393 405
 type DeviceNumberViewModel struct {
394
-	models.DeviceNumber
395
-	ZoneName  string `gorm:"column:zone_name" json:"zone_name"`
396
-	GroupName string `gorm:"column:group_name" json:"group_name"`
406
+	DeviceNumberVM
407
+	ZoneName  string              `gorm:"column:zone_name" json:"zone_name"`
408
+	GroupName string              `gorm:"column:group_name" json:"group_name"`
409
+	Zone      models.VMDeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
397 410
 }
398 411
 
399 412
 func GetAllValidDeviceNumbers(orgID int64) ([]*DeviceNumberViewModel, error) {

+ 1 - 1
service/his_config_service.go View File

@@ -864,7 +864,7 @@ func GetDataConfig(orgid int64) (dataconfig []*models.DictDataconfig, err error)
864 864
 //翻译项目中的组
865 865
 func TranslateZu(sc, orgid int64, types string) (s string, err error) {
866 866
 	var dataconfig []*models.DictDataconfig
867
-	tmp := "select * from xt_drug_data_config where parent_id in (select id from xt_drug_data_config where name = \"" + types + "\" and parent_id = 0) and value = " + config.ToString(sc) + " and status = 1 and (org_id = " + config.ToString(orgid) + " or org_id = 0)"
867
+	tmp := "select * from xt_drug_data_config where parent_id in (select id from xt_d·rug_data_config where name = \"" + types + "\" and parent_id = 0) and value = " + config.ToString(sc) + " and status = 1 and (org_id = " + config.ToString(orgid) + " or org_id = 0)"
868 868
 
869 869
 	err = XTReadDB().Raw(tmp).Scan(&dataconfig).Error
870 870
 	if err != nil {

+ 48 - 12
service/his_service.go View File

@@ -43,18 +43,6 @@ func (HisPatient) TableName() string {
43 43
 	return "his_patient"
44 44
 }
45 45
 
46
-type Schedule struct {
47
-	ID           int64 `gorm:"column:id" json:"id" form:"id"`
48
-	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
49
-	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
50
-	Status       int64 `gorm:"column:status" json:"status" form:"status"`
51
-	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
52
-}
53
-
54
-func (Schedule) TableName() string {
55
-	return "xt_schedule"
56
-}
57
-
58 46
 type VMHisPrescriptionInfo struct {
59 47
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
60 48
 	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -2584,6 +2572,54 @@ func UpDateOrderTwo(order *models.HisOrder) (err error) {
2584 2572
 	return
2585 2573
 }
2586 2574
 
2575
+type HisOrderInfoTen struct {
2576
+	ID                     int64                      `gorm:"column:id" json:"id" form:"id"`
2577
+	OrderNumber            string                     `gorm:"column:order_number" json:"order_number" form:"order_number"`
2578
+	UploadDate             int64                      `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
2579
+	AdviceId               int64                      `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
2580
+	DetItemFeeSumamt       float64                    `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
2581
+	Cnt                    float64                    `gorm:"column:cnt" json:"cnt" form:"cnt"`
2582
+	Pric                   float64                    `gorm:"column:pric" json:"pric" form:"pric"`
2583
+	PatientId              int64                      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2584
+	MedChrgitmType         string                     `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
2585
+	Status                 int64                      `gorm:"column:status" json:"status" form:"status"`
2586
+	FeedetlSn              string                     `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
2587
+	ChldMedcFlag           string                     `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
2588
+	ChrgitmLv              string                     `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
2589
+	UserOrgId              int64                      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
2590
+	ProjectId              int64                      `gorm:"column:project_id" json:"project_id" form:"project_id"`
2591
+	ItemId                 int64                      `gorm:"column:item_id" json:"item_id" form:"item_id"`
2592
+	FulamtOwnpayAmt        float64                    `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
2593
+	HisPrescriptionProject HisPrescriptionProject     `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
2594
+	HisDoctorAdviceInfo    models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
2595
+}
2596
+
2597
+func (HisOrderInfoTen) TableName() string {
2598
+	return "his_order_info"
2599
+}
2600
+func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
2601
+	err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2602
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
2603
+	}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2604
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
2605
+	}).Find(&order).Error
2606
+	return
2607
+}
2608
+
2609
+func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
2610
+	err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2611
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
2612
+	}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2613
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
2614
+	}).Find(&order).Error
2615
+	return
2616
+}
2617
+
2618
+func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
2619
+	err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
2620
+	return
2621
+}
2622
+
2587 2623
 func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
2588 2624
 
2589 2625
 	project := models.HisPrescriptionProject{}

+ 9 - 8
service/mobile_dialysis_service.go View File

@@ -2811,14 +2811,15 @@ func (GoodsType) TableName() string {
2811 2811
 }
2812 2812
 
2813 2813
 type VMGoodInfo struct {
2814
-	ID                int64   `gorm:"column:id" json:"id"`
2815
-	SpecificationName string  `gorm:"column:specification_name" json:"specification_name"`
2816
-	GoodTypeId        int64   `gorm:"column:good_type_id" json:"good_type_id"`
2817
-	OrgId             int64   `gorm:"column:org_id" json:"org_id"`
2818
-	GoodName          string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
2819
-	GoodUnit          int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
2820
-	Total             float64 `gorm:"column:total" json:"total" form:"total"`
2821
-	PackingUnit       string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
2814
+	ID                     int64   `gorm:"column:id" json:"id"`
2815
+	SpecificationName      string  `gorm:"column:specification_name" json:"specification_name"`
2816
+	GoodTypeId             int64   `gorm:"column:good_type_id" json:"good_type_id"`
2817
+	OrgId                  int64   `gorm:"column:org_id" json:"org_id"`
2818
+	GoodName               string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
2819
+	GoodUnit               int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
2820
+	Total                  float64 `gorm:"column:total" json:"total" form:"total"`
2821
+	PackingUnit            string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
2822
+	MedicalInsuranceNumber string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
2822 2823
 }
2823 2824
 
2824 2825
 func (VMGoodInfo) TableName() string {

+ 442 - 41
service/patient_schedule_template_service.go View File

@@ -27,7 +27,7 @@ func GetOrgPatientScheduleTemplateMode(orgID int64) (*models.PatientScheduleTemp
27 27
 // 获取至多两个模板ID
28 28
 func GetOrgPatientScheduleTemplateIDs(orgID int64) ([]*models.PatientScheduleTemplateId, error) {
29 29
 	var ids []*models.PatientScheduleTemplateId
30
-	err := readDb.Model(&models.PatientScheduleTemplateId{}).Where("org_id = ? AND status = 1", orgID).Limit(2).Find(&ids).Error
30
+	err := readDb.Model(&models.PatientScheduleTemplateId{}).Where("org_id = ? AND status = 1", orgID).Limit(4).Find(&ids).Error
31 31
 	if err != nil {
32 32
 		return nil, err
33 33
 	}
@@ -47,10 +47,22 @@ func GetOrgPatientScheduleTemplateIDByTemplateID(orgID int64, templateID int64)
47 47
 	return &id, nil
48 48
 }
49 49
 
50
+type PatientsTwo struct {
51
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
52
+	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
53
+	UserId    int64  `gorm:"column:user_id" json:"user_id" form:"user_id"`
54
+	Name      string `gorm:"column:name" json:"name" form:"name"`
55
+}
56
+
57
+func (PatientsTwo) TableName() string {
58
+	return "xt_patients"
59
+}
60
+
50 61
 type PatientScheduleTemplateItemViewModel struct {
51 62
 	models.PatientScheduleTemplateItem
52 63
 
53
-	Patient *models.Patients `gorm:"ForeignKey:PatientID" json:"patient"`
64
+	Patient               *PatientsTwo          `gorm:"ForeignKey:PatientID" json:"patient"`
65
+	DeviceNumberViewModel DeviceNumberViewModel `gorm:"ForeignKey:DeviceNumberID" json:"devices"`
54 66
 }
55 67
 
56 68
 type PatientScheduleTemplateViewModel struct {
@@ -72,8 +84,9 @@ func GetOrgPatientScheduleTemplateItems(orgID int64) ([]*PatientScheduleTemplate
72 84
 		Model(&PatientScheduleTemplateViewModel{}).
73 85
 		Preload("Items", "org_id = ? AND status = 1", orgID).
74 86
 		Preload("Items.Patient", "user_org_id = ? AND status = 1", orgID).
87
+		Preload("Items.DeviceNumberViewModel.Zone", "status = 1").
75 88
 		Where("org_id = ? AND status = 1", orgID).
76
-		Limit(2).
89
+		Limit(4).
77 90
 		Find(&vms).
78 91
 		Error
79 92
 	if err != nil {
@@ -83,12 +96,12 @@ func GetOrgPatientScheduleTemplateItems(orgID int64) ([]*PatientScheduleTemplate
83 96
 }
84 97
 
85 98
 // 获取指定模板ID的模板排班列表
86
-func GetOrgPatientScheduleTemplateItemsByTemplateID(orgID int64, templateID int64) ([]*PatientScheduleTemplateItemViewModel, error) {
99
+func GetOrgPatientScheduleTemplateItemsByTemplateID(orgID int64) ([]*PatientScheduleTemplateItemViewModel, error) {
87 100
 	var vms []*PatientScheduleTemplateItemViewModel
88 101
 	err := readDb.
89 102
 		Model(&PatientScheduleTemplateItemViewModel{}).
90 103
 		Preload("Patient", "user_org_id = ? AND status = 1", orgID).
91
-		Where("org_id = ? AND template_id = ? AND status = 1", orgID, templateID).
104
+		Where("org_id = ? AND template_id = ? AND status = 1", orgID, 0).
92 105
 		Find(&vms).
93 106
 		Error
94 107
 	if err != nil {
@@ -117,38 +130,63 @@ type ScheduleDeviceNumberViewModel struct {
117 130
 	Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
118 131
 }
119 132
 
120
-func GetScheduleValidDeviceNumbers(orgID int64) ([]*ScheduleDeviceNumberViewModel, error) {
121
-	var vms []*ScheduleDeviceNumberViewModel
122
-	err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1").Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
123
-	if err != nil {
124
-		return nil, err
133
+func GetScheduleValidDeviceNumbers(orgID int64, ids []string) ([]*ScheduleDeviceNumberViewModel, error) {
134
+	if len(ids) == 0 {
135
+		var vms []*ScheduleDeviceNumberViewModel
136
+		err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1").Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
137
+		if err != nil {
138
+			return nil, err
139
+		}
140
+		return vms, nil
141
+
142
+	} else {
143
+		var vms []*ScheduleDeviceNumberViewModel
144
+		err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1 AND id in (?)", ids).Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
145
+		if err != nil {
146
+			return nil, err
147
+		}
148
+		return vms, nil
149
+
125 150
 	}
126
-	return vms, nil
151
+
127 152
 }
128 153
 
129 154
 // 创建两个默认模板
130
-func CreateTwoPatientScheduleTemplates(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
131
-	now := time.Now().Unix()
155
+func CreateTwoPatientScheduleTemplates(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
132 156
 	firstTemp := models.PatientScheduleTemplateId{}
133 157
 	firstTemp.OrgID = orgID
134 158
 	firstTemp.Status = 1
135
-	firstTemp.CreateTime = now
136
-	firstTemp.ModifyTime = now
137 159
 
138 160
 	secondTemp := models.PatientScheduleTemplateId{}
139 161
 	secondTemp.OrgID = orgID
140 162
 	secondTemp.Status = 1
141
-	secondTemp.CreateTime = now
142
-	secondTemp.ModifyTime = now
163
+
164
+	thirdTemp := models.PatientScheduleTemplateId{}
165
+	thirdTemp.OrgID = orgID
166
+	thirdTemp.Status = 1
167
+
168
+	fourTemp := models.PatientScheduleTemplateId{}
169
+	fourTemp.OrgID = orgID
170
+	fourTemp.Status = 1
143 171
 
144 172
 	tx := writeDb.Begin()
145 173
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&firstTemp).Error; err != nil {
146 174
 		tx.Rollback()
147
-		return nil, nil, err
175
+		return nil, nil, nil, nil, err
148 176
 	}
149 177
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&secondTemp).Error; err != nil {
150 178
 		tx.Rollback()
151
-		return nil, nil, err
179
+		return nil, nil, nil, nil, err
180
+	}
181
+
182
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
183
+		tx.Rollback()
184
+		return nil, nil, nil, nil, err
185
+	}
186
+
187
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
188
+		tx.Rollback()
189
+		return nil, nil, nil, nil, err
152 190
 	}
153 191
 
154 192
 	vm1 := PatientScheduleTemplateViewModel{}
@@ -158,32 +196,116 @@ func CreateTwoPatientScheduleTemplates(orgID int64) (*PatientScheduleTemplateVie
158 196
 	vm2 := PatientScheduleTemplateViewModel{}
159 197
 	vm2.ID = secondTemp.ID
160 198
 	vm2.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
199
+
200
+	vm3 := PatientScheduleTemplateViewModel{}
201
+	vm3.ID = thirdTemp.ID
202
+	vm3.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
203
+
204
+	vm4 := PatientScheduleTemplateViewModel{}
205
+	vm4.ID = fourTemp.ID
206
+	vm4.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
207
+
161 208
 	tx.Commit()
162
-	return &vm1, &vm2, nil
209
+	return &vm1, &vm2, &vm3, &vm4, nil
163 210
 }
164 211
 
165
-func CreatePatientScheduleTemplate(orgID int64) (*PatientScheduleTemplateViewModel, error) {
166
-	now := time.Now().Unix()
212
+func CreatePatientScheduleTemplate(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
167 213
 	temp := models.PatientScheduleTemplateId{}
168 214
 	temp.OrgID = orgID
169 215
 	temp.Status = 1
170
-	temp.CreateTime = now
171
-	temp.ModifyTime = now
172 216
 	tx := writeDb.Begin()
173 217
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&temp).Error; err != nil {
174 218
 		tx.Rollback()
175
-		return nil, err
219
+		return nil, nil, nil, err
176 220
 	}
221
+
222
+	thirdTemp := models.PatientScheduleTemplateId{}
223
+	thirdTemp.OrgID = orgID
224
+	thirdTemp.Status = 1
225
+
226
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
227
+		tx.Rollback()
228
+		return nil, nil, nil, err
229
+	}
230
+
231
+	fourTemp := models.PatientScheduleTemplateId{}
232
+	fourTemp.OrgID = orgID
233
+	fourTemp.Status = 1
234
+
235
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
236
+		tx.Rollback()
237
+		return nil, nil, nil, err
238
+	}
239
+
177 240
 	vm := PatientScheduleTemplateViewModel{}
178 241
 	vm.ID = temp.ID
179 242
 	vm.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
243
+
244
+	vm3 := PatientScheduleTemplateViewModel{}
245
+	vm3.ID = thirdTemp.ID
246
+	vm3.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
247
+
248
+	vm4 := PatientScheduleTemplateViewModel{}
249
+	vm4.ID = fourTemp.ID
250
+	vm4.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
251
+
180 252
 	tx.Commit()
181
-	return &vm, nil
253
+	return &vm, &vm3, &vm4, nil
254
+}
255
+func CreatePatientScheduleTemplateTwo(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
256
+
257
+	tx := writeDb.Begin()
258
+
259
+	thirdTemp := models.PatientScheduleTemplateId{}
260
+	thirdTemp.OrgID = orgID
261
+	thirdTemp.Status = 1
262
+
263
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
264
+		tx.Rollback()
265
+		return nil, nil, err
266
+	}
267
+
268
+	fourTemp := models.PatientScheduleTemplateId{}
269
+	fourTemp.OrgID = orgID
270
+	fourTemp.Status = 1
271
+
272
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
273
+		tx.Rollback()
274
+		return nil, nil, err
275
+	}
276
+
277
+	vm3 := PatientScheduleTemplateViewModel{}
278
+	vm3.ID = thirdTemp.ID
279
+	vm3.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
280
+
281
+	vm4 := PatientScheduleTemplateViewModel{}
282
+	vm4.ID = fourTemp.ID
283
+	vm4.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
284
+
285
+	tx.Commit()
286
+	return &vm3, &vm4, nil
287
+}
288
+func CreatePatientScheduleTemplateThree(orgID int64) (*PatientScheduleTemplateViewModel, error) {
289
+	tx := writeDb.Begin()
290
+	fourTemp := models.PatientScheduleTemplateId{}
291
+	fourTemp.OrgID = orgID
292
+	fourTemp.Status = 1
293
+	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
294
+		tx.Rollback()
295
+		return nil, err
296
+	}
297
+	vm4 := PatientScheduleTemplateViewModel{}
298
+	vm4.ID = fourTemp.ID
299
+	vm4.Items = make([]*PatientScheduleTemplateItemViewModel, 0, 0)
300
+
301
+	tx.Commit()
302
+	return &vm4, nil
182 303
 }
183 304
 
184 305
 type PatientScheduleTemplatePatientVM struct {
185
-	ID   int64  `gorm:"column:id" json:"id" form:"id"`
186
-	Name string `gorm:"column:name" json:"name" form:"name"`
306
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
307
+	Name       string `gorm:"column:name" json:"name" form:"name"`
308
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
187 309
 
188 310
 	Contagions []*PatientScheduleContagion `gorm:"ForeignKey:PatientID" json:"contagions"`
189 311
 }
@@ -193,9 +315,10 @@ func (PatientScheduleTemplatePatientVM) TableName() string {
193 315
 }
194 316
 
195 317
 type PatientScheduleContagion struct {
196
-	ID        int64 `gorm:"column:id" json:"id" form:"id"`
197
-	PatientID int64 `gorm:"column:patient_id" json:"-"`
198
-	DiseaseID int64 `gorm:"column:disease_id" json:"disease_id" form:"disease_id"`
318
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
319
+	PatientID  int64  `gorm:"column:patient_id" json:"-"`
320
+	DiseaseID  int64  `gorm:"column:disease_id" json:"disease_id" form:"disease_id"`
321
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
199 322
 }
200 323
 
201 324
 func (PatientScheduleContagion) TableName() string {
@@ -216,7 +339,7 @@ func PatientScheduleTemplateGetAllValidPatient(orgID int64) ([]*PatientScheduleT
216 339
 	return vms, nil
217 340
 }
218 341
 
219
-func UpdateScheduleTemplate(orgID int64, templateID int64,
342
+func UpdateScheduleTemplate(orgID int64, template_id int64,
220 343
 	addTemplateItems []*models.PatientScheduleTemplateItem,
221 344
 	delTemplateItems []*models.PatientScheduleTemplateItem,
222 345
 	changeTemplateItems []*models.PatientScheduleTemplateItem,
@@ -226,15 +349,24 @@ func UpdateScheduleTemplate(orgID int64, templateID int64,
226 349
 	now := time.Now()
227 350
 	tx := writeDb.Begin()
228 351
 
352
+	readDb.Model(&models.XtPatientScheduleTemplateItem{}).Where("template_id = ? AND weekday = ? AND patient_id = ?", template_id)
353
+
229 354
 	// 批量插入 add template item
230 355
 	if len(addTemplateItems) > 0 {
356
+
231 357
 		// utils.TraceLog("addTemplateItems len: %v", len(addTemplateItems))
232 358
 		valueStrs := make([]string, 0, len(addTemplateItems))
233 359
 		values := make([]interface{}, 0, len(addTemplateItems)*10)
234 360
 		for _, item := range addTemplateItems {
361
+			var pst []models.XtPatientScheduleTemplateItem
362
+			readDb.Model(&models.XtPatientScheduleTemplateItem{}).Where("template_id = ? AND weekday = ? AND patient_id = ? AND status = 1", template_id, item.Weekday, item.PatientID).Find(&pst)
363
+			for _, item := range pst {
364
+				item.Status = 0
365
+				writeDb.Save(item)
366
+			}
235 367
 			valueStrs = append(valueStrs, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
236 368
 			values = append(values, orgID)
237
-			values = append(values, templateID)
369
+			values = append(values, template_id)
238 370
 			values = append(values, item.DeviceNumberID)
239 371
 			values = append(values, item.PatientID)
240 372
 			values = append(values, item.TreatMode)
@@ -257,7 +389,7 @@ func UpdateScheduleTemplate(orgID int64, templateID int64,
257 389
 		// utils.TraceLog("delTemplateItems len: %v", len(delTemplateItems))
258 390
 		ins := make([]string, 0, len(delTemplateItems))
259 391
 		for _, item := range delTemplateItems {
260
-			ins = append(ins, fmt.Sprintf("(%v, %v, %v, %v, %v)", orgID, templateID, item.DeviceNumberID, item.Weekday, item.TimeType))
392
+			ins = append(ins, fmt.Sprintf("(%v, %v, %v, %v, %v)", orgID, template_id, item.DeviceNumberID, item.Weekday, item.TimeType))
261 393
 		}
262 394
 
263 395
 		sql := fmt.Sprintf("UPDATE xt_patient_schedule_template_item SET status = 0, mtime = %v WHERE status = 1 AND (org_id, template_id, device_number_id, weekday, time_type) IN (%v);", now.Unix(), strings.Join(ins, ","))
@@ -271,14 +403,14 @@ func UpdateScheduleTemplate(orgID int64, templateID int64,
271 403
 	if len(changeTemplateItems) > 0 {
272 404
 		// utils.TraceLog("changeTemplateItems len: %v", len(changeTemplateItems))
273 405
 		for _, item := range changeTemplateItems {
274
-			if updateErr := tx.Exec("UPDATE xt_patient_schedule_template_item SET patient_id = ?, treat_mode = ?, mtime = ? WHERE status = 1 AND org_id = ? AND template_id = ? AND device_number_id = ? AND weekday = ? AND time_type = ?;", item.PatientID, item.TreatMode, now.Unix(), orgID, templateID, item.DeviceNumberID, item.Weekday, item.TimeType).Error; updateErr != nil {
406
+			if updateErr := tx.Exec("UPDATE xt_patient_schedule_template_item SET patient_id = ?, treat_mode = ?, mtime = ? WHERE status = 1 AND org_id = ? AND template_id = ? AND device_number_id = ? AND weekday = ? AND time_type = ?;", item.PatientID, item.TreatMode, now.Unix(), orgID, template_id, item.DeviceNumberID, item.Weekday, item.TimeType).Error; updateErr != nil {
275 407
 				tx.Rollback()
276 408
 				return updateErr
277 409
 			}
278 410
 		}
279 411
 	}
280 412
 
281
-	// 更改下周的排班
413
+	// 更改下周的排班
282 414
 	deviceNumbers, getDeviceNumbersErr := GetAllValidDeviceNumbers(orgID)
283 415
 	if getDeviceNumbersErr != nil {
284 416
 		tx.Rollback()
@@ -288,6 +420,36 @@ func UpdateScheduleTemplate(orgID int64, templateID int64,
288 420
 	for _, deviceNumber := range deviceNumbers {
289 421
 		devicesMap[deviceNumber.ID] = deviceNumber
290 422
 	}
423
+	//if shouldUpdateNextWeekSchedules {
424
+	//	nextWeek := now.AddDate(0, 0, 7)
425
+	//	if updateErr := _updateWeekSchedules(tx, orgID, nextWeek, addTemplateItems, delTemplateItems, changeTemplateItems, devicesMap); updateErr != nil {
426
+	//		tx.Rollback()
427
+	//		return updateErr
428
+	//	}
429
+	//}
430
+	//if shouldUpdateNextSecondWeekSchedules {
431
+	//	nextWeek := now.AddDate(0, 0, 14)
432
+	//	if updateErr := _updateWeekSchedules(tx, orgID, nextWeek, addTemplateItems, delTemplateItems, changeTemplateItems, devicesMap); updateErr != nil {
433
+	//		tx.Rollback()
434
+	//		return updateErr
435
+	//	}
436
+	//}
437
+	//
438
+	//if shouldUpdateNextThirdWeekSchedules {
439
+	//	nextWeek := now.AddDate(0, 0, 21)
440
+	//	if updateErr := _updateWeekSchedules(tx, orgID, nextWeek, addTemplateItems, delTemplateItems, changeTemplateItems, devicesMap); updateErr != nil {
441
+	//		tx.Rollback()
442
+	//		return updateErr
443
+	//	}
444
+	//}
445
+	//
446
+	//if shouldUpdateNextFourWeekSchedules {
447
+	//	nextWeek := now.AddDate(0, 0, 28)
448
+	//	if updateErr := _updateWeekSchedules(tx, orgID, nextWeek, addTemplateItems, delTemplateItems, changeTemplateItems, devicesMap); updateErr != nil {
449
+	//		tx.Rollback()
450
+	//		return updateErr
451
+	//	}
452
+	//}
291 453
 
292 454
 	if orgID != 9671 && orgID != 10340 {
293 455
 		if shouldUpdateNextWeekSchedules {
@@ -423,7 +585,7 @@ func SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode *m
423 585
 	now := time.Now()
424 586
 	nextWeek := now.AddDate(0, 0, 7)
425 587
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
426
-	nextSecWeek := now.AddDate(0, 0, 14)
588
+	nextSecWeek := now.AddDate(0, 0, 21)
427 589
 	_, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
428 590
 	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
429 591
 	if disableErr != nil {
@@ -435,8 +597,33 @@ func SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode *m
435 597
 	return nil
436 598
 }
437 599
 
438
-// 1 -> 2 清除第二周排班
439
-func SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
600
+// 1 -> 3 清除第二周排班
601
+func SavePatientScheduleTemplateModeAndClearNextThirfWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
602
+	tx := writeDb.Begin()
603
+	saveErr := tx.Save(templateMode).Error
604
+	if saveErr != nil {
605
+		tx.Rollback()
606
+		return saveErr
607
+	}
608
+
609
+	now := time.Now()
610
+	nextSecWeek := now.AddDate(0, 0, 21)
611
+	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
612
+
613
+	//tx.Model(&models.PatientScheduleTemplateId{}).Where("user_org_id = ? AND status = 1", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
614
+
615
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
616
+	if disableErr != nil {
617
+		tx.Rollback()
618
+		return disableErr
619
+	}
620
+
621
+	tx.Commit()
622
+	return nil
623
+}
624
+
625
+// 1 -> 4 清除第二周排班
626
+func SavePatientScheduleTemplateModeAndClearNextFourWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
440 627
 	tx := writeDb.Begin()
441 628
 	saveErr := tx.Save(templateMode).Error
442 629
 	if saveErr != nil {
@@ -447,7 +634,10 @@ func SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode
447 634
 	now := time.Now()
448 635
 	nextSecWeek := now.AddDate(0, 0, 14)
449 636
 	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
450
-	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
637
+
638
+	//tx.Model(&models.PatientScheduleTemplateId{}).Where("user_org_id = ? AND status = 1", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
639
+
640
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
451 641
 	if disableErr != nil {
452 642
 		tx.Rollback()
453 643
 		return disableErr
@@ -457,6 +647,11 @@ func SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode
457 647
 	return nil
458 648
 }
459 649
 
650
+func SaveTemplateMode(templateMode *models.PatientScheduleTemplateMode) error {
651
+	err := writeDb.Model(&models.PatientScheduleTemplateMode{}).Where("id = ? AND status = 1", templateMode.ID).Updates(map[string]interface{}{"mode": templateMode.Mode, "mtime": templateMode.ModifyTime}).Error
652
+	return err
653
+}
654
+
460 655
 // 2 -> 1 清除第二周模板item,清除第二周排班,将第一周的排班重复到第二周
461 656
 func SavePatientScheduleTemplateMode2To1(templateMode *models.PatientScheduleTemplateMode, secondWeekTemplateID int64, firstWeekTemplateItems []*models.PatientScheduleTemplateItem) error {
462 657
 	tx := writeDb.Begin()
@@ -476,7 +671,7 @@ func SavePatientScheduleTemplateMode2To1(templateMode *models.PatientScheduleTem
476 671
 
477 672
 	nextSecWeek := now.AddDate(0, 0, 14)
478 673
 	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
479
-	disableSchsErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
674
+	disableSchsErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
480 675
 	if disableSchsErr != nil {
481 676
 		tx.Rollback()
482 677
 		return disableSchsErr
@@ -524,3 +719,209 @@ func SavePatientScheduleTemplateMode2To1(templateMode *models.PatientScheduleTem
524 719
 	tx.Commit()
525 720
 	return nil
526 721
 }
722
+
723
+// 3 -> 1 清除第三,二周模板item,清除第三,二周排班
724
+func SavePatientScheduleTemplateMode3To1(templateMode *models.PatientScheduleTemplateMode, secondWeekTemplateID int64, thirdWeekTemplateID int64) error {
725
+	tx := writeDb.Begin()
726
+	saveErr := tx.Save(templateMode).Error
727
+	if saveErr != nil {
728
+		tx.Rollback()
729
+		return saveErr
730
+	}
731
+
732
+	now := time.Now()
733
+
734
+	disableItemsErr := tx.Model(&models.PatientScheduleTemplateItem{}).Where("(template_id = ? AND status = 1) OR (template_id = ? AND status = 1) ", secondWeekTemplateID, thirdWeekTemplateID).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
735
+	if disableItemsErr != nil {
736
+		tx.Rollback()
737
+		return disableItemsErr
738
+	}
739
+
740
+	nextSecWeek := now.AddDate(0, 0, 14)
741
+	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
742
+	disableSchsErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
743
+	if disableSchsErr != nil {
744
+		tx.Rollback()
745
+		return disableSchsErr
746
+	}
747
+
748
+	nextThirdWeek := now.AddDate(0, 0, 21)
749
+	nextThirdMonday, nextThirdSunday := utils.GetMondayAndSundayOfWeekDate(&nextThirdWeek)
750
+	disableSchsErr2 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextThirdMonday.Unix(), nextThirdSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
751
+	if disableSchsErr2 != nil {
752
+		tx.Rollback()
753
+		return disableSchsErr2
754
+	}
755
+
756
+	tx.Commit()
757
+	return nil
758
+}
759
+
760
+// 3 -> 2 清除第三周模板item,清除第三周排班
761
+func SavePatientScheduleTemplateMode3To2(templateMode *models.PatientScheduleTemplateMode, thirdWeekTemplateID int64) error {
762
+	tx := writeDb.Begin()
763
+	saveErr := tx.Save(templateMode).Error
764
+	if saveErr != nil {
765
+		tx.Rollback()
766
+		return saveErr
767
+	}
768
+
769
+	now := time.Now()
770
+
771
+	disableItemsErr := tx.Model(&models.PatientScheduleTemplateItem{}).Where("template_id = ? AND status = 1", thirdWeekTemplateID).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
772
+	if disableItemsErr != nil {
773
+		tx.Rollback()
774
+		return disableItemsErr
775
+	}
776
+	nextThirdWeek := now.AddDate(0, 0, 21)
777
+	nextThirdMonday, nextThirdSunday := utils.GetMondayAndSundayOfWeekDate(&nextThirdWeek)
778
+	disableSchsErr2 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextThirdMonday.Unix(), nextThirdSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
779
+	if disableSchsErr2 != nil {
780
+		tx.Rollback()
781
+		return disableSchsErr2
782
+	}
783
+
784
+	tx.Commit()
785
+	return nil
786
+}
787
+
788
+// 4 -> 1 清除第四,三,二周模板item,清除第四,三,二周排班
789
+func SavePatientScheduleTemplateMode4To1(templateMode *models.PatientScheduleTemplateMode, secondWeekTemplateID int64, thirdWeekTemplateID int64, fourWeekTemplateID int64) error {
790
+	tx := writeDb.Begin()
791
+	saveErr := tx.Save(templateMode).Error
792
+	if saveErr != nil {
793
+		tx.Rollback()
794
+		return saveErr
795
+	}
796
+
797
+	now := time.Now()
798
+
799
+	disableItemsErr := tx.Model(&models.PatientScheduleTemplateItem{}).Where("(template_id = ? AND status = 1)OR(template_id = ? AND status = 1)OR(template_id = ? AND status = 1)", secondWeekTemplateID, thirdWeekTemplateID, fourWeekTemplateID).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
800
+	if disableItemsErr != nil {
801
+		tx.Rollback()
802
+		return disableItemsErr
803
+	}
804
+
805
+	nextSecWeek := now.AddDate(0, 0, 14)
806
+	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
807
+	disableSchsErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
808
+	if disableSchsErr != nil {
809
+		tx.Rollback()
810
+		return disableSchsErr
811
+	}
812
+
813
+	nextThirdWeek := now.AddDate(0, 0, 21)
814
+	nextThirdMonday, nextThirdSunday := utils.GetMondayAndSundayOfWeekDate(&nextThirdWeek)
815
+	disableSchsErr2 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextThirdMonday.Unix(), nextThirdSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
816
+	if disableSchsErr2 != nil {
817
+		tx.Rollback()
818
+		return disableSchsErr2
819
+	}
820
+
821
+	nextFourWeek := now.AddDate(0, 0, 28)
822
+	nextFourMonday, nextFourSunday := utils.GetMondayAndSundayOfWeekDate(&nextFourWeek)
823
+	disableSchsErr3 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextFourMonday.Unix(), nextFourSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
824
+	if disableSchsErr3 != nil {
825
+		tx.Rollback()
826
+		return disableSchsErr3
827
+	}
828
+
829
+	tx.Commit()
830
+	return nil
831
+}
832
+
833
+// 4 -> 2 清除第四,三模板item,清除第四,三排班
834
+func SavePatientScheduleTemplateMode4To2(templateMode *models.PatientScheduleTemplateMode, thirdWeekTemplateID int64, fourWeekTemplateID int64) error {
835
+	tx := writeDb.Begin()
836
+	saveErr := tx.Save(templateMode).Error
837
+	if saveErr != nil {
838
+		tx.Rollback()
839
+		return saveErr
840
+	}
841
+
842
+	now := time.Now()
843
+
844
+	disableItemsErr := tx.Model(&models.PatientScheduleTemplateItem{}).Where("(template_id = ? AND status = 1)OR(template_id = ? AND status = 1)", thirdWeekTemplateID, fourWeekTemplateID).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
845
+	if disableItemsErr != nil {
846
+		tx.Rollback()
847
+		return disableItemsErr
848
+	}
849
+
850
+	nextThirdWeek := now.AddDate(0, 0, 21)
851
+	nextThirdMonday, nextThirdSunday := utils.GetMondayAndSundayOfWeekDate(&nextThirdWeek)
852
+	disableSchsErr2 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextThirdMonday.Unix(), nextThirdSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
853
+	if disableSchsErr2 != nil {
854
+		tx.Rollback()
855
+		return disableSchsErr2
856
+	}
857
+
858
+	nextFourWeek := now.AddDate(0, 0, 28)
859
+	nextFourMonday, nextFourSunday := utils.GetMondayAndSundayOfWeekDate(&nextFourWeek)
860
+	disableSchsErr3 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextFourMonday.Unix(), nextFourSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
861
+	if disableSchsErr3 != nil {
862
+		tx.Rollback()
863
+		return disableSchsErr3
864
+	}
865
+
866
+	tx.Commit()
867
+	return nil
868
+}
869
+
870
+// 4 -> 3 清除第四模板item,清除第四周排班
871
+func SavePatientScheduleTemplateMode4To3(templateMode *models.PatientScheduleTemplateMode, fourWeekTemplateID int64) error {
872
+	tx := writeDb.Begin()
873
+	saveErr := tx.Save(templateMode).Error
874
+	if saveErr != nil {
875
+		tx.Rollback()
876
+		return saveErr
877
+	}
878
+
879
+	now := time.Now()
880
+
881
+	disableItemsErr := tx.Model(&models.PatientScheduleTemplateItem{}).Where("(template_id = ? AND status = 1)", fourWeekTemplateID).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
882
+	if disableItemsErr != nil {
883
+		tx.Rollback()
884
+		return disableItemsErr
885
+	}
886
+
887
+	nextFourWeek := now.AddDate(0, 0, 28)
888
+	nextFourMonday, nextFourSunday := utils.GetMondayAndSundayOfWeekDate(&nextFourWeek)
889
+	disableSchsErr3 := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextFourMonday.Unix(), nextFourSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
890
+	if disableSchsErr3 != nil {
891
+		tx.Rollback()
892
+		return disableSchsErr3
893
+	}
894
+
895
+	tx.Commit()
896
+	return nil
897
+}
898
+
899
+type SchTemplatePatient struct {
900
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
901
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
902
+	Name       string `gorm:"column:name" json:"name" form:"name"`
903
+	Lapseto    int64  `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
904
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
905
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
906
+}
907
+
908
+func (SchTemplatePatient) TableName() string {
909
+	return "xt_patients"
910
+}
911
+
912
+func GetSchTemplatePatientList(orgID int64) ([]*SchTemplatePatient, error) {
913
+	var patients []*SchTemplatePatient
914
+	err := readDb.Model(&SchTemplatePatient{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", orgID).Find(&patients).Error
915
+	return patients, err
916
+}
917
+
918
+func UpdateTemplateItemWeek(orgID int64, id int64, week_time int8) {
919
+	readDb.Model(&models.PatientScheduleTemplateId{}).Where("org_id = ? AND status = 1 AND id = ? ", orgID, id).Updates(map[string]interface{}{"week": week_time})
920
+	return
921
+}
922
+
923
+func GetOrgPatientScheduleTemplateModeTwo(orgID int64) (models.PatientScheduleTemplateMode, error) {
924
+	var mode models.PatientScheduleTemplateMode
925
+	err := readDb.Model(&models.PatientScheduleTemplateMode{}).Where("org_id = ? AND status = 1", orgID).First(&mode).Error
926
+	return mode, err
927
+}

+ 17 - 1
service/patient_service.go View File

@@ -1924,7 +1924,7 @@ func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string,
1924 1924
 }
1925 1925
 
1926 1926
 func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
1927
-	err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date>?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
1927
+	err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date > ?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
1928 1928
 	return err
1929 1929
 }
1930 1930
 
@@ -2722,3 +2722,19 @@ func UpdateDialysisBefor(dislysis models.XtAssessmentBeforeDislysis, id int64) e
2722 2722
 	err := XTWriteDB().Model(&models.XtAssessmentBeforeDislysis{}).Where("id = ? and status= 1", id).Update(map[string]interface{}{"systolic_blood_pressure": dislysis.SystolicBloodPressure, "diastolic_blood_pressure": dislysis.DiastolicBloodPressure}).Error
2723 2723
 	return err
2724 2724
 }
2725
+
2726
+func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64) ([]Schedule, error) {
2727
+	var record []Schedule
2728
+	loc, _ := time.LoadLocation("Local")
2729
+	date, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
2730
+
2731
+	err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date >= ? AND patient_id = ? AND user_org_id = ? AND mode_id= ?", date, patient_id, org_id, mode_id).Find(&record).Error
2732
+	if err != nil {
2733
+		if err == gorm.ErrRecordNotFound {
2734
+			return nil, nil
2735
+		} else {
2736
+			return nil, err
2737
+		}
2738
+	}
2739
+	return record, nil
2740
+}

+ 47 - 10
service/schedule_service.go View File

@@ -18,14 +18,14 @@ func GetSchedulePartitionPanel(orgID int64) (partitions []*models.Partition, err
18 18
 	return
19 19
 }
20 20
 
21
-func GetSchedulePartitionPanelOne(orgID int64, partionId int64) (partitions []*models.Partition, err error) {
21
+func GetSchedulePartitionPanelOne(orgID int64, partionId []string) (partitions []*models.Partition, err error) {
22 22
 
23
-	if partionId > 0 {
24
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id = ?", orgID, partionId).Where("org_id=? and status=1 and id = ?", orgID, partionId).Find(&partitions).Error
25
-	}
26
-	if partionId == 0 {
27
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
28
-	}
23
+	//if len(partionId) > 0 {
24
+	//	err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id in (?)", orgID, partionId).Where("org_id=? and status=1 and id  ?", orgID, partionId).Find(&partitions).Error
25
+	//}
26
+	//if len(partionId) == 0 {
27
+	err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
28
+	//}
29 29
 
30 30
 	return
31 31
 }
@@ -85,7 +85,7 @@ func GetWeekSchedule(orgID int64, start, end int64) (schedules []*models.Schedul
85 85
 	err = readDb.Table("xt_schedule as s").Preload("PatientInfectiousDiseases", "status = 1 ").
86 86
 		Joins("JOIN xt_patients as p ON p.id = s.patient_id").
87 87
 		Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
88
-		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").
88
+		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,s.dialysis_machine_name, p.name as patient").
89 89
 		Order("updated_time asc").
90 90
 		Find(&schedules).Error
91 91
 	return
@@ -103,7 +103,7 @@ func GetWeekScheduleOne(orgID int64, start, end int64, partionid int64, schedule
103 103
 	err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
104 104
 		Joins("JOIN xt_patients as p ON p.id = s.patient_id").
105 105
 		Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
106
-		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").
106
+		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.dialysis_machine_name, s.updated_time, p.name as patient").
107 107
 		Order("updated_time asc").
108 108
 		Find(&schedules).Error
109 109
 	return
@@ -122,7 +122,7 @@ func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, schedule
122 122
 	err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
123 123
 		Joins("JOIN xt_patients as p ON p.id = s.patient_id").
124 124
 		Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
125
-		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").
125
+		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,s.dialysis_machine_name, p.name as patient").
126 126
 		Order("updated_time asc").
127 127
 		Find(&schedules).Error
128 128
 	return
@@ -142,7 +142,11 @@ func GetDayScheduleByBedid(orgID, start, bed_id int64, schedule_type int64) (sch
142 142
 	err = readDb.Model(&models.Schedule{}).Where("user_org_id=?  and schedule_date=? and bed_id=? and status=1 AND schedule_type = ?", orgID, start, bed_id, schedule_type).Preload("DialysisOrder", "status = 1").First(&schedule).Error
143 143
 	return
144 144
 }
145
+func GetSourceSch(orgId int64, patient_id int64, record_date int64) (schedule models.Schedule, err error) {
146
+	err = readDb.Model(&models.Schedule{}).Where("user_org_id=?  and schedule_date=? and patient_id =? and status=1", orgId, record_date, patient_id).First(&schedule).Error
147
+	return
145 148
 
149
+}
146 150
 func GetPatientScheduleFormDay(orgID, start, end, patientID int64) (schedules []*models.PatientSchedule, err error) {
147 151
 
148 152
 	err = readDb.Table("xt_schedule as s").
@@ -293,6 +297,20 @@ func UpdateScheduleOne(id int64, schedule models.Schedule) error {
293 297
 	return err
294 298
 }
295 299
 
300
+//参数一:当前操作的患者的排班     参数二被替换床位对应的排班
301
+func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) {
302
+	utx := XTWriteDB()
303
+	var tempPatientID int64
304
+	var tempPatientIDTwo int64
305
+	tempPatientID = schone.PatientId
306
+	tempPatientIDTwo = schtwo.PatientId
307
+	schone.PatientId = tempPatientIDTwo
308
+	schtwo.PatientId = tempPatientID
309
+	utx.Save(&schone)
310
+	utx.Save(&schtwo)
311
+
312
+}
313
+
296 314
 func GetPatientScheduleFormToday(orgId, id, start int64) (schedules []*models.PatientSchedule, err error) {
297 315
 
298 316
 	err = readDb.Table("xt_schedule as s").
@@ -1200,6 +1218,25 @@ func GetLastWeightAfter(patient_id int64, scheduleDate int64, orgid int64) (mode
1200 1218
 	return dislysis, err
1201 1219
 }
1202 1220
 
1221
+func GetScheduleTwo(orgID, id int64) (models.Schedule, error) {
1222
+	var schedule models.Schedule
1223
+	var err error
1224
+	err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
1225
+	return schedule, err
1226
+}
1227
+
1228
+func UpdateSchDName(sch models.Schedule) (err error) {
1229
+	err = writeDb.Model(&models.Schedule{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"dialysis_machine_name": sch.DialysisMachineName}).Error
1230
+	return
1231
+}
1232
+
1233
+func GetDialysisOrderByBedIdTwo(orgID, start, bed_id int64, schedule_type int64) (models.DialysisOrder, error) {
1234
+	order := models.DialysisOrder{}
1235
+	err = readDb.Model(&order).Where("user_org_id=?  and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).Find(&order).Error
1236
+	return order, nil
1237
+
1238
+}
1239
+
1203 1240
 func ChangeScheduleClass(schedule models.Schedule) error {
1204 1241
 
1205 1242
 	err := XTWriteDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status = 1", schedule.PatientId, schedule.ScheduleDate, schedule.UserOrgId).Update(map[string]interface{}{"schedule_type": schedule.ScheduleType}).Error

+ 120 - 0
service/smart_sch.go View File

@@ -0,0 +1,120 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
6
+	"time"
7
+)
8
+
9
+func GetSmartSchPatientByKeyWord(orgID int64, keywords string) (patient []*models.SmartSchPatient, err error) {
10
+	db := readDb.Model(&models.SmartSchPatient{}).Where("user_org_id=? and status=1", orgID)
11
+	if len(keywords) > 0 {
12
+		likekey := "%" + keywords + "%"
13
+		err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
14
+	} else {
15
+		err = db.Find(&patient).Error
16
+	}
17
+
18
+	for _, item := range patient {
19
+		var sch []*models.SmartSchedule
20
+		now := time.Now()
21
+
22
+		offset := int(time.Monday - now.Weekday())
23
+		if offset > 0 {
24
+			offset = -6
25
+		}
26
+
27
+		weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
28
+		readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
29
+			Preload("DeviceZone", "status = 1").
30
+			Preload("SmSchDialysisOrder", "status = 1").
31
+			Preload("DeviceNumber", "status = 1").Find(&sch)
32
+		item.SmartSchedule = sch
33
+	}
34
+
35
+	return
36
+}
37
+
38
+func GetSmartSchTemplatePatientByKeyWord(orgID int64, keywords string) (patient []*models.SmartSchTemplatePatient, err error) {
39
+	db := readDb.Model(&models.SmartSchTemplatePatient{}).Where("user_org_id=? and status=1", orgID)
40
+	if len(keywords) > 0 {
41
+		likekey := "%" + keywords + "%"
42
+		err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
43
+	} else {
44
+		err = db.Find(&patient).Error
45
+	}
46
+
47
+	for _, item := range patient {
48
+		mode, _ := GetOrgPatientScheduleTemplateModeTwo(item.UserOrgId)
49
+		if mode.ID > 0 {
50
+			if mode.Mode == 1 {
51
+				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 1)
52
+				item.XtPatientScheduleTemplateId = schs
53
+
54
+			} else if mode.Mode == 2 {
55
+				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 2)
56
+
57
+				item.XtPatientScheduleTemplateId = schs
58
+
59
+			} else if mode.Mode == 3 {
60
+				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 3)
61
+				item.XtPatientScheduleTemplateId = schs
62
+
63
+			} else if mode.Mode == 4 {
64
+
65
+				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 4)
66
+				item.XtPatientScheduleTemplateId = schs
67
+
68
+			}
69
+		}
70
+
71
+	}
72
+	return
73
+}
74
+
75
+func GetSmartSchPatientByID(orgID int64, patient_id int64) (schs []*models.SmartSchedule, err error) {
76
+	now := time.Now()
77
+	offset := int(time.Monday - now.Weekday())
78
+	if offset > 0 {
79
+		offset = -6
80
+	}
81
+	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
82
+	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
83
+		Preload("DeviceZone", "status = 1").
84
+		Preload("SmSchDialysisOrder", "status = 1").
85
+		Preload("DeviceNumber", "status = 1").Find(&schs).Error
86
+	return
87
+}
88
+
89
+func GetSmartSchTemplatePatientByID(orgID int64, patient_id int64, count int) (schs []*models.XtPatientScheduleTemplateId, err error) {
90
+	err = readDb.Model(&models.XtPatientScheduleTemplateId{}).Preload("XtPatientScheduleTemplateItem", func(db *gorm.DB) *gorm.DB {
91
+		return db.Where("status = 1 AND patient_id = ?", patient_id).Order("weekday")
92
+	}).Where("org_id = ? AND status = 1", orgID).Limit(count).Find(&schs).Error
93
+	for _, items := range schs {
94
+		for _, subItems := range items.XtPatientScheduleTemplateItem {
95
+			number, _ := GetBedNumberById(subItems.DeviceNumberId, subItems.OrgId)
96
+			subItems.ZoneId = number.ZoneID
97
+		}
98
+	}
99
+	return
100
+}
101
+
102
+func GetAllAvaildDeviceNumbersByZone(orgID int64, record_date int64, schedule_type int, zone_id int64, patient_id int64) ([]*DeviceNumberViewModel, error) {
103
+	var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
104
+	rows, err := readDb.Raw("SELECT n.*, z.name as zone_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id AND z.id = ?   WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.patient_id <> ?  AND  s.user_org_id = n.org_id AND s.`bed_id` = n.id  AND s.`schedule_type` = ? AND s.status = 1 )", zone_id, orgID, record_date, patient_id, schedule_type).Rows()
105
+	defer rows.Close()
106
+	if err != nil {
107
+		return nil, err
108
+	}
109
+	for rows.Next() {
110
+		var vm DeviceNumberViewModel
111
+		readDb.ScanRows(rows, &vm)
112
+		vms = append(vms, &vm)
113
+	}
114
+	return vms, nil
115
+}
116
+
117
+func GetScheduleByZoneAndBed(org_id int64, partitionId int64, bed_id int64, schedule_date int64, sch_type int64) (sch models.SmartSchedule, err error) {
118
+	err = readDb.Model(&models.SmartSchedule{}).Where("bed_id = ? AND user_org_id = ? AND schedule_date = ? AND partition_id = ? AND schedule_type = ?  AND status = 1", bed_id, org_id, schedule_date, partitionId, sch_type).First(&sch).Error
119
+	return
120
+}

+ 1 - 0
utils/tools.go View File

@@ -226,6 +226,7 @@ func GetMondayAndSundayOfWeekDate(date *time.Time) (time.Time, time.Time) {
226 226
 	}
227 227
 	loc, _ := time.LoadLocation("Local")
228 228
 	monday, _ := time.ParseInLocation("2006-01-02 15:04:05", date.AddDate(0, 0, 1-weekday).Format("2006-01-02")+" 00:00:00", loc)
229
+
229 230
 	sunday, _ := time.ParseInLocation("2006-01-02 15:04:05", date.AddDate(0, 0, 7-weekday).Format("2006-01-02")+" 23:59:59", loc)
230 231
 	return monday, sunday
231 232
 }