Просмотр исходного кода

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

XMLWAN 3 лет назад
Родитель
Сommit
4bd0f41f99

+ 29 - 29
controllers/base_api_controller.go Просмотреть файл

69
 func (this *BaseAuthAPIController) Prepare() {
69
 func (this *BaseAuthAPIController) Prepare() {
70
 	this.BaseAPIController.Prepare()
70
 	this.BaseAPIController.Prepare()
71
 	if this.GetAdminUserInfo() == nil {
71
 	if this.GetAdminUserInfo() == nil {
72
-		//var userAdmin models.AdminUser
73
-		//userAdmin.Id = 1448
74
-		//userAdmin.Mobile = "13318599895"
75
-		//
76
-		////userAdmin.Id = 597
77
-		////userAdmin.Mobile = "19874122664"
78
-		//userAdmin.IsSuperAdmin = false
79
-		//userAdmin.Status = 1
80
-		//userAdmin.CreateTime = 1530786071
81
-		//userAdmin.ModifyTime = 1530786071
82
-		//var subscibe models.ServeSubscibe
83
-		//subscibe.ID = 1
84
-		//subscibe.OrgId = 4
85
-		//subscibe.PeriodStart = 1538035409
86
-		//subscibe.PeriodEnd = 1569571409
87
-		//subscibe.State = 1
88
-		//subscibe.Status = 1
89
-		//subscibe.CreatedTime = 1538035409
90
-		//subscibe.UpdatedTime = 1538035409
91
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
92
-		//subscibes[4] = &subscibe
93
-		//var adminUserInfo service.AdminUserInfo
94
-		//adminUserInfo.CurrentOrgId = 4
95
-		//adminUserInfo.CurrentAppId = 4
96
-		//adminUserInfo.AdminUser = &userAdmin
97
-		//adminUserInfo.Subscibes = subscibes
98
-		//this.SetSession("admin_user_info", &adminUserInfo)
72
+		var userAdmin models.AdminUser
73
+		userAdmin.Id = 1448
74
+		userAdmin.Mobile = "13318599895"
75
+
76
+		//userAdmin.Id = 597
77
+		//userAdmin.Mobile = "19874122664"
78
+		userAdmin.IsSuperAdmin = false
79
+		userAdmin.Status = 1
80
+		userAdmin.CreateTime = 1530786071
81
+		userAdmin.ModifyTime = 1530786071
82
+		var subscibe models.ServeSubscibe
83
+		subscibe.ID = 1
84
+		subscibe.OrgId = 3877
85
+		subscibe.PeriodStart = 1538035409
86
+		subscibe.PeriodEnd = 1569571409
87
+		subscibe.State = 1
88
+		subscibe.Status = 1
89
+		subscibe.CreatedTime = 1538035409
90
+		subscibe.UpdatedTime = 1538035409
91
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92
+		subscibes[4] = &subscibe
93
+		var adminUserInfo service.AdminUserInfo
94
+		adminUserInfo.CurrentOrgId = 3877
95
+		adminUserInfo.CurrentAppId = 4
96
+		adminUserInfo.AdminUser = &userAdmin
97
+		adminUserInfo.Subscibes = subscibes
98
+		this.SetSession("admin_user_info", &adminUserInfo)
99
 
99
 
100
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
100
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
101
 		this.StopRun()
101
 		this.StopRun()
327
 		userAdmin.ModifyTime = 1530786071
327
 		userAdmin.ModifyTime = 1530786071
328
 		var subscibe models.ServeSubscibe
328
 		var subscibe models.ServeSubscibe
329
 		subscibe.ID = 1
329
 		subscibe.ID = 1
330
-		subscibe.OrgId = 4
330
+		subscibe.OrgId = 3877
331
 		subscibe.PeriodStart = 1538035409
331
 		subscibe.PeriodStart = 1538035409
332
 		subscibe.PeriodEnd = 1569571409
332
 		subscibe.PeriodEnd = 1569571409
333
 		subscibe.State = 1
333
 		subscibe.State = 1
337
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
337
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
 		subscibes[4] = &subscibe
338
 		subscibes[4] = &subscibe
339
 		var adminUserInfo service.AdminUserInfo
339
 		var adminUserInfo service.AdminUserInfo
340
-		adminUserInfo.CurrentOrgId = 4
340
+		adminUserInfo.CurrentOrgId = 3877
341
 		adminUserInfo.CurrentAppId = 4
341
 		adminUserInfo.CurrentAppId = 4
342
 		adminUserInfo.AdminUser = &userAdmin
342
 		adminUserInfo.AdminUser = &userAdmin
343
 		adminUserInfo.Subscibes = subscibes
343
 		adminUserInfo.Subscibes = subscibes

+ 496 - 190
controllers/his_api_controller.go Просмотреть файл

56
 	beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
56
 	beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
57
 
57
 
58
 	beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
58
 	beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
59
-
60
 	beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
59
 	beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
60
+	beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
61
 
61
 
62
 	beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
62
 	beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
63
 
63
 
290
 	record_date := c.GetString("record_date")
290
 	record_date := c.GetString("record_date")
291
 	patient_id, _ := c.GetInt64("patient_id")
291
 	patient_id, _ := c.GetInt64("patient_id")
292
 	reg_type, _ := c.GetInt64("reg_type")
292
 	reg_type, _ := c.GetInt64("reg_type")
293
-	diagnose := c.GetString("diagnose")
293
+	diagnose, _ := c.GetInt64("diagnose")
294
 	sick_type, _ := c.GetInt64("sick_type")
294
 	sick_type, _ := c.GetInt64("sick_type")
295
 	sick_history := c.GetString("sick_history")
295
 	sick_history := c.GetString("sick_history")
296
 	doctor_id, _ := c.GetInt64("doctor", 0)
296
 	doctor_id, _ := c.GetInt64("doctor", 0)
520
 				}
520
 				}
521
 				order_status := int64(items["order_status"].(float64))
521
 				order_status := int64(items["order_status"].(float64))
522
 
522
 
523
+				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
524
+					utils.ErrorLog("med_type")
525
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
526
+					return
527
+				}
528
+				med_type := strconv.Itoa(int(items["med_type"].(float64)))
529
+
530
+				if med_type == "0" {
531
+					med_type = "14"
532
+				}
533
+
523
 				if order_status == 0 {
534
 				if order_status == 0 {
524
 					order_status = 1
535
 					order_status = 1
525
 				}
536
 				}
559
 						PrescriptionNumber: hpInfo.PrescriptionNumber,
570
 						PrescriptionNumber: hpInfo.PrescriptionNumber,
560
 						PreTime:            pTime,
571
 						PreTime:            pTime,
561
 						PType:              p_type,
572
 						PType:              p_type,
573
+						MedType:            med_type,
562
 					}
574
 					}
563
 					tempPrescription = prescription
575
 					tempPrescription = prescription
564
 					service.SaveHisPrescription(tempPrescription)
576
 					service.SaveHisPrescription(tempPrescription)
571
 					tempPrescription.Doctor = role.UserName
583
 					tempPrescription.Doctor = role.UserName
572
 					tempPrescription.OrderStatus = order_status
584
 					tempPrescription.OrderStatus = order_status
573
 					tempPrescription.PreTime = pTime
585
 					tempPrescription.PreTime = pTime
586
+					tempPrescription.MedType = med_type
574
 					service.SaveHisPrescription(tempPrescription)
587
 					service.SaveHisPrescription(tempPrescription)
575
 				}
588
 				}
576
 				//service.SaveHisPrescription(prescription)
589
 				//service.SaveHisPrescription(prescription)
714
 	record_date := c.GetString("record_date")
727
 	record_date := c.GetString("record_date")
715
 	patient_id, _ := c.GetInt64("patient_id")
728
 	patient_id, _ := c.GetInt64("patient_id")
716
 	reg_type, _ := c.GetInt64("reg_type")
729
 	reg_type, _ := c.GetInt64("reg_type")
717
-	diagnose := c.GetString("diagnose")
730
+	diagnose, _ := c.GetInt64("diagnose", 0)
718
 	sick_type, _ := c.GetInt64("sick_type")
731
 	sick_type, _ := c.GetInt64("sick_type")
719
 	sick_history := c.GetString("sick_history")
732
 	sick_history := c.GetString("sick_history")
720
 	doctor_id, _ := c.GetInt64("doctor", 0)
733
 	doctor_id, _ := c.GetInt64("doctor", 0)
819
 				}
832
 				}
820
 				types := int64(items["type"].(float64))
833
 				types := int64(items["type"].(float64))
821
 
834
 
835
+				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
836
+					utils.ErrorLog("med_type")
837
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
838
+					return
839
+				}
840
+				med_type := strconv.Itoa(int(items["med_type"].(float64)))
841
+
822
 				historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
842
 				historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
823
 
843
 
824
 				ctime := time.Now().Unix()
844
 				ctime := time.Now().Unix()
840
 					BatchNumber:        "",
860
 					BatchNumber:        "",
841
 					PrescriptionNumber: hpInfo.PrescriptionNumber,
861
 					PrescriptionNumber: hpInfo.PrescriptionNumber,
842
 					PType:              hpInfo.PType,
862
 					PType:              hpInfo.PType,
863
+					MedType:            med_type,
843
 				}
864
 				}
844
 
865
 
845
 				if historyPrescription.ID > 0 {
866
 				if historyPrescription.ID > 0 {
2727
 	fapiao_code := c.GetString("fapiao_code")
2748
 	fapiao_code := c.GetString("fapiao_code")
2728
 	fapiao_number := c.GetString("fapiao_number")
2749
 	fapiao_number := c.GetString("fapiao_number")
2729
 
2750
 
2751
+	diagnosis_id, _ := c.GetInt64("diagnosis")
2752
+	sick_type, _ := c.GetInt64("sick_type")
2753
+	reg_type, _ := c.GetInt64("p_type")
2754
+	order_id, _ := c.GetInt64("order_id")
2755
+
2756
+	his, _ := service.GetHisPatientByIdThree(his_patient_id)
2757
+
2758
+	tempOrder, _ := service.GetHisOrderByID(order_id)
2759
+
2730
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
2760
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
2731
 	if err != nil {
2761
 	if err != nil {
2732
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2762
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2738
 	var start_time int64
2768
 	var start_time int64
2739
 	var end_time int64
2769
 	var end_time int64
2740
 
2770
 
2741
-	if settle_accounts_type == 1 { //日结
2771
+	if tempOrder.ID == 0 {
2742
 
2772
 
2743
-		prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime)
2773
+		if settle_accounts_type == 1 { //日结
2744
 
2774
 
2745
-	} else { //月结
2746
-		start_time_str := c.GetString("start_time")
2747
-		end_time_str := c.GetString("end_time")
2748
-		timeLayout := "2006-01-02"
2749
-		loc, _ := time.LoadLocation("Local")
2750
-		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
2751
-		if err != nil {
2752
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2753
-			return
2754
-		}
2755
-		recordStartTime := theStartTime.Unix()
2756
-		start_time = recordStartTime
2757
-		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
2758
-		if err != nil {
2759
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2760
-			return
2761
-		}
2762
-		recordEndTime := theEndTime.Unix()
2763
-		end_time = recordEndTime
2764
-		prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
2765
-	}
2775
+			prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
2766
 
2776
 
2767
-	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
2777
+		} else { //月结
2778
+			start_time_str := c.GetString("start_time")
2779
+			end_time_str := c.GetString("end_time")
2780
+			timeLayout := "2006-01-02"
2781
+			loc, _ := time.LoadLocation("Local")
2782
+			theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
2783
+			if err != nil {
2784
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2785
+				return
2786
+			}
2787
+			recordStartTime := theStartTime.Unix()
2788
+			start_time = recordStartTime
2789
+			theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
2790
+			if err != nil {
2791
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2792
+				return
2793
+			}
2794
+			recordEndTime := theEndTime.Unix()
2795
+			end_time = recordEndTime
2796
+			prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
2797
+		}
2768
 
2798
 
2769
-	fmt.Println("~~~~~~~~~")
2770
-	fmt.Println(his.Number)
2771
-	fmt.Println("~~~~~~~~~")
2799
+		fmt.Println("~~~~~~~~~")
2800
+		fmt.Println(his.Number)
2801
+		fmt.Println("~~~~~~~~~")
2772
 
2802
 
2773
-	timestamp := time.Now().Unix()
2774
-	tempTime := time.Unix(timestamp, 0)
2775
-	timeFormat := tempTime.Format("20060102150405")
2776
-	chrgBchno := rand.Intn(100000) + 10000
2777
-	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
2778
-	strconv.FormatInt(his.PatientId, 10)
2803
+		timestamp := time.Now().Unix()
2804
+		tempTime := time.Unix(timestamp, 0)
2805
+		timeFormat := tempTime.Format("20060102150405")
2806
+		chrgBchno := rand.Intn(100000) + 10000
2807
+		chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
2808
+		strconv.FormatInt(his.PatientId, 10)
2779
 
2809
 
2780
-	var ids []int64
2810
+		var ids []int64
2781
 
2811
 
2782
-	for _, item := range prescriptions {
2783
-		ids = append(ids, item.ID)
2784
-	}
2812
+		for _, item := range prescriptions {
2813
+			ids = append(ids, item.ID)
2814
+		}
2785
 
2815
 
2786
-	var total float64
2787
-	for _, item := range prescriptions {
2788
-		if item.Type == 1 { //药品
2789
-			for _, subItem := range item.HisDoctorAdviceInfo {
2790
-				total = total + (subItem.Price * subItem.PrescribingNumber)
2816
+		var total float64
2817
+		for _, item := range prescriptions {
2818
+			if item.Type == 1 { //药品
2819
+				for _, subItem := range item.HisDoctorAdviceInfo {
2820
+					total = total + (subItem.Price * subItem.PrescribingNumber)
2821
+				}
2791
 			}
2822
 			}
2792
-		}
2793
-		if item.Type == 2 { //项目
2794
-			for _, subItem := range item.HisPrescriptionProject {
2823
+			if item.Type == 2 { //项目
2824
+				for _, subItem := range item.HisPrescriptionProject {
2825
+					total = total + (subItem.Price * float64(subItem.Count))
2826
+				}
2827
+			}
2828
+
2829
+			for _, subItem := range item.HisAdditionalCharge {
2795
 				total = total + (subItem.Price * float64(subItem.Count))
2830
 				total = total + (subItem.Price * float64(subItem.Count))
2796
 			}
2831
 			}
2797
 		}
2832
 		}
2798
 
2833
 
2799
-		for _, subItem := range item.HisAdditionalCharge {
2800
-			total = total + (subItem.Price * float64(subItem.Count))
2834
+		allTotal := fmt.Sprintf("%.2f", total)
2835
+		totals, _ := strconv.ParseFloat(allTotal, 64)
2836
+		order := &models.HisOrder{
2837
+			UserOrgId:             adminUser.CurrentOrgId,
2838
+			HisPatientId:          his.ID,
2839
+			PatientId:             id,
2840
+			SettleAccountsDate:    recordDateTime,
2841
+			Ctime:                 time.Now().Unix(),
2842
+			Mtime:                 time.Now().Unix(),
2843
+			Status:                1,
2844
+			OrderStatus:           2,
2845
+			MdtrtId:               his.Number,
2846
+			Number:                chrg_bchno,
2847
+			MedfeeSumamt:          totals,
2848
+			PayWay:                pay_way,
2849
+			PayPrice:              pay_price,
2850
+			MedType:               strconv.Itoa(int(reg_type)),
2851
+			PayCardNo:             pay_card_no,
2852
+			DiscountPrice:         discount_price,
2853
+			PreferentialPrice:     preferential_price,
2854
+			RealityPrice:          reality_price,
2855
+			FoundPrice:            found_price,
2856
+			MedicalInsurancePrice: medical_insurance_price,
2857
+			PrivatePrice:          private_price,
2858
+			SettleEndTime:         end_time,
2859
+			SettleStartTime:       start_time,
2860
+			SettleType:            settle_accounts_type,
2861
+			FaPiaoCode:            fapiao_code,
2862
+			FaPiaoNumber:          fapiao_number,
2863
+			PType:                 2,
2864
+		}
2865
+		err = service.CreateOrder(order)
2866
+		if err != nil {
2867
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
2868
+			return
2801
 		}
2869
 		}
2802
-	}
2803
 
2870
 
2804
-	allTotal := fmt.Sprintf("%.2f", total)
2805
-	totals, _ := strconv.ParseFloat(allTotal, 64)
2806
-	order := &models.HisOrder{
2807
-		UserOrgId:             adminUser.CurrentOrgId,
2808
-		HisPatientId:          his.ID,
2809
-		PatientId:             id,
2810
-		SettleAccountsDate:    recordDateTime,
2811
-		Ctime:                 time.Now().Unix(),
2812
-		Mtime:                 time.Now().Unix(),
2813
-		Status:                1,
2814
-		OrderStatus:           2,
2815
-		MdtrtId:               his.Number,
2816
-		Number:                chrg_bchno,
2817
-		MedfeeSumamt:          totals,
2818
-		PayWay:                pay_way,
2819
-		PayPrice:              pay_price,
2820
-		PayCardNo:             pay_card_no,
2821
-		DiscountPrice:         discount_price,
2822
-		PreferentialPrice:     preferential_price,
2823
-		RealityPrice:          reality_price,
2824
-		FoundPrice:            found_price,
2825
-		MedicalInsurancePrice: medical_insurance_price,
2826
-		PrivatePrice:          private_price,
2827
-		SettleEndTime:         end_time,
2828
-		SettleStartTime:       start_time,
2829
-		SettleType:            settle_accounts_type,
2830
-		FaPiaoCode:            fapiao_code,
2831
-		FaPiaoNumber:          fapiao_number,
2832
-		PType:                 2,
2833
-	}
2834
-	err = service.CreateOrder(order)
2835
-	if err != nil {
2836
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
2837
-		return
2838
-	}
2871
+		var customs []*Custom
2872
+		for _, item := range prescriptions {
2873
+
2874
+			if item.Type == 1 { //药品
2875
+				for _, subItem := range item.HisDoctorAdviceInfo {
2876
+					cus := &Custom{
2877
+						AdviceId:         subItem.ID,
2878
+						ProjectId:        0,
2879
+						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
2880
+						Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
2881
+						FeedetlSn:        subItem.FeedetlSn,
2882
+						Price:            fmt.Sprintf("%.2f", subItem.Price),
2883
+						MedListCodg:      subItem.MedListCodg,
2884
+						Type:             1,
2885
+					}
2886
+					customs = append(customs, cus)
2887
+				}
2888
+			}
2839
 
2889
 
2840
-	var customs []*Custom
2841
-	for _, item := range prescriptions {
2890
+			if item.Type == 2 { //项目
2891
+				for _, subItem := range item.HisPrescriptionProject {
2892
+
2893
+					cus := &Custom{
2894
+						AdviceId:         0,
2895
+						ProjectId:        subItem.ID,
2896
+						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
2897
+						Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
2898
+						FeedetlSn:        subItem.FeedetlSn,
2899
+						Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
2900
+						MedListCodg:      subItem.MedListCodg,
2901
+						Type:             2,
2902
+					}
2842
 
2903
 
2843
-		if item.Type == 1 { //药品
2844
-			for _, subItem := range item.HisDoctorAdviceInfo {
2845
-				cus := &Custom{
2846
-					AdviceId:         subItem.ID,
2847
-					ProjectId:        0,
2848
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
2849
-					Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
2850
-					FeedetlSn:        subItem.FeedetlSn,
2851
-					Price:            fmt.Sprintf("%.2f", subItem.Price),
2852
-					MedListCodg:      subItem.MedListCodg,
2853
-					Type:             1,
2904
+					customs = append(customs, cus)
2854
 				}
2905
 				}
2855
-				customs = append(customs, cus)
2856
 			}
2906
 			}
2857
-		}
2858
-
2859
-		if item.Type == 2 { //项目
2860
-			for _, subItem := range item.HisPrescriptionProject {
2861
 
2907
 
2908
+			for _, item := range item.HisAdditionalCharge {
2862
 				cus := &Custom{
2909
 				cus := &Custom{
2910
+					ItemId:           item.ID,
2863
 					AdviceId:         0,
2911
 					AdviceId:         0,
2864
-					ProjectId:        subItem.ID,
2865
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
2866
-					Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
2867
-					FeedetlSn:        subItem.FeedetlSn,
2868
-					Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
2869
-					MedListCodg:      subItem.MedListCodg,
2870
-					Type:             2,
2912
+					ProjectId:        0,
2913
+					DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
2914
+					Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
2915
+					FeedetlSn:        item.FeedetlSn,
2916
+					Price:            fmt.Sprintf("%.2f", float64(item.Price)),
2917
+					MedListCodg:      item.XtHisAddtionConfig.Code,
2918
+					Type:             3,
2871
 				}
2919
 				}
2872
 
2920
 
2873
 				customs = append(customs, cus)
2921
 				customs = append(customs, cus)
2874
 			}
2922
 			}
2923
+
2875
 		}
2924
 		}
2876
 
2925
 
2877
-		for _, item := range item.HisAdditionalCharge {
2878
-			cus := &Custom{
2879
-				ItemId:           item.ID,
2880
-				AdviceId:         0,
2881
-				ProjectId:        0,
2882
-				DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
2883
-				Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
2884
-				FeedetlSn:        item.FeedetlSn,
2885
-				Price:            fmt.Sprintf("%.2f", float64(item.Price)),
2886
-				MedListCodg:      item.XtHisAddtionConfig.Code,
2887
-				Type:             3,
2926
+		for _, item := range customs {
2927
+			var advice_id int64 = 0
2928
+			var project_id int64 = 0
2929
+			var item_id int64 = 0
2930
+
2931
+			var types int64 = 0
2932
+
2933
+			if item.Type == 1 {
2934
+				advice_id = item.AdviceId
2935
+				project_id = 0
2936
+				item_id = 0
2937
+			} else if item.Type == 2 {
2938
+				advice_id = 0
2939
+				item_id = 0
2940
+
2941
+				project_id = item.ProjectId
2942
+			} else if item.Type == 3 {
2943
+				advice_id = 0
2944
+				item_id = item.ItemId
2945
+				project_id = 0
2888
 			}
2946
 			}
2889
 
2947
 
2890
-			customs = append(customs, cus)
2948
+			detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
2949
+			cut, _ := strconv.ParseFloat(item.Cut, 32)
2950
+			pric, _ := strconv.ParseFloat(item.Price, 32)
2951
+
2952
+			info := &models.HisOrderInfo{
2953
+				OrderNumber:      order.Number,
2954
+				UploadDate:       time.Now().Unix(),
2955
+				AdviceId:         advice_id,
2956
+				DetItemFeeSumamt: detItemFeeSumamt,
2957
+				Cnt:              cut,
2958
+				Pric:             pric,
2959
+				PatientId:        id,
2960
+				Status:           1,
2961
+				Mtime:            time.Now().Unix(),
2962
+				Ctime:            time.Now().Unix(),
2963
+				UserOrgId:        adminUser.CurrentOrgId,
2964
+				HisPatientId:     his.ID,
2965
+				OrderId:          order.ID,
2966
+				ProjectId:        project_id,
2967
+				Type:             types,
2968
+				ItemId:           item_id,
2969
+			}
2970
+			service.CreateOrderInfo(info)
2891
 		}
2971
 		}
2892
-
2893
-	}
2894
-
2895
-	for _, item := range customs {
2896
-		var advice_id int64 = 0
2897
-		var project_id int64 = 0
2898
-		var item_id int64 = 0
2899
-
2900
-		var types int64 = 0
2901
-
2902
-		if item.Type == 1 {
2903
-			advice_id = item.AdviceId
2904
-			project_id = 0
2905
-			item_id = 0
2906
-		} else if item.Type == 2 {
2907
-			advice_id = 0
2908
-			item_id = 0
2909
-
2910
-			project_id = item.ProjectId
2911
-		} else if item.Type == 3 {
2912
-			advice_id = 0
2913
-			item_id = item.ItemId
2914
-			project_id = 0
2972
+		his.Diagnosis = diagnosis_id
2973
+		his.SickType = sick_type
2974
+		his.RegisterType = reg_type
2975
+		his.MedicalTreatmentType = reg_type
2976
+
2977
+		service.UpdataHisPateint(&his)
2978
+		err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2979
+		err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
2980
+		err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
2981
+		if err == nil {
2982
+			c.ServeSuccessJSON(map[string]interface{}{
2983
+				"msg": "结算成功",
2984
+			})
2915
 		}
2985
 		}
2916
 
2986
 
2917
-		detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
2918
-		cut, _ := strconv.ParseFloat(item.Cut, 32)
2919
-		pric, _ := strconv.ParseFloat(item.Price, 32)
2987
+	} else {
2988
+		if tempOrder.IsPre > 0 {
2989
+
2990
+			allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
2991
+			totals, _ := strconv.ParseFloat(allTotal, 64)
2992
+
2993
+			tempOrder.OrderStatus = 2
2994
+			tempOrder.PayWay = pay_way
2995
+			tempOrder.PayPrice = pay_price
2996
+			tempOrder.PayCardNo = pay_card_no
2997
+			tempOrder.DiscountPrice = discount_price
2998
+			tempOrder.PreferentialPrice = preferential_price
2999
+			tempOrder.RealityPrice = reality_price
3000
+			tempOrder.FoundPrice = found_price
3001
+			tempOrder.MedicalInsurancePrice = medical_insurance_price
3002
+			tempOrder.PrivatePrice = private_price
3003
+			tempOrder.FaPiaoCode = fapiao_code
3004
+			tempOrder.FaPiaoNumber = fapiao_number
3005
+			tempOrder.PType = 2
3006
+			tempOrder.MedfeeSumamt = totals
3007
+
3008
+			err = service.SaveHisOrder(&tempOrder)
3009
+			err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
3010
+			if err != nil {
3011
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
3012
+				return
3013
+			}
3014
+			if err == nil {
3015
+				c.ServeSuccessJSON(map[string]interface{}{
3016
+					"msg": "结算成功",
3017
+				})
3018
+			}
2920
 
3019
 
2921
-		info := &models.HisOrderInfo{
2922
-			OrderNumber:      order.Number,
2923
-			UploadDate:       time.Now().Unix(),
2924
-			AdviceId:         advice_id,
2925
-			DetItemFeeSumamt: detItemFeeSumamt,
2926
-			Cnt:              cut,
2927
-			Pric:             pric,
2928
-			PatientId:        id,
2929
-			Status:           1,
2930
-			Mtime:            time.Now().Unix(),
2931
-			Ctime:            time.Now().Unix(),
2932
-			UserOrgId:        adminUser.CurrentOrgId,
2933
-			HisPatientId:     his.ID,
2934
-			OrderId:          order.ID,
2935
-			ProjectId:        project_id,
2936
-			Type:             types,
2937
-			ItemId:           item_id,
2938
 		}
3020
 		}
2939
-		service.CreateOrderInfo(info)
2940
-	}
2941
-	err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2942
-	err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
2943
-	err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
2944
-	if err == nil {
2945
-		c.ServeSuccessJSON(map[string]interface{}{
2946
-			"msg": "结算成功",
2947
-		})
2948
 	}
3021
 	}
3022
+
2949
 }
3023
 }
2950
 
3024
 
2951
 //退款
3025
 //退款
3149
 
3223
 
3150
 func (c *HisApiController) GetHisChargePatientList() {
3224
 func (c *HisApiController) GetHisChargePatientList() {
3151
 	record_date := c.GetString("record_date")
3225
 	record_date := c.GetString("record_date")
3226
+	order_status, _ := c.GetInt64("type")
3227
+
3152
 	timeLayout := "2006-01-02"
3228
 	timeLayout := "2006-01-02"
3153
 	loc, _ := time.LoadLocation("Local")
3229
 	loc, _ := time.LoadLocation("Local")
3154
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
3230
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
3158
 	}
3234
 	}
3159
 	recordDateTime := theTime.Unix()
3235
 	recordDateTime := theTime.Unix()
3160
 	adminInfo := c.GetAdminUserInfo()
3236
 	adminInfo := c.GetAdminUserInfo()
3237
+	var tempPatients []*service.NewTempPatients
3161
 	//tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
3238
 	//tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
3162
-	tempPatients, _ := service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
3239
+	if order_status != 2 {
3240
+		tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
3241
+	} else {
3242
+		tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
3243
+	}
3163
 
3244
 
3164
 	var patients []*service.NewTempPatients
3245
 	var patients []*service.NewTempPatients
3165
 	var patients_two []*service.NewTempPatients
3246
 	var patients_two []*service.NewTempPatients
3233
 	end_time := c.GetString("end_time")
3314
 	end_time := c.GetString("end_time")
3234
 	order_status, _ := c.GetInt64("type", 0)
3315
 	order_status, _ := c.GetInt64("type", 0)
3235
 	p_type, _ := c.GetInt64("p_type", 0)
3316
 	p_type, _ := c.GetInt64("p_type", 0)
3317
+	order_id, _ := c.GetInt64("order_id", 0)
3236
 
3318
 
3237
 	timeLayout := "2006-01-02"
3319
 	timeLayout := "2006-01-02"
3238
 	loc, _ := time.LoadLocation("Local")
3320
 	loc, _ := time.LoadLocation("Local")
3261
 
3343
 
3262
 	var prescriptions []*models.HisPrescription
3344
 	var prescriptions []*models.HisPrescription
3263
 
3345
 
3346
+	order, _ := service.GetHisOrderByID(order_id)
3347
+
3264
 	if order_status == 1 || order_status == 0 {
3348
 	if order_status == 1 || order_status == 0 {
3265
 		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
3349
 		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
3266
 	} else if order_status == 2 {
3350
 	} else if order_status == 2 {
3267
-		prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
3351
+		prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
3268
 	}
3352
 	}
3269
 
3353
 
3270
 	var monthPrescriptions []*models.HisPrescription
3354
 	var monthPrescriptions []*models.HisPrescription
3271
 	if order_status == 1 || order_status == 0 {
3355
 	if order_status == 1 || order_status == 0 {
3272
 		monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
3356
 		monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
3273
 	} else if order_status == 2 {
3357
 	} else if order_status == 2 {
3274
-		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
3358
+		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
3275
 	}
3359
 	}
3276
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
3360
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
3277
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
3361
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
3278
-	order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
3279
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
3362
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
3280
 	//获取所有科室信息
3363
 	//获取所有科室信息
3281
 	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
3364
 	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
3541
 	admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
3624
 	admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
3542
 
3625
 
3543
 	c.ServeSuccessJSON(map[string]interface{}{
3626
 	c.ServeSuccessJSON(map[string]interface{}{
3544
-		"order_number":    order.Number,             //业务流水号
3545
-		"id_card_no":      his.IdCardNo,             //社会保障号
3546
-		"department_name": department.Name,          //科室
3547
-		"number":          his.Number,               //门诊号
3548
-		"date":            order.SettleAccountsDate, //结算日期
3549
-		"name":            order.PsnName,            //姓名
3550
-		"gender":          order.Gend,               //性别
3551
-		"psn_cash_money":  order.PsnCashPay,         //个人支付
3552
-		"pay_way":         "门诊",                     //结算方式
3553
-		"medfee_sumamt":   order.MedfeeSumamt,       //总费用
3554
-		"admin_user_name": admin.UserName,           //收款员
3627
+		"order_number":    order.Number,        //业务流水号
3628
+		"id_card_no":      his.IdCardNo,        //社会保障号
3629
+		"department_name": department.Name,     //科室
3630
+		"number":          his.Number,          //门诊号
3631
+		"date":            order.SettleEndTime, //结算日期
3632
+		"name":            order.PsnName,       //姓名
3633
+		"gender":          order.Gend,          //性别
3634
+		"psn_cash_money":  order.PsnCashPay,    //个人支付
3635
+		"pay_way":         "门诊",                //结算方式
3636
+		"medfee_sumamt":   order.MedfeeSumamt,  //总费用
3637
+		"admin_user_name": admin.UserName,      //收款员
3555
 
3638
 
3556
 		"bedCostTotal":                                bedCostTotal,
3639
 		"bedCostTotal":                                bedCostTotal,
3557
 		"bedCostSelfTotal":                            bedCostSelfTotal,
3640
 		"bedCostSelfTotal":                            bedCostSelfTotal,
4296
 	}
4379
 	}
4297
 
4380
 
4298
 }
4381
 }
4382
+
4383
+func (c *HisApiController) PreSettle() {
4384
+	id, _ := c.GetInt64("id")
4385
+	record_time := c.GetString("record_time")
4386
+	his_patient_id, _ := c.GetInt64("his_patient_id")
4387
+
4388
+	timeLayout := "2006-01-02"
4389
+	loc, _ := time.LoadLocation("Local")
4390
+	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
4391
+	diagnosis_id, _ := c.GetInt64("diagnosis")
4392
+	sick_type, _ := c.GetInt64("sick_type")
4393
+	reg_type, _ := c.GetInt64("p_type")
4394
+
4395
+	his, _ := service.GetHisPatientByIdThree(his_patient_id)
4396
+
4397
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
4398
+	if err != nil {
4399
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4400
+		return
4401
+	}
4402
+	recordDateTime := theTime.Unix()
4403
+	adminUser := c.GetAdminUserInfo()
4404
+	var prescriptions []*models.HisPrescription
4405
+	var start_time int64
4406
+	var end_time int64
4407
+
4408
+	if settle_accounts_type == 1 { //日结
4409
+
4410
+		prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
4411
+
4412
+	} else { //月结
4413
+		start_time_str := c.GetString("start_time")
4414
+		end_time_str := c.GetString("end_time")
4415
+		timeLayout := "2006-01-02"
4416
+		loc, _ := time.LoadLocation("Local")
4417
+		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
4418
+		if err != nil {
4419
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4420
+			return
4421
+		}
4422
+		recordStartTime := theStartTime.Unix()
4423
+		start_time = recordStartTime
4424
+		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
4425
+		if err != nil {
4426
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
4427
+			return
4428
+		}
4429
+		recordEndTime := theEndTime.Unix()
4430
+		end_time = recordEndTime
4431
+		prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
4432
+	}
4433
+
4434
+	timestamp := time.Now().Unix()
4435
+	tempTime := time.Unix(timestamp, 0)
4436
+	timeFormat := tempTime.Format("20060102150405")
4437
+	chrgBchno := rand.Intn(100000) + 10000
4438
+	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
4439
+	strconv.FormatInt(his.PatientId, 10)
4440
+
4441
+	var ids []int64
4442
+
4443
+	for _, item := range prescriptions {
4444
+		ids = append(ids, item.ID)
4445
+	}
4446
+
4447
+	var total float64
4448
+	for _, item := range prescriptions {
4449
+		if item.Type == 1 { //药品
4450
+			for _, subItem := range item.HisDoctorAdviceInfo {
4451
+				total = total + (subItem.Price * subItem.PrescribingNumber)
4452
+			}
4453
+		}
4454
+		if item.Type == 2 { //项目
4455
+			for _, subItem := range item.HisPrescriptionProject {
4456
+				total = total + (subItem.Price * float64(subItem.Count))
4457
+			}
4458
+		}
4459
+
4460
+		for _, subItem := range item.HisAdditionalCharge {
4461
+			total = total + (subItem.Price * float64(subItem.Count))
4462
+		}
4463
+	}
4464
+
4465
+	allTotal := fmt.Sprintf("%.2f", total)
4466
+	totals, _ := strconv.ParseFloat(allTotal, 64)
4467
+	order := &models.HisOrder{
4468
+		UserOrgId:          adminUser.CurrentOrgId,
4469
+		HisPatientId:       his.ID,
4470
+		PatientId:          id,
4471
+		SettleAccountsDate: recordDateTime,
4472
+		Ctime:              time.Now().Unix(),
4473
+		Mtime:              time.Now().Unix(),
4474
+		Status:             1,
4475
+		OrderStatus:        1,
4476
+		MdtrtId:            his.Number,
4477
+		Number:             chrg_bchno,
4478
+		MedfeeSumamt:       totals,
4479
+		SettleEndTime:      end_time,
4480
+		SettleStartTime:    start_time,
4481
+		SettleType:         settle_accounts_type,
4482
+		PType:              2,
4483
+		IsPre:              1,
4484
+		MedType:            strconv.Itoa(int(reg_type)),
4485
+	}
4486
+	err = service.CreateOrder(order)
4487
+	if err != nil {
4488
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
4489
+		return
4490
+	}
4491
+
4492
+	var customs []*Custom
4493
+	for _, item := range prescriptions {
4494
+
4495
+		if item.Type == 1 { //药品
4496
+			for _, subItem := range item.HisDoctorAdviceInfo {
4497
+				cus := &Custom{
4498
+					AdviceId:         subItem.ID,
4499
+					ProjectId:        0,
4500
+					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
4501
+					Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
4502
+					FeedetlSn:        subItem.FeedetlSn,
4503
+					Price:            fmt.Sprintf("%.2f", subItem.Price),
4504
+					MedListCodg:      subItem.MedListCodg,
4505
+					Type:             1,
4506
+				}
4507
+				customs = append(customs, cus)
4508
+			}
4509
+		}
4510
+
4511
+		if item.Type == 2 { //项目
4512
+			for _, subItem := range item.HisPrescriptionProject {
4513
+
4514
+				cus := &Custom{
4515
+					AdviceId:         0,
4516
+					ProjectId:        subItem.ID,
4517
+					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
4518
+					Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
4519
+					FeedetlSn:        subItem.FeedetlSn,
4520
+					Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
4521
+					MedListCodg:      subItem.MedListCodg,
4522
+					Type:             2,
4523
+				}
4524
+
4525
+				customs = append(customs, cus)
4526
+			}
4527
+		}
4528
+
4529
+		for _, item := range item.HisAdditionalCharge {
4530
+			cus := &Custom{
4531
+				ItemId:           item.ID,
4532
+				AdviceId:         0,
4533
+				ProjectId:        0,
4534
+				DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
4535
+				Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
4536
+				FeedetlSn:        item.FeedetlSn,
4537
+				Price:            fmt.Sprintf("%.2f", float64(item.Price)),
4538
+				MedListCodg:      item.XtHisAddtionConfig.Code,
4539
+				Type:             3,
4540
+			}
4541
+
4542
+			customs = append(customs, cus)
4543
+		}
4544
+
4545
+	}
4546
+
4547
+	for _, item := range customs {
4548
+		var advice_id int64 = 0
4549
+		var project_id int64 = 0
4550
+		var item_id int64 = 0
4551
+
4552
+		var types int64 = 0
4553
+
4554
+		if item.Type == 1 {
4555
+			advice_id = item.AdviceId
4556
+			project_id = 0
4557
+			item_id = 0
4558
+		} else if item.Type == 2 {
4559
+			advice_id = 0
4560
+			item_id = 0
4561
+
4562
+			project_id = item.ProjectId
4563
+		} else if item.Type == 3 {
4564
+			advice_id = 0
4565
+			item_id = item.ItemId
4566
+			project_id = 0
4567
+		}
4568
+
4569
+		detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
4570
+		cut, _ := strconv.ParseFloat(item.Cut, 32)
4571
+		pric, _ := strconv.ParseFloat(item.Price, 32)
4572
+
4573
+		info := &models.HisOrderInfo{
4574
+			OrderNumber:      order.Number,
4575
+			UploadDate:       time.Now().Unix(),
4576
+			AdviceId:         advice_id,
4577
+			DetItemFeeSumamt: detItemFeeSumamt,
4578
+			Cnt:              cut,
4579
+			Pric:             pric,
4580
+			PatientId:        id,
4581
+			Status:           1,
4582
+			Mtime:            time.Now().Unix(),
4583
+			Ctime:            time.Now().Unix(),
4584
+			UserOrgId:        adminUser.CurrentOrgId,
4585
+			HisPatientId:     his.ID,
4586
+			OrderId:          order.ID,
4587
+			ProjectId:        project_id,
4588
+			Type:             types,
4589
+			ItemId:           item_id,
4590
+		}
4591
+		service.CreateOrderInfo(info)
4592
+	}
4593
+	his.Diagnosis = diagnosis_id
4594
+	his.SickType = sick_type
4595
+	service.UpdataHisPateint(&his)
4596
+	err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
4597
+	err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
4598
+	//err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
4599
+	if err == nil {
4600
+		c.ServeSuccessJSON(map[string]interface{}{
4601
+			"msg": "结算成功",
4602
+		})
4603
+	}
4604
+}

+ 21 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Просмотреть файл

470
 				}
470
 				}
471
 				types := int64(items["type"].(float64))
471
 				types := int64(items["type"].(float64))
472
 
472
 
473
+				if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
474
+					utils.ErrorLog("med_type")
475
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
476
+					return
477
+				}
478
+				//med_type := int64(items["med_type"].(float64))
479
+				//med_type := strconv.Itoa(int(items["med_type"].(float64)))
480
+				//med_type := strconv.Itoa(int(items["med_type"].(float64)))
481
+
482
+				//if med_type == "0" {
483
+				//}
484
+				var med_type string
485
+				if adminInfo.Org.Id == 9504 || adminInfo.Org.Id == 10138 {
486
+					med_type = "13"
487
+
488
+				} else {
489
+					med_type = "14"
490
+				}
491
+
473
 				if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
492
 				if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
474
 					utils.ErrorLog("order_status")
493
 					utils.ErrorLog("order_status")
475
 				}
494
 				}
515
 						PrescriptionNumber: hpInfo.PrescriptionNumber,
534
 						PrescriptionNumber: hpInfo.PrescriptionNumber,
516
 						PreTime:            pTime,
535
 						PreTime:            pTime,
517
 						PType:              2,
536
 						PType:              2,
537
+						MedType:            med_type,
518
 					}
538
 					}
519
 					tempPrescription = prescription
539
 					tempPrescription = prescription
520
 				} else {
540
 				} else {
525
 					tempPrescription.OrderStatus = order_status
545
 					tempPrescription.OrderStatus = order_status
526
 					tempPrescription.PreTime = pTime
546
 					tempPrescription.PreTime = pTime
527
 					tempPrescription.PType = 2
547
 					tempPrescription.PType = 2
548
+					tempPrescription.MedType = med_type
528
 
549
 
529
 				}
550
 				}
530
 				service.SaveHisPrescription(tempPrescription)
551
 				service.SaveHisPrescription(tempPrescription)

+ 2 - 0
models/his_hospital_models.go Просмотреть файл

27
 
27
 
28
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
28
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
29
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
29
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
30
+
31
+	IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
30
 }
32
 }
31
 
33
 
32
 func (HisHospitalOrder) TableName() string {
34
 func (HisHospitalOrder) TableName() string {

+ 94 - 2
models/his_models.go Просмотреть файл

1
 package models
1
 package models
2
 
2
 
3
 import (
3
 import (
4
-	//"gdyb/models"
5
 	"time"
4
 	"time"
6
 )
5
 )
7
 
6
 
374
 	Mtime              int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
373
 	Mtime              int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
375
 	Creator            int64           `gorm:"column:creator" json:"creator" form:"creator"`
374
 	Creator            int64           `gorm:"column:creator" json:"creator" form:"creator"`
376
 	Modifier           int64           `gorm:"column:modifier" json:"modifier" form:"modifier"`
375
 	Modifier           int64           `gorm:"column:modifier" json:"modifier" form:"modifier"`
377
-	Diagnosis          string          `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
376
+	Diagnosis          int64           `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
378
 	RegisterType       int64           `gorm:"column:register_type" json:"register_type" form:"register_type"`
377
 	RegisterType       int64           `gorm:"column:register_type" json:"register_type" form:"register_type"`
379
 	Doctor             string          `gorm:"column:doctor" json:"doctor" form:"doctor"`
378
 	Doctor             string          `gorm:"column:doctor" json:"doctor" form:"doctor"`
380
 	Departments        int64           `gorm:"column:departments" json:"departments" form:"departments"`
379
 	Departments        int64           `gorm:"column:departments" json:"departments" form:"departments"`
392
 	return "his_prescription_info"
391
 	return "his_prescription_info"
393
 }
392
 }
394
 
393
 
394
+type TempHisOrder struct {
395
+	ID                    int64     `gorm:"column:id" json:"id" form:"id"`
396
+	UserOrgId             int64     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
397
+	HisPatientId          int64     `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
398
+	SettleAccountsDate    int64     `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
399
+	Ctime                 int64     `gorm:"column:ctime" json:"ctime" form:"ctime"`
400
+	Mtime                 int64     `gorm:"column:mtime" json:"mtime" form:"mtime"`
401
+	Status                int64     `gorm:"column:status" json:"status" form:"status"`
402
+	Number                string    `gorm:"column:number" json:"number" form:"number"`
403
+	PatientId             int64     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
404
+	Infcode               int64     `gorm:"column:infcode" json:"infcode" form:"infcode"`
405
+	WarnMsg               string    `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
406
+	Cainfo                string    `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
407
+	ErrMsg                string    `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
408
+	RespondTime           string    `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
409
+	InfRefmsgid           string    `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
410
+	OrderStatus           int64     `gorm:"column:order_status" json:"order_status" form:"order_status"`
411
+	MdtrtId               string    `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
412
+	SetlId                string    `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
413
+	PsnNo                 string    `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
414
+	PsnName               string    `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
415
+	PsnCertType           string    `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
416
+	Certno                string    `gorm:"column:certno" json:"certno" form:"certno"`
417
+	Gend                  string    `gorm:"column:gend" json:"gend" form:"gend"`
418
+	Naty                  string    `gorm:"column:naty" json:"naty" form:"naty"`
419
+	Brdy                  time.Time `gorm:"column:brdy" json:"brdy" form:"brdy"`
420
+	Age                   float64   `gorm:"column:age" json:"age" form:"age"`
421
+	Insutype              string    `gorm:"column:insutype" json:"insutype" form:"insutype"`
422
+	PsnType               string    `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
423
+	CvlservFlag           string    `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
424
+	SetlTime              string    `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
425
+	MdtrtCertType         string    `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
426
+	MedType               string    `gorm:"column:med_type" json:"med_type" form:"med_type"`
427
+	MedfeeSumamt          float64   `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
428
+	FulamtOwnpayAmt       float64   `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
429
+	OverlmtSelfPay        float64   `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
430
+	PreselfpayAmt         float64   `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
431
+	InscpScpAmt           float64   `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
432
+	ActPayDedc            float64   `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
433
+	HifpPay               float64   `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
434
+	CvlservPay            float64   `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
435
+	PoolPropSelfpay       float64   `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
436
+	HifesPay              float64   `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
437
+	HifmiPay              float64   `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
438
+	HifobPay              float64   `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
439
+	MafPay                float64   `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
440
+	OthPay                float64   `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
441
+	FundPaySumamt         float64   `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
442
+	PsnPartAmt            float64   `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
443
+	AcctPay               float64   `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
444
+	PsnCashPay            float64   `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
445
+	HospPartAmt           float64   `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
446
+	Balc                  float64   `gorm:"column:balc" json:"balc" form:"balc"`
447
+	AcctMulaidPay         float64   `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
448
+	MedinsSetlId          string    `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
449
+	ClrOptins             string    `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
450
+	ClrWay                string    `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
451
+	ClrType               string    `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
452
+	SetlDetail            string    `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
453
+	IsMedicineInsurance   int64     `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
454
+	PayWay                int64     `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
455
+	PayPrice              float64   `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
456
+	PayCardNo             string    `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
457
+	DiscountPrice         float64   `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
458
+	PreferentialPrice     float64   `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
459
+	RealityPrice          float64   `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
460
+	FoundPrice            float64   `gorm:"column:found_price" json:"found_price" form:"found_price"`
461
+	MedicalInsurancePrice float64   `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
462
+	PrivatePrice          float64   `gorm:"column:private_price" json:"private_price" form:"private_price"`
463
+	DepartmentName        string    `gorm:"-" json:"department_name" form:"department_name"`
464
+	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
465
+	Creator               int64     `gorm:"column:creator" json:"creator" form:"creator"`
466
+	PType                 int64     `gorm:"column:p_type" json:"p_type" form:"p_type"`
467
+	AccountPrice          float64   `gorm:"column:account_price" json:"account_price" form:"account_price"`
468
+
469
+	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
470
+	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
471
+
472
+	AdminUser AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
473
+
474
+	SettleType      int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
475
+	SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
476
+	SettleEndTime   int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
477
+	IsPre           int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
478
+}
479
+
480
+func (TempHisOrder) TableName() string {
481
+	return "his_order"
482
+}
483
+
395
 type HisPrescription struct {
484
 type HisPrescription struct {
396
 	ID                     int64                     `gorm:"column:id" json:"id" form:"id"`
485
 	ID                     int64                     `gorm:"column:id" json:"id" form:"id"`
397
 	UserOrgId              int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
486
 	UserOrgId              int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
419
 	VMHisPrescriptionInfo HisPrescriptionInfo    `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
508
 	VMHisPrescriptionInfo HisPrescriptionInfo    `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
420
 	Total                 string                 `gorm:"-" json:"total" form:"total"`
509
 	Total                 string                 `gorm:"-" json:"total" form:"total"`
421
 	PType                 int64                  `gorm:"column:p_type" json:"p_type" form:"p_type"`
510
 	PType                 int64                  `gorm:"column:p_type" json:"p_type" form:"p_type"`
511
+	MedType               string                 `gorm:"column:med_type" json:"med_type" form:"med_type"`
512
+	TempHisOrder          TempHisOrder           `gorm:"ForeignKey:Number,MedType;AssociationForeignKey:BatchNumber,MedType" json:"order"`
422
 }
513
 }
423
 
514
 
424
 func (HisPrescription) TableName() string {
515
 func (HisPrescription) TableName() string {
863
 	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"p_info"`
954
 	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"p_info"`
864
 
955
 
865
 	HisFundSettleListResult HisFundSettleListResult `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"result"`
956
 	HisFundSettleListResult HisFundSettleListResult `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"result"`
957
+	IsPre                   int64                   `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
866
 }
958
 }
867
 
959
 
868
 func (HisOrder) TableName() string {
960
 func (HisOrder) TableName() string {

+ 0 - 5
service/app_version.go Просмотреть файл

266
 	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 4 AND status = 1 AND order_status = 2").Last(&his).Error
266
 	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 4 AND status = 1 AND order_status = 2").Last(&his).Error
267
 	return
267
 	return
268
 }
268
 }
269
-
270
-func SaveOrder(his *models.HisOrder) {
271
-	writeDb.Save(&his)
272
-
273
-}

+ 1 - 1
service/his_hospital_service.go Просмотреть файл

140
 	Mtime              int64              `gorm:"column:mtime" json:"mtime" form:"mtime"`
140
 	Mtime              int64              `gorm:"column:mtime" json:"mtime" form:"mtime"`
141
 	Creator            int64              `gorm:"column:creator" json:"creator" form:"creator"`
141
 	Creator            int64              `gorm:"column:creator" json:"creator" form:"creator"`
142
 	Modifier           int64              `gorm:"column:modifier" json:"modifier" form:"modifier"`
142
 	Modifier           int64              `gorm:"column:modifier" json:"modifier" form:"modifier"`
143
-	Diagnosis          string             `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
143
+	Diagnosis          int64              `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
144
 	RegisterType       int64              `gorm:"column:register_type" json:"register_type" form:"register_type"`
144
 	RegisterType       int64              `gorm:"column:register_type" json:"register_type" form:"register_type"`
145
 	Doctor             string             `gorm:"column:doctor" json:"doctor" form:"doctor"`
145
 	Doctor             string             `gorm:"column:doctor" json:"doctor" form:"doctor"`
146
 	Departments        string             `gorm:"column:departments" json:"departments" form:"departments"`
146
 	Departments        string             `gorm:"column:departments" json:"departments" form:"departments"`

+ 6 - 0
service/his_project_service.go Просмотреть файл

713
 	error = XTReadDB().Model(&hisProjectList).Preload("XtHisProject").Preload("GoodInfo", "status = 1").Where(" status = 1 and id in (?)", ids).Find(&hisProjectList).Error
713
 	error = XTReadDB().Model(&hisProjectList).Preload("XtHisProject").Preload("GoodInfo", "status = 1").Where(" status = 1 and id in (?)", ids).Find(&hisProjectList).Error
714
 	return hisProjectList, error
714
 	return hisProjectList, error
715
 }
715
 }
716
+
717
+func GetHisPatientByIdThree(id int64) (models.HisPatient, error) {
718
+	patient := models.HisPatient{}
719
+	err := XTReadDB().Model(&patient).Where("id = ? and status = 1", id).First(&patient).Error
720
+	return patient, err
721
+}

+ 143 - 27
service/his_service.go Просмотреть файл

66
 	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
66
 	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
67
 	Creator            int64  `gorm:"column:creator" json:"creator" form:"creator"`
67
 	Creator            int64  `gorm:"column:creator" json:"creator" form:"creator"`
68
 	Modifier           int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
68
 	Modifier           int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
69
-	Diagnosis          string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
69
+	Diagnosis          int64  `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
70
 	RegisterType       int64  `gorm:"column:register_type" json:"register_type" form:"register_type"`
70
 	RegisterType       int64  `gorm:"column:register_type" json:"register_type" form:"register_type"`
71
 	Doctor             string `gorm:"column:doctor" json:"doctor" form:"doctor"`
71
 	Doctor             string `gorm:"column:doctor" json:"doctor" form:"doctor"`
72
 	Departments        string `gorm:"column:departments" json:"departments" form:"departments"`
72
 	Departments        string `gorm:"column:departments" json:"departments" form:"departments"`
110
 
110
 
111
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
111
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
112
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
112
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
113
+	IsPre        int64  `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
113
 }
114
 }
114
 
115
 
115
 func (VMHisOrder) TableName() string {
116
 func (VMHisOrder) TableName() string {
136
 }
137
 }
137
 
138
 
138
 type HisPrescription struct {
139
 type HisPrescription struct {
139
-	ID           int64 `gorm:"column:id" json:"id" form:"id"`
140
-	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
141
-	RecordDate   int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
142
-	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
143
-	HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
144
-	Status       int64 `gorm:"column:status" json:"status" form:"status"`
140
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
141
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
142
+	RecordDate   int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
143
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
144
+	HisPatientId int64  `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
145
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
146
+	MedType      string `gorm:"column:med_type" json:"med_type" form:"med_type"`
147
+	OrderStatus  int64  `gorm:"column:order_status" json:"order_status" form:"order_status"`
145
 }
148
 }
146
 
149
 
147
 func (HisPrescription) TableName() string {
150
 func (HisPrescription) TableName() string {
249
 	PreTime            int64  `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
252
 	PreTime            int64  `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
250
 	BatchNumber        string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
253
 	BatchNumber        string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
251
 	PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
254
 	PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
255
+	MedType            string `gorm:"column:med_type" json:"med_type" form:"med_type"`
252
 }
256
 }
253
 
257
 
254
 func (HisPrescriptionTwo) TableName() string {
258
 func (HisPrescriptionTwo) TableName() string {
377
 }
381
 }
378
 
382
 
379
 func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
383
 func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
380
-	err = writeDb.Save(&prescription).Error
384
+	tx := writeDb.Begin()
385
+
386
+	if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
387
+		tx.Rollback()
388
+		return
389
+	}
390
+	tx.Commit()
381
 	return
391
 	return
382
 }
392
 }
383
 
393
 
458
 		}).
468
 		}).
459
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
469
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
460
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
470
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
461
-		}).
471
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
472
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
473
+	}).
462
 		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
474
 		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
463
 		Find(&prescription).Error
475
 		Find(&prescription).Error
464
 	return
476
 	return
465
 }
477
 }
466
 
478
 
467
-func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
479
+func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
468
 	err = readDb.Model(&models.HisPrescription{}).
480
 	err = readDb.Model(&models.HisPrescription{}).
469
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
481
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
470
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
482
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
475
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
487
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
476
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
488
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
477
 		}).
489
 		}).
478
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1", org_id, record_date, patient_id, his_patient_id).
490
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
479
 		Find(&prescription).Error
491
 		Find(&prescription).Error
480
 	return
492
 	return
481
 }
493
 }
482
 
494
 
483
-func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
495
+func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
484
 	err = readDb.Model(&models.HisPrescription{}).
496
 	err = readDb.Model(&models.HisPrescription{}).
485
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
497
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
486
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
498
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
491
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
503
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
492
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
504
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
493
 		}).
505
 		}).
494
-		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, start_date, end_date, patient_id).
506
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
495
 		Find(&prescription).Error
507
 		Find(&prescription).Error
496
 	return
508
 	return
497
 }
509
 }
539
 		}).
551
 		}).
540
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
552
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
541
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
553
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
542
-		}).
554
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
555
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
556
+	}).
543
 		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND  order_status <> 2 AND order_status <> 3  AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
557
 		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND  order_status <> 2 AND order_status <> 3  AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
544
 		Find(&prescription).Error
558
 		Find(&prescription).Error
545
 	return
559
 	return
738
 }
752
 }
739
 
753
 
740
 func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
754
 func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
741
-	err = writeDb.Save(s).Error
755
+
756
+	tx := writeDb.Begin()
757
+	if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
758
+		tx.Rollback()
759
+		return
760
+	}
761
+	tx.Commit()
762
+
742
 	return
763
 	return
743
 }
764
 }
744
 
765
 
745
 func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
766
 func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
746
-	err = writeDb.Save(project).Error
767
+	tx := writeDb.Begin()
768
+	if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
769
+		tx.Rollback()
770
+		return
771
+	}
772
+	tx.Commit()
773
+
747
 	return
774
 	return
748
 }
775
 }
749
 
776
 
790
 }
817
 }
791
 
818
 
792
 func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
819
 func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
793
-	err = writeDb.Save(&info).Error
794
-	return
820
+	tx := writeDb.Begin()
795
 
821
 
822
+	if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
823
+		tx.Rollback()
824
+		return
825
+	}
826
+	tx.Commit()
827
+	return
796
 }
828
 }
797
 
829
 
798
 func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string, p_type int64) (order []*models.HisOrder, err error, total int64) {
830
 func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string, p_type int64) (order []*models.HisOrder, err error, total int64) {
880
 
912
 
881
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
913
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
882
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
914
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
915
+	IsPre        int64  `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
883
 }
916
 }
884
 
917
 
885
 func (HisOrder) TableName() string {
918
 func (HisOrder) TableName() string {
1070
 
1103
 
1071
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
1104
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
1072
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
1105
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
1106
+	IsPre        int64  `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
1073
 }
1107
 }
1074
 
1108
 
1075
 func (XtHisOrder) TableName() string {
1109
 func (XtHisOrder) TableName() string {
1165
 	Type                   int64                            `gorm:"column:type" json:"type" form:"type"`
1199
 	Type                   int64                            `gorm:"column:type" json:"type" form:"type"`
1166
 	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
1200
 	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
1167
 	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
1201
 	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
1202
+	MedType                string                           `gorm:"column:med_type" json:"med_type" form:"med_type"`
1168
 }
1203
 }
1169
 
1204
 
1170
 func (VMHisPrescription) TableName() string {
1205
 func (VMHisPrescription) TableName() string {
1367
 }
1402
 }
1368
 
1403
 
1369
 type VMHisPrescriptionTwo struct {
1404
 type VMHisPrescriptionTwo struct {
1370
-	ID        int64 `gorm:"column:id" json:"id" form:"id"`
1371
-	UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1372
-	PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1373
-	Status    int64 `gorm:"column:status" json:"status" form:"status"`
1374
-	Ctime     int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
1375
-	Mtime     int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
1376
-	Type      int64 `gorm:"column:type" json:"type" form:"type"`
1405
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
1406
+	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1407
+	PatientId int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1408
+	Status    int64  `gorm:"column:status" json:"status" form:"status"`
1409
+	Ctime     int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1410
+	Mtime     int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1411
+	Type      int64  `gorm:"column:type" json:"type" form:"type"`
1412
+	MedType   string `gorm:"column:med_type" json:"med_type" form:"med_type"`
1377
 }
1413
 }
1378
 
1414
 
1379
 func (VMHisPrescriptionTwo) TableName() string {
1415
 func (VMHisPrescriptionTwo) TableName() string {
1623
 	AcctPay            float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
1659
 	AcctPay            float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
1624
 	CashPay            float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
1660
 	CashPay            float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
1625
 	Sumamt             float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
1661
 	Sumamt             float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
1662
+	Iinfo              string  `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
1663
+	DiagnosisId        int64   `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
1664
+	DialysisCount      int64   `gorm:"-"`
1665
+	PatientId          int64   `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
1626
 }
1666
 }
1627
 
1667
 
1628
 func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
1668
 func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
1629
-	err = readDb.Raw("select o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt  from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2  AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
1669
+	err = readDb.Raw("select o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt  from his_order o  Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2  AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
1670
+
1671
+	for _, item := range cus {
1672
+		var total int64
1673
+		readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND  dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
1674
+		fmt.Println(total)
1675
+		item.DialysisCount = total
1676
+		fmt.Println(item.DialysisCount)
1677
+	}
1630
 	return
1678
 	return
1631
 }
1679
 }
1632
 
1680
 
1709
 
1757
 
1710
 //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
1758
 //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
1711
 
1759
 
1760
+func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
1761
+	db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
1762
+	db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
1763
+		return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
1764
+	})
1765
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2", org_id, record_date)
1766
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
1767
+
1768
+	for _, item := range patients {
1769
+		for _, sumItem := range item.HisPatient {
1770
+			if len(sumItem.VMHisOrders) > 0 {
1771
+				sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
1772
+			}
1773
+		}
1774
+
1775
+	}
1776
+
1777
+	return
1778
+}
1779
+
1712
 func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
1780
 func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
1713
 	db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
1781
 	db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
1714
 	db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
1782
 	db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
1752
 
1820
 
1753
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
1821
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
1754
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
1822
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
1823
+	IsPre        int64  `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
1755
 }
1824
 }
1756
 
1825
 
1757
 func (CustomInComeStatistics) TableName() string {
1826
 func (CustomInComeStatistics) TableName() string {
1903
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
1972
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
1904
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
1973
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
1905
 		}).
1974
 		}).
1906
-		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND p_type = ? AND order_status == 2 ", org_id, start_date, end_date, patient_id, p_type).
1975
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
1976
+		Find(&prescription).Error
1977
+	return
1978
+}
1979
+
1980
+func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
1981
+	err = readDb.Model(&models.HisPrescription{}).
1982
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
1983
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
1984
+		}).
1985
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1986
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
1987
+		}).
1988
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
1989
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
1990
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
1991
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
1992
+	}).
1993
+		Where("user_org_id = ? AND status = 1  AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
1907
 		Find(&prescription).Error
1994
 		Find(&prescription).Error
1908
 	return
1995
 	return
1909
 }
1996
 }
1997
+
1998
+//已收费
1999
+func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
2000
+	err = readDb.Model(&models.HisPrescription{}).
2001
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
2002
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
2003
+		}).
2004
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2005
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
2006
+		}).
2007
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2008
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
2009
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
2010
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
2011
+	}).
2012
+		Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
2013
+		Find(&prescription).Error
2014
+	return
2015
+}
2016
+
2017
+func UpdataHisPateint(his *models.HisPatient) {
2018
+	writeDb.Save(&his)
2019
+
2020
+}
2021
+
2022
+func SaveHisOrder(his *models.HisOrder) (err error) {
2023
+	err = writeDb.Save(&his).Error
2024
+	return
2025
+}