Kaynağa Gözat

Merge remote-tracking branch 'origin/20230223_xt_api_new_branch' into 20230223_xt_api_new_branch

28169 2 yıl önce
ebeveyn
işleme
0d5d75596c
29 değiştirilmiş dosya ile 2105 ekleme ve 298 silme
  1. 10 6
      controllers/dialysis_api_controller.go
  2. 38 0
      controllers/gobal_config_api_controller.go
  3. 195 2
      controllers/his_api_controller.go
  4. 7 2
      controllers/mobile_api_controllers/check_weight_api_controller.go
  5. 29 25
      controllers/mobile_api_controllers/dialysis_api_controller.go
  6. 1 1
      controllers/mobile_api_controllers/dialysis_api_controller_extend.go
  7. 13 3
      controllers/mobile_api_controllers/patient_api_controller.go
  8. 14 0
      controllers/new_mobile_api_controllers/mobile_his_api_controller.go
  9. 2 0
      controllers/new_mobile_api_controllers/new_mobile_api_router_register.go
  10. 73 43
      controllers/new_mobile_api_controllers/staff_schedule_api_controller.go
  11. 15 0
      controllers/patient_api_controller.go
  12. 152 55
      controllers/pharmacy_controller.go
  13. 5 2
      controllers/print_data_api_controller.go
  14. 63 53
      controllers/schedule_api_controller.go
  15. 1158 7
      controllers/schedule_template_api_controller.go
  16. 2 0
      enums/error_code.go
  17. 1 0
      models/patient_models.go
  18. 11 0
      models/pharmacy_models.go
  19. 1 1
      routers/router.go
  20. 11 2
      service/device_service.go
  21. 6 0
      service/dialysis_service.go
  22. 3 3
      service/dialysis_solution_service.go
  23. 1 1
      service/his_print_service.go
  24. 12 0
      service/his_service.go
  25. 49 11
      service/patient_schedule_template_service.go
  26. 125 54
      service/pharmacy_service.go
  27. 1 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go
  28. 8 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go
  29. 99 27
      service/schedule_service.go

+ 10 - 6
controllers/dialysis_api_controller.go Dosyayı Görüntüle

@@ -582,7 +582,7 @@ func (c *DialysisApiController) PostPrescription() {
582 582
 			if filedConfig.ID > 0 {
583 583
 				str = dialyzerPerfusionApparatus
584 584
 			} else {
585
-				str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
585
+				str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
586 586
 			}
587 587
 			service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
588 588
 		}
@@ -858,7 +858,8 @@ func (c *DialysisApiController) PostSoulution() {
858 858
 		if filedConfig.ID > 0 {
859 859
 			str = dialyzerPerfusionApparatus
860 860
 		} else {
861
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
861
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
862
+
862 863
 		}
863 864
 		service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
864 865
 	}
@@ -4391,7 +4392,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
4391 4392
 			}
4392 4393
 
4393 4394
 			//长沙南雅
4394
-			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 {
4395
+			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4395 4396
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4396 4397
 
4397 4398
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -4420,7 +4421,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
4420 4421
 	}
4421 4422
 
4422 4423
 	//长沙南雅
4423
-	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 {
4424
+	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4424 4425
 
4425 4426
 		if ultrafiltration_rate > 0 {
4426 4427
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
@@ -6033,14 +6034,17 @@ func (this *DialysisApiController) GetDialysisAdviceToday() {
6033 6034
 
6034 6035
 	schedule_type, _ := this.GetInt64("schedule_type")
6035 6036
 
6036
-	partion_type, _ := this.GetInt64("partion_type")
6037
+	//partion_type, _ := this.GetInt64("partion_type")
6037 6038
 
6039
+	partion_type := this.GetString("partion_type")
6040
+	var ids []string
6041
+	ids = strings.Split(partion_type, ",")
6038 6042
 	start_time := this.GetString("selected_date")
6039 6043
 	timeLayout := "2006-01-02"
6040 6044
 	loc, _ := time.LoadLocation("Local")
6041 6045
 	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6042 6046
 
6043
-	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, partion_type, startTime.Unix())
6047
+	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
6044 6048
 
6045 6049
 	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
6046 6050
 	_, config := service.FindXTHisRecordByOrgId(orgId)

+ 38 - 0
controllers/gobal_config_api_controller.go Dosyayı Görüntüle

@@ -121,10 +121,48 @@ func GobalConfigRegistRouters() {
121 121
 	beego.Router("/api/changesettleopenconfig", &GobalConfigApiController{}, "Get:ChangeSettleOpenConfig")
122 122
 
123 123
 	beego.Router("/api/changegoodoutopen", &GobalConfigApiController{}, "Get:ChangeGoodOutOpen")
124
+
125
+	beego.Router("/api/schedule/config/commit", &GobalConfigApiController{}, "post:PostScheduleConfig")
126
+	beego.Router("/api/schedule/config/get", &GobalConfigApiController{}, "get:GetScheduleConfig")
124 127
 }
125 128
 
126 129
 //provinces, _ := service.GetDistrictsByUpid(0)21
127 130
 
131
+func (c *GobalConfigApiController) PostScheduleConfig() {
132
+	is_show_mode, _ := c.GetInt64("is_show_mode", 0)
133
+	is_show_machine, _ := c.GetInt64("is_show_machine", 0)
134
+	id, _ := c.GetInt64("id", 0)
135
+
136
+	config, _ := service.GetScheduleConfigById(id)
137
+	var err error
138
+	if config.ID == 0 {
139
+		config.IsShowMode = is_show_mode
140
+		config.IsShowMachine = is_show_machine
141
+		config.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
142
+		config.Ctime = time.Now().Unix()
143
+		config.Mtime = time.Now().Unix()
144
+		config.Status = 1
145
+		err = service.CreateScheduleConfig(config)
146
+	} else {
147
+		config.IsShowMachine = is_show_machine
148
+		config.IsShowMode = is_show_mode
149
+		config.Mtime = time.Now().Unix()
150
+		err = service.SaveScheduleConfig(config)
151
+	}
152
+	if err == nil {
153
+		c.ServeSuccessJSON(map[string]interface{}{
154
+			"config": config,
155
+		})
156
+	}
157
+}
158
+
159
+func (c *GobalConfigApiController) GetScheduleConfig() {
160
+	config, _ := service.GetScheduleConfigByOrgId(c.GetAdminUserInfo().CurrentOrgId)
161
+	c.ServeSuccessJSON(map[string]interface{}{
162
+		"config": config,
163
+	})
164
+}
165
+
128 166
 func (c *GobalConfigApiController) PostStockConfig() {
129 167
 	is_open, _ := c.GetInt64("is_open", 0)
130 168
 	adminUserInfo := c.GetAdminUserInfo()

+ 195 - 2
controllers/his_api_controller.go Dosyayı Görüntüle

@@ -1054,8 +1054,201 @@ func (c *HisApiController) CreateHisPrescription() {
1054 1054
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
1055 1055
 		return
1056 1056
 	}
1057
-	//已发药和已收费限制逻辑
1058 1057
 
1058
+	pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
1059
+
1060
+	fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
1061
+	//药品发药出库
1062
+	if pharmacyConfig.IsOpen == 1 {
1063
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1064
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1065
+			if len(prescriptions) > 0 {
1066
+				for _, item := range prescriptions {
1067
+					items := item.(map[string]interface{})
1068
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
1069
+						advices := items["advices"].([]interface{})
1070
+						if len(advices) > 0 {
1071
+							for _, advice := range advices {
1072
+								var drug_id int64
1073
+								var prescribing_number float64
1074
+								var prescribingNumberUnit string
1075
+
1076
+								var adviceId int64
1077
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1078
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1079
+								}
1080
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1081
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1082
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1083
+								}
1084
+
1085
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1086
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1087
+								}
1088
+
1089
+								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1090
+									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1091
+								}
1092
+
1093
+								drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1094
+								if drug.ID == 0 {
1095
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1096
+									return
1097
+								}
1098
+
1099
+								//查询药品的所有库存
1100
+								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1101
+
1102
+								var total_count int64
1103
+								for _, it := range list {
1104
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1105
+								}
1106
+								totals := strconv.FormatInt(total_count, 10)
1107
+								//查询该药品是否存在开药记录
1108
+								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1109
+
1110
+								//新增处方
1111
+								if advicelist.ID == 0 {
1112
+									all_count, _ := strconv.ParseFloat(totals, 64)
1113
+									if prescribingNumberUnit == drug.MinUnit {
1114
+
1115
+										if drug.IsUse != 1 {
1116
+											if prescribing_number > all_count {
1117
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1118
+												return
1119
+											}
1120
+
1121
+										}
1122
+
1123
+									}
1124
+									if prescribingNumberUnit == drug.MaxUnit {
1125
+										num := prescribing_number * float64(drug.MinNumber)
1126
+										if drug.IsUse != 1 {
1127
+											if num > all_count {
1128
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1129
+												return
1130
+											}
1131
+										}
1132
+									}
1133
+								}
1134
+
1135
+								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1136
+								if drugOutConfig.IsOpen != 1 {
1137
+									//修改处方
1138
+									for _, advice := range advices {
1139
+										var drug_id int64
1140
+										var prescribing_number float64
1141
+										var prescribingNumberUnit string
1142
+										var prescribingNumber string
1143
+
1144
+										var adviceId int64
1145
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1146
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1147
+										}
1148
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1149
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1150
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1151
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1152
+										}
1153
+
1154
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1155
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1156
+										}
1157
+
1158
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1159
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1160
+										}
1161
+
1162
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1163
+										if drug.ID == 0 {
1164
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1165
+											return
1166
+										}
1167
+										//查询药品的所有库存
1168
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1169
+										var total_count int64
1170
+										for _, it := range list {
1171
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1172
+										}
1173
+										totals := strconv.FormatInt(total_count, 10)
1174
+										//查询该药品是否存在开药记录
1175
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1176
+
1177
+										//新增处方
1178
+										if advicelist.ID == 0 {
1179
+
1180
+											all_count, _ := strconv.ParseFloat(totals, 64)
1181
+											if prescribingNumberUnit == drug.MinUnit {
1182
+												if drug.IsUse != 1 {
1183
+													if prescribing_number > all_count {
1184
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1185
+														return
1186
+													}
1187
+
1188
+												}
1189
+
1190
+											} else {
1191
+												if prescribingNumberUnit == drug.MaxUnit {
1192
+													num := prescribing_number * float64(drug.MinNumber)
1193
+													if drug.IsUse != 1 {
1194
+														if num > all_count {
1195
+															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1196
+															return
1197
+														}
1198
+
1199
+													}
1200
+
1201
+												}
1202
+											}
1203
+										}
1204
+										//修改处方
1205
+										if advicelist.ID > 0 {
1206
+
1207
+											var device_number int64
1208
+
1209
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1210
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1211
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1212
+												device_number = prescribingNumberInt * drug.MinNumber
1213
+											}
1214
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1215
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1216
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1217
+												device_number = prescribingNumberInt
1218
+											}
1219
+
1220
+											var number_count int64
1221
+											if prescribingNumberUnit == drug.MaxUnit {
1222
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1223
+												number_count = prescribingNumberInt * drug.MinNumber
1224
+											}
1225
+											if prescribingNumberUnit == drug.MinUnit {
1226
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1227
+												number_count = prescribingNumberInt
1228
+											}
1229
+
1230
+											//如果修改的数量大于之前修改的数量
1231
+											if (number_count - device_number) > 0 {
1232
+												//如果修改的差数量 大于库存数量
1233
+												if drug.IsUse != 1 {
1234
+													if (number_count - device_number) > total_count {
1235
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1236
+														return
1237
+													}
1238
+												}
1239
+											}
1240
+										}
1241
+									}
1242
+								}
1243
+							}
1244
+						}
1245
+					}
1246
+				}
1247
+			}
1248
+		}
1249
+	}
1250
+
1251
+	//已发药和已收费限制逻辑
1059 1252
 	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1060 1253
 		//校验库存总量
1061 1254
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -2388,7 +2581,7 @@ func (c *HisApiController) CreateHisPrescription() {
2388 2581
 						//如果历史数和当前数据不想等才进行退库出库
2389 2582
 						if out_count != parseIntCount {
2390 2583
 							service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2391
-							fmt.Println("9999999----------------------------------------")
2584
+
2392 2585
 							service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
2393 2586
 							detail := models.AutomaticReduceDetail{
2394 2587
 								WarehouseOutId:          0,

+ 7 - 2
controllers/mobile_api_controllers/check_weight_api_controller.go Dosyayı Görüntüle

@@ -269,7 +269,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
269 269
 
270 270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
271 271
 
272
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
272
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
273 273
 		if adminUserInfo.Org.Id != 10447 {
274 274
 			dewater_amount = dewater_amount * 1000
275 275
 		}
@@ -378,6 +378,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
378 378
 			newprescribe.RecordDate = theAssessmentDateTime
379 379
 			newprescribe.DewaterAmount = dewater_amount
380 380
 			newprescribe.TargetUltrafiltration = dewater_amount
381
+			newprescribe.PrescriptionWater = dewater_amount
381 382
 			newprescribe.Status = 1
382 383
 			if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
383 384
 				newprescribe.Remark = dialysisSolution.Remark
@@ -461,6 +462,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
461 462
 				newprescribe.RecordDate = theAssessmentDateTime
462 463
 				newprescribe.DewaterAmount = dewater_amount
463 464
 				newprescribe.TargetUltrafiltration = dewater_amount
465
+				newprescribe.PrescriptionWater = dewater_amount
464 466
 				newprescribe.Status = 1
465 467
 				newprescribe.Remark = lastDialysisPrescribe.Remark
466 468
 				if adminUserInfo.Org.Id == 10340 {
@@ -681,7 +683,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
681 683
 					evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
682 684
 				}
683 685
 
684
-				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
686
+				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
685 687
 					evaluation.PulseFrequency = 80
686 688
 				}
687 689
 				if adminUserInfo.Org.Id == 10440 {
@@ -690,6 +692,9 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
690 692
 				if adminUserInfo.Org.Id == 10469 {
691 693
 					evaluation.Temperature = 36.5
692 694
 				}
695
+				if adminUserInfo.Org.Id == 10471 {
696
+					evaluation.Temperature = 36.5
697
+				}
693 698
 			}
694 699
 		} else {
695 700
 			evaluation.UpdatedTime = time.Now().Unix()

+ 29 - 25
controllers/mobile_api_controllers/dialysis_api_controller.go Dosyayı Görüntüle

@@ -1490,7 +1490,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1490 1490
 		if filedConfig.ID > 0 {
1491 1491
 			str = dialyzerPerfusionApparatus
1492 1492
 		} else {
1493
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
1493
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
1494 1494
 		}
1495 1495
 		service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
1496 1496
 	}
@@ -2391,6 +2391,19 @@ func (c *DialysisAPIController) Finish() {
2391 2391
 		dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
2392 2392
 		dialysisOrder.EndTime = endDate.Unix()
2393 2393
 
2394
+		// 长沙南雅需求
2395
+		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
2396
+
2397
+			//获取最后1条监测的数据
2398
+			fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2399
+			lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2400
+			var accumulatedBloodVolume float64
2401
+			accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
2402
+			fmt.Println("累计血容量", accumulatedBloodVolume)
2403
+			err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
2404
+			fmt.Println(err)
2405
+		}
2406
+
2394 2407
 		go func() {
2395 2408
 			ssoDomain := beego.AppConfig.String("call_domain")
2396 2409
 			api := ssoDomain + "/index/downpatient"
@@ -2449,7 +2462,6 @@ func (c *DialysisAPIController) GetSchedualPatientsList() {
2449 2462
 // @param nurse:int 上机护士
2450 2463
 // @param bed:int 床位号
2451 2464
 func (this *DialysisAPIController) StartDialysis() {
2452
-
2453 2465
 	patientID, _ := this.GetInt64("patient_id")
2454 2466
 	recordDateStr := this.GetString("record_date")
2455 2467
 	nurseID, _ := this.GetInt64("nurse")
@@ -2599,19 +2611,11 @@ func (this *DialysisAPIController) StartDialysis() {
2599 2611
 			} else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
2600 2612
 				daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
2601 2613
 				if daySchedule.ID > 0 {
2602
-					//daySchedule.PartitionId = deviceNumber.ZoneID
2603
-					//daySchedule.BedId = bedID
2604
-					//daySchedule.ScheduleType = schedual_type
2605
-					//daySchedule.UpdatedTime = time.Now().Unix()
2606
-					//err := service.UpdateSchedule(&daySchedule)
2607
-					//xtSchedule := models.Schedule{
2608
-					//	PartitionId:  deviceNumber.ZoneID,
2609
-					//	BedId:        bedID,
2610
-					//	ScheduleType: schedual_type,
2611
-					//	UpdatedTime:  time.Now().Unix(),
2612
-					//}
2613
-					//err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
2614
-					service.UpdateScheduleTwo(daySchedule, schedule)
2614
+					err := service.UpdateScheduleTwo(daySchedule, schedule)
2615
+					if err != nil {
2616
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2617
+						return
2618
+					}
2615 2619
 
2616 2620
 				}
2617 2621
 			}
@@ -3031,7 +3035,7 @@ func (c *DialysisAPIController) PostSolution() {
3031 3035
 		if filedConfig.ID > 0 {
3032 3036
 			str = dialyzerPerfusionApparatus
3033 3037
 		} else {
3034
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
3038
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
3035 3039
 		}
3036 3040
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
3037 3041
 	}
@@ -3613,10 +3617,9 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3613 3617
 				record.UltrafiltrationRate = ultrafiltration_rate
3614 3618
 			}
3615 3619
 
3616
-			fmt.Println("adminiNof2323323232", adminInfo.Org.Id)
3617
-			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 {
3620
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3618 3621
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3619
-				fmt.Println("ooooooooooo", ultrafiltration_rate)
3622
+
3620 3623
 				record.UltrafiltrationRate = ultrafiltration_rate
3621 3624
 			}
3622 3625
 			//if template.TemplateId == 47 {
@@ -3645,19 +3648,19 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3645 3648
 	}
3646 3649
 
3647 3650
 	//长沙南雅
3648
-	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 {
3649
-		fmt.Println("ultrafiltration_rate-------", ultrafiltration_rate)
3651
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3652
+
3650 3653
 		if ultrafiltration_rate > 0 {
3651 3654
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
3652
-			fmt.Println("ultrafiltration_volume=======", ultrafiltration_volume)
3655
+
3653 3656
 			record.UltrafiltrationVolume = ultrafiltration_volume
3654 3657
 		}
3655 3658
 
3656 3659
 	}
3657 3660
 	//长沙南雅累计血容量自动计算
3658
-	if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 {
3659
-		record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3660
-	}
3661
+	//if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 ||  adminInfo.Org.Id == 3877{
3662
+	//	record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3663
+	//}
3661 3664
 
3662 3665
 	if template.TemplateId == 47 || template.TemplateId == 54 {
3663 3666
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
@@ -4573,6 +4576,7 @@ func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
4573 4576
 	}
4574 4577
 
4575 4578
 	if len(advices) > 0 {
4579
+
4576 4580
 		list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
4577 4581
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
4578 4582
 		redis := service.RedisClient()

+ 1 - 1
controllers/mobile_api_controllers/dialysis_api_controller_extend.go Dosyayı Görüntüle

@@ -514,7 +514,7 @@ func (this *DialysisAPIController) AddUrgentSchedule() {
514 514
 				UpdatedTime:  time.Now().Unix(),
515 515
 				IsExport:     5,
516 516
 			}
517
-			createErr := service.CreateSchedule(newSchedule)
517
+			createErr := service.CreateScheduleTwo(newSchedule)
518 518
 			redis := service.RedisClient()
519 519
 			timeStr := time.Now().Format("2006-01-02")
520 520
 			key := "scheduals_" + timeStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)

+ 13 - 3
controllers/mobile_api_controllers/patient_api_controller.go Dosyayı Görüntüle

@@ -3640,7 +3640,6 @@ func (c *PatientApiController) CreateGroupAdvice() {
3640 3640
 			return
3641 3641
 		}
3642 3642
 		advice_date, _ := dataBody["advice_date"].(string)
3643
-		fmt.Println("advice_date----------------------------------", advice_date)
3644 3643
 
3645 3644
 		var advicedateunix int64
3646 3645
 		if len(advice_date) > 0 {
@@ -3674,12 +3673,16 @@ func (c *PatientApiController) CreateGroupAdvice() {
3674 3673
 			return
3675 3674
 		}
3676 3675
 		startTime, _ := dataBody["start_time"].(string)
3676
+
3677 3677
 		if len(startTime) == 0 {
3678 3678
 			utils.ErrorLog("len(start_time) == 0")
3679 3679
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3680 3680
 			return
3681 3681
 		}
3682 3682
 		theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
3683
+
3684
+		theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
3685
+
3683 3686
 		if err != nil {
3684 3687
 			utils.ErrorLog(err.Error())
3685 3688
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -3707,8 +3710,15 @@ func (c *PatientApiController) CreateGroupAdvice() {
3707 3710
 			advice.Remark = Remark
3708 3711
 			advice.AdviceType = adviceType
3709 3712
 			advice.StartTime = StartTime
3710
-			advice.AdviceDate = AdviceDate
3711
-			advice.RecordDate = RecordDate
3713
+			if adminUserInfo.Org.Id == 10340 {
3714
+				advice.AdviceDate = AdviceDate
3715
+				advice.RecordDate = RecordDate
3716
+			}
3717
+			if adminUserInfo.Org.Id != 10340 {
3718
+				advice.AdviceDate = theTimeOne.Unix()
3719
+				advice.RecordDate = theTimeOne.Unix()
3720
+			}
3721
+
3712 3722
 			advice.Status = 1
3713 3723
 			advice.CreatedTime = time.Now().Unix()
3714 3724
 			advice.UpdatedTime = time.Now().Unix()

+ 14 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Dosyayı Görüntüle

@@ -1255,3 +1255,17 @@ func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patie
1255 1255
 	}
1256 1256
 	return
1257 1257
 }
1258
+
1259
+func (c *MobileHisApiController) GetPatientPlan() {
1260
+
1261
+	plan, _ := service.GetPatientPlan(10340)
1262
+
1263
+	for _, item := range plan {
1264
+		service.UpdatePatienPlan(item.ID, item.TreatmentPlan)
1265
+	}
1266
+	c.ServeSuccessJSON(map[string]interface{}{
1267
+		"plan": plan,
1268
+		"msg":  "ok",
1269
+	})
1270
+	return
1271
+}

+ 2 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Dosyayı Görüntüle

@@ -180,4 +180,6 @@ func NewMobileAPIControllersRegisterRouters() {
180 180
 	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteProject")
181 181
 	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
182 182
 
183
+	beego.Router("/m/api/patient/getpatientplan", &MobileHisApiController{}, "Get:GetPatientPlan")
184
+
183 185
 }

+ 73 - 43
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go Dosyayı Görüntüle

@@ -377,43 +377,45 @@ func (this *StaffScheduleApiController) GetPatientScheduleList() {
377 377
 
378 378
 func (this *StaffScheduleApiController) DeleteSchedule() {
379 379
 	id, _ := this.GetInt64("id")
380
-	fmt.Println("id", id)
381
-
382 380
 	org_id := this.GetMobileAdminUserInfo().Org.Id
383 381
 	err := service.DeleteSchedule(id)
384
-	schedule, _ := service.GetScheduleNight(org_id, id)
385
-
386
-	redis := service.RedisClient()
382
+	if err == nil {
383
+		schedule, _ := service.GetScheduleNight(org_id, id)
384
+		redis := service.RedisClient()
385
+		//处方
386
+		keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
387
+		redis.Set(keyOne, "", time.Second)
387 388
 
388
-	//处方
389
-	keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
390
-	redis.Set(keyOne, "", time.Second)
389
+		//医嘱
390
+		keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
391
+		redis.Set(keyTwo, "", time.Second)
391 392
 
392
-	//医嘱
393
-	keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
394
-	redis.Set(keyTwo, "", time.Second)
393
+		keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
394
+		redis.Set(keySix, "", time.Second)
395
+		keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
396
+		redis.Set(keyThree, "", time.Second)
395 397
 
396
-	keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
397
-	redis.Set(keySix, "", time.Second)
398
-	keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
399
-	redis.Set(keyThree, "", time.Second)
398
+		keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
399
+		redis.Set(keyFour, "", time.Second)
400 400
 
401
-	keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
402
-	redis.Set(keyFour, "", time.Second)
401
+		keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
402
+		redis.Set(keyFive, "", time.Second)
403 403
 
404
-	keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
405
-	redis.Set(keyFive, "", time.Second)
404
+		keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
405
+		redis.Set(keySeven, "", time.Second)
406 406
 
407
-	keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
408
-	redis.Set(keySeven, "", time.Second)
407
+		defer redis.Close()
408
+		fmt.Println(err)
409 409
 
410
-	defer redis.Close()
411
-	fmt.Println(err)
410
+		returnData := make(map[string]interface{}, 0)
411
+		returnData["msg"] = "ok"
412
+		this.ServeSuccessJSON(returnData)
413
+		return
412 414
 
413
-	returnData := make(map[string]interface{}, 0)
414
-	returnData["msg"] = "ok"
415
-	this.ServeSuccessJSON(returnData)
416
-	return
415
+	} else {
416
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "删除失败")
417
+		return
418
+	}
417 419
 }
418 420
 
419 421
 func (this *StaffScheduleApiController) SearchPatient() {
@@ -758,7 +760,7 @@ func (c *StaffScheduleApiController) CreateMobileSchedulePatient() {
758 760
 	}
759 761
 
760 762
 	redis := service.RedisClient()
761
-	err = service.CreateSchedule(&schedule)
763
+	err = service.CreateScheduleTwo(&schedule)
762 764
 	key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
763 765
 	redis.Set(key, "", time.Second)
764 766
 	defer redis.Close()
@@ -842,7 +844,6 @@ func (c *StaffScheduleApiController) ChangeScheduleType() {
842 844
 			PatientId: schedule.PatientId,
843 845
 			ModeId:    schedule.ModeId,
844 846
 		}
845
-
846 847
 		var DialysisMachineName string
847 848
 		so, _ := service.GetDialysisSolutionTwo(org_id, sch.PatientId, sch.ModeId)
848 849
 		filedRecordOne, _ := service.FindFiledBy(org_id, "透析器")
@@ -871,8 +872,6 @@ func (c *StaffScheduleApiController) ChangeScheduleType() {
871 872
 			}
872 873
 		}
873 874
 		sch.DialysisMachineName = DialysisMachineName
874
-		service.UpdateScheduleById(id, sch)
875
-
876 875
 		schedu := models.Schedule{
877 876
 			PatientId: patient_id,
878 877
 			ModeId:    mode_id,
@@ -900,7 +899,15 @@ func (c *StaffScheduleApiController) ChangeScheduleType() {
900 899
 			}
901 900
 		}
902 901
 		schedu.DialysisMachineName = DialysisMachineName1
903
-		service.UpdateScheduleById(schedule.ID, schedu)
902
+		err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
903
+		if err == nil {
904
+			c.ServeSuccessJSON(map[string]interface{}{
905
+				"msg": "ok",
906
+			})
907
+		} else {
908
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
909
+			return
910
+		}
904 911
 	} else {
905 912
 		xtSchedule := models.Schedule{
906 913
 			ScheduleDate: schedule_date,
@@ -909,11 +916,17 @@ func (c *StaffScheduleApiController) ChangeScheduleType() {
909 916
 			UserOrgId:    org_id,
910 917
 		}
911 918
 
912
-		service.ChangeScheduleClass(xtSchedule)
919
+		err := service.ChangeScheduleClass(xtSchedule)
920
+		if err == nil {
921
+			c.ServeSuccessJSON(map[string]interface{}{
922
+				"msg": "ok",
923
+			})
924
+		} else {
925
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
926
+			return
927
+		}
913 928
 	}
914
-	c.ServeSuccessJSON(map[string]interface{}{
915
-		"msg": "ok",
916
-	})
929
+
917 930
 }
918 931
 func (c *StaffScheduleApiController) ChangeScheduleBed() {
919 932
 	schedule_type, _ := c.GetInt64("schedule_type")
@@ -972,7 +985,7 @@ func (c *StaffScheduleApiController) ChangeScheduleBed() {
972 985
 			}
973 986
 		}
974 987
 		sch.DialysisMachineName = DialysisMachineName
975
-		service.UpdateScheduleById(id, sch)
988
+
976 989
 		schedu := models.Schedule{
977 990
 			PatientId:           patient_id,
978 991
 			ModeId:              mode_id,
@@ -1002,7 +1015,18 @@ func (c *StaffScheduleApiController) ChangeScheduleBed() {
1002 1015
 			}
1003 1016
 		}
1004 1017
 		schedu.DialysisMachineName = DialysisMachineName1
1005
-		service.UpdateScheduleById(schedule.ID, schedu)
1018
+		err := service.UpdateScheduleById(schedule.ID, schedu, id, sch)
1019
+		if err == nil {
1020
+			c.ServeSuccessJSON(map[string]interface{}{
1021
+				"msg": "ok",
1022
+			})
1023
+
1024
+		} else {
1025
+
1026
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1027
+			return
1028
+		}
1029
+
1006 1030
 	} else {
1007 1031
 		var str string
1008 1032
 		//查找该机构用的是什么透析器
@@ -1029,10 +1053,16 @@ func (c *StaffScheduleApiController) ChangeScheduleBed() {
1029 1053
 			IsExport:            20000,
1030 1054
 			DialysisMachineName: str,
1031 1055
 		}
1032
-		service.DeleteSchedule(id)
1033
-		service.CreateSchedule(&xtSchedule)
1056
+		var err error
1057
+		err = service.CreateSchedule(&xtSchedule, id)
1058
+		if err == nil {
1059
+			c.ServeSuccessJSON(map[string]interface{}{
1060
+				"msg": "ok",
1061
+			})
1062
+			return
1063
+		} else {
1064
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1065
+			return
1066
+		}
1034 1067
 	}
1035
-	c.ServeSuccessJSON(map[string]interface{}{
1036
-		"msg": "ok",
1037
-	})
1038 1068
 }

+ 15 - 0
controllers/patient_api_controller.go Dosyayı Görüntüle

@@ -1470,6 +1470,7 @@ func (c *PatientApiController) CreateGroupAdvice() {
1470 1470
 					child.PatientId = patientInfo.ID
1471 1471
 					child.AdviceDoctor = adminUserInfo.AdminUser.Id
1472 1472
 					child.IsSettle = 2
1473
+
1473 1474
 					if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
1474 1475
 						utils.ErrorLog("child advice_name")
1475 1476
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1535,6 +1536,20 @@ func (c *PatientApiController) CreateGroupAdvice() {
1535 1536
 
1536 1537
 					child.DeliveryWay = advice.DeliveryWay
1537 1538
 					child.ExecutionFrequency = advice.ExecutionFrequency
1539
+
1540
+					if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
1541
+						if child.PrescribingNumber == 0 {
1542
+							child.PrescribingNumber = 1
1543
+						}
1544
+						//查询该患者今日有没有双人核对
1545
+						check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
1546
+
1547
+						if check.ID > 0 {
1548
+							child.Checker = check.Modifier
1549
+							child.CheckState = 1
1550
+							child.CheckTime = time.Now().Unix()
1551
+						}
1552
+					}
1538 1553
 					advice.Children = append(advice.Children, &child)
1539 1554
 				}
1540 1555
 			}

+ 152 - 55
controllers/pharmacy_controller.go Dosyayı Görüntüle

@@ -7,6 +7,8 @@ import (
7 7
 	"XT_New/utils"
8 8
 	"fmt"
9 9
 	"github.com/astaxie/beego"
10
+	"math"
11
+	"strconv"
10 12
 	"time"
11 13
 )
12 14
 
@@ -78,16 +80,7 @@ func (this *PharmacyController) TodayNumber() {
78 80
 	times := this.GetString("time", "")
79 81
 	timeLayout := "2006-01-02"
80 82
 	loc, _ := time.LoadLocation("Local")
81
-	//shift, err := this.GetInt64("shift", 0) //班次
82
-	//if err != nil {
83
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
84
-	//	return
85
-	//}
86
-	//partition, err := this.GetInt64("partition", 0) //分区
87
-	//if err != nil {
88
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
89
-	//	return
90
-	//}
83
+
91 84
 	var stime, etime int64
92 85
 	if times == "" {
93 86
 		stime, etime = service.GetNowTime()
@@ -96,26 +89,47 @@ func (this *PharmacyController) TodayNumber() {
96 89
 		stime = stmp.Unix()
97 90
 		etime = stime + 86399
98 91
 	}
99
-	//查询表里当天的数据
100
-	var wtotal int
101
-	wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
102
-	if err != nil {
103
-		utils.ErrorLog(err.Error())
104
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
92
+
93
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
94
+		//查询表里当天的数据
95
+		var wtotal int
96
+		wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
97
+
98
+		if err != nil {
99
+			utils.ErrorLog(err.Error())
100
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
101
+			return
102
+		}
103
+
104
+		var itotal int
105
+		itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
106
+
107
+		if err != nil {
108
+			utils.ErrorLog(err.Error())
109
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
110
+			return
111
+		}
112
+		this.ServeSuccessJSON(map[string]interface{}{
113
+			"wtotal": wtotal,
114
+			"itotal": itotal,
115
+		})
105 116
 		return
106 117
 	}
107
-	var itotal int
108
-	itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
109
-	if err != nil {
110
-		utils.ErrorLog(err.Error())
111
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
118
+
119
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
120
+		var wtotal int
121
+		var itotal int
122
+		//查找出库数量
123
+		wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
124
+
125
+		itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
126
+		this.ServeSuccessJSON(map[string]interface{}{
127
+			"wtotal": wtotal,
128
+			"itotal": itotal,
129
+		})
112 130
 		return
113 131
 	}
114
-	this.ServeSuccessJSON(map[string]interface{}{
115
-		"wtotal": wtotal,
116
-		"itotal": itotal,
117
-	})
118
-	return
132
+
119 133
 }
120 134
 func (this *PharmacyController) IssuedDrug() {
121 135
 	var err error
@@ -150,24 +164,43 @@ func (this *PharmacyController) IssuedDrug() {
150 164
 		stime = stmp.Unix()
151 165
 		etime = stime + 86399
152 166
 	}
153
-	//查询表里当天的数据
154
-	var flist []*models.TmpPatient
155
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
156
-	if err != nil {
157
-		utils.ErrorLog(err.Error())
158
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
159
-		return
167
+
168
+	if orgid == 10164 || orgid == 3877 || orgid == 10188 || orgid == 10217 || orgid == 9671 {
169
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1)
170
+		fmt.Println("list23323232323232", list)
171
+		var flist []models.TmpPatientOne
172
+		if len(list) > 0 {
173
+			for _, item := range list {
174
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
175
+				flist = append(flist, patientlist)
176
+			}
177
+		}
178
+		this.ServeSuccessJSON(map[string]interface{}{
179
+			"list": flist,
180
+		})
160 181
 	}
161
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
162
-	if err != nil {
163
-		utils.ErrorLog(err.Error())
164
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
182
+
183
+	if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 {
184
+		//查询表里当天的数据
185
+		var flist []*models.TmpPatient
186
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
187
+		if err != nil {
188
+			utils.ErrorLog(err.Error())
189
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
190
+			return
191
+		}
192
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
193
+		if err != nil {
194
+			utils.ErrorLog(err.Error())
195
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
+			return
197
+		}
198
+		this.ServeSuccessJSON(map[string]interface{}{
199
+			"list": listt,
200
+		})
165 201
 		return
166 202
 	}
167
-	this.ServeSuccessJSON(map[string]interface{}{
168
-		"list": listt,
169
-	})
170
-	return
203
+
171 204
 }
172 205
 func (this *PharmacyController) WaitingDrug() {
173 206
 	var err error
@@ -202,24 +235,47 @@ func (this *PharmacyController) WaitingDrug() {
202 235
 		stime = stmp.Unix()
203 236
 		etime = stime + 86399
204 237
 	}
205
-	//查询表里当天的数据
206
-	var flist []*models.TmpPatient
207
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
208
-	if err != nil {
209
-		utils.ErrorLog(err.Error())
210
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
238
+
239
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
240
+		//查询表里当天的数据
241
+		var flist []*models.TmpPatient
242
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
243
+
244
+		if err != nil {
245
+			utils.ErrorLog(err.Error())
246
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
247
+			return
248
+		}
249
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
250
+		if err != nil {
251
+			utils.ErrorLog(err.Error())
252
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
253
+			return
254
+		}
255
+		this.ServeSuccessJSON(map[string]interface{}{
256
+			"list": listt,
257
+		})
211 258
 		return
212 259
 	}
213
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
214
-	if err != nil {
215
-		utils.ErrorLog(err.Error())
216
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
260
+
261
+	//当天已发药的人数
262
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
263
+
264
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0)
265
+
266
+		var flist []models.TmpPatientOne
267
+		if len(list) > 0 {
268
+			for _, item := range list {
269
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
270
+				flist = append(flist, patientlist)
271
+			}
272
+		}
273
+		this.ServeSuccessJSON(map[string]interface{}{
274
+			"list": flist,
275
+		})
217 276
 		return
218 277
 	}
219
-	this.ServeSuccessJSON(map[string]interface{}{
220
-		"list": listt,
221
-	})
222
-	return
278
+
223 279
 }
224 280
 
225 281
 //
@@ -290,6 +346,47 @@ func (this *PharmacyController) DispensingMedicine() {
290 346
 		etime = stime + 86399
291 347
 	}
292 348
 
349
+	advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
350
+	if len(advicelist) > 0 {
351
+		var total int64
352
+		var prescribing_number_total int64
353
+		for _, item := range advicelist {
354
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
355
+			//查询该药品是否有库存
356
+			list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
357
+
358
+			//查询改药品信息
359
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
360
+			//判断单位是否相等
361
+			if medical.MaxUnit == item.PrescribingNumberUnit {
362
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
363
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
364
+				//转化为最小单位
365
+				total = list.Count*medical.MinNumber + list.StockMinNumber
366
+				prescribing_number_total = count * medical.MinNumber
367
+			}
368
+			if medical.MinUnit == item.PrescribingNumberUnit {
369
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
370
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
371
+				total = list.Count*medical.MinNumber + list.StockMinNumber
372
+				prescribing_number_total = count
373
+			}
374
+
375
+			if medical.IsUse != 1 {
376
+				//如果出库数量大于库存数量
377
+				if prescribing_number_total > total {
378
+					err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
379
+					if err != nil {
380
+						utils.ErrorLog(err.Error())
381
+						this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
382
+						return
383
+					}
384
+				}
385
+			}
386
+
387
+		}
388
+	}
389
+
293 390
 	err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
294 391
 	if err != nil {
295 392
 		utils.ErrorLog(err.Error())

+ 5 - 2
controllers/print_data_api_controller.go Dosyayı Görüntüle

@@ -37,7 +37,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
37 37
 	idStrs := strings.Split(schIDStr, ",")
38 38
 	adminUserInfo := this.GetAdminUserInfo()
39 39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 {
41 41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42 42
 		for _, item := range schedules {
43 43
 
@@ -136,7 +136,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
136 136
 		})
137 137
 	}
138 138
 
139
-	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 {
139
+	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 && this.GetAdminUserInfo().CurrentOrgId != 10188 && this.GetAdminUserInfo().CurrentOrgId != 10217 && this.GetAdminUserInfo().CurrentOrgId != 10340 {
140 140
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
141 141
 		for _, item := range schedules {
142 142
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
@@ -259,6 +259,8 @@ func (this *PrintDataAPIController) CourseRecordPrintData() {
259 259
 	patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
260 260
 
261 261
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
262
+
263
+	operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId)
262 264
 	if err != nil {
263 265
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
264 266
 		return
@@ -267,6 +269,7 @@ func (this *PrintDataAPIController) CourseRecordPrintData() {
267 269
 			"record":    record,
268 270
 			"patient":   patient,
269 271
 			"adminUser": adminUser,
272
+			"operators": operators,
270 273
 		})
271 274
 	}
272 275
 }

+ 63 - 53
controllers/schedule_api_controller.go Dosyayı Görüntüle

@@ -79,11 +79,8 @@ func ScheduleApiRegistRouters() {
79 79
 	beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
80 80
 
81 81
 	beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
82
-
83 82
 	beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
84
-
85 83
 	beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
86
-
87 84
 	beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
88 85
 	beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
89 86
 	beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
@@ -122,13 +119,22 @@ func (c *ScheduleApiController) CoverSch() {
122 119
 	new_sch.ScheduleType = sch_two.ScheduleType
123 120
 	new_sch.ID = 0
124 121
 	//删除原来的排班
125
-	service.SaveSchTwo(sch, sch_two)
122
+	err := service.SaveSchTwo(sch, sch_two)
126 123
 	//生成新的排班
127
-	service.SaveSch(new_sch)
128
-	c.ServeSuccessJSON(map[string]interface{}{
129
-		"msg": "覆盖成功",
130
-	})
131
-
124
+	if err == nil {
125
+		err2 := service.SaveSch(new_sch)
126
+		if err2 == nil {
127
+			c.ServeSuccessJSON(map[string]interface{}{
128
+				"msg": "覆盖成功",
129
+			})
130
+		} else {
131
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
132
+			return
133
+		}
134
+	} else {
135
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
136
+		return
137
+	}
132 138
 }
133 139
 func (c *ScheduleApiController) ExchangeSch() {
134 140
 	id_one, _ := c.GetInt64("id_one")
@@ -161,10 +167,18 @@ func (c *ScheduleApiController) ExchangeSch() {
161 167
 		}
162 168
 	}
163 169
 
164
-	service.UpdateScheduleThree(sch, sch_two)
165
-	c.ServeSuccessJSON(map[string]interface{}{
166
-		"msg": "交换成功",
167
-	})
170
+	err := service.UpdateScheduleThree(sch, sch_two)
171
+	if err == nil {
172
+		c.ServeSuccessJSON(map[string]interface{}{
173
+			"msg": "交换成功",
174
+		})
175
+
176
+	} else {
177
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
178
+		return
179
+
180
+	}
181
+
168 182
 }
169 183
 func (c *ScheduleApiController) BatchPostSmartSch() {
170 184
 	patient_id, _ := c.GetInt64("patient_id")
@@ -186,7 +200,6 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
186 200
 
187 201
 	//数据校验
188 202
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
189
-
190 203
 		schs, _ := dataBody["smart_schs"].([]interface{})
191 204
 		if len(schs) > 0 {
192 205
 			for _, item := range schs {
@@ -1000,7 +1013,7 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
1000 1013
 							service.SaveSch(daySchedule)
1001 1014
 						} else {
1002 1015
 							existSchedule.IsExport = 3003
1003
-							service.CreateSchedule(&schedule)
1016
+							service.CreateScheduleTwo(&schedule)
1004 1017
 						}
1005 1018
 					}
1006 1019
 				}
@@ -1527,7 +1540,7 @@ func (c *ScheduleApiController) CreateSchedule() {
1527 1540
 
1528 1541
 	redis := service.RedisClient()
1529 1542
 	schedule.IsExport = 1000
1530
-	err = service.CreateSchedule(&schedule)
1543
+	err = service.CreateScheduleTwo(&schedule)
1531 1544
 
1532 1545
 	key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
1533 1546
 
@@ -2670,26 +2683,18 @@ func (this *ScheduleApiController) ExportSchedule() {
2670 2683
 				for _, item := range schedules {
2671 2684
 					if item.ScheduleDate > clear_schedule_date {
2672 2685
 						//查询该患者是否转出获取死亡
2673
-						fmt.Println("11111323242423")
2674
-
2675 2686
 						//查找当天日期是否存在
2676 2687
 						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
2677 2688
 						if errcode == gorm.ErrRecordNotFound {
2678 2689
 							//查询该床位是否有患者
2679
-							fmt.Println("errcodes")
2680 2690
 							sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
2681
-							fmt.Println("errcodes")
2682
-							fmt.Println(errcodes)
2683
-							fmt.Println(sch)
2684 2691
 
2685 2692
 							if errcodes == gorm.ErrRecordNotFound {
2686
-								fmt.Println("1111111")
2687
-								service.CreateSchedule(item)
2693
+								service.CreateScheduleTwo(item)
2688 2694
 							} else if errcodes == nil {
2689
-								fmt.Println("1111222222222")
2690 2695
 								//清除当天该床位已有的患者
2691 2696
 								service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
2692
-								service.CreateSchedule(item)
2697
+								service.CreateScheduleTwo(item)
2693 2698
 							}
2694 2699
 
2695 2700
 						} else if errcode == nil {
@@ -2704,8 +2709,6 @@ func (this *ScheduleApiController) ExportSchedule() {
2704 2709
 								Status:              1,
2705 2710
 								DialysisMachineName: item.DialysisMachineName,
2706 2711
 							}
2707
-							fmt.Println("1111222222223333333333333333332")
2708
-
2709 2712
 							service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
2710 2713
 						}
2711 2714
 					}
@@ -4556,38 +4559,45 @@ func (c *ScheduleApiController) DeleteScheduleTwo() {
4556 4559
 	schedule.Status = 0
4557 4560
 	schedule.UpdatedTime = time.Now().Unix()
4558 4561
 	err = service.UpdateSchedule(schedule)
4559
-	redis := service.RedisClient()
4560 4562
 
4561
-	//处方
4562
-	keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
4563
-	redis.Set(keyOne, "", time.Second)
4563
+	if err == nil {
4564
+		redis := service.RedisClient()
4565
+		//处方
4566
+		keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
4567
+		redis.Set(keyOne, "", time.Second)
4564 4568
 
4565
-	//医嘱
4566
-	keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
4567
-	redis.Set(keyTwo, "", time.Second)
4569
+		//医嘱
4570
+		keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
4571
+		redis.Set(keyTwo, "", time.Second)
4568 4572
 
4569
-	keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
4570
-	redis.Set(keySix, "", time.Second)
4571
-	keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
4572
-	redis.Set(keyThree, "", time.Second)
4573
+		keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
4574
+		redis.Set(keySix, "", time.Second)
4575
+		keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
4576
+		redis.Set(keyThree, "", time.Second)
4573 4577
 
4574
-	keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
4575
-	redis.Set(keyFour, "", time.Second)
4578
+		keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
4579
+		redis.Set(keyFour, "", time.Second)
4576 4580
 
4577
-	keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
4578
-	redis.Set(keyFive, "", time.Second)
4581
+		keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
4582
+		redis.Set(keyFive, "", time.Second)
4579 4583
 
4580
-	keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
4581
-	redis.Set(keySeven, "", time.Second)
4582
-	fmt.Println(err)
4583
-	defer redis.Close()
4584
-	if err != nil {
4585
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
4584
+		keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
4585
+		redis.Set(keySeven, "", time.Second)
4586
+		defer redis.Close()
4587
+		if err != nil {
4588
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
4589
+			return
4590
+		}
4591
+		c.ServeSuccessJSON(map[string]interface{}{
4592
+			"msg":      "ok",
4593
+			"schedule": &schedule,
4594
+		})
4595
+
4596
+	} else {
4597
+
4598
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4586 4599
 		return
4600
+
4587 4601
 	}
4588 4602
 
4589
-	c.ServeSuccessJSON(map[string]interface{}{
4590
-		"msg":      "ok",
4591
-		"schedule": &schedule,
4592
-	})
4593 4603
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1158 - 7
controllers/schedule_template_api_controller.go


+ 2 - 0
enums/error_code.go Dosyayı Görüntüle

@@ -273,6 +273,8 @@ const ( // ErrorCode
273 273
 	ErrorCodePatientDialysisOrderTwo      = 60000001
274 274
 	ErrorCodePatientScheduleRepeat        = 60000002
275 275
 	ErrorCodeDelScheduleFailByDialysisTwo = 60000003
276
+
277
+	ErrorCodeSyncWrong = 60000006
276 278
 )
277 279
 
278 280
 var ErrCodeMsgs = map[int]string{

+ 1 - 0
models/patient_models.go Dosyayı Görüntüle

@@ -1176,6 +1176,7 @@ type XtPatients struct {
1176 1176
 	UserSysBeforeCount           int64   `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
1177 1177
 	SchRemark                    string  `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
1178 1178
 	ScheduleRemark               string  `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1179
+	TreatmentPlan                string  `gorm:"column:treatment_plan" json:"treatment_plan" form:"treatment_plan"`
1179 1180
 }
1180 1181
 
1181 1182
 func (XtPatients) TableName() string {

+ 11 - 0
models/pharmacy_models.go Dosyayı Görüntüle

@@ -31,6 +31,17 @@ type TmpPatient struct {
31 31
 	PatientID  int64
32 32
 	Name       string
33 33
 	DialysisNo string //透析号
34
+
35
+}
36
+
37
+type TmpPatientOne struct {
38
+	PatientID  int64  `gorm:"column:id" json:"PatientID" form:"id"`
39
+	DialysisNo string `gorm:"column:dialysis_no" json:"DialysisNo" form:"dialysis_no"`
40
+	Name       string `gorm:"column:name" json:"Name" form:"name"`
41
+}
42
+
43
+func (TmpPatientOne) TableName() string {
44
+	return "xt_patients"
34 45
 }
35 46
 
36 47
 //药品信息

+ 1 - 1
routers/router.go Dosyayı Görüntüle

@@ -11,7 +11,7 @@ import (
11 11
 func init() {
12 12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13 13
 		//AllowAllOrigins:  true,
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://api.xt.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"},
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://api.xt.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", "https://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 17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},

+ 11 - 2
service/device_service.go Dosyayı Görüntüle

@@ -831,9 +831,18 @@ func GetPartionId(bed_id int64, org_id int64) (models.XtDeviceNumber, error) {
831 831
 	return number, err
832 832
 }
833 833
 
834
-func UpdateScheduleById(id int64, schedule models.Schedule) error {
834
+func UpdateScheduleById(id int64, schedule models.Schedule, id_two int64, schedule_two models.Schedule) error {
835
+	utx := XTWriteDB().Begin()
835 836
 
836
-	err := XTWriteDB().Model(&models.Schedule{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId, "is_export": 10000, "dialysis_machine_name": schedule.DialysisMachineName}).Error
837
+	if err = utx.Model(&models.Schedule{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId, "is_export": 50000, "dialysis_machine_name": schedule.DialysisMachineName}).Error; err != nil {
838
+		utx.Rollback()
839
+		return err
840
+	}
841
+	if err = utx.Model(&models.Schedule{}).Where("id = ? and status =1", id_two).Update(map[string]interface{}{"patient_id": schedule_two.PatientId, "mode_id": schedule_two.ModeId, "is_export": 50000, "dialysis_machine_name": schedule_two.DialysisMachineName}).Error; err != nil {
842
+		utx.Rollback()
843
+		return err
844
+	}
845
+	utx.Commit()
837 846
 	return err
838 847
 }
839 848
 

+ 6 - 0
service/dialysis_service.go Dosyayı Görüntüle

@@ -2084,3 +2084,9 @@ func UpdateDoctorAdviceList(id int64, checker int64) error {
2084 2084
 	err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
2085 2085
 	return err
2086 2086
 }
2087
+
2088
+func UpdateLastMonitorRecordToday(accumulated_blood_volume float64, id int64) error {
2089
+
2090
+	err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
2091
+	return err
2092
+}

+ 3 - 3
service/dialysis_solution_service.go Dosyayı Görüntüle

@@ -495,7 +495,7 @@ func GetDialysisAdviceSchedulistSeven(orgID int64, schedule_type int64, partitio
495 495
 
496 496
 }
497 497
 
498
-func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
498
+func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
499 499
 
500 500
 	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
501 501
 
@@ -505,8 +505,8 @@ func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_
505 505
 	if schedule_type > 0 {
506 506
 		db = db.Where("schedule_type = ?", schedule_type)
507 507
 	}
508
-	if partition_id > 0 {
509
-		db = db.Where("partition_id = ?", partition_id)
508
+	if len(partition_id) > 0 {
509
+		db = db.Where("partition_id in(?)", partition_id)
510 510
 	}
511 511
 
512 512
 	if orgID > 0 {

+ 1 - 1
service/his_print_service.go Dosyayı Görüntüle

@@ -23,7 +23,7 @@ func GetBatchProjectHisPrescription(ids []string, record_time int64, user_org_id
23 23
 		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
24 24
 			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
25 25
 				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
26
-					return db.Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
26
+					return db.Joins("Join xt_his_project p On p.id = his_prescription_project.project_id  AND p.cost_classify != 3").Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
27 27
 				})
28 28
 		}).
29 29
 		Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).

+ 12 - 0
service/his_service.go Dosyayı Görüntüle

@@ -2702,3 +2702,15 @@ func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
2702 2702
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
2703 2703
 	return order, err
2704 2704
 }
2705
+
2706
+func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
2707
+
2708
+	err = XTReadDB().Where("user_org_id = ? and status=  1", orgid).Find(&patient).Error
2709
+	return patient, err
2710
+}
2711
+
2712
+func UpdatePatienPlan(id int64, trement_plan string) error {
2713
+
2714
+	err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
2715
+	return err
2716
+}

+ 49 - 11
service/patient_schedule_template_service.go Dosyayı Görüntüle

@@ -34,17 +34,10 @@ func GetOrgPatientScheduleTemplateIDs(orgID int64) ([]*models.PatientScheduleTem
34 34
 	return ids, nil
35 35
 }
36 36
 
37
-func GetOrgPatientScheduleTemplateIDByTemplateID(orgID int64, templateID int64) (*models.PatientScheduleTemplateId, error) {
38
-	var id models.PatientScheduleTemplateId
39
-	err := readDb.Model(&models.PatientScheduleTemplateId{}).Where("org_id = ? AND id = ? AND status = 1", orgID, templateID).First(&id).Error
40
-	if err != nil {
41
-		if err == gorm.ErrRecordNotFound {
42
-			return nil, nil
43
-		} else {
44
-			return nil, err
45
-		}
46
-	}
47
-	return &id, nil
37
+func GetOrgPatientScheduleTemplateIDByTemplateID(orgID int64, templateID int64) (id models.PatientScheduleTemplateId, err error) {
38
+	err = readDb.Model(&models.PatientScheduleTemplateId{}).Where("org_id = ? AND id = ? AND status = 1", orgID, templateID).First(&id).Error
39
+
40
+	return id, nil
48 41
 }
49 42
 
50 43
 type PatientsTwo struct {
@@ -954,3 +947,48 @@ func UpdateTemplateItemModeWeek(orgID int64, id int64, week_time int64) {
954 947
 	readDb.Model(&models.PatientScheduleTemplateMode{}).Where("org_id = ? AND status = 1 AND id = ? ", orgID, id).Updates(map[string]interface{}{"original_week": week_time, "week": week_time})
955 948
 	return
956 949
 }
950
+
951
+func ClearAndCreateSyncSch(user_org_id int64, start_time int64, schs []models.Schedule) (err error) {
952
+	utx := writeDb.Begin()
953
+	err = utx.Table("xt_schedule as s").
954
+		Where("s.schedule_date > ? AND s.status = 1 AND "+
955
+			"s.user_org_id = ?", start_time, user_org_id).
956
+		Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
957
+	if err != nil {
958
+		utx.Rollback()
959
+		return
960
+	}
961
+	if len(schs) > 0 {
962
+		if len(schs) > 0 {
963
+			thisSQL := "INSERT INTO xt_schedule (user_org_id, partition_id, bed_id, patient_id, schedule_date,schedule_type,schedule_week,mode_id,status,created_time,updated_time,is_export,dialysis_machine_name,remark) VALUES "
964
+			insertParams := make([]string, 0)
965
+			insertData := make([]interface{}, 0)
966
+			for _, info := range schs {
967
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
968
+				insertData = append(insertData, info.UserOrgId)
969
+				insertData = append(insertData, info.PartitionId)
970
+				insertData = append(insertData, info.BedId)
971
+				insertData = append(insertData, info.PatientId)
972
+				insertData = append(insertData, info.ScheduleDate)
973
+				insertData = append(insertData, info.ScheduleType)
974
+				insertData = append(insertData, info.ScheduleWeek)
975
+				insertData = append(insertData, info.ModeId)
976
+				insertData = append(insertData, info.Status)
977
+				insertData = append(insertData, info.CreatedTime)
978
+				insertData = append(insertData, info.UpdatedTime)
979
+				insertData = append(insertData, info.IsExport)
980
+				insertData = append(insertData, info.DialysisMachineName)
981
+				insertData = append(insertData, "")
982
+			}
983
+			thisSQL += strings.Join(insertParams, ", ")
984
+			err = utx.Exec(thisSQL, insertData...).Error
985
+			if err != nil {
986
+				utx.Rollback()
987
+				return
988
+			}
989
+		}
990
+		utx.Commit()
991
+	}
992
+	return
993
+
994
+}

+ 125 - 54
service/pharmacy_service.go Dosyayı Görüntüle

@@ -46,11 +46,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
46 46
 	var tmp []*models.TmpTTT
47 47
 	if is_medicine == 0 {
48 48
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
49
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
49
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
50 50
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
51 51
 			"union "+
52 52
 			"select distinct patient_id from xt_doctor_advice where "+
53
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
53
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
54 54
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
55 55
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
56 56
 		if err != nil {
@@ -58,11 +58,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
58 58
 		}
59 59
 	} else {
60 60
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
61
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
61
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
62 62
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
63 63
 			"union "+
64 64
 			"select distinct patient_id from xt_doctor_advice where "+
65
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
65
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
66 66
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
67 67
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
68 68
 		if err != nil {
@@ -74,6 +74,52 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
74 74
 
75 75
 }
76 76
 
77
+func GetTodayAdviceCount(stime, etime, orgid, is_medicine int64) (num int, err error) {
78
+
79
+	//orgid = 9675
80
+	InitDrugidIsNil(orgid, stime, etime)
81
+	var tmp []*models.TmpTTT
82
+	if is_medicine == 0 {
83
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=0 group by patient_id",
84
+			stime, etime, orgid).Scan(&tmp).Error
85
+		if err != nil {
86
+			return
87
+		}
88
+	} else {
89
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=1 group by patient_id",
90
+			stime, etime, orgid).Scan(&tmp).Error
91
+		if err != nil {
92
+			return
93
+		}
94
+	}
95
+
96
+	return len(tmp), err
97
+}
98
+
99
+func GetTodayAdviceCountOne(stime int64, etime int64, orgid int64, is_medicine int64) (advice []*models.HisDoctorAdviceInfo, err error) {
100
+
101
+	db := XTReadDB().Model(&advice).Where("status=1 and is_medicine = ?", is_medicine)
102
+	if stime > 0 {
103
+		db = db.Where("advice_date>=?", stime)
104
+	}
105
+	if etime > 0 {
106
+		db = db.Where("advice_date<=?", stime)
107
+	}
108
+	if orgid > 0 {
109
+		db = db.Where("user_org_id = ?", orgid)
110
+	}
111
+
112
+	err = db.Group("patient_id").Find(&advice).Error
113
+	return advice, err
114
+}
115
+
116
+func GetPatientByAdviceId(patient_id int64) (models.TmpPatientOne, error) {
117
+
118
+	patient := models.TmpPatientOne{}
119
+	err = XTReadDB().Where("id = ?", patient_id).Find(&patient).Error
120
+	return patient, err
121
+}
122
+
77 123
 // (改)
78 124
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
79 125
 	InitDrugidIsNil(orgid, stime, etime)
@@ -84,22 +130,22 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
84 130
 		if keyword != "" {
85 131
 			keyword = "%" + keyword + "%"
86 132
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
87
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
133
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
88 134
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
89 135
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
90 136
 				"union "+
91 137
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
92
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
138
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
93 139
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
94 140
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
95 141
 				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
96 142
 		} else {
97 143
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
98
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
144
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
99 145
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
100 146
 				"union "+
101 147
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
102
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
148
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
103 149
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
104 150
 				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
105 151
 		}
@@ -172,13 +218,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
172 218
 	var tmp []*models.HisDoctorAdviceInfoL
173 219
 	if is_medicine == 0 {
174 220
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
175
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
221
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
176 222
 		if err != nil {
177 223
 			return pp, err
178 224
 		}
179 225
 	} else {
180 226
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
181
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
227
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
182 228
 		if err != nil {
183 229
 			return pp, err
184 230
 		}
@@ -201,13 +247,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
201 247
 	var tmp_advice []*models.XtDoctorAdviceL
202 248
 	if is_medicine == 0 {
203 249
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
204
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
250
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
205 251
 		if err != nil {
206 252
 			return pp, err
207 253
 		}
208 254
 	} else {
209 255
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
210
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
256
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
211 257
 		if err != nil {
212 258
 			return pp, err
213 259
 		}
@@ -580,7 +626,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
580 626
 	time_now := time.Now().Unix()
581 627
 	var hids []*models.TmpID
582 628
 	var xids []*models.TmpID
583
-	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
629
+	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and advice_date >= ? and advice_date <= ? "+
584 630
 		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
585 631
 	if err != nil {
586 632
 		return
@@ -600,7 +646,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
600 646
 			if PettyCash(v.DrugId) {
601 647
 				continue
602 648
 			}
603
-			//判断药品库存是否充足
649
+			////判断药品库存是否充足
604 650
 			kou := FenDrugInventory(v, orgid)
605 651
 			if !kou {
606 652
 				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
@@ -629,48 +675,52 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
629 675
 		return err1
630 676
 	}
631 677
 
632
-	err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
633
-		"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
634
-	if err != nil {
635
-		return
636
-	}
637
-	xid := make([]int64, 0)
638
-	for _, v := range xids {
639
-		xid = append(xid, v.Id)
640
-	}
641
-	var advice []*models.HisDoctorAdviceInfo
642
-	err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
643
-	if err != nil {
644
-		return
645
-	}
646
-	for _, v := range advice {
647
-		tmp_bool := IsPharmacyConfig(orgid)
648
-		if tmp_bool {
649
-			if PettyCash(v.DrugId) {
650
-				continue
651
-			}
652
-			kou := FenDrugInventory(v, orgid)
653
-			if !kou {
654
-				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
655
-				return
656
-			}
657
-			//扣减库存
658
-			err = FenStock(orgid, creater, v)
659
-			if err != nil {
660
-				err = fmt.Errorf("!:%v", err)
661
-				return
678
+	//针对大丰响水
679
+	if orgid != 10217 && orgid != 10188 && orgid != 9671 && orgid != 10164 {
680
+		err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and "+
681
+			"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
682
+		if err != nil {
683
+			return
684
+		}
685
+		xid := make([]int64, 0)
686
+		for _, v := range xids {
687
+			xid = append(xid, v.Id)
688
+		}
689
+		var advice []*models.HisDoctorAdviceInfo
690
+		err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
691
+		if err != nil {
692
+			return
693
+		}
694
+
695
+		for _, v := range advice {
696
+			tmp_bool := IsPharmacyConfig(orgid)
697
+			if tmp_bool {
698
+				if PettyCash(v.DrugId) {
699
+					continue
700
+				}
701
+				kou := FenDrugInventory(v, orgid)
702
+				if !kou {
703
+					err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
704
+					return
705
+				}
706
+				//扣减库存
707
+				err = FenStock(orgid, creater, v)
708
+				if err != nil {
709
+					err = fmt.Errorf("!:%v", err)
710
+					return
711
+				}
662 712
 			}
663 713
 		}
664
-	}
665
-	//修改状态
666
-	errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
667
-		"is_medicine":     1,
668
-		"people":          0,
669
-		"dispensing_time": time_now,
670
-		"updated_time":    time.Now().Unix(),
671
-	}).Error
672
-	if errs1 != nil {
673
-		return errs1
714
+		//修改状态
715
+		errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
716
+			"is_medicine":     1,
717
+			"people":          0,
718
+			"dispensing_time": time_now,
719
+			"updated_time":    time.Now().Unix(),
720
+		}).Error
721
+		if errs1 != nil {
722
+			return errs1
723
+		}
674 724
 	}
675 725
 
676 726
 	//生成明细记录
@@ -1911,3 +1961,24 @@ func GetAllValidDeviceZones02(orgID int64) ([]*models.DeviceZone, error) {
1911 1961
 	}
1912 1962
 	return zones, nil
1913 1963
 }
1964
+
1965
+func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
1966
+
1967
+	db := XTReadDB().Model(&advice).Where("status= 1")
1968
+
1969
+	if orgid > 0 {
1970
+		db = db.Where("user_org_id = ?", orgid)
1971
+	}
1972
+	if patient_id > 0 {
1973
+		db = db.Where("patient_id = ?", patient_id)
1974
+	}
1975
+	if stime > 0 {
1976
+		db = db.Where("advice_date >=?", stime)
1977
+	}
1978
+	if etime > 0 {
1979
+		db = db.Where("advice_date<=?", etime)
1980
+	}
1981
+	err = db.Find(&advice).Error
1982
+
1983
+	return advice, err
1984
+}

+ 1 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go Dosyayı Görüntüle

@@ -104,6 +104,7 @@ type DialysisOrderVM struct {
104 104
 	WashpipeNurse  int64           `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
105 105
 	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
106 106
 	QualityNurseId int64           `gorm:"column:quality_nurse_id" json:"quality_nurse_id" form:"quality_nurse_id"`
107
+	Url            string          `gorm:"column:url" json:"url" form:"url"`
107 108
 }
108 109
 
109 110
 func (DialysisOrderVM) TableName() string {

+ 8 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go Dosyayı Görüntüle

@@ -479,3 +479,11 @@ func GetBatchSummerVM(orgid int64, patient_id int64, assessment_date int64) (*Su
479 479
 	err := p_service.XTReadDB().Where("user_org_id = ? and patient_id = ? and assessment_date =? and status = 1", orgid, patient_id, assessment_date).Find(&SummerVM).Error
480 480
 	return &SummerVM, err
481 481
 }
482
+
483
+func GetAdminUserEsTwo(orgid int64) (admin []*models.UserAdminRoles, err error) {
484
+	db := p_service.UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
485
+	table := p_service.UserReadDB().Table("sgj_user_admin_electronic_signature as s")
486
+	fmt.Println("table", table)
487
+	err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
488
+	return admin, err
489
+}

+ 99 - 27
service/schedule_service.go Dosyayı Görüntüle

@@ -226,9 +226,19 @@ func GetPointSchedule(orgID, scheduleDate, scheduleWeek, scheduleType, bedId int
226 226
 	return
227 227
 }
228 228
 
229
-func CreateSchedule(m *models.Schedule) error {
229
+func CreateSchedule(m *models.Schedule, id int64) (err error) {
230 230
 	utx := XTWriteDB().Begin()
231
-	err := utx.Create(&m).Error
231
+	schedule := models.XtSchedule{}
232
+	err = utx.Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
233
+	if err != nil {
234
+		utx.Rollback()
235
+		return err
236
+	}
237
+	err = utx.Create(&m).Error
238
+	if err != nil {
239
+		utx.Rollback()
240
+		return err
241
+	}
232 242
 	utx.Commit()
233 243
 	return err
234 244
 }
@@ -346,8 +356,8 @@ func UpdateScheduleOne(id int64, schedule models.Schedule) error {
346 356
 }
347 357
 
348 358
 // 参数一:当前操作的患者的排班     参数二被替换床位对应的排班
349
-func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) {
350
-	utx := XTWriteDB()
359
+func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) (err error) {
360
+	utx := XTWriteDB().Begin()
351 361
 	//床位
352 362
 	var tempBedID int64
353 363
 	var tempBedIDTwo int64
@@ -377,16 +387,22 @@ func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) {
377 387
 
378 388
 	schone.ScheduleType = tempTypeTwo
379 389
 	schtwo.ScheduleType = tempTypeID
380
-	schone.IsExport = 9000
381
-	schtwo.IsExport = 9000
382 390
 
383
-	utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "is_export": 9000})
384
-	utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "is_export": 9000})
391
+	if err = utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "is_export": 90000}).Error; err != nil {
392
+		utx.Rollback()
393
+		return err
394
+	}
385 395
 
396
+	if err = utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "is_export": 90000}).Error; err != nil {
397
+		utx.Rollback()
398
+		return err
399
+	}
400
+	utx.Commit()
401
+	return err
386 402
 }
387 403
 
388
-func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) {
389
-	utx := XTWriteDB()
404
+func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) (err error) {
405
+	utx := XTWriteDB().Begin()
390 406
 	//床位
391 407
 	var tempBedID int64
392 408
 	var tempBedIDTwo int64
@@ -407,6 +423,7 @@ func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) {
407 423
 	var sch_week_one int64
408 424
 	var sch_week_two int64
409 425
 
426
+	//原数据
410 427
 	tempBedID = schone.BedId
411 428
 	tempBedIDTwo = schtwo.BedId
412 429
 
@@ -422,6 +439,7 @@ func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) {
422 439
 	sch_week_one = schone.ScheduleWeek
423 440
 	sch_week_two = schtwo.ScheduleWeek
424 441
 
442
+	//交换数据
425 443
 	schone.BedId = tempBedIDTwo
426 444
 	schtwo.BedId = tempBedID
427 445
 
@@ -437,12 +455,18 @@ func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) {
437 455
 	schone.ScheduleWeek = sch_week_two
438 456
 	schtwo.ScheduleWeek = sch_week_one
439 457
 
440
-	schone.IsExport = 9000
441
-	schtwo.IsExport = 9000
458
+	if err = utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "schedule_date": schone.ScheduleDate, "schedule_week": schone.ScheduleWeek, "is_export": 80000}).Error; err != nil {
459
+		utx.Rollback()
460
+		return err
461
+	}
442 462
 
443
-	utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "schedule_date": schone.ScheduleDate, "schedule_week": schone.ScheduleWeek, "is_export": 9000})
444
-	utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "schedule_date": schtwo.ScheduleDate, "schedule_week": schtwo.ScheduleWeek, "is_export": 9000})
463
+	if err = utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "schedule_date": schtwo.ScheduleDate, "schedule_week": schtwo.ScheduleWeek, "is_export": 80000}).Error; err != nil {
464
+		utx.Rollback()
465
+		return err
466
+	}
467
+	utx.Commit()
445 468
 
469
+	return err
446 470
 }
447 471
 
448 472
 func GetPatientScheduleFormToday(orgId, id, start int64) (schedules []*models.PatientSchedule, err error) {
@@ -1500,21 +1524,43 @@ func GetScheduleTemplateCountByDate(org_id int64, week_day int8, patient_id int6
1500 1524
 	return
1501 1525
 }
1502 1526
 
1503
-func SaveSchTemplateTwo(sch models.PatientScheduleTemplateItem, sch_two models.PatientScheduleTemplateItem) (err error) {
1504
-	//err = writeDb.Save(&sch).Error
1505
-	err = writeDb.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"status": 0}).Error
1506
-	err = writeDb.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch_two.ID).Updates(map[string]interface{}{"status": 0}).Error
1527
+func SaveSchTemplateTwo(sch models.PatientScheduleTemplateItem, sch_two models.PatientScheduleTemplateItem, new_sch models.PatientScheduleTemplateItem) (err error) {
1528
+	utx := writeDb.Begin()
1529
+	if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"status": 0}).Error; err != nil {
1530
+		utx.Rollback()
1531
+		return err
1532
+	}
1533
+	if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch_two.ID).Updates(map[string]interface{}{"status": 0}).Error; err != nil {
1534
+		utx.Rollback()
1535
+		return err
1536
+	}
1537
+	if err = utx.Save(&new_sch).Error; err != nil {
1538
+		utx.Rollback()
1539
+		return err
1540
+	}
1541
+	utx.Commit()
1507 1542
 
1508
-	return
1543
+	return err
1509 1544
 }
1510 1545
 
1511
-func SaveSchTemplate(sch models.PatientScheduleTemplateItem) (err error) {
1512
-	err = writeDb.Save(&sch).Error
1513
-	return
1546
+func SaveSchTemplate(sch models.PatientScheduleTemplateItem, sch_two models.PatientScheduleTemplateItem) (err error) {
1547
+	utx := writeDb.Begin()
1548
+	if err = utx.Save(&sch).Error; err != nil {
1549
+		utx.Rollback()
1550
+		return err
1551
+	}
1552
+
1553
+	if err = utx.Save(&sch_two).Error; err != nil {
1554
+		utx.Rollback()
1555
+		return err
1556
+	}
1557
+	utx.Commit()
1558
+
1559
+	return err
1514 1560
 }
1515 1561
 
1516
-func UpdateScheduleTemplateThree(schone models.PatientScheduleTemplateItem, schtwo models.PatientScheduleTemplateItem) {
1517
-	utx := XTWriteDB()
1562
+func UpdateScheduleTemplateThree(schone models.PatientScheduleTemplateItem, schtwo models.PatientScheduleTemplateItem) error {
1563
+	utx := XTWriteDB().Begin()
1518 1564
 	//床位
1519 1565
 	var tempBedID int64
1520 1566
 	var tempBedIDTwo int64
@@ -1544,10 +1590,17 @@ func UpdateScheduleTemplateThree(schone models.PatientScheduleTemplateItem, scht
1544 1590
 
1545 1591
 	schone.Weekday = sch_week_two
1546 1592
 	schtwo.Weekday = sch_week_one
1593
+	if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"device_number_id": schone.DeviceNumberID, "time_type": schone.TimeType, "weekday": schone.Weekday, "is_export": 70000}).Error; err != nil {
1594
+		utx.Rollback()
1595
+		return err
1596
+	}
1597
+	if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"device_number_id": schtwo.DeviceNumberID, "time_type": schtwo.TimeType, "weekday": schtwo.Weekday, "is_export": 70000}).Error; err != nil {
1598
+		utx.Rollback()
1599
+		return err
1600
+	}
1601
+	utx.Commit()
1547 1602
 
1548
-	utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"device_number_id": schone.DeviceNumberID, "time_type": schone.TimeType, "weekday": schone.Weekday, "is_export": 9000})
1549
-	utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"device_number_id": schtwo.DeviceNumberID, "time_type": schtwo.TimeType, "weekday": schtwo.Weekday, "is_export": 9000})
1550
-
1603
+	return err
1551 1604
 }
1552 1605
 
1553 1606
 func GetScheduleTemplateForDeviceNumberTwo(orgID int64, deviceNumberID int64, template_id int64, week_type int64, time_type int64, patient_id int64) (models.PatientScheduleTemplateItem, error) {
@@ -1555,3 +1608,22 @@ func GetScheduleTemplateForDeviceNumberTwo(orgID int64, deviceNumberID int64, te
1555 1608
 	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ? AND time_type = ? AND patient_id = ?", deviceNumberID, orgID, template_id, week_type, time_type, patient_id).First(&item).Error
1556 1609
 	return item, err
1557 1610
 }
1611
+
1612
+func ClearSchedules(user_org_id int64, start_time int64) (err error) {
1613
+	err = writeDb.Table("xt_schedule as s").
1614
+		Where("s.schedule_date > ? AND s.status = 1 AND "+
1615
+			"s.user_org_id = ?", start_time, user_org_id).
1616
+		Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
1617
+	return
1618
+}
1619
+
1620
+func CreateScheduleTwo(m *models.Schedule) error {
1621
+	utx := XTWriteDB().Begin()
1622
+	err = utx.Create(&m).Error
1623
+	if err != nil {
1624
+		utx.Rollback()
1625
+		return err
1626
+	}
1627
+	utx.Commit()
1628
+	return err
1629
+}