csx 3 yıl önce
ebeveyn
işleme
84f8cb3a87
3 değiştirilmiş dosya ile 282 ekleme ve 135 silme
  1. 232 128
      controllers/his_api_controller.go
  2. 8 0
      models/his_models.go
  3. 42 7
      service/his_service.go

+ 232 - 128
controllers/his_api_controller.go Dosyayı Görüntüle

@@ -672,6 +672,9 @@ func (c *HisApiController) GetUploadInfo() {
672 672
 	found_price, _ := c.GetFloat("found_price")
673 673
 	medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
674 674
 	private_price, _ := c.GetFloat("private_price")
675
+
676
+	//settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
677
+
675 678
 	timeLayout := "2006-01-02"
676 679
 	loc, _ := time.LoadLocation("Local")
677 680
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
@@ -681,7 +684,83 @@ func (c *HisApiController) GetUploadInfo() {
681 684
 	}
682 685
 	recordDateTime := theTime.Unix()
683 686
 	adminUser := c.GetAdminUserInfo()
684
-	prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
687
+
688
+	var prescriptions []*models.HisPrescription
689
+	prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
690
+
691
+	//if settle_accounts_type == 1 { //日结
692
+	//
693
+	//} else { //月结
694
+	//	start_time := c.GetString("start_time")
695
+	//	end_time := c.GetString("end_time")
696
+	//	timeLayout := "2006-01-02"
697
+	//	loc, _ := time.LoadLocation("Local")
698
+	//	theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
699
+	//	if err != nil {
700
+	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
701
+	//		return
702
+	//	}
703
+	//	recordStartTime := theStartTime.Unix()
704
+	//	theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
705
+	//	if err != nil {
706
+	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
707
+	//		return
708
+	//	}
709
+	//	recordEndTime := theEndTime.Unix()
710
+	//	monthPrescriptions, _ := service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
711
+	//	var advices []*models.HisDoctorAdviceInfo
712
+	//	var projects []*models.HisPrescriptionProject
713
+	//	var additions []*models.HisAdditionalCharge
714
+	//	var customs []*models.Custom
715
+	//	for _, item := range monthPrescriptions {
716
+	//		advices = append(advices, item.HisDoctorAdviceInfo...)
717
+	//		projects = append(projects, item.HisPrescriptionProject...)
718
+	//		additions = append(additions, item.HisAdditionalCharge...)
719
+	//	}
720
+	//
721
+	//	var adviceCodes []string
722
+	//	var projectCodes []string
723
+	//	var additionCodes []string
724
+	//
725
+	//
726
+	//
727
+	//
728
+	//	for _, item := range advices {
729
+	//		adviceCodes = append(adviceCodes, item.MedListCodg)
730
+	//	}
731
+	//	for _, item := range projects {
732
+	//		projectCodes = append(projectCodes, item.MedListCodg)
733
+	//	}
734
+	//	for _, item := range additions {
735
+	//		additionCodes = append(additionCodes, item.XtHisAddtionConfig.Code)
736
+	//	}
737
+	//	adviceCodes = RemoveRepeatedCode(adviceCodes)
738
+	//	projectCodes = RemoveRepeatedCode(projectCodes)
739
+	//	additionCodes = RemoveRepeatedCode(additionCodes)
740
+	//
741
+	//	for  _, item := range adviceCodes{
742
+	//		var custom models.Custom
743
+	//		for _,subItem := range advices{
744
+	//			if item == subItem.MedListCodg{
745
+	//
746
+	//
747
+	//
748
+	//			}
749
+	//		}
750
+	//	}
751
+	//
752
+	//
753
+	//
754
+	//
755
+	//
756
+	//
757
+	//
758
+	//
759
+	//
760
+	//
761
+	//
762
+	//}
763
+
685 764
 	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
686 765
 
687 766
 	timestamp := time.Now().Unix()
@@ -826,149 +905,157 @@ func (c *HisApiController) GetUploadInfo() {
826 905
 					Type:             types,
827 906
 				}
828 907
 				service.CreateOrderInfo(info)
829
-				service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
830
-				service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
831
-
832
-				var total float64
833
-				for _, item := range prescriptions {
834
-					if item.Type == 1 { //药品
835
-						for _, subItem := range item.HisDoctorAdviceInfo {
836
-							total = total + (subItem.Price * subItem.PrescribingNumber)
837
-						}
838
-					}
839
-					if item.Type == 2 { //项目
840
-						for _, subItem := range item.HisPrescriptionProject {
841
-							total = total + (subItem.Price * float64(subItem.Count))
842
-						}
908
+
909
+			}
910
+			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
911
+			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
912
+
913
+			var total float64
914
+			for _, item := range prescriptions {
915
+				if item.Type == 1 { //药品
916
+					for _, subItem := range item.HisDoctorAdviceInfo {
917
+						total = total + (subItem.Price * subItem.PrescribingNumber)
843 918
 					}
844 919
 				}
845
-				allTotal := fmt.Sprintf("%.2f", total)
846
-				if res.Infcode == 0 {
847
-					var rf []*ResultFive
848
-					json.Unmarshal([]byte(his.Iinfo), &rf)
849
-					psn_no := his.PsnNo
850
-					mdtrt_id := his.Number
851
-					chrg_bchno := chrg_bchno
852
-					cert_no := his.Certno
853
-					insutype := rf[0].Insutype
854
-					api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
855
-						insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
856
-						"&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
857
-					resp, requestErr := http.Get(api)
858
-
859
-					if requestErr != nil {
860
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
861
-						return
862
-					}
863
-					defer resp.Body.Close()
864
-					body, ioErr := ioutil.ReadAll(resp.Body)
865
-					if ioErr != nil {
866
-						utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
867
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
868
-						return
920
+				if item.Type == 2 { //项目
921
+					for _, subItem := range item.HisPrescriptionProject {
922
+						total = total + (subItem.Price * float64(subItem.Count))
869 923
 					}
870
-					var respJSON map[string]interface{}
871
-					if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
872
-						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
873
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
874
-						return
875
-					}
876
-					fmt.Println(respJSON)
877
-					respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
878
-					userJSONBytes, _ := json.Marshal(respJSON)
879
-					var res ResultSeven
880
-					if err := json.Unmarshal(userJSONBytes, &res); err != nil {
881
-						utils.ErrorLog("解析失败:%v", err)
882
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
883
-						return
884
-					}
885
-					if res.Infcode == -1 {
886
-						errlog := &models.HisOrderError{
887
-							UserOrgId:  adminUser.CurrentOrgId,
888
-							Ctime:      time.Now().Unix(),
889
-							Mtime:      time.Now().Unix(),
890
-							Number:     chrg_bchno,
891
-							ErrMsg:     res.ErrMsg,
892
-							Status:     1,
893
-							PatientId:  id,
894
-							RecordTime: recordDateTime,
895
-							Stage:      7,
896
-						}
897
-						service.CreateErrMsgLog(errlog)
898
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
899
-						return
900
-					} else {
901
-						order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
902
-						order.OrderStatus = 2
903
-						order.MdtrtId = res.Output.Setlinfo.MdtrtID
904
-						order.SetlId = res.Output.Setlinfo.SetlID
905
-						order.PsnNo = res.Output.Setlinfo.PsnNo
906
-						order.PsnName = res.Output.Setlinfo.PsnName
907
-						order.PsnCertType = res.Output.Setlinfo.PsnCertType
908
-						order.Certno = res.Output.Setlinfo.Certno
909
-						order.Gend = res.Output.Setlinfo.Gend
910
-						order.Naty = res.Output.Setlinfo.Naty
911
-						order.Age = res.Output.Setlinfo.Age
912
-						order.Insutype = res.Output.Setlinfo.Insutype
913
-						order.PsnType = res.Output.Setlinfo.PsnType
914
-						order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
915
-						order.SetlTime = res.Output.Setlinfo.SetlTime
916
-						order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
917
-						order.MedType = res.Output.Setlinfo.MedType
918
-						order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
919
-						order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
920
-						order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
921
-						order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
922
-						order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
923
-						order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
924
-						order.HifpPay = res.Output.Setlinfo.HifpPay
925
-						order.CvlservPay = res.Output.Setlinfo.CvlservPay
926
-						order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
927
-						order.HifesPay = res.Output.Setlinfo.HifesPay
928
-						order.HifobPay = res.Output.Setlinfo.HifobPay
929
-						order.MafPay = res.Output.Setlinfo.MafPay
930
-						order.OthPay = res.Output.Setlinfo.OthPay
931
-						order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
932
-						order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
933
-						order.AcctPay = res.Output.Setlinfo.AcctPay
934
-						order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
935
-						order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
936
-						order.Balc = res.Output.Setlinfo.Balc
937
-						order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
938
-						order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
939
-						order.ClrOptins = res.Output.Setlinfo.ClrOptins
940
-						order.ClrWay = res.Output.Setlinfo.ClrWay
941
-						setlDetail, _ := json.Marshal(res.Output.Setldetail)
942
-						detailStr := string(setlDetail)
943
-						order.SetlDetail = detailStr
944
-						err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
945
-						err = service.UpDateOrder(order)
946
-						if err == nil {
947
-							c.ServeSuccessJSON(map[string]interface{}{
948
-								"msg": "结算成功",
949
-							})
950
-						} else {
951
-							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
952
-							return
953
-						}
954
-					}
955
-				} else {
956
-					adminUser := c.GetAdminUserInfo()
924
+				}
925
+			}
926
+
927
+			for _, item := range prescriptions {
928
+				for _, subItem := range item.HisAdditionalCharge {
929
+					total = total + (subItem.Price * float64(subItem.Count))
930
+				}
931
+			}
932
+
933
+			allTotal := fmt.Sprintf("%.2f", total)
934
+			if res.Infcode == 0 {
935
+				var rf []*ResultFive
936
+				json.Unmarshal([]byte(his.Iinfo), &rf)
937
+				psn_no := his.PsnNo
938
+				mdtrt_id := his.Number
939
+				chrg_bchno := chrg_bchno
940
+				cert_no := his.Certno
941
+				insutype := rf[0].Insutype
942
+				api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
943
+					insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
944
+					"&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
945
+				resp, requestErr := http.Get(api)
946
+
947
+				if requestErr != nil {
948
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
949
+					return
950
+				}
951
+				defer resp.Body.Close()
952
+				body, ioErr := ioutil.ReadAll(resp.Body)
953
+				if ioErr != nil {
954
+					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
955
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
956
+					return
957
+				}
958
+				var respJSON map[string]interface{}
959
+				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
960
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
961
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
962
+					return
963
+				}
964
+				fmt.Println(respJSON)
965
+				respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
966
+				userJSONBytes, _ := json.Marshal(respJSON)
967
+				var res ResultSeven
968
+				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
969
+					utils.ErrorLog("解析失败:%v", err)
970
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
971
+					return
972
+				}
973
+				if res.Infcode == -1 {
957 974
 					errlog := &models.HisOrderError{
958 975
 						UserOrgId:  adminUser.CurrentOrgId,
959 976
 						Ctime:      time.Now().Unix(),
960 977
 						Mtime:      time.Now().Unix(),
978
+						Number:     chrg_bchno,
961 979
 						ErrMsg:     res.ErrMsg,
962 980
 						Status:     1,
963 981
 						PatientId:  id,
964 982
 						RecordTime: recordDateTime,
965
-						Stage:      5,
983
+						Stage:      6,
966 984
 					}
967 985
 					service.CreateErrMsgLog(errlog)
968
-
969 986
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
970 987
 					return
988
+				} else {
989
+					order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
990
+					order.OrderStatus = 2
991
+					order.MdtrtId = res.Output.Setlinfo.MdtrtID
992
+					order.SetlId = res.Output.Setlinfo.SetlID
993
+					order.PsnNo = res.Output.Setlinfo.PsnNo
994
+					order.PsnName = res.Output.Setlinfo.PsnName
995
+					order.PsnCertType = res.Output.Setlinfo.PsnCertType
996
+					order.Certno = res.Output.Setlinfo.Certno
997
+					order.Gend = res.Output.Setlinfo.Gend
998
+					order.Naty = res.Output.Setlinfo.Naty
999
+					order.Age = res.Output.Setlinfo.Age
1000
+					order.Insutype = res.Output.Setlinfo.Insutype
1001
+					order.PsnType = res.Output.Setlinfo.PsnType
1002
+					order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
1003
+					order.SetlTime = res.Output.Setlinfo.SetlTime
1004
+					order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
1005
+					order.MedType = res.Output.Setlinfo.MedType
1006
+					order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
1007
+					order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
1008
+					order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
1009
+					order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
1010
+					order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
1011
+					order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
1012
+					order.HifpPay = res.Output.Setlinfo.HifpPay
1013
+					order.CvlservPay = res.Output.Setlinfo.CvlservPay
1014
+					order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
1015
+					order.HifesPay = res.Output.Setlinfo.HifesPay
1016
+					order.HifobPay = res.Output.Setlinfo.HifobPay
1017
+					order.MafPay = res.Output.Setlinfo.MafPay
1018
+					order.OthPay = res.Output.Setlinfo.OthPay
1019
+					order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
1020
+					order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
1021
+					order.AcctPay = res.Output.Setlinfo.AcctPay
1022
+					order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
1023
+					order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
1024
+					order.Balc = res.Output.Setlinfo.Balc
1025
+					order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
1026
+					order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
1027
+					order.ClrOptins = res.Output.Setlinfo.ClrOptins
1028
+					order.ClrWay = res.Output.Setlinfo.ClrWay
1029
+					setlDetail, _ := json.Marshal(res.Output.Setldetail)
1030
+					detailStr := string(setlDetail)
1031
+					order.SetlDetail = detailStr
1032
+					err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
1033
+					err = service.UpDateOrder(order)
1034
+					if err == nil {
1035
+						c.ServeSuccessJSON(map[string]interface{}{
1036
+							"msg": "结算成功",
1037
+						})
1038
+					} else {
1039
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
1040
+						return
1041
+					}
971 1042
 				}
1043
+			} else {
1044
+				adminUser := c.GetAdminUserInfo()
1045
+				errlog := &models.HisOrderError{
1046
+					UserOrgId:  adminUser.CurrentOrgId,
1047
+					Ctime:      time.Now().Unix(),
1048
+					Mtime:      time.Now().Unix(),
1049
+					ErrMsg:     res.ErrMsg,
1050
+					Status:     1,
1051
+					PatientId:  id,
1052
+					RecordTime: recordDateTime,
1053
+					Stage:      4,
1054
+				}
1055
+				service.CreateErrMsgLog(errlog)
1056
+
1057
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
1058
+				return
972 1059
 			}
973 1060
 		} else {
974 1061
 			adminUser := c.GetAdminUserInfo()
@@ -1820,3 +1907,20 @@ func ReadFile(filePath string) []byte {
1820 1907
 
1821 1908
 	return fd
1822 1909
 }
1910
+
1911
+func RemoveRepeatedCode(arr []string) (newArr []string) {
1912
+	newArr = make([]string, 0)
1913
+	for i := 0; i < len(arr); i++ {
1914
+		repeat := false
1915
+		for j := i + 1; j < len(arr); j++ {
1916
+			if arr[i] == arr[j] {
1917
+				repeat = true
1918
+				break
1919
+			}
1920
+		}
1921
+		if !repeat {
1922
+			newArr = append(newArr, arr[i])
1923
+		}
1924
+	}
1925
+	return
1926
+}

+ 8 - 0
models/his_models.go Dosyayı Görüntüle

@@ -949,3 +949,11 @@ type BusinessParams struct {
949 949
 	MdtrtId          string
950 950
 	SetlId           string
951 951
 }
952
+
953
+type Custom struct {
954
+	DetItemFeeSumamt string
955
+	Cut              string
956
+	FeedetlSn        string
957
+	Price            string
958
+	MedListCodg      string
959
+}

+ 42 - 7
service/his_service.go Dosyayı Görüntüle

@@ -201,7 +201,7 @@ func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (pres
201 201
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
202 202
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
203 203
 		}).
204
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
204
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?  AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id).
205 205
 		Find(&prescription).Error
206 206
 	return
207 207
 }
@@ -325,9 +325,6 @@ func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
325 325
 	return
326 326
 }
327 327
 
328
-
329
-
330
-
331 328
 func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
332 329
 	err = writeDb.Create(&charge).Error
333 330
 	return
@@ -749,7 +746,6 @@ func (VMHisPrescription) TableName() string {
749 746
 	return "his_prescription"
750 747
 }
751 748
 
752
-
753 749
 func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
754 750
 	err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND  status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
755 751
 		Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
@@ -783,8 +779,6 @@ func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders [
783 779
 	return
784 780
 }
785 781
 
786
-
787
-
788 782
 func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
789 783
 	var patient models.Patients
790 784
 	err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
@@ -804,3 +798,44 @@ func FindDiagnoseById(id int64) (*models.HisXtDiagnoseConfig, error) {
804 798
 	return dealer, err
805 799
 }
806 800
 
801
+//
802
+//type MonthHisPrescription struct {
803
+//	ID                     int64                            `gorm:"column:id" json:"id" form:"id"`
804
+//	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
805
+//	RecordDate             int64                            `gorm:"column:record_date" json:"record_date" form:"record_date"`
806
+//	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
807
+//	HisPatientId           int64                            `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
808
+//	Status                 int64                            `gorm:"column:status" json:"status" form:"status"`
809
+//	Ctime                  int64                            `gorm:"column:ctime" json:"ctime" form:"ctime"`
810
+//	Mtime                  int64                            `gorm:"column:mtime" json:"mtime" form:"mtime"`
811
+//	Number                 string                           `gorm:"column:number" json:"number" form:"number"`
812
+//	Type                   int64                            `gorm:"column:type" json:"type" form:"type"`
813
+//	Doctor                 string                           `gorm:"column:doctor" json:"doctor" form:"doctor"`
814
+//	Creator                int64                            `gorm:"column:creator" json:"creator" form:"creator"`
815
+//	Modifier               int64                            `gorm:"column:modifier" json:"modifier" form:"modifier"`
816
+//	OrderStatus            int64                            `gorm:"column:order_status" json:"order_status" form:"order_status"`
817
+//	BatchNumber            string                           `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
818
+//	PrescriptionNumber     string                           `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
819
+//	Patients               Patients                         `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
820
+//	HisPatient             models.VMHisPatient              `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
821
+//	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
822
+//	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
823
+//	HisAdditionalCharge    []*models.HisAdditionalCharge    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
824
+//	VMHisPrescriptionInfo  models.HisPrescriptionInfo              `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
825
+//}
826
+//
827
+//func (MonthHisPrescription) TableName() string {
828
+//	return "his_prescription"
829
+//}
830
+
831
+func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
832
+	err = readDb.Model(&models.HisPrescription{}).
833
+		Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ? AND med_list_codg <> ''", org_id).
834
+		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
835
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
836
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
837
+		}).
838
+		Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND status = 1 ", org_id, start_time, end_time, patient_id).
839
+		Find(&prescription).Error
840
+	return
841
+}