Browse Source

修改redis清除数据时间

csx 4 years ago
parent
commit
473771071a

+ 59 - 61
controllers/base_api_controller.go View File

@@ -2,8 +2,6 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
-	"XT_New/models"
6
-
7 5
 	//"XT_New/models"
8 6
 	"XT_New/service"
9 7
 	"strconv"
@@ -66,36 +64,36 @@ type BaseAuthAPIController struct {
66 64
 func (this *BaseAuthAPIController) Prepare() {
67 65
 	this.BaseAPIController.Prepare()
68 66
 	if this.GetAdminUserInfo() == nil {
69
-		var userAdmin models.AdminUser
70
-		userAdmin.Id = 558
71
-		userAdmin.Mobile = "13318464649"
72
-
73
-		//userAdmin.Id = 597
74
-		//userAdmin.Mobile = "19874122664"
75
-		userAdmin.IsSuperAdmin = false
76
-		userAdmin.Status = 1
77
-		userAdmin.CreateTime = 1530786071
78
-		userAdmin.ModifyTime = 1530786071
79
-		var subscibe models.ServeSubscibe
80
-		subscibe.ID = 1
81
-		subscibe.OrgId = 4
82
-		subscibe.PeriodStart = 1538035409
83
-		subscibe.PeriodEnd = 1569571409
84
-		subscibe.State = 1
85
-		subscibe.Status = 1
86
-		subscibe.CreatedTime = 1538035409
87
-		subscibe.UpdatedTime = 1538035409
88
-		subscibes := make(map[int64]*models.ServeSubscibe, 0)
89
-		subscibes[4] = &subscibe
90
-		var adminUserInfo service.AdminUserInfo
91
-		adminUserInfo.CurrentOrgId = 4
92
-		adminUserInfo.CurrentAppId = 18
93
-		adminUserInfo.AdminUser = &userAdmin
94
-		adminUserInfo.Subscibes = subscibes
95
-		this.SetSession("admin_user_info", &adminUserInfo)
96
-
97
-		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
98
-		//this.StopRun()
67
+		//var userAdmin models.AdminUser
68
+		//userAdmin.Id = 558
69
+		//userAdmin.Mobile = "13318464649"
70
+		//
71
+		////userAdmin.Id = 597
72
+		////userAdmin.Mobile = "19874122664"
73
+		//userAdmin.IsSuperAdmin = false
74
+		//userAdmin.Status = 1
75
+		//userAdmin.CreateTime = 1530786071
76
+		//userAdmin.ModifyTime = 1530786071
77
+		//var subscibe models.ServeSubscibe
78
+		//subscibe.ID = 1
79
+		//subscibe.OrgId = 4
80
+		//subscibe.PeriodStart = 1538035409
81
+		//subscibe.PeriodEnd = 1569571409
82
+		//subscibe.State = 1
83
+		//subscibe.Status = 1
84
+		//subscibe.CreatedTime = 1538035409
85
+		//subscibe.UpdatedTime = 1538035409
86
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
87
+		//subscibes[4] = &subscibe
88
+		//var adminUserInfo service.AdminUserInfo
89
+		//adminUserInfo.CurrentOrgId = 4
90
+		//adminUserInfo.CurrentAppId = 18
91
+		//adminUserInfo.AdminUser = &userAdmin
92
+		//adminUserInfo.Subscibes = subscibes
93
+		//this.SetSession("admin_user_info", &adminUserInfo)
94
+
95
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
96
+		this.StopRun()
99 97
 
100 98
 	}
101 99
 
@@ -308,35 +306,35 @@ type BaseServeAPIController struct {
308 306
 func (this *BaseServeAPIController) Prepare() {
309 307
 	this.BaseAPIController.Prepare()
310 308
 	if this.GetAdminUserInfo() == nil {
311
-		var userAdmin models.AdminUser
312
-		userAdmin.Id = 558
313
-		userAdmin.Mobile = "13535547901"
314
-		//userAdmin.Id = 597
315
-		//userAdmin.Mobile = "19874122664"
316
-		userAdmin.IsSuperAdmin = false
317
-		userAdmin.Status = 1
318
-		userAdmin.CreateTime = 1530786071
319
-		userAdmin.ModifyTime = 1530786071
320
-		var subscibe models.ServeSubscibe
321
-		subscibe.ID = 1
322
-		subscibe.OrgId = 4
323
-		subscibe.PeriodStart = 1538035409
324
-		subscibe.PeriodEnd = 1569571409
325
-		subscibe.State = 1
326
-		subscibe.Status = 1
327
-		subscibe.CreatedTime = 1538035409
328
-		subscibe.UpdatedTime = 1538035409
329
-		subscibes := make(map[int64]*models.ServeSubscibe, 0)
330
-		subscibes[4] = &subscibe
331
-		var adminUserInfo service.AdminUserInfo
332
-		adminUserInfo.CurrentOrgId = 4
333
-		adminUserInfo.CurrentAppId = 18
334
-		adminUserInfo.AdminUser = &userAdmin
335
-		adminUserInfo.Subscibes = subscibes
336
-		this.SetSession("admin_user_info", &adminUserInfo)
337
-
338
-		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
339
-		//this.StopRun()
309
+		//var userAdmin models.AdminUser
310
+		//userAdmin.Id = 558
311
+		//userAdmin.Mobile = "13535547901"
312
+		////userAdmin.Id = 597
313
+		////userAdmin.Mobile = "19874122664"
314
+		//userAdmin.IsSuperAdmin = false
315
+		//userAdmin.Status = 1
316
+		//userAdmin.CreateTime = 1530786071
317
+		//userAdmin.ModifyTime = 1530786071
318
+		//var subscibe models.ServeSubscibe
319
+		//subscibe.ID = 1
320
+		//subscibe.OrgId = 4
321
+		//subscibe.PeriodStart = 1538035409
322
+		//subscibe.PeriodEnd = 1569571409
323
+		//subscibe.State = 1
324
+		//subscibe.Status = 1
325
+		//subscibe.CreatedTime = 1538035409
326
+		//subscibe.UpdatedTime = 1538035409
327
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
328
+		//subscibes[4] = &subscibe
329
+		//var adminUserInfo service.AdminUserInfo
330
+		//adminUserInfo.CurrentOrgId = 4
331
+		//adminUserInfo.CurrentAppId = 18
332
+		//adminUserInfo.AdminUser = &userAdmin
333
+		//adminUserInfo.Subscibes = subscibes
334
+		//this.SetSession("admin_user_info", &adminUserInfo)
335
+
336
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
337
+		this.StopRun()
340 338
 	}
341 339
 
342 340
 	//if adminUserInfo.AppRole != nil {

+ 17 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -4235,3 +4235,20 @@ func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.D
4235 4235
 	}
4236 4236
 	return
4237 4237
 }
4238
+
4239
+func (c *DialysisAPIController) GetAllDrug() {
4240
+	patient_id, _ := c.GetInt64("patient_id", 0)
4241
+	adminInfo := c.GetMobileAdminUserInfo()
4242
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
4243
+	privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
4244
+	drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
4245
+	privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
4246
+
4247
+	c.ServeSuccessJSON(map[string]interface{}{
4248
+		"base_drug_config":    drugStockConfig,
4249
+		"private_drug_config": privateDrugConfig,
4250
+		"base_drug_list":      drugList,
4251
+		"private_drug_list":   privateDrugList,
4252
+	})
4253
+
4254
+}

+ 505 - 96
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -609,118 +609,483 @@ func (c *PatientApiController) ExecDoctorAdvice() {
609 609
 	advice.ExecutionState = 1
610 610
 	advice.Modifier = adminUserInfo.AdminUser.Id
611 611
 
612
-	//查询医嘱是否已经实行
613
-	if groupno > 0 {
614
-		advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
615
-		for _, item := range advices {
616
-			//如果医嘱已经执行生成自备药出库单
617
-			if item.ExecutionState == 1 {
612
+	//处理出库相关逻辑
618 613
 
619
-				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
620
-				outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
621
-				timeStr := time.Now().Format("2006-01-02")
622
-				timeArr := strings.Split(timeStr, "-")
623
-				total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
624
-				total = total + 1
625
-				warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
626
-				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
627
-				number = number + total
628
-				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
629
-
630
-				medicalName, errcode := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
631
-				if errcode == gorm.ErrRecordNotFound {
632
-					c.ServeSuccessJSON(map[string]interface{}{
633
-						"msg":    "ok",
634
-						"advice": advice,
635
-						"ids":    ids,
636
-					})
637
-					return
638
-				} else if errcode == nil {
639
-					stock := models.XtSelfOutStock{
640
-						DrugName:       item.AdviceName,
641
-						DrugNameId:     medicalName.DrugNameId,
642
-						DrugSpec:       item.AdviceDesc,
643
-						OutstoreNumber: outStoreNumber,
644
-						AdminUserId:    adminUserInfo.AdminUser.Id,
645
-						StorckTime:     item.AdviceDate,
646
-						UserOrgId:      adminUserInfo.Org.Id,
647
-						CreatedTime:    time.Now().Unix(),
648
-						Status:         1,
649
-						PatientId:      item.PatientId,
650
-						StockOutNumber: warehousing_out_order,
651
-						ExitMode:       2,
652
-						MedicId:        medicalName.ID,
614
+	//1.判断是否启用药品管理和自备药出库功能
615
+
616
+	//药品管理信息
617
+	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
618
+
619
+	//自备药信息
620
+	privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
621
+
622
+	if drugStockConfig.IsOpen == 1 {
623
+		if groupno > 0 {
624
+			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
625
+			isHasWay := false //用来判断是否包含来自药品库的医嘱
626
+			record_time := int64(0)
627
+			for _, item := range advices {
628
+				if item.Way == 1 {
629
+					isHasWay = true
630
+					record_time = item.RecordDate
631
+				}
632
+			}
633
+
634
+			if isHasWay {
635
+				out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
636
+				if err == gorm.ErrRecordNotFound {
637
+					//没有记录,则创建出库单
638
+					timeStr := time.Now().Format("2006-01-02")
639
+					timeArr := strings.Split(timeStr, "-")
640
+					total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
641
+					total = total + 1
642
+					warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
643
+					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
644
+					number = number + total
645
+					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
646
+					creater := adminUserInfo.AdminUser.Id
647
+					warehouseOut := models.DrugWarehouseOut{
648
+						WarehouseOutOrderNumber: warehousing_out_order,
649
+						OperationTime:           time.Now().Unix(),
650
+						OrgId:                   adminUserInfo.Org.Id,
651
+						Creater:                 creater,
652
+						Ctime:                   time.Now().Unix(),
653
+						Status:                  1,
654
+						WarehouseOutTime:        record_time,
655
+						Dealer:                  0,
656
+						Manufacturer:            0,
657
+						Type:                    1,
658
+						IsSys:                   1,
653 659
 					}
660
+					err := service.AddSigleDrugWarehouseOut(&warehouseOut)
661
+					if err != nil {
662
+						utils.TraceLog("创建出库单失败 err = %v", err)
663
+					} else {
664
+						for _, item := range advices {
665
+							if item.Way == 1 {
666
+								if item.PrescribingNumber > 0 {
667
+									warehouseOutInfo := &models.DrugWarehouseOutInfo{
668
+										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
669
+										WarehouseOutId:          warehouseOut.ID,
670
+										Status:                  1,
671
+										Ctime:                   time.Now().Unix(),
672
+										Remark:                  "",
673
+										OrgId:                   adminUserInfo.Org.Id,
674
+										Type:                    1,
675
+										Manufacturer:            0,
676
+										Dealer:                  0,
677
+										IsSys:                   1,
678
+										SysRecordTime:           record_time,
679
+										DrugId:                  item.DrugId,
680
+									}
681
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
682
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
683
+									warehouseOutInfo.Count = count
684
+									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
685
+									warehouseOutInfo.Price = stockInInfo.Price
686
+									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
687
+									if err == nil {
688
+										details := &models.DrugAutomaticReduceDetail{
689
+											WarehouseOutId:          warehouseOutInfo.ID,
690
+											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
691
+											PatientId:               item.PatientId,
692
+											Ctime:                   time.Now().Unix(),
693
+											Mtime:                   time.Now().Unix(),
694
+											Status:                  1,
695
+											RecordTime:              record_time,
696
+											OrgId:                   adminUserInfo.Org.Id,
697
+											DrugId:                  item.DrugId,
698
+											Count:                   count,
699
+										}
700
+										service.AddSigleDrugAutoReduceRecordInfo(details)
701
+									}
702
+								}
703
+							}
654 704
 
655
-					//创建出库单
656
-					service.CreateOutStock(&stock)
705
+						}
706
+					}
707
+
708
+				} else if err == nil {
709
+					for _, item := range advices {
710
+						if item.Way == 1 {
711
+							outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
712
+							if err == gorm.ErrRecordNotFound {
713
+								warehouseOutInfo := &models.DrugWarehouseOutInfo{
714
+									WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
715
+									WarehouseOutId:          out.ID,
716
+									Status:                  1,
717
+									Ctime:                   time.Now().Unix(),
718
+									Remark:                  "",
719
+									OrgId:                   adminUserInfo.Org.Id,
720
+									Type:                    1,
721
+									Manufacturer:            0,
722
+									Dealer:                  0,
723
+									IsSys:                   1,
724
+									SysRecordTime:           record_time,
725
+								}
726
+
727
+								stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
728
+								warehouseOutInfo.Price = stockInInfo.Price
729
+								warehouseOutInfo.DrugId = item.DrugId
730
+								prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
731
+								count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
732
+								warehouseOutInfo.Count = count
733
+								err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
734
+								if err == nil {
735
+									details := &models.DrugAutomaticReduceDetail{
736
+										WarehouseOutId:          warehouseOutInfo.ID,
737
+										WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
738
+										PatientId:               item.PatientId,
739
+										Ctime:                   time.Now().Unix(),
740
+										Mtime:                   time.Now().Unix(),
741
+										Status:                  1,
742
+										RecordTime:              record_time,
743
+										OrgId:                   adminUserInfo.Org.Id,
744
+										DrugId:                  item.DrugId,
745
+										Count:                   count,
746
+									}
747
+									service.AddSigleDrugAutoReduceRecordInfo(details)
748
+								}
749
+
750
+							} else if err == nil { //记录存在,则将增加数量
751
+								if outInfo.ID > 0 {
752
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
753
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
754
+									service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
755
+								}
756
+
757
+								count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
758
+								if count == 0 {
759
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
760
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
761
+									details := &models.DrugAutomaticReduceDetail{
762
+										WarehouseOutId:          outInfo.ID,
763
+										WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
764
+										PatientId:               item.PatientId,
765
+										Ctime:                   time.Now().Unix(),
766
+										Mtime:                   time.Now().Unix(),
767
+										Status:                  1,
768
+										RecordTime:              record_time,
769
+										OrgId:                   adminUserInfo.Org.Id,
770
+										DrugId:                  item.DrugId,
771
+										Count:                   count,
772
+									}
773
+									service.AddSigleDrugAutoReduceRecordInfo(details)
774
+								} else if count == 1 {
775
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
776
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
777
+									service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
778
+								}
779
+
780
+							}
781
+						}
782
+					}
657 783
 
658
-					c.ServeSuccessJSON(map[string]interface{}{
659
-						"msg":    "ok",
660
-						"advice": advice,
661
-						"ids":    ids,
662
-					})
663
-					return
664 784
 				}
665 785
 
666 786
 			}
667
-		}
668
-	} else {
669
-		advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
670
-		for _, item := range advices {
671
-			if item.ExecutionState == 1 {
672
-				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
673
-				outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
674
-				timeStr := time.Now().Format("2006-01-02")
675
-				timeArr := strings.Split(timeStr, "-")
676
-				total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
677
-				total = total + 1
678
-				warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
679
-				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
680
-				number = number + total
681
-				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
682
-
683
-				medicalName, errc := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
684
-				if errc == gorm.ErrRecordNotFound {
685
-					c.ServeSuccessJSON(map[string]interface{}{
686
-						"msg":    "ok",
687
-						"advice": advice,
688
-						"ids":    ids,
689
-					})
690
-					return
691
-				} else if errc == nil {
692
-
693
-					stock := models.XtSelfOutStock{
694
-						DrugName:       item.AdviceName,
695
-						DrugNameId:     medicalName.DrugNameId,
696
-						DrugSpec:       item.AdviceDesc,
697
-						OutstoreNumber: outStoreNumber,
698
-						AdminUserId:    adminUserInfo.AdminUser.Id,
699
-						StorckTime:     item.AdviceDate,
700
-						UserOrgId:      adminUserInfo.Org.Id,
701
-						CreatedTime:    time.Now().Unix(),
702
-						Status:         1,
703
-						PatientId:      item.PatientId,
704
-						StockOutNumber: warehousing_out_order,
705
-						ExitMode:       2,
706
-						MedicId:        medicalName.ID,
787
+		} else {
788
+			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
789
+			isHasWay := false //用来判断是否包含来自药品库的医嘱
790
+			record_time := int64(0)
791
+			for _, item := range advices {
792
+				if item.Way == 1 {
793
+					isHasWay = true
794
+					record_time = item.RecordDate
795
+				}
796
+			}
797
+
798
+			if isHasWay {
799
+				out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
800
+				if err == gorm.ErrRecordNotFound {
801
+					//没有记录,则创建出库单
802
+					timeStr := time.Now().Format("2006-01-02")
803
+					timeArr := strings.Split(timeStr, "-")
804
+					total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
805
+					total = total + 1
806
+					warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
807
+					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
808
+					number = number + total
809
+					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
810
+					creater := adminUserInfo.AdminUser.Id
811
+					warehouseOut := models.DrugWarehouseOut{
812
+						WarehouseOutOrderNumber: warehousing_out_order,
813
+						OperationTime:           time.Now().Unix(),
814
+						OrgId:                   adminUserInfo.Org.Id,
815
+						Creater:                 creater,
816
+						Ctime:                   time.Now().Unix(),
817
+						Status:                  1,
818
+						WarehouseOutTime:        record_time,
819
+						Dealer:                  0,
820
+						Manufacturer:            0,
821
+						Type:                    1,
822
+						IsSys:                   1,
707 823
 					}
824
+					err := service.AddSigleDrugWarehouseOut(&warehouseOut)
825
+					if err != nil {
826
+						utils.TraceLog("创建出库单失败 err = %v", err)
827
+					} else {
828
+						for _, item := range advices {
829
+							if item.Way == 1 {
830
+								if item.PrescribingNumber > 0 {
831
+									warehouseOutInfo := &models.DrugWarehouseOutInfo{
832
+										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
833
+										WarehouseOutId:          warehouseOut.ID,
834
+										Status:                  1,
835
+										Ctime:                   time.Now().Unix(),
836
+										Remark:                  "",
837
+										OrgId:                   adminUserInfo.Org.Id,
838
+										Type:                    1,
839
+										Manufacturer:            0,
840
+										Dealer:                  0,
841
+										IsSys:                   1,
842
+										SysRecordTime:           record_time,
843
+										DrugId:                  item.DrugId,
844
+									}
845
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
846
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
847
+									warehouseOutInfo.Count = count
848
+									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
849
+									warehouseOutInfo.Price = stockInInfo.Price
850
+									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
851
+									if err == nil {
852
+										details := &models.DrugAutomaticReduceDetail{
853
+											WarehouseOutId:          warehouseOutInfo.ID,
854
+											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
855
+											PatientId:               item.PatientId,
856
+											Ctime:                   time.Now().Unix(),
857
+											Mtime:                   time.Now().Unix(),
858
+											Status:                  1,
859
+											RecordTime:              record_time,
860
+											OrgId:                   adminUserInfo.Org.Id,
861
+											DrugId:                  item.DrugId,
862
+											Count:                   count,
863
+										}
864
+										service.AddSigleDrugAutoReduceRecordInfo(details)
865
+									}
866
+								}
867
+							}
708 868
 
709
-					//创建出库单
710
-					service.CreateOutStock(&stock)
869
+						}
870
+					}
871
+
872
+				} else if err == nil {
873
+					for _, item := range advices {
874
+						if item.Way == 1 {
875
+							outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
876
+							if err == gorm.ErrRecordNotFound {
877
+								warehouseOutInfo := &models.DrugWarehouseOutInfo{
878
+									WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
879
+									WarehouseOutId:          out.ID,
880
+									Status:                  1,
881
+									Ctime:                   time.Now().Unix(),
882
+									Remark:                  "",
883
+									OrgId:                   adminUserInfo.Org.Id,
884
+									Type:                    1,
885
+									Manufacturer:            0,
886
+									Dealer:                  0,
887
+									IsSys:                   1,
888
+									SysRecordTime:           record_time,
889
+								}
890
+
891
+								stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
892
+								warehouseOutInfo.Price = stockInInfo.Price
893
+								warehouseOutInfo.DrugId = item.DrugId
894
+								//warehouseOutInfo.Count = item.
895
+								prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
896
+								count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
897
+								err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
898
+								if err == nil {
899
+									details := &models.DrugAutomaticReduceDetail{
900
+										WarehouseOutId:          warehouseOutInfo.ID,
901
+										WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
902
+										PatientId:               item.PatientId,
903
+										Ctime:                   time.Now().Unix(),
904
+										Mtime:                   time.Now().Unix(),
905
+										Status:                  1,
906
+										RecordTime:              record_time,
907
+										OrgId:                   adminUserInfo.Org.Id,
908
+										DrugId:                  item.DrugId,
909
+										Count:                   count,
910
+									}
911
+									service.AddSigleDrugAutoReduceRecordInfo(details)
912
+								}
913
+
914
+							} else if err == nil { //记录存在,则将增加数量
915
+								if outInfo.ID > 0 {
916
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
917
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
918
+									service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
919
+								}
920
+
921
+								count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
922
+								if count == 0 {
923
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
924
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
925
+									details := &models.DrugAutomaticReduceDetail{
926
+										WarehouseOutId:          outInfo.ID,
927
+										WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
928
+										PatientId:               item.PatientId,
929
+										Ctime:                   time.Now().Unix(),
930
+										Mtime:                   time.Now().Unix(),
931
+										Status:                  1,
932
+										RecordTime:              record_time,
933
+										OrgId:                   adminUserInfo.Org.Id,
934
+										DrugId:                  item.DrugId,
935
+										Count:                   count,
936
+									}
937
+									service.AddSigleDrugAutoReduceRecordInfo(details)
938
+								} else if count == 1 {
939
+									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
940
+									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
941
+									service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
942
+								}
943
+
944
+							}
945
+						}
946
+					}
711 947
 
712
-					c.ServeSuccessJSON(map[string]interface{}{
713
-						"msg":    "ok",
714
-						"advice": advice,
715
-						"ids":    ids,
716
-					})
717
-					return
718 948
 				}
719 949
 
720 950
 			}
721 951
 		}
722 952
 	}
723 953
 
954
+	if privateDrugConfig.DrugStart == 1 {
955
+		if groupno > 0 {
956
+			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
957
+			for _, item := range advices {
958
+				if item.ExecutionState == 2 {
959
+					advice = item
960
+
961
+				}
962
+			}
963
+		} else {
964
+			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
965
+			for _, item := range advices {
966
+				if item.ExecutionState == 2 {
967
+					advice = item
968
+
969
+				}
970
+			}
971
+		}
972
+	}
973
+
974
+	c.ServeSuccessJSON(map[string]interface{}{
975
+		"msg":    "ok",
976
+		"advice": advice,
977
+		"ids":    ids,
978
+	})
979
+	return
980
+
981
+	//查询医嘱是否已经实行
982
+	//if groupno > 0 {
983
+	//	advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
984
+	//	for _, item := range advices {
985
+	//		//如果医嘱已经执行生成自备药出库单
986
+	//		if item.ExecutionState == 1 {
987
+	//
988
+	//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
989
+	//			outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
990
+	//
991
+	//			timeStr := time.Now().Format("2006-01-02")
992
+	//			timeArr := strings.Split(timeStr, "-")
993
+	//			total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
994
+	//			total = total + 1
995
+	//			warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
996
+	//			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
997
+	//			number = number + total
998
+	//			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
999
+	//
1000
+	//			medicalName, errcode := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
1001
+	//			if errcode == gorm.ErrRecordNotFound {
1002
+	//				c.ServeSuccessJSON(map[string]interface{}{
1003
+	//					"msg":    "ok",
1004
+	//					"advice": advice,
1005
+	//					"ids":    ids,
1006
+	//				})
1007
+	//				return
1008
+	//			} else if errcode == nil {
1009
+	//				stock := models.XtSelfOutStock{
1010
+	//					DrugName:       item.AdviceName,
1011
+	//					DrugNameId:     medicalName.DrugNameId,
1012
+	//					DrugSpec:       item.AdviceDesc,
1013
+	//					OutstoreNumber: outStoreNumber,
1014
+	//					AdminUserId:    adminUserInfo.AdminUser.Id,
1015
+	//					StorckTime:     item.AdviceDate,
1016
+	//					UserOrgId:      adminUserInfo.Org.Id,
1017
+	//					CreatedTime:    time.Now().Unix(),
1018
+	//					Status:         1,
1019
+	//					PatientId:      item.PatientId,
1020
+	//					StockOutNumber: warehousing_out_order,
1021
+	//					ExitMode:       2,
1022
+	//					MedicId:        medicalName.ID,
1023
+	//				}
1024
+	//
1025
+	//				//创建出库单
1026
+	//				service.CreateOutStock(&stock)
1027
+	//
1028
+	//				c.ServeSuccessJSON(map[string]interface{}{
1029
+	//					"msg":    "ok",
1030
+	//					"advice": advice,
1031
+	//					"ids":    ids,
1032
+	//				})
1033
+	//				return
1034
+	//			}
1035
+	//
1036
+	//		}
1037
+	//	}
1038
+	//} else {
1039
+	//	advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
1040
+	//	for _, item := range advices {
1041
+	//		if item.ExecutionState == 1 {
1042
+	//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1043
+	//			outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1044
+	//			timeStr := time.Now().Format("2006-01-02")
1045
+	//			timeArr := strings.Split(timeStr, "-")
1046
+	//			total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
1047
+	//			total = total + 1
1048
+	//			warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1049
+	//			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1050
+	//			number = number + total
1051
+	//			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1052
+	//
1053
+	//			medicalName, errc := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
1054
+	//			if errc == gorm.ErrRecordNotFound {
1055
+	//
1056
+	//			} else if errc == nil {
1057
+	//
1058
+	//				stock := models.XtSelfOutStock{
1059
+	//					DrugName:       item.AdviceName,
1060
+	//					DrugNameId:     medicalName.DrugNameId,
1061
+	//					DrugSpec:       item.AdviceDesc,
1062
+	//					OutstoreNumber: outStoreNumber,
1063
+	//					AdminUserId:    adminUserInfo.AdminUser.Id,
1064
+	//					StorckTime:     item.AdviceDate,
1065
+	//					UserOrgId:      adminUserInfo.Org.Id,
1066
+	//					CreatedTime:    time.Now().Unix(),
1067
+	//					Status:         1,
1068
+	//					PatientId:      item.PatientId,
1069
+	//					StockOutNumber: warehousing_out_order,
1070
+	//					ExitMode:       2,
1071
+	//					MedicId:        medicalName.ID,
1072
+	//				}
1073
+	//
1074
+	//				//创建出库单
1075
+	//				service.CreateOutStock(&stock)
1076
+	//
1077
+	//				c.ServeSuccessJSON(map[string]interface{}{
1078
+	//					"msg":    "ok",
1079
+	//					"advice": advice,
1080
+	//					"ids":    ids,
1081
+	//				})
1082
+	//				return
1083
+	//			}
1084
+	//
1085
+	//		}
1086
+	//	}
1087
+	//}
1088
+
724 1089
 }
725 1090
 func (c *PatientApiController) ModifyExecDoctorAdvice() {
726 1091
 	execution_time := c.GetString("execution_time")
@@ -1918,6 +2283,26 @@ func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (co
1918 2283
 		advice.AdviceDesc = adviceDsc
1919 2284
 	}
1920 2285
 
2286
+	if dataBody["src_type"] == nil {
2287
+		advice.Way = 0
2288
+
2289
+	} else {
2290
+		if dataBody["src_type"] != nil || reflect.TypeOf(dataBody["src_type"]).String() == "float64" {
2291
+			src_type := int64(dataBody["src_type"].(float64))
2292
+			advice.Way = src_type
2293
+		}
2294
+
2295
+	}
2296
+
2297
+	if dataBody["drug_id"] == nil {
2298
+		advice.DrugId = 0
2299
+	} else {
2300
+		if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
2301
+			drug_id := int64(dataBody["drug_id"].(float64))
2302
+			advice.DrugId = drug_id
2303
+		}
2304
+	}
2305
+
1921 2306
 	if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
1922 2307
 		singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
1923 2308
 		advice.SingleDose = singleDose
@@ -2619,6 +3004,30 @@ func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, jso
2619 3004
 		advice.Remark = remark
2620 3005
 	}
2621 3006
 
3007
+	//if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
3008
+	//	src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
3009
+	//	advice.Way = src_type
3010
+	//}
3011
+	if json["src_type"] == nil {
3012
+		advice.Way = 0
3013
+
3014
+	} else {
3015
+		if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
3016
+			src_type := int64(json["src_type"].(float64))
3017
+			advice.Way = src_type
3018
+		}
3019
+
3020
+	}
3021
+
3022
+	if json["drug_id"] == nil {
3023
+		advice.DrugId = 0
3024
+	} else {
3025
+		if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
3026
+			drug_id := int64(json["drug_id"].(float64))
3027
+			advice.DrugId = drug_id
3028
+		}
3029
+	}
3030
+
2622 3031
 	if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
2623 3032
 		drugSpecUnit, _ := json["drug_spec_unit"].(string)
2624 3033
 		advice.DrugSpecUnit = drugSpecUnit

+ 18 - 0
models/drug_stock.go View File

@@ -197,3 +197,21 @@ type DrugCancelStockInfo struct {
197 197
 func (DrugCancelStockInfo) TableName() string {
198 198
 	return "xt_drug_cancel_stock_info"
199 199
 }
200
+
201
+type DrugAutomaticReduceDetail struct {
202
+	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
203
+	WarehouseOutId          int64  `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
204
+	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
205
+	PatientId               int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
206
+	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
207
+	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
208
+	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
209
+	RecordTime              int64  `gorm:"column:record_time" json:"record_time" form:"record_time"`
210
+	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
211
+	DrugId                  int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
212
+	Count                   int64  `gorm:"column:count" json:"count" form:"count"`
213
+}
214
+
215
+func (DrugAutomaticReduceDetail) TableName() string {
216
+	return "xt_drug_automatic_reduce_detail"
217
+}

+ 6 - 0
service/dialysis_service.go View File

@@ -1092,6 +1092,12 @@ func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id
1092 1092
 
1093 1093
 }
1094 1094
 
1095
+func UpdateDrugUserInfoDetails(drug_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.DrugWarehouseOutInfo) {
1096
+	writeDb.Model(&models.DrugAutomaticReduceDetail{}).Where("drug_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", drug_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count})
1097
+	//writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count)
1098
+
1099
+}
1100
+
1095 1101
 func FindDialysisBeforePrepare(patient_id int64, good_id int64, good_type_id int64, user_org_id int64, record_time int64) (count int64) {
1096 1102
 	readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ?  AND good_id = ? AND good_type_id = ? AND record_date = ? AND status = 1", user_org_id, patient_id, good_id, good_type_id, record_time).Count(&count)
1097 1103
 	return

+ 1 - 1
service/mobile_dialysis_service.go View File

@@ -508,7 +508,7 @@ func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int
508 508
 	err := readDb.
509 509
 		Model(&models.DoctorAdvice{}).
510 510
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
511
-		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").
511
+		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id, IF(parent_id > 0, parent_id, id) as advice_order").
512 512
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
513 513
 		Scan(&records).Error
514 514
 

+ 59 - 0
service/self_drug_service.go View File

@@ -375,3 +375,62 @@ func CreateAotoMaticReduceDetail(detail *models.XtDrugAutomaticReduceDetail) err
375 375
 	err := XTWriteDB().Model(&detail).Create(&detail).Error
376 376
 	return err
377 377
 }
378
+
379
+type Drugs struct {
380
+	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
381
+	DrugName           string   `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
382
+	Pinyin             string   `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
383
+	Wubi               string   `gorm:"column:wubi" json:"wubi" form:"wubi"`
384
+	DrugAlias          string   `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
385
+	DrugAliasPinyin    string   `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
386
+	DrugAliasWubi      string   `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
387
+	DrugCategory       int64    `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
388
+	DrugSpec           float64  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
389
+	DrugType           int64    `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
390
+	DrugStockLimit     string   `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
391
+	DrugStatus         string   `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
392
+	DeliveryWay        string   `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
393
+	ExecutionFrequency string   `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
394
+	SingleDose         float64  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
395
+	PrescribingNumber  float64  `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
396
+	Status             int64    `gorm:"column:status" json:"status" form:"status"`
397
+	OrgId              int64    `gorm:"column:org_id" json:"org_id" form:"org_id"`
398
+	Drugs              []*Drugs `gorm:"ForeignKey:DrugName;AssociationForeignKey:DrugName" json:"drug_specs"`
399
+}
400
+
401
+func (Drugs) TableName() string {
402
+	return "xt_base_drug"
403
+}
404
+
405
+func GetAllBaseDrugLibList(org_id int64) (drugs []*Drugs, err error) {
406
+	db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ?  AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
407
+	err = db.Find(&drugs).Error
408
+	return
409
+}
410
+
411
+type PrivateDrug struct {
412
+	DrugName           string         `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
413
+	ID                 int64          `gorm:"column:id" json:"id" form:"id"`
414
+	DrugSpec           string         `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
415
+	PatientId          int64          `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
416
+	DrugNameId         int64          `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
417
+	Status             int64          `gorm:"column:status" json:"status" form:"status"`
418
+	UserOrgId          int64          `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
419
+	CreatedTime        int64          `gorm:"column:created_time" json:"created_time" form:"created_time"`
420
+	UpdatedTime        int64          `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
421
+	MinUnit            string         `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
422
+	ExecutionFrequency string         `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
423
+	PrescribingNumber  float64        `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
424
+	DeliveryWay        string         `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
425
+	SingleDose         float64        `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
426
+	PrivateDrug        []*PrivateDrug `gorm:"ForeignKey:DrugName;AssociationForeignKey:DrugName" json:"drug_specs"`
427
+}
428
+
429
+func (PrivateDrug) TableName() string {
430
+	return "xt_self_medical"
431
+}
432
+
433
+func GetPrivateDrugList(patient_id int64, org_id int64) (pds []*PrivateDrug, err error) {
434
+	err = XTReadDB().Model(&PrivateDrug{}).Preload("PrivateDrug", "status = 1 AND user_org_id = ? AND patient_id = ? ", org_id, patient_id).Where("patient_id = ? and status = 1 AND user_org_id = ?", patient_id, org_id).Group("drug_name").Find(&pds).Error
435
+	return
436
+}

+ 41 - 0
service/stock_service.go View File

@@ -1892,29 +1892,58 @@ func FindStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out model
1892 1892
 
1893 1893
 }
1894 1894
 
1895
+func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out models.DrugWarehouseOut, err error) {
1896
+	err = readDb.Model(&models.DrugWarehouseOut{}).Where("is_sys = ? AND status = 1 AND org_id = ? AND warehouse_out_time = ?", is_sys, org_id, record_time).First(&out).Error
1897
+	return
1898
+
1899
+}
1900
+
1895 1901
 func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
1896 1902
 	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).Last(&in).Error
1897 1903
 	return
1898 1904
 
1899 1905
 }
1900 1906
 
1907
+func FindLastDrugStockInInfoRecord(drug_id int64, org_id int64) (in models.WarehousingInfo, err error) {
1908
+	err = readDb.Model(&models.DrugWarehouseInfo{}).Where("status = 1 AND org_id = ? AND drug_id = ?", org_id, drug_id).Last(&in).Error
1909
+	return
1910
+
1911
+}
1912
+
1901 1913
 func AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo) error {
1902 1914
 	err := writeDb.Create(&info).Error
1903 1915
 	return err
1904 1916
 
1905 1917
 }
1906 1918
 
1919
+func AddSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) error {
1920
+	err := writeDb.Create(&info).Error
1921
+	return err
1922
+
1923
+}
1924
+
1907 1925
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
1908 1926
 	err := writeDb.Create(&detail).Error
1909 1927
 	return err
1910 1928
 
1911 1929
 }
1912 1930
 
1931
+func AddSigleDrugAutoReduceRecordInfo(detail *models.DrugAutomaticReduceDetail) error {
1932
+	err := writeDb.Create(&detail).Error
1933
+	return err
1934
+
1935
+}
1936
+
1913 1937
 func FindStockOutInfoByTypeId(org_id int64, good_type_id int64, good_id int64, out_id int64, number string) (out models.WarehouseOutInfo, err error) {
1914 1938
 	err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND  (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, good_type_id, good_id, out_id, number).First(&out).Error
1915 1939
 	return
1916 1940
 }
1917 1941
 
1942
+func FindDrugStockOutInfoByTypeId(org_id int64, drug_id int64, out_id int64, number string) (out models.DrugWarehouseOutInfo, err error) {
1943
+	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND  drug_id = ? AND is_sys = 1 AND  (warehouse_out_id = ? or warehouse_out_order_number = ?)", org_id, drug_id, out_id, number).First(&out).Error
1944
+	return
1945
+}
1946
+
1918 1947
 func UpdateStockOutInfoCount(org_id int64, id int64) {
1919 1948
 	writeDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", 1))
1920 1949
 
@@ -1936,6 +1965,11 @@ func UpdateStockOutInfoCount2(org_id int64, id int64, count int64) {
1936 1965
 
1937 1966
 }
1938 1967
 
1968
+func UpdateDrugStockOutInfoCount2(org_id int64, id int64, count int64) {
1969
+	writeDb.Model(&models.DrugWarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND id = ?", org_id, id).UpdateColumn("count", gorm.Expr("count + ?", count))
1970
+
1971
+}
1972
+
1939 1973
 func FindPatientAutomaticReduceRecord(org_id int64, record_time int64, good_id int64, good_type_id int64, patient_id int64) (count int64, err error) {
1940 1974
 
1941 1975
 	err = readDb.Model(&models.AutomaticReduceDetail{}).Where("org_id = ? AND status = 1 AND good_id = ? AND good_type_id = ? AND patient_id = ? AND record_time = ?", org_id, good_id, good_type_id, patient_id, record_time).Count(&count).Error
@@ -1943,6 +1977,13 @@ func FindPatientAutomaticReduceRecord(org_id int64, record_time int64, good_id i
1943 1977
 
1944 1978
 }
1945 1979
 
1980
+func FindPatientDrugAutomaticReduceRecord(org_id int64, record_time int64, drug_id int64, patient_id int64) (count int64, err error) {
1981
+
1982
+	err = readDb.Model(&models.DrugAutomaticReduceDetail{}).Where("org_id = ? AND status = 1 AND drug_id = ?AND patient_id = ? AND record_time = ?", org_id, drug_id, patient_id, record_time).Count(&count).Error
1983
+	return
1984
+
1985
+}
1986
+
1946 1987
 type VMWarehousingInfo struct {
1947 1988
 	ID            int64    `gorm:"column:id" json:"id"`
1948 1989
 	WarehousingId int64    `gorm:"column:warehousing_id" json:"warehousing_id"`