test_user hace 1 año
padre
commit
7f8984665b

+ 2 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Ver fichero

@@ -7647,6 +7647,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7647 7647
 					} else {
7648 7648
 						this.ServeSuccessJSON(map[string]interface{}{
7649 7649
 							"status": 0,
7650
+							"msg":    "",
7650 7651
 						})
7651 7652
 					}
7652 7653
 				}
@@ -7663,6 +7664,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7663 7664
 	} else {
7664 7665
 		this.ServeSuccessJSON(map[string]interface{}{
7665 7666
 			"status": 0,
7667
+			"msg":    "",
7666 7668
 		})
7667 7669
 
7668 7670
 	}

+ 216 - 85
controllers/schedule_api_controller.go Ver fichero

@@ -72,7 +72,7 @@ func ScheduleApiRegistRouters() {
72 72
 	beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
73 73
 	beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
74 74
 
75
-	beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSch")
75
+	beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
76 76
 	beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
77 77
 
78 78
 	beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
@@ -83,6 +83,8 @@ func ScheduleApiRegistRouters() {
83 83
 
84 84
 	beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
85 85
 
86
+	beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
87
+
86 88
 }
87 89
 func (c *ScheduleApiController) BatchPostSmartSch() {
88 90
 	patient_id, _ := c.GetInt64("patient_id")
@@ -119,6 +121,7 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
119 121
 				sch_id := int64(items["sch_id"].(float64))
120 122
 				if sch_id > 0 { //修改排班信息
121 123
 					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
124
+					fmt.Println("2222222")
122 125
 
123 126
 					if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
124 127
 						utils.ErrorLog("mode_id")
@@ -381,7 +384,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
381 384
 
382 385
 				} else { //新的排班信息
383 386
 
387
+					fmt.Println("111111111")
384 388
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
389
+						fmt.Println("33333333")
390
+
385 391
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
386 392
 						return
387 393
 					}
@@ -400,6 +406,15 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
400 406
 						return
401 407
 					}
402 408
 					schedule.ScheduleDate = theTime.Unix()
409
+					//existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
410
+					//
411
+					//if existSch.ID > 0{
412
+					//	fmt.Println("555555555")
413
+					//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
414
+					//	return
415
+					//
416
+					//}
417
+
403 418
 					timeNow := time.Now().Format("2006-01-02")
404 419
 					if timeNow > scheduleDate {
405 420
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
@@ -468,7 +483,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
468 483
 
469 484
 					sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
470 485
 
471
-					if sch.ID > 0 {
486
+					fmt.Println(sch.PatientId)
487
+					fmt.Println(schedule.PatientId)
488
+
489
+					if sch.ID > 0 && sch.PatientId != patient_id {
472 490
 						week_type, _ := items["week_type"].(string)
473 491
 						week_name, _ := items["week_name"].(string)
474 492
 
@@ -540,7 +558,32 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
540 558
 			}
541 559
 		}
542 560
 	}
561
+	////删除数据
562
+	if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
543 563
 
564
+		schs, _ := dataBody["del_schs"].([]interface{})
565
+		if len(schs) > 0 {
566
+			for _, item := range schs {
567
+				items := item.(map[string]interface{})
568
+				if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
569
+					utils.ErrorLog("id")
570
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
571
+					return
572
+				}
573
+				var schedule models.Schedule
574
+				sch_id := int64(items["sch_id"].(float64))
575
+				if sch_id > 0 { //修改排班信息
576
+					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
577
+					schedule.Status = 0
578
+					service.SaveSch(schedule)
579
+				}
580
+
581
+				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
582
+
583
+			}
584
+		}
585
+	}
586
+	////修改或保存数据
544 587
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
545 588
 
546 589
 		schs, _ := dataBody["smart_schs"].([]interface{})
@@ -658,33 +701,34 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
658 701
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
659 702
 						return
660 703
 					}
661
-
704
+					var DialysisMachineName string
662 705
 					so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
663 706
 					filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
664 707
 					filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
665 708
 					filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
666 709
 
667 710
 					if filedRecordOne.IsShow == 1 {
668
-						schedule.DialysisMachineName = so.DialysisDialyszers
711
+						DialysisMachineName = so.DialysisDialyszers
669 712
 					}
670 713
 					if filedRecordThree.IsShow == 1 {
671
-						if len(schedule.DialysisMachineName) > 0 {
672
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
714
+						if len(DialysisMachineName) > 0 {
715
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
673 716
 
674 717
 						} else {
675
-							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
718
+							DialysisMachineName = so.DialyzerPerfusionApparatus
676 719
 
677 720
 						}
678 721
 					}
679 722
 					if filedRecordTwo.IsShow == 1 {
680
-						if len(schedule.DialysisMachineName) > 0 {
681
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
723
+						if len(DialysisMachineName) > 0 {
724
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
682 725
 
683 726
 						} else {
684
-							schedule.DialysisMachineName = so.DialysisIrrigation
727
+							DialysisMachineName = so.DialysisIrrigation
685 728
 
686 729
 						}
687 730
 					}
731
+					schedule.DialysisMachineName = DialysisMachineName
688 732
 
689 733
 					service.SaveSch(schedule)
690 734
 				} else { //新的排班信息
@@ -778,17 +822,11 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
778 822
 
779 823
 					sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
780 824
 
781
-					if sch.ID > 0 {
825
+					if sch.ID > 0 && sch.PatientId != patient_id {
782 826
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
783 827
 						return
784 828
 					}
785
-
786
-					schedule.ModeId = modeId
787
-					schedule.PatientId = patient_id
788
-					schedule.CreatedTime = time.Now().Unix()
789
-					schedule.UpdatedTime = time.Now().Unix()
790
-					schedule.Status = 1
791
-					schedule.UserOrgId = adminInfo.CurrentOrgId
829
+					var DialysisMachineName string
792 830
 
793 831
 					so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
794 832
 					filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
@@ -796,48 +834,98 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
796 834
 					filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
797 835
 
798 836
 					if filedRecordOne.IsShow == 1 {
799
-						schedule.DialysisMachineName = so.DialysisDialyszers
837
+						DialysisMachineName = so.DialysisDialyszers
800 838
 					}
801 839
 					if filedRecordThree.IsShow == 1 {
802 840
 						if len(schedule.DialysisMachineName) > 0 {
803
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
841
+							DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
804 842
 
805 843
 						} else {
806
-							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
844
+							DialysisMachineName = so.DialyzerPerfusionApparatus
807 845
 
808 846
 						}
809 847
 					}
810 848
 					if filedRecordTwo.IsShow == 1 {
811
-						if len(schedule.DialysisMachineName) > 0 {
812
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
849
+						if len(DialysisMachineName) > 0 {
850
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
813 851
 
814 852
 						} else {
815
-							schedule.DialysisMachineName = so.DialysisIrrigation
853
+							DialysisMachineName = so.DialysisIrrigation
816 854
 
817 855
 						}
818 856
 					}
857
+					schedule.DialysisMachineName = DialysisMachineName
858
+
859
+					//判断当前保存的患者是否已经有排班
860
+					existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
861
+					if existSchedule.ID > 0 {
862
+						existSchedule.ModeId = modeId
863
+						existSchedule.BedId = schedule.BedId
864
+						existSchedule.PartitionId = schedule.PartitionId
865
+						existSchedule.ScheduleType = schedule.ScheduleType
866
+						existSchedule.DialysisMachineName = schedule.DialysisMachineName
867
+						service.SaveSmartSch(existSchedule)
819 868
 
820
-					daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
821
-					if daySchedule.ID > 0 {
822
-						daySchedule.ModeId = schedule.ModeId
823
-						daySchedule.ScheduleType = schedule.ScheduleType
824
-						daySchedule.PartitionId = schedule.PartitionId
825
-						daySchedule.BedId = schedule.BedId
826
-						daySchedule.DialysisMachineName = schedule.DialysisMachineName
827
-						service.SaveSch(daySchedule)
828 869
 					} else {
829
-						service.CreateSchedule(&schedule)
870
+						schedule.ModeId = modeId
871
+						schedule.PatientId = patient_id
872
+						schedule.CreatedTime = time.Now().Unix()
873
+						schedule.UpdatedTime = time.Now().Unix()
874
+						schedule.Status = 1
875
+						schedule.UserOrgId = adminInfo.CurrentOrgId
876
+
877
+						var DialysisMachineName string
878
+						so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
879
+						filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
880
+						filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
881
+						filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
882
+
883
+						if filedRecordOne.IsShow == 1 {
884
+							DialysisMachineName = so.DialysisDialyszers
885
+						}
886
+						if filedRecordThree.IsShow == 1 {
887
+							if len(DialysisMachineName) > 0 {
888
+								DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
889
+
890
+							} else {
891
+								DialysisMachineName = so.DialyzerPerfusionApparatus
892
+
893
+							}
894
+						}
895
+						if filedRecordTwo.IsShow == 1 {
896
+							if len(DialysisMachineName) > 0 {
897
+								DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
898
+
899
+							} else {
900
+								DialysisMachineName = so.DialysisIrrigation
901
+
902
+							}
903
+						}
904
+						schedule.DialysisMachineName = DialysisMachineName
905
+						//schedule.DialysisMachineName = schedule.DialysisMachineName
906
+						daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
907
+						if daySchedule.ID > 0 {
908
+							daySchedule.ModeId = schedule.ModeId
909
+							daySchedule.ScheduleType = schedule.ScheduleType
910
+							daySchedule.PartitionId = schedule.PartitionId
911
+							daySchedule.BedId = schedule.BedId
912
+							daySchedule.DialysisMachineName = schedule.DialysisMachineName
913
+							service.SaveSch(daySchedule)
914
+						} else {
915
+							service.CreateSchedule(&schedule)
916
+						}
830 917
 					}
831 918
 				}
919
+
832 920
 				c.ServeSuccessJSON(map[string]interface{}{
833 921
 					"msg": "保存成功",
834 922
 				})
835
-
836 923
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
837 924
 
838 925
 			}
839 926
 		}
840 927
 	}
928
+
841 929
 }
842 930
 func HandleRedis(org_id int64, sch_date int64) {
843 931
 	redis := service.RedisClient()
@@ -861,7 +949,25 @@ func HandleRedis(org_id int64, sch_date int64) {
861 949
 
862 950
 }
863 951
 
864
-func (c *ScheduleApiController) GetPatientSch() {
952
+func (c *ScheduleApiController) GetSmartSch() {
953
+	patient_id, _ := c.GetInt64("patient_id")
954
+	fmt.Println("~~~~~~")
955
+	fmt.Println(patient_id)
956
+	fmt.Println("~~~~~~")
957
+
958
+	adminUserInfo := c.GetAdminUserInfo()
959
+	sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
960
+	if err != nil {
961
+		utils.ErrorLog(err.Error())
962
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
963
+		return
964
+	}
965
+	c.ServeSuccessJSON(map[string]interface{}{
966
+		"sch": sch,
967
+	})
968
+}
969
+
970
+func (c *ScheduleApiController) GetPatient() {
865 971
 	keyWord := c.GetString("keyword")
866 972
 	adminUserInfo := c.GetAdminUserInfo()
867 973
 	patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
@@ -876,6 +982,7 @@ func (c *ScheduleApiController) GetPatientSch() {
876 982
 }
877 983
 
878 984
 func (c *ScheduleApiController) GetPatientSchTemplate() {
985
+	//patient_id, _ := c.GetInt64("patient_id",0)
879 986
 	keyWord := c.GetString("keyword")
880 987
 	adminUserInfo := c.GetAdminUserInfo()
881 988
 	patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
@@ -1264,32 +1371,34 @@ func (c *ScheduleApiController) CreateSchedule() {
1264 1371
 	schedule.UserOrgId = adminUserInfo.CurrentOrgId
1265 1372
 	schedule.IsExport = 5
1266 1373
 
1374
+	var DialysisMachineName string
1267 1375
 	so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
1268 1376
 	filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
1269 1377
 	filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
1270 1378
 	filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
1271 1379
 
1272 1380
 	if filedRecordOne.IsShow == 1 {
1273
-		schedule.DialysisMachineName = so.DialysisDialyszers
1381
+		DialysisMachineName = so.DialysisDialyszers
1274 1382
 	}
1275 1383
 	if filedRecordThree.IsShow == 1 {
1276
-		if len(schedule.DialysisMachineName) > 0 {
1277
-			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1384
+		if len(DialysisMachineName) > 0 {
1385
+			DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1278 1386
 
1279 1387
 		} else {
1280
-			schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1388
+			DialysisMachineName = so.DialyzerPerfusionApparatus
1281 1389
 
1282 1390
 		}
1283 1391
 	}
1284 1392
 	if filedRecordTwo.IsShow == 1 {
1285
-		if len(schedule.DialysisMachineName) > 0 {
1286
-			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1393
+		if len(DialysisMachineName) > 0 {
1394
+			DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
1287 1395
 
1288 1396
 		} else {
1289
-			schedule.DialysisMachineName = so.DialysisIrrigation
1397
+			DialysisMachineName = so.DialysisIrrigation
1290 1398
 
1291 1399
 		}
1292 1400
 	}
1401
+	schedule.DialysisMachineName = DialysisMachineName
1293 1402
 
1294 1403
 	bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
1295 1404
 	if bed == nil {
@@ -1494,28 +1603,29 @@ func (c *ScheduleApiController) ChangeSchedule() {
1494 1603
 		filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
1495 1604
 		filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
1496 1605
 		filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
1497
-
1606
+		var DialysisMachineName string
1498 1607
 		if filedRecordOne.IsShow == 1 {
1499
-			schedule.DialysisMachineName = so.DialysisDialyszers
1608
+			DialysisMachineName = so.DialysisDialyszers
1500 1609
 		}
1501 1610
 		if filedRecordThree.IsShow == 1 {
1502 1611
 			if len(schedule.DialysisMachineName) > 0 {
1503
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1612
+				DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1504 1613
 
1505 1614
 			} else {
1506
-				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1615
+				DialysisMachineName = so.DialyzerPerfusionApparatus
1507 1616
 
1508 1617
 			}
1509 1618
 		}
1510 1619
 		if filedRecordTwo.IsShow == 1 {
1511
-			if len(schedule.DialysisMachineName) > 0 {
1512
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1620
+			if len(DialysisMachineName) > 0 {
1621
+				DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1513 1622
 
1514 1623
 			} else {
1515
-				schedule.DialysisMachineName = so.DialysisIrrigation
1624
+				DialysisMachineName = so.DialysisIrrigation
1516 1625
 
1517 1626
 			}
1518 1627
 		}
1628
+		schedule.DialysisMachineName = DialysisMachineName
1519 1629
 
1520 1630
 		order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
1521 1631
 		if err != nil {
@@ -2418,32 +2528,35 @@ func (this *ScheduleApiController) ExportSchedule() {
2418 2528
 			sch.Status = 1
2419 2529
 			sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
2420 2530
 			sch.IsExport = 1
2531
+
2532
+			var DialysisMachineName string
2421 2533
 			so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
2422 2534
 			filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
2423 2535
 			filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
2424 2536
 			filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
2425 2537
 
2426 2538
 			if filedRecordOne.IsShow == 1 {
2427
-				sch.DialysisMachineName = so.DialysisDialyszers
2539
+				DialysisMachineName = so.DialysisDialyszers
2428 2540
 			}
2429 2541
 			if filedRecordThree.IsShow == 1 {
2430
-				if len(sch.DialysisMachineName) > 0 {
2431
-					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
2542
+				if len(DialysisMachineName) > 0 {
2543
+					DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
2432 2544
 
2433 2545
 				} else {
2434
-					sch.DialysisMachineName = so.DialyzerPerfusionApparatus
2546
+					DialysisMachineName = so.DialyzerPerfusionApparatus
2435 2547
 
2436 2548
 				}
2437 2549
 			}
2438 2550
 			if filedRecordTwo.IsShow == 1 {
2439
-				if len(sch.DialysisMachineName) > 0 {
2440
-					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
2551
+				if len(DialysisMachineName) > 0 {
2552
+					DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
2441 2553
 
2442 2554
 				} else {
2443
-					sch.DialysisMachineName = so.DialysisIrrigation
2555
+					DialysisMachineName = so.DialysisIrrigation
2444 2556
 
2445 2557
 				}
2446 2558
 			}
2559
+			sch.DialysisMachineName = DialysisMachineName
2447 2560
 
2448 2561
 			schedules = append(schedules, &sch)
2449 2562
 		}
@@ -2455,21 +2568,29 @@ func (this *ScheduleApiController) ExportSchedule() {
2455 2568
 			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
2456 2569
 			clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
2457 2570
 
2571
+			service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
2572
+
2458 2573
 			if err == nil {
2459 2574
 				for _, item := range schedules {
2460 2575
 					if item.ScheduleDate > clear_schedule_date {
2461 2576
 						//查询该患者是否转出获取死亡
2577
+						fmt.Println("11111323242423")
2462 2578
 
2463 2579
 						//查找当天日期是否存在
2464 2580
 						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
2465 2581
 						if errcode == gorm.ErrRecordNotFound {
2466 2582
 							//查询该床位是否有患者
2583
+							fmt.Println("errcodes")
2467 2584
 							sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
2585
+							fmt.Println("errcodes")
2586
+							fmt.Println(errcodes)
2587
+							fmt.Println(sch)
2468 2588
 
2469 2589
 							if errcodes == gorm.ErrRecordNotFound {
2590
+								fmt.Println("1111111")
2470 2591
 								service.CreateSchedule(item)
2471 2592
 							} else if errcodes == nil {
2472
-
2593
+								fmt.Println("1111222222222")
2473 2594
 								//清除当天该床位已有的患者
2474 2595
 								service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
2475 2596
 								service.CreateSchedule(item)
@@ -2477,15 +2598,17 @@ func (this *ScheduleApiController) ExportSchedule() {
2477 2598
 
2478 2599
 						} else if errcode == nil {
2479 2600
 							schedule := models.XtSchedule{
2480
-								PartitionId:  item.PartitionId,
2481
-								BedId:        item.BedId,
2482
-								PatientId:    item.PatientId,
2483
-								ScheduleDate: item.ScheduleDate,
2484
-								ScheduleType: item.ScheduleType,
2485
-								ScheduleWeek: item.ScheduleWeek,
2486
-								ModeId:       item.ModeId,
2487
-								Status:       1,
2601
+								PartitionId:         item.PartitionId,
2602
+								BedId:               item.BedId,
2603
+								PatientId:           item.PatientId,
2604
+								ScheduleDate:        item.ScheduleDate,
2605
+								ScheduleType:        item.ScheduleType,
2606
+								ScheduleWeek:        item.ScheduleWeek,
2607
+								ModeId:              1,
2608
+								Status:              1,
2609
+								DialysisMachineName: item.DialysisMachineName,
2488 2610
 							}
2611
+							fmt.Println("1111222222223333333333333333332")
2489 2612
 
2490 2613
 							service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
2491 2614
 						}
@@ -3321,32 +3444,35 @@ func (this *ScheduleApiController) GetCopyPatientSchedules() {
3321 3444
 			CreatedTime:  time.Now().Unix(),
3322 3445
 		}
3323 3446
 
3447
+		var DialysisMachineName string
3448
+
3324 3449
 		so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
3325 3450
 		filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
3326 3451
 		filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
3327 3452
 		filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
3328 3453
 
3329 3454
 		if filedRecordOne.IsShow == 1 {
3330
-			schedule.DialysisMachineName = so.DialysisDialyszers
3455
+			DialysisMachineName = so.DialysisDialyszers
3331 3456
 		}
3332 3457
 		if filedRecordThree.IsShow == 1 {
3333
-			if len(schedule.DialysisMachineName) > 0 {
3334
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3458
+			if len(DialysisMachineName) > 0 {
3459
+				DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
3335 3460
 
3336 3461
 			} else {
3337
-				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
3462
+				DialysisMachineName = so.DialyzerPerfusionApparatus
3338 3463
 
3339 3464
 			}
3340 3465
 		}
3341 3466
 		if filedRecordTwo.IsShow == 1 {
3342
-			if len(schedule.DialysisMachineName) > 0 {
3343
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3467
+			if len(DialysisMachineName) > 0 {
3468
+				DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
3344 3469
 
3345 3470
 			} else {
3346
-				schedule.DialysisMachineName = so.DialysisIrrigation
3471
+				DialysisMachineName = so.DialysisIrrigation
3347 3472
 
3348 3473
 			}
3349 3474
 		}
3475
+		schedule.DialysisMachineName = DialysisMachineName
3350 3476
 
3351 3477
 		err = service.AddPatientSchedule(&schedule)
3352 3478
 
@@ -4030,32 +4156,34 @@ func (c *ScheduleApiController) SynchroSchedule() {
4030 4156
 				UpdatedTime:  0,
4031 4157
 			}
4032 4158
 
4159
+			var DialysisMachineName string
4033 4160
 			so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
4034 4161
 			filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
4035 4162
 			filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
4036 4163
 			filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
4037 4164
 
4038 4165
 			if filedRecordOne.IsShow == 1 {
4039
-				schedule.DialysisMachineName = so.DialysisDialyszers
4166
+				DialysisMachineName = so.DialysisDialyszers
4040 4167
 			}
4041 4168
 			if filedRecordThree.IsShow == 1 {
4042
-				if len(schedule.DialysisMachineName) > 0 {
4043
-					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4169
+				if len(DialysisMachineName) > 0 {
4170
+					DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4044 4171
 
4045 4172
 				} else {
4046
-					schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
4173
+					DialysisMachineName = so.DialyzerPerfusionApparatus
4047 4174
 
4048 4175
 				}
4049 4176
 			}
4050 4177
 			if filedRecordTwo.IsShow == 1 {
4051
-				if len(schedule.DialysisMachineName) > 0 {
4052
-					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
4178
+				if len(DialysisMachineName) > 0 {
4179
+					DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
4053 4180
 
4054 4181
 				} else {
4055
-					schedule.DialysisMachineName = so.DialysisIrrigation
4182
+					DialysisMachineName = so.DialysisIrrigation
4056 4183
 
4057 4184
 				}
4058 4185
 			}
4186
+			schedule.DialysisMachineName = DialysisMachineName
4059 4187
 
4060 4188
 			service.CreatePatientSchedule(&schedule)
4061 4189
 		}
@@ -4119,32 +4247,35 @@ func (c *ScheduleApiController) SynchroSchedule() {
4119 4247
 					CreatedTime:  time.Now().Unix(),
4120 4248
 					UpdatedTime:  0,
4121 4249
 				}
4250
+
4251
+				var DialysisMachineName string
4122 4252
 				so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
4123 4253
 				filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
4124 4254
 				filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
4125 4255
 				filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
4126 4256
 
4127 4257
 				if filedRecordOne.IsShow == 1 {
4128
-					schedule.DialysisMachineName = so.DialysisDialyszers
4258
+					DialysisMachineName = so.DialysisDialyszers
4129 4259
 				}
4130 4260
 				if filedRecordThree.IsShow == 1 {
4131
-					if len(schedule.DialysisMachineName) > 0 {
4132
-						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4261
+					if len(DialysisMachineName) > 0 {
4262
+						DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4133 4263
 
4134 4264
 					} else {
4135
-						schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
4265
+						DialysisMachineName = so.DialyzerPerfusionApparatus
4136 4266
 
4137 4267
 					}
4138 4268
 				}
4139 4269
 				if filedRecordTwo.IsShow == 1 {
4140 4270
 					if len(schedule.DialysisMachineName) > 0 {
4141
-						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
4271
+						DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
4142 4272
 
4143 4273
 					} else {
4144
-						schedule.DialysisMachineName = so.DialysisIrrigation
4274
+						DialysisMachineName = so.DialysisIrrigation
4145 4275
 
4146 4276
 					}
4147 4277
 				}
4278
+				schedule.DialysisMachineName = DialysisMachineName
4148 4279
 				service.CreatePatientSchedule(&schedule)
4149 4280
 			}
4150 4281
 		}

+ 139 - 2
controllers/schedule_template_api_controller.go Ver fichero

@@ -6,6 +6,7 @@ import (
6 6
 	"XT_New/service"
7 7
 	"encoding/json"
8 8
 	"fmt"
9
+	"strconv"
9 10
 	"strings"
10 11
 	"time"
11 12
 
@@ -19,8 +20,30 @@ func PatientScheduleTemplateAPIControllerRegistRouters() {
19 20
 
20 21
 	beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList")
21 22
 
23
+	beego.Router("/api/schedule/update_schtemplate", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedulesTemplate")
24
+	beego.Router("/api/schtemplate_device/get", &ScheduleApiController{}, "Get:GetTemplateDevicesNumbers")
25
+
22 26
 	// beego.Router("/api/test", &TestCtr{}, "get:Test")
23 27
 }
28
+func (c *ScheduleApiController) GetTemplateDevicesNumbers() {
29
+	sch_type, _ := c.GetInt("sch_type", 0)
30
+	zone_id, _ := c.GetInt64("zone_id", 0)
31
+	patient_id, _ := c.GetInt64("patient_id", 0)
32
+	template_id, _ := c.GetInt64("template_id", 0)
33
+
34
+	weekday, _ := c.GetInt64("weekday")
35
+
36
+	deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildTemplateDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, weekday, sch_type, zone_id, patient_id, template_id)
37
+	if getDeviceNumbersErr != nil {
38
+		c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
39
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
40
+		return
41
+	}
42
+	c.ServeSuccessJSON(map[string]interface{}{
43
+		"devices": deviceNumbers,
44
+	})
45
+
46
+}
24 47
 
25 48
 // type TestCtr struct {
26 49
 // 	BaseAPIController
@@ -189,6 +212,7 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
189 212
 		return
190 213
 	}
191 214
 	templateMode.Week = int64(week_time)
215
+	templateMode.OriginalWeek = int64(week_time)
192 216
 
193 217
 	if mode != templateMode.Mode {
194 218
 		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2  则直接清除下四周的排班
@@ -422,6 +446,10 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
422 446
 			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
423 447
 		}
424 448
 
449
+	} else {
450
+		fmt.Println("~~~~~~~~")
451
+		service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek)
452
+
425 453
 	}
426 454
 
427 455
 	this.ServeSuccessJSON(nil)
@@ -619,14 +647,17 @@ func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
619 647
 		return
620 648
 	}
621 649
 
622
-	newItems, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItemsByTemplateID(adminUserInfo.CurrentOrgId)
650
+	//newItems, getTemplateItemsErr := service.GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId)
651
+	templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
652
+
653
+	//newItems, getTemplateItemsErr := service.GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId)
623 654
 	if getTemplateItemsErr != nil {
624 655
 		this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
625 656
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
626 657
 		return
627 658
 	}
628 659
 	this.ServeSuccessJSON(map[string]interface{}{
629
-		"items": newItems,
660
+		"items": templates,
630 661
 	})
631 662
 }
632 663
 
@@ -648,3 +679,109 @@ func (this *PatientScheduleTemplateAPIController) GetPatientList() {
648 679
 	})
649 680
 
650 681
 }
682
+
683
+type ParamModelEditSchedule struct {
684
+	ID             int64  `json:"sch_id"`
685
+	DeviceNumberID int64  `json:"jihao_id"`
686
+	PatientID      int64  `json:"patient_id"`
687
+	Mode           int64  `json:"mode_id"`
688
+	Weekday        int64  `json:"schedule_week"`
689
+	TimeType       int64  `json:"time_type"`
690
+	TemplateID     int64  `json:"t_id"`
691
+	Title          string `json:"title"`
692
+}
693
+
694
+func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() {
695
+	addOrEditSchedulesJSON := this.GetString("edit_schs")
696
+	//delSchedulesJSON := this.GetString("del_schs")
697
+
698
+	fmt.Println(addOrEditSchedulesJSON)
699
+	var addOrEditSchedules []*ParamModelEditSchedule
700
+	//var delSchedules []*ParamModelEditSchedule
701
+
702
+	parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules)
703
+	//parseDelErr := json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
704
+
705
+	fmt.Println(parseErr)
706
+	if parseErr != nil {
707
+		this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr)
708
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
709
+		return
710
+	}
711
+	//if parseDelErr != nil {
712
+	//	this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
713
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
714
+	//	return
715
+	//}
716
+
717
+	for _, item := range addOrEditSchedules {
718
+
719
+		if item.ID > 0 { //已经存在的数据
720
+			src_template, _ := service.GetScheduleTemplateItem(item.ID)
721
+			src_template.DeviceNumberID = item.DeviceNumberID
722
+			src_template.TimeType = int8(item.TimeType)
723
+			src_template.TreatMode = item.Mode
724
+			//service.SaveSchTemplateItem(src_template)
725
+			fmt.Println("11111")
726
+		} else {
727
+			schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
728
+			fmt.Println("222222")
729
+
730
+			if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
731
+				fmt.Println("333333333")
732
+				src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
733
+				src_template.DeviceNumberID = item.DeviceNumberID
734
+				src_template.TimeType = int8(item.TimeType)
735
+				src_template.TreatMode = item.Mode
736
+				service.SaveSchTemplateItem(src_template)
737
+
738
+			} else {
739
+				schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday)
740
+
741
+				if schItem.ID == 0 { //床位未被占用
742
+
743
+					var template models.PatientScheduleTemplateItem
744
+					template.TreatMode = item.Mode
745
+					template.TemplateID = int64(item.TemplateID)
746
+					template.TimeType = int8(item.TimeType)
747
+					template.DeviceNumberID = item.DeviceNumberID
748
+					template.CreateTime = time.Now().Unix()
749
+					template.ModifyTime = time.Now().Unix()
750
+					template.OrgID = this.GetAdminUserInfo().CurrentOrgId
751
+					template.PatientID = item.PatientID
752
+					template.Weekday = int8(item.Weekday)
753
+					template.Status = 1
754
+					service.SaveSchTemplateItem(template)
755
+
756
+				} else { //床位被占用 1.被自己占用,2。被别人占用
757
+					//fmt.Println("555555555")
758
+
759
+					if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作
760
+						//fmt.Println("66666")
761
+						src_template, _ := service.GetScheduleTemplateItem(schItem.ID)
762
+						src_template.DeviceNumberID = item.DeviceNumberID
763
+						src_template.TimeType = int8(item.TimeType)
764
+						src_template.TreatMode = item.Mode
765
+						service.SaveSchTemplateItem(src_template)
766
+
767
+					} else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存
768
+						//fmt.Println("7777777")
769
+						json := make(map[string]interface{})
770
+						json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存"
771
+						json["state"] = 0
772
+						this.Data["json"] = json
773
+						this.ServeJSON()
774
+						break
775
+					}
776
+				}
777
+
778
+			}
779
+
780
+		}
781
+	}
782
+
783
+	templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId)
784
+	this.ServeSuccessJSON(map[string]interface{}{
785
+		"items": templates,
786
+	})
787
+}

+ 1 - 0
models/patient_schedule_template_models.go Ver fichero

@@ -9,6 +9,7 @@ type PatientScheduleTemplateMode struct {
9 9
 	CreateTime   int64 `gorm:"column:ctime" json:"-" form:"ctime"`
10 10
 	ModifyTime   int64 `gorm:"column:mtime" json:"-" form:"mtime"`
11 11
 	Week         int64 `gorm:"column:week" json:"-" form:"week"`
12
+	OriginalWeek int64 `gorm:"column:original_week" json:"original_week" form:"original_week"`
12 13
 }
13 14
 
14 15
 func (PatientScheduleTemplateMode) TableName() string {

+ 18 - 17
models/smart_sch.go Ver fichero

@@ -6,7 +6,7 @@ type SmartSchPatient struct {
6 6
 	Name       string `gorm:"column:name" json:"name" form:"name"`
7 7
 	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8 8
 
9
-	SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
9
+	//SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
10 10
 }
11 11
 
12 12
 func (SmartSchPatient) TableName() string {
@@ -27,22 +27,23 @@ func (SmartSchTemplatePatient) TableName() string {
27 27
 }
28 28
 
29 29
 type SmartSchedule struct {
30
-	ID                 int64              `gorm:"column:id" json:"id" form:"id"`
31
-	UserOrgId          int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
-	PartitionId        int64              `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
33
-	BedId              int64              `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
34
-	PatientId          int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
35
-	ScheduleDate       int64              `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36
-	ScheduleType       int64              `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
37
-	ScheduleWeek       int64              `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
38
-	ModeId             int64              `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
39
-	Status             int64              `gorm:"column:status" json:"status" form:"status"`
40
-	CreatedTime        int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
41
-	UpdatedTime        int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
42
-	IsExport           int64              `gorm:"column:is_export" json:"is_export" form:"is_export"`
43
-	DeviceZone         DeviceZone         `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
44
-	DeviceNumber       DeviceNumber       `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
45
-	SmSchDialysisOrder SmSchDialysisOrder `json:"order" gorm:"foreignkey:BedId,PatientId,DialysisDate;AssociationForeignKey:BedId,PatientId,ScheduleDate;"`
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:"-"`
46
+	DialysisMachineName string             `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
46 47
 }
47 48
 
48 49
 func (SmartSchedule) TableName() string {

+ 20 - 0
service/device_service.go Ver fichero

@@ -834,3 +834,23 @@ func UpdateScheduleById(id int64, schedule models.Schedule) error {
834 834
 	err := XTWriteDB().Model(&models.Schedule{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId}).Error
835 835
 	return err
836 836
 }
837
+
838
+func GetScheduleTemplateForDeviceNumber(orgID int64, deviceNumberID int64, template_id int64, week_type int64, time_type int64) (models.PatientScheduleTemplateItem, error) {
839
+	var item models.PatientScheduleTemplateItem
840
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ? AND time_type = ?", deviceNumberID, orgID, template_id, week_type, time_type).First(&item).Error
841
+	return item, err
842
+}
843
+
844
+//某模板下,某周几下,该床位是否有患者
845
+func GetScheduleTemplateOne(orgID int64, deviceNumberID int64, template_id int64, week_type int64) (models.PatientScheduleTemplateItem, error) {
846
+	var item models.PatientScheduleTemplateItem
847
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", deviceNumberID, orgID, template_id, week_type).First(&item).Error
848
+	return item, err
849
+}
850
+
851
+//某模板下,某周几下,是否有排班
852
+func GetScheduleTemplateTwo(orgID int64, template_id int64, week_type int64, patient_id int64) (models.PatientScheduleTemplateItem, error) {
853
+	var item models.PatientScheduleTemplateItem
854
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", patient_id, orgID, template_id, week_type).First(&item).Error
855
+	return item, err
856
+}

+ 29 - 0
service/patient_schedule_template_service.go Ver fichero

@@ -925,3 +925,32 @@ func GetOrgPatientScheduleTemplateModeTwo(orgID int64) (models.PatientScheduleTe
925 925
 	err := readDb.Model(&models.PatientScheduleTemplateMode{}).Where("org_id = ? AND status = 1", orgID).First(&mode).Error
926 926
 	return mode, err
927 927
 }
928
+
929
+func GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(orgID int64) ([]*models.PatientScheduleTemplateItem, error) {
930
+	var items []*models.PatientScheduleTemplateItem
931
+	err := readDb.Raw("select item.id,item.org_id,item.template_id,item.device_number_id,item.patient_id,item.treat_mode,item.weekday,item.time_type,item.status,item.status,item.ctime,item.mtime from xt_patient_schedule_template_item as item left join xt_patients as patient on item.patient_id = patient.id where item.org_id = ? AND item.status = 1 and patient.lapseto = 1 and patient.status = 1", orgID).Scan(&items).Error
932
+	// err := readDb.
933
+	// 	Model(&models.PatientScheduleTemplateItem{}).
934
+	// 	Where("org_id = ? AND template_id = ? AND status = 1", orgID, templateID).
935
+	// 	Find(&items).
936
+	// 	Error
937
+	if err != nil {
938
+		return nil, err
939
+	}
940
+	return items, nil
941
+}
942
+
943
+func GetScheduleTemplateItem(id int64) (item models.PatientScheduleTemplateItem, err error) {
944
+	err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", id).First(&item).Error
945
+	return
946
+}
947
+
948
+func SaveSchTemplateItem(item models.PatientScheduleTemplateItem) (err error) {
949
+	err = writeDb.Save(&item).Error
950
+	return
951
+}
952
+
953
+func UpdateTemplateItemModeWeek(orgID int64, id int64, week_time int64) {
954
+	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
+	return
956
+}

+ 5 - 0
service/patient_service.go Ver fichero

@@ -2738,3 +2738,8 @@ func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64)
2738 2738
 	}
2739 2739
 	return record, nil
2740 2740
 }
2741
+
2742
+func UpdateScheduleByExport(org_id int64, shcheduledate int64) error {
2743
+	err := XTWriteDB().Model(models.XtSchedule{}).Where("user_org_id = ? and schedule_date > ?", org_id, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
2744
+	return err
2745
+}

+ 34 - 8
service/schedule_service.go Ver fichero

@@ -36,7 +36,9 @@ func GetSchedulePartitionPanelTwo(orgID int64, schIDs []string) (partitions []*m
36 36
 		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
37 37
 	}
38 38
 	if len(schIDs) > 0 {
39
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id in(?)", orgID, schIDs).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
39
+		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", func(db *gorm.DB) *gorm.DB {
40
+			return db.Where("org_id=? and status=1 and zone_id in (?)", orgID, schIDs).Order("sort desc")
41
+		}).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
40 42
 	}
41 43
 
42 44
 	return
@@ -259,7 +261,7 @@ func UpdateScheduleByOrgId(patientid int64, scheduledate int64, orgid int64, mod
259 261
 }
260 262
 
261 263
 func UpdateScheduleByOrgIdOne(patientid int64, scheduledate int64, orgid int64, sch *models.XtSchedule) error {
262
-	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
264
+	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix(), "dialysis_machine_name": sch.DialysisMachineName}).Error
263 265
 	return err
264 266
 }
265 267
 
@@ -300,12 +302,36 @@ func UpdateScheduleOne(id int64, schedule models.Schedule) error {
300 302
 //参数一:当前操作的患者的排班     参数二被替换床位对应的排班
301 303
 func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) {
302 304
 	utx := XTWriteDB()
303
-	var tempPatientID int64
304
-	var tempPatientIDTwo int64
305
-	tempPatientID = schone.PatientId
306
-	tempPatientIDTwo = schtwo.PatientId
307
-	schone.PatientId = tempPatientIDTwo
308
-	schtwo.PatientId = tempPatientID
305
+	//床位
306
+	var tempBedID int64
307
+	var tempBedIDTwo int64
308
+
309
+	//分區
310
+	var tempPID int64
311
+	var tempPIDTwo int64
312
+
313
+	//上下午
314
+	var tempTypeID int64
315
+	var tempTypeTwo int64
316
+
317
+	tempBedID = schone.BedId
318
+	tempBedIDTwo = schtwo.BedId
319
+
320
+	tempPID = schone.PartitionId
321
+	tempPIDTwo = schtwo.PartitionId
322
+
323
+	tempTypeID = schone.ScheduleType
324
+	tempTypeTwo = schtwo.ScheduleType
325
+
326
+	schone.BedId = tempBedIDTwo
327
+	schtwo.BedId = tempBedID
328
+
329
+	schone.PartitionId = tempPIDTwo
330
+	schtwo.PartitionId = tempPID
331
+
332
+	schone.ScheduleType = tempTypeTwo
333
+	schtwo.ScheduleType = tempTypeID
334
+
309 335
 	utx.Save(&schone)
310 336
 	utx.Save(&schtwo)
311 337
 

+ 63 - 14
service/smart_sch.go Ver fichero

@@ -15,21 +15,41 @@ func GetSmartSchPatientByKeyWord(orgID int64, keywords string) (patient []*model
15 15
 		err = db.Find(&patient).Error
16 16
 	}
17 17
 
18
-	for _, item := range patient {
19
-		var sch []*models.SmartSchedule
20
-		now := time.Now()
18
+	//for _, item := range patient {
19
+	//	var sch []*models.SmartSchedule
20
+	//	now := time.Now()
21
+	//
22
+	//	offset := int(time.Monday - now.Weekday())
23
+	//	if offset > 0 {
24
+	//		offset = -6
25
+	//	}
26
+	//
27
+	//	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
28
+	//	readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
29
+	//		Preload("DeviceZone", "status = 1").
30
+	//		Preload("SmSchDialysisOrder", "status = 1").
31
+	//		Preload("DeviceNumber", "status = 1").Find(&sch)
32
+	//	item.SmartSchedule = sch
33
+	//}
21 34
 
22
-		offset := int(time.Monday - now.Weekday())
23
-		if offset > 0 {
24
-			offset = -6
25
-		}
35
+	return
36
+}
37
+
38
+func GetSmartSchPatientByPatientID(orgID int64, id int64) (sch []*models.SmartSchedule, err error) {
39
+	now := time.Now()
40
+	offset := int(time.Monday - now.Weekday())
41
+	if offset > 0 {
42
+		offset = -6
43
+	}
44
+	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
45
+	readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, id, weekStart.Unix()).
46
+		Preload("DeviceZone", "status = 1").
47
+		Preload("DeviceNumber", "status = 1").Find(&sch)
26 48
 
27
-		weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
28
-		readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
29
-			Preload("DeviceZone", "status = 1").
30
-			Preload("SmSchDialysisOrder", "status = 1").
31
-			Preload("DeviceNumber", "status = 1").Find(&sch)
32
-		item.SmartSchedule = sch
49
+	for _, item := range sch {
50
+		var order models.SmSchDialysisOrder
51
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
52
+		item.SmSchDialysisOrder = order
33 53
 	}
34 54
 
35 55
 	return
@@ -81,8 +101,13 @@ func GetSmartSchPatientByID(orgID int64, patient_id int64) (schs []*models.Smart
81 101
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
82 102
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
83 103
 		Preload("DeviceZone", "status = 1").
84
-		Preload("SmSchDialysisOrder", "status = 1").
85 104
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
105
+
106
+	for _, item := range schs {
107
+		var order models.SmSchDialysisOrder
108
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
109
+		item.SmSchDialysisOrder = order
110
+	}
86 111
 	return
87 112
 }
88 113
 
@@ -118,3 +143,27 @@ func GetScheduleByZoneAndBed(org_id int64, partitionId int64, bed_id int64, sche
118 143
 	err = readDb.Model(&models.SmartSchedule{}).Where("bed_id = ? AND user_org_id = ? AND schedule_date = ? AND partition_id = ? AND schedule_type = ?  AND status = 1", bed_id, org_id, schedule_date, partitionId, sch_type).First(&sch).Error
119 144
 	return
120 145
 }
146
+
147
+func GetScheduleByDate(org_id int64, schedule_date int64, patient_id int64) (sch models.SmartSchedule, err error) {
148
+	err = readDb.Model(&models.SmartSchedule{}).Where(" user_org_id = ? AND schedule_date = ? AND status = 1 AND patient_id = ?", org_id, schedule_date, patient_id).First(&sch).Error
149
+	return
150
+}
151
+func SaveSmartSch(sch models.SmartSchedule) {
152
+	writeDb.Save(&sch)
153
+	return
154
+}
155
+
156
+func GetAllAvaildTemplateDeviceNumbersByZone(orgID int64, weekday int64, schedule_type int, zone_id int64, patient_id int64, template_id int64) ([]*DeviceNumberViewModel, error) {
157
+	var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
158
+	rows, err := readDb.Raw("SELECT n.*, z.name as zone_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id AND z.id = ?   WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_patient_schedule_template_item as s Where s.`weekday` = ? AND s.patient_id <> ?  AND  s.org_id = n.org_id AND s.`device_number_id` = n.id  AND s.`time_type` = ? AND s.status = 1 AND s.template_id = ?)", zone_id, orgID, weekday, patient_id, schedule_type, template_id).Rows()
159
+	defer rows.Close()
160
+	if err != nil {
161
+		return nil, err
162
+	}
163
+	for rows.Next() {
164
+		var vm DeviceNumberViewModel
165
+		readDb.ScanRows(rows, &vm)
166
+		vms = append(vms, &vm)
167
+	}
168
+	return vms, nil
169
+}