Browse Source

医保对接

csx 2 years ago
parent
commit
637f985b64

+ 4 - 0
controllers/his_api_controller.go View File

5234
 			PrivatePrice:          private_price,
5234
 			PrivatePrice:          private_price,
5235
 			SettleEndTime:         end_time,
5235
 			SettleEndTime:         end_time,
5236
 			SettleStartTime:       start_time,
5236
 			SettleStartTime:       start_time,
5237
+			PsnPartAmt:            totals,
5238
+			PsnCashPay:            totals,
5237
 			SettleType:            settle_accounts_type,
5239
 			SettleType:            settle_accounts_type,
5238
 			FaPiaoCode:            fapiao_code,
5240
 			FaPiaoCode:            fapiao_code,
5239
 			FaPiaoNumber:          fapiao_number,
5241
 			FaPiaoNumber:          fapiao_number,
7819
 		SettleEndTime:      end_time,
7821
 		SettleEndTime:      end_time,
7820
 		SettleStartTime:    start_time,
7822
 		SettleStartTime:    start_time,
7821
 		SettleType:         settle_accounts_type,
7823
 		SettleType:         settle_accounts_type,
7824
+		PsnPartAmt:         totals,
7825
+		PsnCashPay:         totals,
7822
 		PType:              2,
7826
 		PType:              2,
7823
 		IsPre:              1,
7827
 		IsPre:              1,
7824
 		MedType:            strconv.Itoa(int(reg_type)),
7828
 		MedType:            strconv.Itoa(int(reg_type)),

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

170
 	beego.Router("/m/api/savepatientsign", &DialysisAPIController{}, "Post:SavePatientSign")
170
 	beego.Router("/m/api/savepatientsign", &DialysisAPIController{}, "Post:SavePatientSign")
171
 	beego.Router("/m/api/getpatientsign", &DialysisAPIController{}, "Get:GetPatientSign")
171
 	beego.Router("/m/api/getpatientsign", &DialysisAPIController{}, "Get:GetPatientSign")
172
 
172
 
173
-	beego.Router("/m/api/checksch/get", &DialysisAPIController{}, "Get:CheckSchedule")
174
-
175
 	beego.Router("/m/api/patient/getschedulebypatient", &DialysisAPIController{}, "Get:GetScheduleByPatient")
173
 	beego.Router("/m/api/patient/getschedulebypatient", &DialysisAPIController{}, "Get:GetScheduleByPatient")
176
 
174
 
177
 	beego.Router("/m/api/getdialysisrecordeorder", &DialysisAPIController{}, "Get:GetDialysisRecordOrder")
175
 	beego.Router("/m/api/getdialysisrecordeorder", &DialysisAPIController{}, "Get:GetDialysisRecordOrder")
176
+
177
+	beego.Router("/m/api/getdialysisrecordeorder", &DialysisAPIController{}, "Get:GetDialysisRecordOrder")
178
+	beego.Router("/m/api/checksch/get", &DialysisAPIController{}, "Get:CheckSchedule")
179
+
180
+	//beego.Router("/m/api/getscheduletypebyidlist",&DialysisAPIController{},"Get:GetScheduleTypeByIdList")
178
 }
181
 }

+ 36 - 0
controllers/patient_api_controller.go View File

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

+ 282 - 66
controllers/schedule_api_controller.go View File

498
 						return
498
 						return
499
 					}
499
 					}
500
 
500
 
501
+					//daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
502
+					//if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
503
+					//	week_type, _ := items["week_type"].(string)
504
+					//	week_name, _ := items["week_name"].(string)
505
+					//
506
+					//	switch week_type {
507
+					//	case "1":
508
+					//		json := make(map[string]interface{})
509
+					//		json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
510
+					//		json["state"] = 0
511
+					//		c.Data["json"] = json
512
+					//		c.ServeJSON()
513
+					//		break
514
+					//	case "2":
515
+					//		json := make(map[string]interface{})
516
+					//		json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
517
+					//		json["state"] = 0
518
+					//		c.Data["json"] = json
519
+					//		c.ServeJSON()
520
+					//		break
521
+					//	case "3":
522
+					//		json := make(map[string]interface{})
523
+					//		json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
524
+					//		json["state"] = 0
525
+					//		c.Data["json"] = json
526
+					//		c.ServeJSON()
527
+					//		break
528
+					//	}
529
+					//
530
+					//	return
531
+					//
532
+					//
533
+					//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
534
+					//	return
535
+					//}
536
+					//
501
 				}
537
 				}
502
 
538
 
503
 			}
539
 			}
629
 
665
 
630
 					if filedRecordOne.IsShow == 1 {
666
 					if filedRecordOne.IsShow == 1 {
631
 						schedule.DialysisMachineName = so.DialysisDialyszers
667
 						schedule.DialysisMachineName = so.DialysisDialyszers
632
-						//service.UpdateSchDName(schedule)
633
 					}
668
 					}
634
-					if filedRecordTwo.IsShow == 1 {
635
-						schedule.DialysisMachineName = so.DialysisIrrigation
636
-						//service.UpdateSchDName(schedule)
669
+					if filedRecordThree.IsShow == 1 {
670
+						if len(schedule.DialysisMachineName) > 0 {
671
+							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
672
+
673
+						} else {
674
+							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
675
+
676
+						}
637
 					}
677
 					}
678
+					if filedRecordTwo.IsShow == 1 {
679
+						if len(schedule.DialysisMachineName) > 0 {
680
+							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
638
 
681
 
639
-					if filedRecordThree.IsShow == 1 {
640
-						schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
641
-						//service.UpdateSchDName(schedule)
682
+						} else {
683
+							schedule.DialysisMachineName = so.DialysisIrrigation
684
+
685
+						}
642
 					}
686
 					}
643
 
687
 
644
 					service.SaveSch(schedule)
688
 					service.SaveSch(schedule)
645
-
646
 				} else { //新的排班信息
689
 				} else { //新的排班信息
690
+
647
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
691
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
648
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
692
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
649
 						return
693
 						return
663
 						return
707
 						return
664
 					}
708
 					}
665
 					schedule.ScheduleDate = theTime.Unix()
709
 					schedule.ScheduleDate = theTime.Unix()
710
+
666
 					timeNow := time.Now().Format("2006-01-02")
711
 					timeNow := time.Now().Format("2006-01-02")
667
 					if timeNow > scheduleDate {
712
 					if timeNow > scheduleDate {
668
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
713
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
751
 
796
 
752
 					if filedRecordOne.IsShow == 1 {
797
 					if filedRecordOne.IsShow == 1 {
753
 						schedule.DialysisMachineName = so.DialysisDialyszers
798
 						schedule.DialysisMachineName = so.DialysisDialyszers
754
-						//service.UpdateSchDName(schedule)
755
 					}
799
 					}
756
-					if filedRecordTwo.IsShow == 1 {
757
-						schedule.DialysisMachineName = so.DialysisIrrigation
758
-						//service.UpdateSchDName(schedule)
759
-					}
760
-
761
 					if filedRecordThree.IsShow == 1 {
800
 					if filedRecordThree.IsShow == 1 {
762
-						schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
763
-						//service.UpdateSchDName(schedule)
801
+						if len(schedule.DialysisMachineName) > 0 {
802
+							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
803
+
804
+						} else {
805
+							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
806
+
807
+						}
764
 					}
808
 					}
809
+					if filedRecordTwo.IsShow == 1 {
810
+						if len(schedule.DialysisMachineName) > 0 {
811
+							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
765
 
812
 
766
-					service.CreateSchedule(&schedule)
813
+						} else {
814
+							schedule.DialysisMachineName = so.DialysisIrrigation
767
 
815
 
816
+						}
817
+					}
818
+
819
+					daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
820
+					if daySchedule.ID > 0 {
821
+						daySchedule.ModeId = schedule.ModeId
822
+						daySchedule.ScheduleType = schedule.ScheduleType
823
+						daySchedule.PartitionId = schedule.PartitionId
824
+						daySchedule.BedId = schedule.BedId
825
+						daySchedule.DialysisMachineName = schedule.DialysisMachineName
826
+						service.SaveSch(daySchedule)
827
+					} else {
828
+						service.CreateSchedule(&schedule)
829
+					}
768
 				}
830
 				}
769
 				c.ServeSuccessJSON(map[string]interface{}{
831
 				c.ServeSuccessJSON(map[string]interface{}{
770
 					"msg": "保存成功",
832
 					"msg": "保存成功",
919
 func (c *ScheduleApiController) GetWeekPanels() {
981
 func (c *ScheduleApiController) GetWeekPanels() {
920
 
982
 
921
 	data, _ := c.GetInt64("data", 1)
983
 	data, _ := c.GetInt64("data", 1)
922
-	patitionId, _ := c.GetInt64("patitionid")
984
+	patitionIdStr := c.GetString("patitionid")
985
+	var ids []string
986
+	if len(patitionIdStr) > 0 {
987
+		ids = strings.Split(patitionIdStr, ",")
988
+	}
989
+
923
 	adminInfo := c.GetAdminUserInfo()
990
 	adminInfo := c.GetAdminUserInfo()
924
 	thisTime := time.Now()
991
 	thisTime := time.Now()
925
 	year, monthTime, day := thisTime.Date()
992
 	year, monthTime, day := thisTime.Date()
926
 	month := int(monthTime)
993
 	month := int(monthTime)
927
 	_, theWeek := thisTime.ISOWeek()
994
 	_, theWeek := thisTime.ISOWeek()
995
+
996
+	lastWeek := thisTime.AddDate(0, 0, -7)
997
+
998
+	nextWeek := thisTime.AddDate(0, 0, 7)
999
+	nextSecWeek := thisTime.AddDate(0, 0, 14)
1000
+
1001
+	_, theLastWeek := lastWeek.ISOWeek()
1002
+	_, theNextWeek := nextWeek.ISOWeek()
1003
+	_, theNextSecWeek := nextSecWeek.ISOWeek()
1004
+
928
 	weekDay := int(thisTime.Weekday())
1005
 	weekDay := int(thisTime.Weekday())
929
 	if weekDay == 0 {
1006
 	if weekDay == 0 {
930
 		weekDay = 7
1007
 		weekDay = 7
941
 	}
1018
 	}
942
 
1019
 
943
 	returnData := map[string]interface{}{
1020
 	returnData := map[string]interface{}{
944
-		"year":     year,
945
-		"month":    month,
946
-		"day":      day,
947
-		"theWeek":  theWeek,
948
-		"weekDay":  weekDay,
949
-		"weekDays": weekDays,
1021
+		"year":           year,
1022
+		"month":          month,
1023
+		"day":            day,
1024
+		"theWeek":        theWeek,
1025
+		"theNextWeek":    theNextWeek,
1026
+		"theNextSecWeek": theNextSecWeek,
1027
+		"theLastWeek":    theLastWeek,
1028
+		"weekDay":        weekDay,
1029
+		"weekDays":       weekDays,
950
 	}
1030
 	}
951
 
1031
 
952
 	if data == 1 {
1032
 	if data == 1 {
953
-		partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, patitionId)
1033
+		fmt.Println(ids)
1034
+
1035
+		partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
1036
+		fmt.Println("````~~")
1037
+		fmt.Println(partitions)
1038
+
954
 		returnData["partitions"] = partitions
1039
 		returnData["partitions"] = partitions
955
 	}
1040
 	}
956
 
1041
 
1184
 
1269
 
1185
 	if filedRecordOne.IsShow == 1 {
1270
 	if filedRecordOne.IsShow == 1 {
1186
 		schedule.DialysisMachineName = so.DialysisDialyszers
1271
 		schedule.DialysisMachineName = so.DialysisDialyszers
1187
-		//service.UpdateSchDName(schedule)
1188
 	}
1272
 	}
1189
-	if filedRecordTwo.IsShow == 1 {
1190
-		schedule.DialysisMachineName = so.DialysisIrrigation
1191
-		//service.UpdateSchDName(schedule)
1273
+	if filedRecordThree.IsShow == 1 {
1274
+		if len(schedule.DialysisMachineName) > 0 {
1275
+			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1276
+
1277
+		} else {
1278
+			schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1279
+
1280
+		}
1192
 	}
1281
 	}
1282
+	if filedRecordTwo.IsShow == 1 {
1283
+		if len(schedule.DialysisMachineName) > 0 {
1284
+			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1193
 
1285
 
1194
-	if filedRecordThree.IsShow == 1 {
1195
-		schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1196
-		//service.UpdateSchDName(schedule)
1286
+		} else {
1287
+			schedule.DialysisMachineName = so.DialysisIrrigation
1288
+
1289
+		}
1197
 	}
1290
 	}
1291
+
1198
 	bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
1292
 	bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
1199
 	if bed == nil {
1293
 	if bed == nil {
1200
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
1294
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
1383
 	if changeAction == "change_mode" {
1477
 	if changeAction == "change_mode" {
1384
 		if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
1478
 		if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
1385
 			utils.ErrorLog("mode_id")
1479
 			utils.ErrorLog("mode_id")
1386
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1480
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
1387
 			return
1481
 			return
1388
 		}
1482
 		}
1389
 		modeId := int64(dataBody["mode_id"].(float64))
1483
 		modeId := int64(dataBody["mode_id"].(float64))
1390
 		if modeId < 1 {
1484
 		if modeId < 1 {
1391
 			utils.ErrorLog("modeId < 1")
1485
 			utils.ErrorLog("modeId < 1")
1392
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1486
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
1393
 			return
1487
 			return
1394
 		}
1488
 		}
1395
 		schedule.ModeId = modeId
1489
 		schedule.ModeId = modeId
1401
 
1495
 
1402
 		if filedRecordOne.IsShow == 1 {
1496
 		if filedRecordOne.IsShow == 1 {
1403
 			schedule.DialysisMachineName = so.DialysisDialyszers
1497
 			schedule.DialysisMachineName = so.DialysisDialyszers
1404
-			//service.UpdateSchDName(schedule)
1405
 		}
1498
 		}
1406
-		if filedRecordTwo.IsShow == 1 {
1407
-			schedule.DialysisMachineName = so.DialysisIrrigation
1408
-			//service.UpdateSchDName(schedule)
1499
+		if filedRecordThree.IsShow == 1 {
1500
+			if len(schedule.DialysisMachineName) > 0 {
1501
+				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1502
+
1503
+			} else {
1504
+				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1505
+
1506
+			}
1409
 		}
1507
 		}
1508
+		if filedRecordTwo.IsShow == 1 {
1509
+			if len(schedule.DialysisMachineName) > 0 {
1510
+				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1410
 
1511
 
1411
-		if filedRecordThree.IsShow == 1 {
1412
-			schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1413
-			//service.UpdateSchDName(schedule)
1512
+			} else {
1513
+				schedule.DialysisMachineName = so.DialysisIrrigation
1514
+
1515
+			}
1414
 		}
1516
 		}
1415
 
1517
 
1416
 		order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
1518
 		order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
2321
 
2423
 
2322
 			if filedRecordOne.IsShow == 1 {
2424
 			if filedRecordOne.IsShow == 1 {
2323
 				sch.DialysisMachineName = so.DialysisDialyszers
2425
 				sch.DialysisMachineName = so.DialysisDialyszers
2324
-				//service.UpdateSchDName(schedule)
2325
 			}
2426
 			}
2326
-			if filedRecordTwo.IsShow == 1 {
2327
-				sch.DialysisMachineName = so.DialysisIrrigation
2328
-				//service.UpdateSchDName(schedule)
2427
+			if filedRecordThree.IsShow == 1 {
2428
+				if len(sch.DialysisMachineName) > 0 {
2429
+					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
2430
+
2431
+				} else {
2432
+					sch.DialysisMachineName = so.DialyzerPerfusionApparatus
2433
+
2434
+				}
2329
 			}
2435
 			}
2436
+			if filedRecordTwo.IsShow == 1 {
2437
+				if len(sch.DialysisMachineName) > 0 {
2438
+					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
2330
 
2439
 
2331
-			if filedRecordThree.IsShow == 1 {
2332
-				sch.DialysisMachineName = so.DialyzerPerfusionApparatus
2333
-				//service.UpdateSchDName(schedule)
2440
+				} else {
2441
+					sch.DialysisMachineName = so.DialysisIrrigation
2442
+
2443
+				}
2334
 			}
2444
 			}
2445
+
2335
 			schedules = append(schedules, &sch)
2446
 			schedules = append(schedules, &sch)
2336
 		}
2447
 		}
2337
 
2448
 
2785
 				sch.Weekday = int8(schedule_week)
2896
 				sch.Weekday = int8(schedule_week)
2786
 
2897
 
2787
 			}
2898
 			}
2788
-
2899
+			treat_mode, _ := schMapM["treat_mode"].(string)
2900
+			treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
2789
 			sch.CreateTime = time.Now().Unix()
2901
 			sch.CreateTime = time.Now().Unix()
2790
 			sch.ModifyTime = time.Now().Unix()
2902
 			sch.ModifyTime = time.Now().Unix()
2791
-			sch.TreatMode = 1
2903
+			sch.TreatMode = treat_mode_int
2792
 			sch.Status = 1
2904
 			sch.Status = 1
2793
 			sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
2905
 			sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
2794
 			sch.IsExport = 1
2906
 			sch.IsExport = 1
2797
 
2909
 
2798
 		errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
2910
 		errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
2799
 
2911
 
2912
+		//for _, item := range schedules {
2913
+		//
2914
+		//}
2915
+
2800
 		if len(schedules) > 0 {
2916
 		if len(schedules) > 0 {
2801
 			err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
2917
 			err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
2802
 			if err == nil {
2918
 			if err == nil {
2803
 				for _, item := range schedules {
2919
 				for _, item := range schedules {
2804
 					service.CreateScheduleTemplate(item)
2920
 					service.CreateScheduleTemplate(item)
2805
 				}
2921
 				}
2806
-				//查询已经转出或者死亡的患者
2807
-				patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
2808
-				for _, it := range patientList {
2809
-					timeStr := time.Now().Format("2006-01-02")
2810
-					timeLayout := "2006-01-02 15:04:05"
2811
-					timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
2812
-					timenow := timeStringToTime.Unix()
2813
-					service.UpdateScheduleByDeathTime(it.ID, timenow)
2814
-					service.UpdateScheduleItemByPatientId(it.ID)
2815
-				}
2922
+				////查询已经转出或者死亡的患者
2923
+				//patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
2924
+				//for _, it := range patientList {
2925
+				//	timeStr := time.Now().Format("2006-01-02")
2926
+				//	timeLayout := "2006-01-02 15:04:05"
2927
+				//	timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
2928
+				//	timenow := timeStringToTime.Unix()
2929
+				//	service.UpdateScheduleByDeathTime(it.ID, timenow)
2930
+				//	service.UpdateScheduleItemByPatientId(it.ID)
2931
+				//}
2816
 				log := models.ExportLog{
2932
 				log := models.ExportLog{
2817
 					LogType:    3,
2933
 					LogType:    3,
2818
 					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
2934
 					UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
2883
 	thisTime := time.Now()
2999
 	thisTime := time.Now()
2884
 	thisTime1 := time.Now()
3000
 	thisTime1 := time.Now()
2885
 	thisTime2 := time.Now()
3001
 	thisTime2 := time.Now()
3002
+	thisTime3 := time.Now()
3003
+	thisTime4 := time.Now()
2886
 
3004
 
2887
 	thisTime1 = thisTime1.AddDate(0, 0, 7)
3005
 	thisTime1 = thisTime1.AddDate(0, 0, 7)
2888
 	thisTime2 = thisTime2.AddDate(0, 0, 14)
3006
 	thisTime2 = thisTime2.AddDate(0, 0, 14)
3007
+	thisTime3 = thisTime3.AddDate(0, 0, 21)
3008
+	thisTime4 = thisTime4.AddDate(0, 0, 28)
2889
 
3009
 
2890
 	weekDay := int(thisTime.Weekday())
3010
 	weekDay := int(thisTime.Weekday())
2891
 	if weekDay == 0 {
3011
 	if weekDay == 0 {
2921
 		days = append(days, theDay.Format("2006-01-02"))
3041
 		days = append(days, theDay.Format("2006-01-02"))
2922
 	}
3042
 	}
2923
 
3043
 
3044
+	weekDay3 := int(thisTime3.Weekday())
3045
+	if weekDay3 == 0 {
3046
+		weekDay3 = 7
3047
+	}
3048
+	weekEnd3 := 7 - weekDay3
3049
+	weekStart3 := weekEnd3 - 6
3050
+	for index := weekStart3; index <= weekEnd3; index++ {
3051
+		theDay := thisTime3.AddDate(0, 0, index)
3052
+		days = append(days, theDay.Format("2006-01-02"))
3053
+	}
3054
+
3055
+	weekDay4 := int(thisTime4.Weekday())
3056
+	if weekDay4 == 0 {
3057
+		weekDay4 = 7
3058
+	}
3059
+	weekEnd4 := 7 - weekDay4
3060
+	weekStart4 := weekEnd4 - 6
3061
+	for index := weekStart4; index <= weekEnd4; index++ {
3062
+		theDay := thisTime4.AddDate(0, 0, index)
3063
+		days = append(days, theDay.Format("2006-01-02"))
3064
+	}
3065
+
2924
 	c.ServeSuccessJSON(map[string]interface{}{
3066
 	c.ServeSuccessJSON(map[string]interface{}{
2925
 		"days": days,
3067
 		"days": days,
2926
 	})
3068
 	})
3135
 			CreatedTime:  time.Now().Unix(),
3277
 			CreatedTime:  time.Now().Unix(),
3136
 		}
3278
 		}
3137
 
3279
 
3280
+		so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
3281
+		filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
3282
+		filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
3283
+		filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
3284
+
3285
+		if filedRecordOne.IsShow == 1 {
3286
+			schedule.DialysisMachineName = so.DialysisDialyszers
3287
+		}
3288
+		if filedRecordThree.IsShow == 1 {
3289
+			if len(schedule.DialysisMachineName) > 0 {
3290
+				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3291
+
3292
+			} else {
3293
+				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
3294
+
3295
+			}
3296
+		}
3297
+		if filedRecordTwo.IsShow == 1 {
3298
+			if len(schedule.DialysisMachineName) > 0 {
3299
+				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3300
+
3301
+			} else {
3302
+				schedule.DialysisMachineName = so.DialysisIrrigation
3303
+
3304
+			}
3305
+		}
3306
+
3138
 		err = service.AddPatientSchedule(&schedule)
3307
 		err = service.AddPatientSchedule(&schedule)
3139
 
3308
 
3140
 	}
3309
 	}
3738
 
3907
 
3739
 	recordDateStr := time.Now().Format("2006-01-02")
3908
 	recordDateStr := time.Now().Format("2006-01-02")
3740
 	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3909
 	recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
3741
-
3742
 	nowtime := recordDate.Unix()
3910
 	nowtime := recordDate.Unix()
3743
 	fmt.Println("今日时间", nowtime)
3911
 	fmt.Println("今日时间", nowtime)
3744
 	fmt.Println("后期日期", copy_startime)
3912
 	fmt.Println("后期日期", copy_startime)
3752
 	if copy_startime > nowtime {
3920
 	if copy_startime > nowtime {
3753
 		//清空该时间段的所有排班数据
3921
 		//清空该时间段的所有排班数据
3754
 		service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
3922
 		service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
3755
-
3756
 		tuesday = copy_startime + 86400
3923
 		tuesday = copy_startime + 86400
3757
 		wednesday = copy_startime + 172800
3924
 		wednesday = copy_startime + 172800
3758
 		thursday = copy_startime + 259200
3925
 		thursday = copy_startime + 259200
3759
 		friday = copy_startime + 345600
3926
 		friday = copy_startime + 345600
3760
 		saturday = copy_startime + 432000
3927
 		saturday = copy_startime + 432000
3761
-
3762
 		for _, item := range list {
3928
 		for _, item := range list {
3763
 			if item.Weekday == 1 {
3929
 			if item.Weekday == 1 {
3764
 				item.ScheduleDate = copy_startime
3930
 				item.ScheduleDate = copy_startime
3786
 			number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
3952
 			number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
3787
 			item.ZoneId = number.ZoneID
3953
 			item.ZoneId = number.ZoneID
3788
 		}
3954
 		}
3789
-
3790
 		for _, item := range list {
3955
 		for _, item := range list {
3791
 			schedule := models.XtSchedule{
3956
 			schedule := models.XtSchedule{
3792
 				UserOrgId:    orgId,
3957
 				UserOrgId:    orgId,
3802
 				UpdatedTime:  0,
3967
 				UpdatedTime:  0,
3803
 			}
3968
 			}
3804
 
3969
 
3970
+			so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
3971
+			filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
3972
+			filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
3973
+			filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
3974
+
3975
+			if filedRecordOne.IsShow == 1 {
3976
+				schedule.DialysisMachineName = so.DialysisDialyszers
3977
+			}
3978
+			if filedRecordThree.IsShow == 1 {
3979
+				if len(schedule.DialysisMachineName) > 0 {
3980
+					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
3981
+
3982
+				} else {
3983
+					schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
3984
+
3985
+				}
3986
+			}
3987
+			if filedRecordTwo.IsShow == 1 {
3988
+				if len(schedule.DialysisMachineName) > 0 {
3989
+					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3990
+
3991
+				} else {
3992
+					schedule.DialysisMachineName = so.DialysisIrrigation
3993
+
3994
+				}
3995
+			}
3996
+
3805
 			service.CreatePatientSchedule(&schedule)
3997
 			service.CreatePatientSchedule(&schedule)
3806
 		}
3998
 		}
3807
 	}
3999
 	}
3848
 			number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
4040
 			number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
3849
 			item.ZoneId = number.ZoneID
4041
 			item.ZoneId = number.ZoneID
3850
 		}
4042
 		}
3851
-
3852
 		for _, item := range list {
4043
 		for _, item := range list {
3853
 			// 同步今日以后的数据
4044
 			// 同步今日以后的数据
3854
 			if item.ScheduleDate > nowtime {
4045
 			if item.ScheduleDate > nowtime {
3865
 					CreatedTime:  time.Now().Unix(),
4056
 					CreatedTime:  time.Now().Unix(),
3866
 					UpdatedTime:  0,
4057
 					UpdatedTime:  0,
3867
 				}
4058
 				}
4059
+				so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
4060
+				filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
4061
+				filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
4062
+				filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
4063
+
4064
+				if filedRecordOne.IsShow == 1 {
4065
+					schedule.DialysisMachineName = so.DialysisDialyszers
4066
+				}
4067
+				if filedRecordThree.IsShow == 1 {
4068
+					if len(schedule.DialysisMachineName) > 0 {
4069
+						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4070
+
4071
+					} else {
4072
+						schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
4073
+
4074
+					}
4075
+				}
4076
+				if filedRecordTwo.IsShow == 1 {
4077
+					if len(schedule.DialysisMachineName) > 0 {
4078
+						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
4079
+
4080
+					} else {
4081
+						schedule.DialysisMachineName = so.DialysisIrrigation
4082
+
4083
+					}
4084
+				}
3868
 				service.CreatePatientSchedule(&schedule)
4085
 				service.CreatePatientSchedule(&schedule)
3869
 			}
4086
 			}
3870
 		}
4087
 		}
3871
-
3872
 	}
4088
 	}
3873
 
4089
 
3874
 	returnData := make(map[string]interface{}, 0)
4090
 	returnData := make(map[string]interface{}, 0)

+ 26 - 7
controllers/schedule_template_api_controller.go View File

6
 	"XT_New/service"
6
 	"XT_New/service"
7
 	"encoding/json"
7
 	"encoding/json"
8
 	"fmt"
8
 	"fmt"
9
+	"strings"
9
 	"time"
10
 	"time"
10
 
11
 
11
 	"github.com/astaxie/beego"
12
 	"github.com/astaxie/beego"
53
 func (this *PatientScheduleTemplateAPIController) InitData() {
54
 func (this *PatientScheduleTemplateAPIController) InitData() {
54
 	adminUserInfo := this.GetAdminUserInfo()
55
 	adminUserInfo := this.GetAdminUserInfo()
55
 
56
 
57
+	patitionIdStr := this.GetString("patitionid")
58
+	var ids []string
59
+	if len(patitionIdStr) > 0 {
60
+		ids = strings.Split(patitionIdStr, ",")
61
+	}
62
+
56
 	mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
63
 	mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
57
 	if getModeErr != nil {
64
 	if getModeErr != nil {
58
 		this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr)
65
 		this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr)
77
 		}
84
 		}
78
 	}
85
 	}
79
 
86
 
80
-	deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId)
87
+	deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId, ids)
81
 
88
 
82
 	fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers)
89
 	fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers)
83
 	if getDeviceNumbersErr != nil {
90
 	if getDeviceNumbersErr != nil {
184
 	templateMode.Week = int64(week_time)
191
 	templateMode.Week = int64(week_time)
185
 
192
 
186
 	if mode != templateMode.Mode {
193
 	if mode != templateMode.Mode {
187
-		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下四周的排班
194
+		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2  则直接清除下四周的排班
188
 			templateMode.Mode = mode
195
 			templateMode.Mode = mode
189
 			templateMode.ExecuteTimes = 0
196
 			templateMode.ExecuteTimes = 0
190
 			templateMode.ModifyTime = time.Now().Unix()
197
 			templateMode.ModifyTime = time.Now().Unix()
210
 			templateMode.Mode = mode
217
 			templateMode.Mode = mode
211
 			templateMode.ExecuteTimes = 0
218
 			templateMode.ExecuteTimes = 0
212
 			templateMode.ModifyTime = time.Now().Unix()
219
 			templateMode.ModifyTime = time.Now().Unix()
213
-			updateErr := service.SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode)
220
+			updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
214
 			if updateErr != nil {
221
 			if updateErr != nil {
215
 				this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
222
 				this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
216
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
223
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
263
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
270
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
264
 				return
271
 				return
265
 			}
272
 			}
266
-		} else if templateMode.Mode == 2 && mode == 3 { // 2 -> 1 清除第二周模板item,清除第二周排班
273
+		} else if templateMode.Mode == 2 && mode == 3 { //
267
 			templateMode.Mode = mode
274
 			templateMode.Mode = mode
268
 			templateMode.ExecuteTimes = 0
275
 			templateMode.ExecuteTimes = 0
269
 			templateMode.ModifyTime = time.Now().Unix()
276
 			templateMode.ModifyTime = time.Now().Unix()
273
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
280
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
274
 				return
281
 				return
275
 			}
282
 			}
276
-		} else if templateMode.Mode == 2 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班
283
+		} else if templateMode.Mode == 2 && mode == 4 { //
277
 			templateMode.Mode = mode
284
 			templateMode.Mode = mode
278
 			templateMode.ExecuteTimes = 0
285
 			templateMode.ExecuteTimes = 0
279
 			templateMode.ModifyTime = time.Now().Unix()
286
 			templateMode.ModifyTime = time.Now().Unix()
384
 		}
391
 		}
385
 		templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
392
 		templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
386
 		//处理第几周数问题
393
 		//处理第几周数问题
387
-		if mode == 1 {
394
+		if mode == 0 {
395
+			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0)
396
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
397
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
398
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
399
+
400
+		} else if mode == 1 {
388
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
401
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
402
+			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
403
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
404
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
389
 
405
 
390
 		} else if mode == 2 {
406
 		} else if mode == 2 {
391
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
407
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
392
 			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
408
 			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
409
+			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
410
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
393
 
411
 
394
 		} else if mode == 3 {
412
 		} else if mode == 3 {
395
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
413
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
396
 			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
414
 			service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
397
 			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
415
 			service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
416
+			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
398
 
417
 
399
 		} else if mode == 4 {
418
 		} else if mode == 4 {
400
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
419
 			service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
593
 	//	}
612
 	//	}
594
 	//}
613
 	//}
595
 
614
 
596
-	updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems)
615
+	updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false)
597
 	if updateErr != nil {
616
 	if updateErr != nil {
598
 		this.ErrorLog("更新排班模板排班失败:%v", updateErr)
617
 		this.ErrorLog("更新排班模板排班失败:%v", updateErr)
599
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
618
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)

+ 3 - 0
enums/error_code.go View File

266
 	ErrorCodeCantDeleteScheduleBeforeNow = 40000001
266
 	ErrorCodeCantDeleteScheduleBeforeNow = 40000001
267
 
267
 
268
 	ErrorCodeSchedule = 50000000
268
 	ErrorCodeSchedule = 50000000
269
+
270
+	ErrorCodeParamWrongForSchMode = 40000002
269
 )
271
 )
270
 
272
 
271
 var ErrCodeMsgs = map[int]string{
273
 var ErrCodeMsgs = map[int]string{
518
 
520
 
519
 	ErrorCodeHisPatientNoRegException: "该患者尚未挂号,请先挂号",
521
 	ErrorCodeHisPatientNoRegException: "该患者尚未挂号,请先挂号",
520
 	ErrorCodeSchedule:                 "该班次该床位已有患者",
522
 	ErrorCodeSchedule:                 "该班次该床位已有患者",
523
+	ErrorCodeParamWrongForSchMode:     "透析模式不能为空",
521
 }
524
 }
522
 
525
 
523
 type SGJError struct {
526
 type SGJError struct {

+ 15 - 14
models/device_models.go View File

403
 }
403
 }
404
 
404
 
405
 type XtSchedule struct {
405
 type XtSchedule struct {
406
-	ID              int64                   `gorm:"column:id" json:"id" form:"id"`
407
-	UserOrgId       int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
408
-	PartitionId     int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
409
-	BedId           int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
410
-	PatientId       int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
411
-	ScheduleDate    int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
412
-	ScheduleType    int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
413
-	ScheduleWeek    int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
414
-	ModeId          int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
415
-	Status          int64                   `gorm:"column:status" json:"status" form:"status"`
416
-	CreatedTime     int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
417
-	UpdatedTime     int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
418
-	IsExport        int64                   `gorm:"column:is_export" json:"is_export" form:"is_export"`
419
-	LastAfterWeight AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
406
+	ID                  int64                   `gorm:"column:id" json:"id" form:"id"`
407
+	UserOrgId           int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
408
+	PartitionId         int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
409
+	BedId               int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
410
+	PatientId           int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
411
+	ScheduleDate        int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
412
+	ScheduleType        int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
413
+	ScheduleWeek        int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
414
+	ModeId              int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
415
+	Status              int64                   `gorm:"column:status" json:"status" form:"status"`
416
+	CreatedTime         int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
417
+	UpdatedTime         int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
418
+	IsExport            int64                   `gorm:"column:is_export" json:"is_export" form:"is_export"`
419
+	LastAfterWeight     AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
420
+	DialysisMachineName string                  `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
420
 }
421
 }
421
 
422
 
422
 func (XtSchedule) TableName() string {
423
 func (XtSchedule) TableName() string {

+ 4 - 6
models/patient_schedule_template_models.go View File

16
 }
16
 }
17
 
17
 
18
 type PatientScheduleTemplateId struct {
18
 type PatientScheduleTemplateId struct {
19
-	ID         int64 `gorm:"column:id" json:"id" form:"id"`
20
-	OrgID      int64 `gorm:"column:org_id" json:"-" form:"org_id"`
21
-	Status     int8  `gorm:"column:status" json:"-" form:"status"`
22
-	CreateTime int64 `gorm:"column:ctime" json:"-" form:"ctime"`
23
-	ModifyTime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
24
-	Week       int   `gorm:"column:week" json:"week" form:"week"`
19
+	ID     int64 `gorm:"column:id" json:"id" form:"id"`
20
+	OrgID  int64 `gorm:"column:org_id" json:"-" form:"org_id"`
21
+	Status int8  `gorm:"column:status" json:"-" form:"status"`
22
+	Week   int   `gorm:"column:week" json:"week" form:"week"`
25
 }
23
 }
26
 
24
 
27
 func (PatientScheduleTemplateId) TableName() string {
25
 func (PatientScheduleTemplateId) TableName() string {

+ 43 - 21
models/smart_sch.go View File

1
 package models
1
 package models
2
 
2
 
3
 type SmartSchPatient struct {
3
 type SmartSchPatient struct {
4
-	ID            int64            `gorm:"column:id" json:"id" form:"id"`
5
-	UserOrgId     int64            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
-	Name          string           `gorm:"column:name" json:"name" form:"name"`
4
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	Name       string `gorm:"column:name" json:"name" form:"name"`
7
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8
+
7
 	SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
9
 	SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
8
 }
10
 }
9
 
11
 
12
 }
14
 }
13
 
15
 
14
 type SmartSchTemplatePatient struct {
16
 type SmartSchTemplatePatient struct {
15
-	ID                          int64  `gorm:"column:id" json:"id" form:"id"`
16
-	UserOrgId                   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
17
-	Name                        string `gorm:"column:name" json:"name" form:"name"`
17
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
18
+	UserOrgId  int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
19
+	Name       string `gorm:"column:name" json:"name" form:"name"`
20
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
21
+
18
 	XtPatientScheduleTemplateId []*XtPatientScheduleTemplateId
22
 	XtPatientScheduleTemplateId []*XtPatientScheduleTemplateId
19
 }
23
 }
20
 
24
 
23
 }
27
 }
24
 
28
 
25
 type SmartSchedule struct {
29
 type SmartSchedule struct {
26
-	ID           int64        `gorm:"column:id" json:"id" form:"id"`
27
-	UserOrgId    int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
28
-	PartitionId  int64        `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
29
-	BedId        int64        `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
30
-	PatientId    int64        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
31
-	ScheduleDate int64        `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
32
-	ScheduleType int64        `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
33
-	ScheduleWeek int64        `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
34
-	ModeId       int64        `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
35
-	Status       int64        `gorm:"column:status" json:"status" form:"status"`
36
-	CreatedTime  int64        `gorm:"column:created_time" json:"created_time" form:"created_time"`
37
-	UpdatedTime  int64        `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
38
-	IsExport     int64        `gorm:"column:is_export" json:"is_export" form:"is_export"`
39
-	DeviceZone   DeviceZone   `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
40
-	DeviceNumber DeviceNumber `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
30
+	ID                 int64              `gorm:"column:id" json:"id" form:"id"`
31
+	UserOrgId          int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
+	PartitionId        int64              `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
33
+	BedId              int64              `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
34
+	PatientId          int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
35
+	ScheduleDate       int64              `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36
+	ScheduleType       int64              `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
37
+	ScheduleWeek       int64              `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
38
+	ModeId             int64              `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
39
+	Status             int64              `gorm:"column:status" json:"status" form:"status"`
40
+	CreatedTime        int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
41
+	UpdatedTime        int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
42
+	IsExport           int64              `gorm:"column:is_export" json:"is_export" form:"is_export"`
43
+	DeviceZone         DeviceZone         `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
44
+	DeviceNumber       DeviceNumber       `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
45
+	SmSchDialysisOrder SmSchDialysisOrder `json:"order" gorm:"foreignkey:BedId,PatientId,DialysisDate;AssociationForeignKey:BedId,PatientId,ScheduleDate;"`
41
 }
46
 }
42
 
47
 
43
 func (SmartSchedule) TableName() string {
48
 func (SmartSchedule) TableName() string {
77
 func (XtPatientScheduleTemplateItem) TableName() string {
82
 func (XtPatientScheduleTemplateItem) TableName() string {
78
 	return "xt_patient_schedule_template_item"
83
 	return "xt_patient_schedule_template_item"
79
 }
84
 }
85
+
86
+type SmSchDialysisOrder struct {
87
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
88
+	DialysisDate int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
89
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
90
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
91
+	Stage        int64  `gorm:"column:stage" json:"stage" form:"stage"`
92
+	Remark       string `gorm:"column:remark" json:"remark" form:"remark"`
93
+	BedId        int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
94
+	StartNurse   int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
95
+	FinishNurse  int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
96
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
97
+}
98
+
99
+func (SmSchDialysisOrder) TableName() string {
100
+	return "xt_dialysis_order"
101
+}

File diff suppressed because it is too large
+ 636 - 193
service/auto_create_week_schedules_service.go


+ 16 - 3
service/device_service.go View File

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

+ 9 - 8
service/mobile_dialysis_service.go View File

2642
 }
2642
 }
2643
 
2643
 
2644
 type VMGoodInfo struct {
2644
 type VMGoodInfo struct {
2645
-	ID                int64   `gorm:"column:id" json:"id"`
2646
-	SpecificationName string  `gorm:"column:specification_name" json:"specification_name"`
2647
-	GoodTypeId        int64   `gorm:"column:good_type_id" json:"good_type_id"`
2648
-	OrgId             int64   `gorm:"column:org_id" json:"org_id"`
2649
-	GoodName          string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
2650
-	GoodUnit          int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
2651
-	Total             float64 `gorm:"column:total" json:"total" form:"total"`
2652
-	PackingUnit       string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
2645
+	ID                     int64   `gorm:"column:id" json:"id"`
2646
+	SpecificationName      string  `gorm:"column:specification_name" json:"specification_name"`
2647
+	GoodTypeId             int64   `gorm:"column:good_type_id" json:"good_type_id"`
2648
+	OrgId                  int64   `gorm:"column:org_id" json:"org_id"`
2649
+	GoodName               string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
2650
+	GoodUnit               int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
2651
+	Total                  float64 `gorm:"column:total" json:"total" form:"total"`
2652
+	PackingUnit            string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
2653
+	MedicalInsuranceNumber string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
2653
 }
2654
 }
2654
 
2655
 
2655
 func (VMGoodInfo) TableName() string {
2656
 func (VMGoodInfo) TableName() string {

+ 76 - 38
service/patient_schedule_template_service.go View File

47
 	return &id, nil
47
 	return &id, nil
48
 }
48
 }
49
 
49
 
50
+type PatientsTwo struct {
51
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
52
+	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
53
+	UserId    int64  `gorm:"column:user_id" json:"user_id" form:"user_id"`
54
+	Name      string `gorm:"column:name" json:"name" form:"name"`
55
+}
56
+
57
+func (PatientsTwo) TableName() string {
58
+	return "xt_patients"
59
+}
60
+
50
 type PatientScheduleTemplateItemViewModel struct {
61
 type PatientScheduleTemplateItemViewModel struct {
51
 	models.PatientScheduleTemplateItem
62
 	models.PatientScheduleTemplateItem
52
 
63
 
53
-	Patient *models.Patients `gorm:"ForeignKey:PatientID" json:"patient"`
64
+	Patient               *PatientsTwo          `gorm:"ForeignKey:PatientID" json:"patient"`
65
+	DeviceNumberViewModel DeviceNumberViewModel `gorm:"ForeignKey:DeviceNumberID" json:"devices"`
54
 }
66
 }
55
 
67
 
56
 type PatientScheduleTemplateViewModel struct {
68
 type PatientScheduleTemplateViewModel struct {
72
 		Model(&PatientScheduleTemplateViewModel{}).
84
 		Model(&PatientScheduleTemplateViewModel{}).
73
 		Preload("Items", "org_id = ? AND status = 1", orgID).
85
 		Preload("Items", "org_id = ? AND status = 1", orgID).
74
 		Preload("Items.Patient", "user_org_id = ? AND status = 1", orgID).
86
 		Preload("Items.Patient", "user_org_id = ? AND status = 1", orgID).
87
+		Preload("Items.DeviceNumberViewModel.Zone", "status = 1").
75
 		Where("org_id = ? AND status = 1", orgID).
88
 		Where("org_id = ? AND status = 1", orgID).
76
 		Limit(4).
89
 		Limit(4).
77
 		Find(&vms).
90
 		Find(&vms).
117
 	Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
130
 	Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
118
 }
131
 }
119
 
132
 
120
-func GetScheduleValidDeviceNumbers(orgID int64) ([]*ScheduleDeviceNumberViewModel, error) {
121
-	var vms []*ScheduleDeviceNumberViewModel
122
-	err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1").Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
123
-	if err != nil {
124
-		return nil, err
133
+func GetScheduleValidDeviceNumbers(orgID int64, ids []string) ([]*ScheduleDeviceNumberViewModel, error) {
134
+	if len(ids) == 0 {
135
+		var vms []*ScheduleDeviceNumberViewModel
136
+		err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1").Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
137
+		if err != nil {
138
+			return nil, err
139
+		}
140
+		return vms, nil
141
+
142
+	} else {
143
+		var vms []*ScheduleDeviceNumberViewModel
144
+		err := readDb.Model(&ScheduleDeviceNumberViewModel{}).Preload("Zone", "status = 1 AND id in (?)", ids).Where("org_id = ? AND status = 1", orgID).Order("zone_id asc").Order("id asc").Find(&vms).Error
145
+		if err != nil {
146
+			return nil, err
147
+		}
148
+		return vms, nil
149
+
125
 	}
150
 	}
126
-	return vms, nil
151
+
127
 }
152
 }
128
 
153
 
129
 // 创建两个默认模板
154
 // 创建两个默认模板
130
 func CreateTwoPatientScheduleTemplates(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
155
 func CreateTwoPatientScheduleTemplates(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
131
-	now := time.Now().Unix()
132
 	firstTemp := models.PatientScheduleTemplateId{}
156
 	firstTemp := models.PatientScheduleTemplateId{}
133
 	firstTemp.OrgID = orgID
157
 	firstTemp.OrgID = orgID
134
 	firstTemp.Status = 1
158
 	firstTemp.Status = 1
135
-	firstTemp.CreateTime = now
136
-	firstTemp.ModifyTime = now
137
 
159
 
138
 	secondTemp := models.PatientScheduleTemplateId{}
160
 	secondTemp := models.PatientScheduleTemplateId{}
139
 	secondTemp.OrgID = orgID
161
 	secondTemp.OrgID = orgID
140
 	secondTemp.Status = 1
162
 	secondTemp.Status = 1
141
-	secondTemp.CreateTime = now
142
-	secondTemp.ModifyTime = now
143
 
163
 
144
 	thirdTemp := models.PatientScheduleTemplateId{}
164
 	thirdTemp := models.PatientScheduleTemplateId{}
145
 	thirdTemp.OrgID = orgID
165
 	thirdTemp.OrgID = orgID
146
 	thirdTemp.Status = 1
166
 	thirdTemp.Status = 1
147
-	thirdTemp.CreateTime = now
148
-	thirdTemp.ModifyTime = now
149
 
167
 
150
 	fourTemp := models.PatientScheduleTemplateId{}
168
 	fourTemp := models.PatientScheduleTemplateId{}
151
 	fourTemp.OrgID = orgID
169
 	fourTemp.OrgID = orgID
152
 	fourTemp.Status = 1
170
 	fourTemp.Status = 1
153
-	fourTemp.CreateTime = now
154
-	fourTemp.ModifyTime = now
155
 
171
 
156
 	tx := writeDb.Begin()
172
 	tx := writeDb.Begin()
157
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&firstTemp).Error; err != nil {
173
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&firstTemp).Error; err != nil {
194
 }
210
 }
195
 
211
 
196
 func CreatePatientScheduleTemplate(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
212
 func CreatePatientScheduleTemplate(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
197
-	now := time.Now().Unix()
198
 	temp := models.PatientScheduleTemplateId{}
213
 	temp := models.PatientScheduleTemplateId{}
199
 	temp.OrgID = orgID
214
 	temp.OrgID = orgID
200
 	temp.Status = 1
215
 	temp.Status = 1
201
-	temp.CreateTime = now
202
-	temp.ModifyTime = now
203
 	tx := writeDb.Begin()
216
 	tx := writeDb.Begin()
204
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&temp).Error; err != nil {
217
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&temp).Error; err != nil {
205
 		tx.Rollback()
218
 		tx.Rollback()
209
 	thirdTemp := models.PatientScheduleTemplateId{}
222
 	thirdTemp := models.PatientScheduleTemplateId{}
210
 	thirdTemp.OrgID = orgID
223
 	thirdTemp.OrgID = orgID
211
 	thirdTemp.Status = 1
224
 	thirdTemp.Status = 1
212
-	thirdTemp.CreateTime = now
213
-	thirdTemp.ModifyTime = now
214
 
225
 
215
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
226
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
216
 		tx.Rollback()
227
 		tx.Rollback()
220
 	fourTemp := models.PatientScheduleTemplateId{}
231
 	fourTemp := models.PatientScheduleTemplateId{}
221
 	fourTemp.OrgID = orgID
232
 	fourTemp.OrgID = orgID
222
 	fourTemp.Status = 1
233
 	fourTemp.Status = 1
223
-	fourTemp.CreateTime = now
224
-	fourTemp.ModifyTime = now
225
 
234
 
226
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
235
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
227
 		tx.Rollback()
236
 		tx.Rollback()
244
 	return &vm, &vm3, &vm4, nil
253
 	return &vm, &vm3, &vm4, nil
245
 }
254
 }
246
 func CreatePatientScheduleTemplateTwo(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
255
 func CreatePatientScheduleTemplateTwo(orgID int64) (*PatientScheduleTemplateViewModel, *PatientScheduleTemplateViewModel, error) {
247
-	now := time.Now().Unix()
248
 
256
 
249
 	tx := writeDb.Begin()
257
 	tx := writeDb.Begin()
250
 
258
 
251
 	thirdTemp := models.PatientScheduleTemplateId{}
259
 	thirdTemp := models.PatientScheduleTemplateId{}
252
 	thirdTemp.OrgID = orgID
260
 	thirdTemp.OrgID = orgID
253
 	thirdTemp.Status = 1
261
 	thirdTemp.Status = 1
254
-	thirdTemp.CreateTime = now
255
-	thirdTemp.ModifyTime = now
256
 
262
 
257
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
263
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&thirdTemp).Error; err != nil {
258
 		tx.Rollback()
264
 		tx.Rollback()
262
 	fourTemp := models.PatientScheduleTemplateId{}
268
 	fourTemp := models.PatientScheduleTemplateId{}
263
 	fourTemp.OrgID = orgID
269
 	fourTemp.OrgID = orgID
264
 	fourTemp.Status = 1
270
 	fourTemp.Status = 1
265
-	fourTemp.CreateTime = now
266
-	fourTemp.ModifyTime = now
267
 
271
 
268
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
272
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
269
 		tx.Rollback()
273
 		tx.Rollback()
282
 	return &vm3, &vm4, nil
286
 	return &vm3, &vm4, nil
283
 }
287
 }
284
 func CreatePatientScheduleTemplateThree(orgID int64) (*PatientScheduleTemplateViewModel, error) {
288
 func CreatePatientScheduleTemplateThree(orgID int64) (*PatientScheduleTemplateViewModel, error) {
285
-	now := time.Now().Unix()
286
 	tx := writeDb.Begin()
289
 	tx := writeDb.Begin()
287
 	fourTemp := models.PatientScheduleTemplateId{}
290
 	fourTemp := models.PatientScheduleTemplateId{}
288
 	fourTemp.OrgID = orgID
291
 	fourTemp.OrgID = orgID
289
 	fourTemp.Status = 1
292
 	fourTemp.Status = 1
290
-	fourTemp.CreateTime = now
291
-	fourTemp.ModifyTime = now
292
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
293
 	if err := tx.Model(&models.PatientScheduleTemplateId{}).Create(&fourTemp).Error; err != nil {
293
 		tx.Rollback()
294
 		tx.Rollback()
294
 		return nil, err
295
 		return nil, err
302
 }
303
 }
303
 
304
 
304
 type PatientScheduleTemplatePatientVM struct {
305
 type PatientScheduleTemplatePatientVM struct {
305
-	ID   int64  `gorm:"column:id" json:"id" form:"id"`
306
-	Name string `gorm:"column:name" json:"name" form:"name"`
306
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
307
+	Name       string `gorm:"column:name" json:"name" form:"name"`
308
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
307
 
309
 
308
 	Contagions []*PatientScheduleContagion `gorm:"ForeignKey:PatientID" json:"contagions"`
310
 	Contagions []*PatientScheduleContagion `gorm:"ForeignKey:PatientID" json:"contagions"`
309
 }
311
 }
313
 }
315
 }
314
 
316
 
315
 type PatientScheduleContagion struct {
317
 type PatientScheduleContagion struct {
316
-	ID        int64 `gorm:"column:id" json:"id" form:"id"`
317
-	PatientID int64 `gorm:"column:patient_id" json:"-"`
318
-	DiseaseID int64 `gorm:"column:disease_id" json:"disease_id" form:"disease_id"`
318
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
319
+	PatientID  int64  `gorm:"column:patient_id" json:"-"`
320
+	DiseaseID  int64  `gorm:"column:disease_id" json:"disease_id" form:"disease_id"`
321
+	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
319
 }
322
 }
320
 
323
 
321
 func (PatientScheduleContagion) TableName() string {
324
 func (PatientScheduleContagion) TableName() string {
346
 	now := time.Now()
349
 	now := time.Now()
347
 	tx := writeDb.Begin()
350
 	tx := writeDb.Begin()
348
 
351
 
352
+	readDb.Model(&models.XtPatientScheduleTemplateItem{}).Where("template_id = ? AND weekday = ? AND patient_id = ?", template_id)
353
+
349
 	// 批量插入 add template item
354
 	// 批量插入 add template item
350
 	if len(addTemplateItems) > 0 {
355
 	if len(addTemplateItems) > 0 {
356
+
351
 		// utils.TraceLog("addTemplateItems len: %v", len(addTemplateItems))
357
 		// utils.TraceLog("addTemplateItems len: %v", len(addTemplateItems))
352
 		valueStrs := make([]string, 0, len(addTemplateItems))
358
 		valueStrs := make([]string, 0, len(addTemplateItems))
353
 		values := make([]interface{}, 0, len(addTemplateItems)*10)
359
 		values := make([]interface{}, 0, len(addTemplateItems)*10)
354
 		for _, item := range addTemplateItems {
360
 		for _, item := range addTemplateItems {
361
+			var pst []models.XtPatientScheduleTemplateItem
362
+			readDb.Model(&models.XtPatientScheduleTemplateItem{}).Where("template_id = ? AND weekday = ? AND patient_id = ? AND status = 1", template_id, item.Weekday, item.PatientID).Find(&pst)
363
+			for _, item := range pst {
364
+				item.Status = 0
365
+				writeDb.Save(item)
366
+			}
355
 			valueStrs = append(valueStrs, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
367
 			valueStrs = append(valueStrs, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
356
 			values = append(values, orgID)
368
 			values = append(values, orgID)
357
 			values = append(values, template_id)
369
 			values = append(values, template_id)
585
 	return nil
597
 	return nil
586
 }
598
 }
587
 
599
 
588
-// 1 -> 2 清除第二周排班
589
-func SavePatientScheduleTemplateModeAndClearNextSecondWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
600
+// 1 -> 3 清除第二周排班
601
+func SavePatientScheduleTemplateModeAndClearNextThirfWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
602
+	tx := writeDb.Begin()
603
+	saveErr := tx.Save(templateMode).Error
604
+	if saveErr != nil {
605
+		tx.Rollback()
606
+		return saveErr
607
+	}
608
+
609
+	now := time.Now()
610
+	nextSecWeek := now.AddDate(0, 0, 21)
611
+	nextSecMonday, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
612
+
613
+	//tx.Model(&models.PatientScheduleTemplateId{}).Where("user_org_id = ? AND status = 1", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
614
+
615
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextSecMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
616
+	if disableErr != nil {
617
+		tx.Rollback()
618
+		return disableErr
619
+	}
620
+
621
+	tx.Commit()
622
+	return nil
623
+}
624
+
625
+// 1 -> 4 清除第二周排班
626
+func SavePatientScheduleTemplateModeAndClearNextFourWeekSchedules(templateMode *models.PatientScheduleTemplateMode) error {
590
 	tx := writeDb.Begin()
627
 	tx := writeDb.Begin()
591
 	saveErr := tx.Save(templateMode).Error
628
 	saveErr := tx.Save(templateMode).Error
592
 	if saveErr != nil {
629
 	if saveErr != nil {
609
 	tx.Commit()
646
 	tx.Commit()
610
 	return nil
647
 	return nil
611
 }
648
 }
649
+
612
 func SaveTemplateMode(templateMode *models.PatientScheduleTemplateMode) error {
650
 func SaveTemplateMode(templateMode *models.PatientScheduleTemplateMode) error {
613
 	err := writeDb.Model(&models.PatientScheduleTemplateMode{}).Where("id = ? AND status = 1", templateMode.ID).Updates(map[string]interface{}{"mode": templateMode.Mode, "mtime": templateMode.ModifyTime}).Error
651
 	err := writeDb.Model(&models.PatientScheduleTemplateMode{}).Where("id = ? AND status = 1", templateMode.ID).Updates(map[string]interface{}{"mode": templateMode.Mode, "mtime": templateMode.ModifyTime}).Error
614
 	return err
652
 	return err

+ 17 - 1
service/patient_service.go View File

1907
 }
1907
 }
1908
 
1908
 
1909
 func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
1909
 func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
1910
-	err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date>?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
1910
+	err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date > ?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
1911
 	return err
1911
 	return err
1912
 }
1912
 }
1913
 
1913
 
2675
 	err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
2675
 	err = db.Count(&total).Offset(offset).Limit(limit).Find(&solution).Order("created_time desc").Error
2676
 	return solution, total, err
2676
 	return solution, total, err
2677
 }
2677
 }
2678
+
2679
+func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64) ([]Schedule, error) {
2680
+	var record []Schedule
2681
+	loc, _ := time.LoadLocation("Local")
2682
+	date, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
2683
+
2684
+	err := readDb.Model(&Schedule{}).Where("status = 1 AND schedule_date >= ? AND patient_id = ? AND user_org_id = ? AND mode_id= ?", date, patient_id, org_id, mode_id).Find(&record).Error
2685
+	if err != nil {
2686
+		if err == gorm.ErrRecordNotFound {
2687
+			return nil, nil
2688
+		} else {
2689
+			return nil, err
2690
+		}
2691
+	}
2692
+	return record, nil
2693
+}

+ 9 - 9
service/schedule_service.go View File

18
 	return
18
 	return
19
 }
19
 }
20
 
20
 
21
-func GetSchedulePartitionPanelOne(orgID int64, partionId int64) (partitions []*models.Partition, err error) {
21
+func GetSchedulePartitionPanelOne(orgID int64, partionId []string) (partitions []*models.Partition, err error) {
22
 
22
 
23
-	if partionId > 0 {
24
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id = ?", orgID, partionId).Where("org_id=? and status=1 and id = ?", orgID, partionId).Find(&partitions).Error
25
-	}
26
-	if partionId == 0 {
27
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
28
-	}
23
+	//if len(partionId) > 0 {
24
+	//	err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id in (?)", orgID, partionId).Where("org_id=? and status=1 and id  ?", orgID, partionId).Find(&partitions).Error
25
+	//}
26
+	//if len(partionId) == 0 {
27
+	err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
28
+	//}
29
 
29
 
30
 	return
30
 	return
31
 }
31
 }
306
 	tempPatientIDTwo = schtwo.PatientId
306
 	tempPatientIDTwo = schtwo.PatientId
307
 	schone.PatientId = tempPatientIDTwo
307
 	schone.PatientId = tempPatientIDTwo
308
 	schtwo.PatientId = tempPatientID
308
 	schtwo.PatientId = tempPatientID
309
-	utx.Save(schone)
310
-	utx.Save(schtwo)
309
+	utx.Save(&schone)
310
+	utx.Save(&schtwo)
311
 
311
 
312
 }
312
 }
313
 
313
 

+ 6 - 1
service/smart_sch.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"XT_New/models"
4
 	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
5
 	"time"
6
 	"time"
6
 )
7
 )
7
 
8
 
26
 		weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
27
 		weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
27
 		readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
28
 		readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
28
 			Preload("DeviceZone", "status = 1").
29
 			Preload("DeviceZone", "status = 1").
30
+			Preload("SmSchDialysisOrder", "status = 1").
29
 			Preload("DeviceNumber", "status = 1").Find(&sch)
31
 			Preload("DeviceNumber", "status = 1").Find(&sch)
30
 		item.SmartSchedule = sch
32
 		item.SmartSchedule = sch
31
 	}
33
 	}
79
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
81
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
80
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
82
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
81
 		Preload("DeviceZone", "status = 1").
83
 		Preload("DeviceZone", "status = 1").
84
+		Preload("SmSchDialysisOrder", "status = 1").
82
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
85
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
83
 	return
86
 	return
84
 }
87
 }
85
 
88
 
86
 func GetSmartSchTemplatePatientByID(orgID int64, patient_id int64, count int) (schs []*models.XtPatientScheduleTemplateId, err error) {
89
 func GetSmartSchTemplatePatientByID(orgID int64, patient_id int64, count int) (schs []*models.XtPatientScheduleTemplateId, err error) {
87
-	err = readDb.Model(&models.XtPatientScheduleTemplateId{}).Preload("XtPatientScheduleTemplateItem", "status=1 AND patient_id = ?", patient_id).Where("org_id = ? AND status = 1", orgID).Limit(count).Find(&schs).Error
90
+	err = readDb.Model(&models.XtPatientScheduleTemplateId{}).Preload("XtPatientScheduleTemplateItem", func(db *gorm.DB) *gorm.DB {
91
+		return db.Where("status = 1 AND patient_id = ?", patient_id).Order("weekday")
92
+	}).Where("org_id = ? AND status = 1", orgID).Limit(count).Find(&schs).Error
88
 	for _, items := range schs {
93
 	for _, items := range schs {
89
 		for _, subItems := range items.XtPatientScheduleTemplateItem {
94
 		for _, subItems := range items.XtPatientScheduleTemplateItem {
90
 			number, _ := GetBedNumberById(subItems.DeviceNumberId, subItems.OrgId)
95
 			number, _ := GetBedNumberById(subItems.DeviceNumberId, subItems.OrgId)

+ 1 - 0
utils/tools.go View File

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