Browse Source

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

csx 4 years ago
parent
commit
d7844b7889
5 changed files with 360 additions and 122 deletions
  1. 283 102
      controllers/his_api_controller.go
  2. 4 0
      enums/error_code.go
  3. 15 8
      models/his_models.go
  4. 8 8
      service/gdyb_service.go
  5. 50 4
      service/his_service.go

+ 283 - 102
controllers/his_api_controller.go View File

@@ -14,6 +14,7 @@ import (
14 14
 	"net/http"
15 15
 	"reflect"
16 16
 	"strconv"
17
+	"strings"
17 18
 	"time"
18 19
 )
19 20
 
@@ -27,6 +28,10 @@ func HisManagerApiRegistRouters() {
27 28
 	beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
28 29
 	beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
29 30
 
31
+	beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
32
+	beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
33
+	beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
34
+
30 35
 	beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
31 36
 
32 37
 	beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
@@ -116,8 +121,6 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
116 121
 	//获取所有基础药
117 122
 	drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
118 123
 
119
-	//drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
120
-	//drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
121 124
 	drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
122 125
 	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
123 126
 
@@ -137,10 +140,12 @@ func (c *HisApiController) CreateHisPrescription() {
137 140
 	record_date := c.GetString("record_date")
138 141
 	fmt.Println("record_date", record_date)
139 142
 	patient_id, _ := c.GetInt64("patient_id")
140
-	//diagnose := c.GetString("diagnose")
141
-	//sick_history := c.GetString("sick_history")
143
+	reg_type, _ := c.GetInt64("reg_type")
144
+
145
+	diagnose := c.GetString("diagnose")
146
+	sick_history := c.GetString("sick_history")
142 147
 	doctor, _ := c.GetInt64("doctor")
143
-	//department, _ := c.GetInt64("department")
148
+	department, _ := c.GetInt64("department")
144 149
 	his_patient_id, _ := c.GetInt64("his_patient_id")
145 150
 	dataBody := make(map[string]interface{}, 0)
146 151
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -160,21 +165,42 @@ func (c *HisApiController) CreateHisPrescription() {
160 165
 	adminInfo := c.GetAdminUserInfo()
161 166
 	recordDateTime := theTime.Unix()
162 167
 
163
-	//hpInfo := models.HisPrescriptionInfo{
164
-	//	UserOrgId: adminInfo.CurrentOrgId,
165
-	//	RecordDate: theTime.Unix(),
166
-	//	PatientId:   patient_id,
167
-	//	Status: 1,
168
-	//	Ctime: time.Now().Unix(),
169
-	//	Mtime: time.Now().Unix(),
170
-	//	Creator: adminInfo.AdminUser.Id,
171
-	//	Modifier: adminInfo.AdminUser.Id,
172
-	//	Diagnosis: diagnose,
173
-	//	SickHistory: sick_history,
174
-	//	Departments:department,
175
-	//
176
-	//}
177
-	//
168
+	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
169
+	if info.ID == 0 {
170
+		hpInfo := models.HisPrescriptionInfo{
171
+			UserOrgId:    adminInfo.CurrentOrgId,
172
+			RecordDate:   theTime.Unix(),
173
+			PatientId:    patient_id,
174
+			Status:       1,
175
+			Ctime:        time.Now().Unix(),
176
+			Mtime:        time.Now().Unix(),
177
+			Creator:      adminInfo.AdminUser.Id,
178
+			Modifier:     adminInfo.AdminUser.Id,
179
+			Diagnosis:    diagnose,
180
+			SickHistory:  sick_history,
181
+			Departments:  department,
182
+			RegisterType: reg_type,
183
+		}
184
+		service.SavePatientPrescriptionInfo(hpInfo)
185
+
186
+	} else {
187
+		hpInfo := models.HisPrescriptionInfo{
188
+			ID:           info.ID,
189
+			UserOrgId:    adminInfo.CurrentOrgId,
190
+			RecordDate:   info.RecordDate,
191
+			PatientId:    info.PatientId,
192
+			Status:       1,
193
+			Ctime:        info.Ctime,
194
+			Mtime:        time.Now().Unix(),
195
+			Creator:      info.Creator,
196
+			Modifier:     adminInfo.AdminUser.Id,
197
+			Diagnosis:    diagnose,
198
+			SickHistory:  sick_history,
199
+			Departments:  department,
200
+			RegisterType: reg_type,
201
+		}
202
+		service.SavePatientPrescriptionInfo(hpInfo)
203
+	}
178 204
 
179 205
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
180 206
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
@@ -182,6 +208,12 @@ func (c *HisApiController) CreateHisPrescription() {
182 208
 		if len(prescriptions) > 0 {
183 209
 			for _, item := range prescriptions {
184 210
 				items := item.(map[string]interface{})
211
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
212
+					utils.ErrorLog("id")
213
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
214
+					return
215
+				}
216
+				id := int64(items["id"].(float64))
185 217
 
186 218
 				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
187 219
 					utils.ErrorLog("type")
@@ -192,6 +224,7 @@ func (c *HisApiController) CreateHisPrescription() {
192 224
 
193 225
 				ctime := time.Now().Unix()
194 226
 				prescription := &models.HisPrescription{
227
+					ID:           id,
195 228
 					PatientId:    patient_id,
196 229
 					UserOrgId:    adminInfo.CurrentOrgId,
197 230
 					RecordDate:   recordDateTime,
@@ -203,6 +236,8 @@ func (c *HisApiController) CreateHisPrescription() {
203 236
 					Status:       1,
204 237
 					Doctor:       doctor,
205 238
 					HisPatientId: his_patient_id,
239
+					IsFinish:     1,
240
+					BatchNumber:  "",
206 241
 				}
207 242
 				service.SaveHisPrescription(prescription)
208 243
 
@@ -236,6 +271,14 @@ func (c *HisApiController) CreateHisPrescription() {
236 271
 								return
237 272
 							}
238 273
 							service.CreateHisDoctorAdvice(&s)
274
+							var randNum int
275
+							randNum = rand.Intn(10000) + 1000
276
+							timestamp := time.Now().Unix()
277
+							tempTime := time.Unix(timestamp, 0)
278
+							timeFormat := tempTime.Format("20060102150405")
279
+							s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
280
+							service.CreateHisDoctorAdvice(&s)
281
+
239 282
 						}
240 283
 					}
241 284
 				}
@@ -258,27 +301,71 @@ func (c *HisApiController) CreateHisPrescription() {
258 301
 								return
259 302
 							}
260 303
 							service.CreateHisProjectTwo(&p)
304
+							var randNum int
305
+							randNum = rand.Intn(10000) + 1000
306
+							timestamp := time.Now().Unix()
307
+							tempTime := time.Unix(timestamp, 0)
308
+							timeFormat := tempTime.Format("20060102150405")
309
+							p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
310
+							service.SaveHisProjectTwo(&p)
311
+
261 312
 						}
262 313
 					}
263 314
 				}
264 315
 			}
265 316
 		}
317
+	}
318
+	if err == nil {
319
+		c.ServeSuccessJSON(map[string]interface{}{
320
+			"msg": "保存成功",
321
+		})
322
+		return
266 323
 
267
-		//查询患者今日处方信息
268
-		//_, errcode := service.GetHisPrescriptionTwo(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
269
-		//if errcode == nil{
270
-		//    //改变患者信息状态
271
-		//   service.UpdatedHisPatient(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
272
-		//
273
-		//}
324
+	} else {
325
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
326
+		return
274 327
 	}
328
+}
275 329
 
330
+func (c *HisApiController) DeletePrescription() {
331
+	prescription_id, _ := c.GetInt64("id")
332
+	//TODO 需要判断是否已经结算
333
+	err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
276 334
 	if err == nil {
277 335
 		c.ServeSuccessJSON(map[string]interface{}{
278
-			"msg": "保存成功",
336
+			"msg": "删除成功",
279 337
 		})
280 338
 		return
339
+	} else {
340
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
341
+		return
342
+	}
343
+}
281 344
 
345
+func (c *HisApiController) DeleteDoctorAdvice() {
346
+	id, _ := c.GetInt64("id")
347
+	//TODO 需要判断是否已经结算
348
+	err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
349
+	if err == nil {
350
+		c.ServeSuccessJSON(map[string]interface{}{
351
+			"msg": "删除成功",
352
+		})
353
+		return
354
+	} else {
355
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
356
+		return
357
+	}
358
+}
359
+
360
+func (c *HisApiController) DeleteProject() {
361
+	id, _ := c.GetInt64("id")
362
+	//TODO 需要判断是否已经结算
363
+	err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
364
+	if err == nil {
365
+		c.ServeSuccessJSON(map[string]interface{}{
366
+			"msg": "删除成功",
367
+		})
368
+		return
282 369
 	} else {
283 370
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
284 371
 		return
@@ -591,7 +678,7 @@ func (c *HisApiController) GetRegisterInfo() {
591 678
 		return
592 679
 	}
593 680
 
594
-	api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + "44020219710324062X"
681
+	api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo
595 682
 	resp, requestErr := http.Get(api)
596 683
 
597 684
 	if requestErr != nil {
@@ -743,6 +830,10 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
743 830
 			advice.DrugId = drug_id
744 831
 		}
745 832
 	}
833
+	if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
834
+		advice_id := int64(json["advice_id"].(float64))
835
+		advice.ID = advice_id
836
+	}
746 837
 
747 838
 	if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
748 839
 		drugSpecUnit, _ := json["min_unit"].(string)
@@ -795,7 +886,12 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
795 886
 func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
796 887
 
797 888
 	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
798
-		project_id := int64(json["id"].(float64))
889
+		id := int64(json["id"].(float64))
890
+		project.ID = id
891
+	}
892
+
893
+	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
894
+		project_id := int64(json["project_id"].(float64))
799 895
 		project.ProjectId = project_id
800 896
 	}
801 897
 
@@ -811,6 +907,11 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
811 907
 		totals, _ := strconv.ParseInt(total, 10, 64)
812 908
 		project.Count = totals
813 909
 	}
910
+
911
+	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
912
+		medical_code, _ := json["medical_code"].(string)
913
+		project.MedListCodg = medical_code
914
+	}
814 915
 	return 0
815 916
 }
816 917
 
@@ -821,25 +922,25 @@ type ResultFour struct {
821 922
 	Infcode     int64  `json:"infcode"`
822 923
 	Output      struct {
823 924
 		Result []struct {
824
-			BasMednFlag      string `json:"bas_medn_flag"`
825
-			ChldMedcFlag     string `json:"chld_medc_flag"`
826
-			ChrgitmLv        string `json:"chrgitm_lv"`
827
-			Cnt              int64  `json:"cnt"`
828
-			DetItemFeeSumamt int64  `json:"det_item_fee_sumamt"`
829
-			DrtReimFlag      string `json:"drt_reim_flag"`
830
-			FeedetlSn        string `json:"feedetl_sn"`
831
-			FulamtOwnpayAmt  int64  `json:"fulamt_ownpay_amt"`
832
-			HiNegoDrugFlag   string `json:"hi_nego_drug_flag"`
833
-			InscpScpAmt      int64  `json:"inscp_scp_amt"`
834
-			ListSpItemFlag   string `json:"list_sp_item_flag"`
835
-			LmtUsedFlag      string `json:"lmt_used_flag"`
836
-			MedChrgitmType   string `json:"med_chrgitm_type"`
837
-			Memo             string `json:"memo"`
838
-			OverlmtAmt       int64  `json:"overlmt_amt"`
839
-			PreselfpayAmt    int64  `json:"preselfpay_amt"`
840
-			Pric             int64  `json:"pric"`
841
-			PricUplmtAmt     int64  `json:"pric_uplmt_amt"`
842
-			SelfpayProp      int64  `json:"selfpay_prop"`
925
+			BasMednFlag      string  `json:"bas_medn_flag"`
926
+			ChldMedcFlag     string  `json:"chld_medc_flag"`
927
+			ChrgitmLv        string  `json:"chrgitm_lv"`
928
+			Cnt              float64 `json:"cnt"`
929
+			DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
930
+			DrtReimFlag      string  `json:"drt_reim_flag"`
931
+			FeedetlSn        string  `json:"feedetl_sn"`
932
+			FulamtOwnpayAmt  float64 `json:"fulamt_ownpay_amt"`
933
+			HiNegoDrugFlag   string  `json:"hi_nego_drug_flag"`
934
+			InscpScpAmt      float64 `json:"inscp_scp_amt"`
935
+			ListSpItemFlag   string  `json:"list_sp_item_flag"`
936
+			LmtUsedFlag      string  `json:"lmt_used_flag"`
937
+			MedChrgitmType   string  `json:"med_chrgitm_type"`
938
+			Memo             string  `json:"memo"`
939
+			OverlmtAmt       float64 `json:"overlmt_amt"`
940
+			PreselfpayAmt    float64 `json:"preselfpay_amt"`
941
+			Pric             float64 `json:"pric"`
942
+			PricUplmtAmt     float64 `json:"pric_uplmt_amt"`
943
+			SelfpayProp      float64 `json:"selfpay_prop"`
843 944
 		} `json:"result"`
844 945
 	} `json:"output"`
845 946
 	RefmsgTime  string `json:"refmsg_time"`
@@ -855,9 +956,6 @@ type ResultFive struct {
855 956
 func (c *HisApiController) GetUploadInfo() {
856 957
 	id, _ := c.GetInt64("id")
857 958
 	record_time := c.GetString("record_time")
858
-
859
-	//record_date := c.GetString("record_date")
860
-
861 959
 	timeLayout := "2006-01-02"
862 960
 	loc, _ := time.LoadLocation("Local")
863 961
 
@@ -876,7 +974,7 @@ func (c *HisApiController) GetUploadInfo() {
876 974
 	tempTime := time.Unix(timestamp, 0)
877 975
 	timeFormat := tempTime.Format("20060102150405")
878 976
 	chrgBchno := rand.Intn(100000) + 10000
879
-	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
977
+	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
880 978
 
881 979
 	client := &http.Client{}
882 980
 	data := make(map[string]interface{})
@@ -887,7 +985,6 @@ func (c *HisApiController) GetUploadInfo() {
887 985
 	bytesData, _ := json.Marshal(data)
888 986
 	req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
889 987
 	resp, _ := client.Do(req)
890
-
891 988
 	defer resp.Body.Close()
892 989
 	body, ioErr := ioutil.ReadAll(resp.Body)
893 990
 	if ioErr != nil {
@@ -911,62 +1008,146 @@ func (c *HisApiController) GetUploadInfo() {
911 1008
 		return
912 1009
 	}
913 1010
 
914
-	var total float64
915
-	for _, item := range prescriptions {
916
-		if item.Type == 1 { //药品
917
-			for _, subItem := range item.HisDoctorAdviceInfo {
918
-				total = total + (subItem.Price * subItem.PrescribingNumber)
919
-			}
920
-		}
921
-		if item.Type == 2 { //项目
922
-			for _, subItem := range item.HisPrescriptionProject {
923
-				total = total + (subItem.Price * float64(subItem.Count))
924
-			}
925
-		}
926
-	}
927
-	allTotal := fmt.Sprintf("%.2f", total)
928
-	fmt.Println(allTotal)
929 1011
 	if res.Infcode == 0 {
930
-		var rf []*ResultFive
931
-		json.Unmarshal([]byte(his.Iinfo), &rf)
932
-		psn_no := his.PsnNo
933
-		mdtrt_id := his.Number
934
-		chrg_bchno := chrg_bchno
935
-		cert_no := his.Certno
936
-		insutype := rf[0].Insutype
937
-		api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
938
-			insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
939
-			"&total=" + allTotal
940
-		resp, requestErr := http.Get(api)
941
-
942
-		if requestErr != nil {
943
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
944
-			return
1012
+		order := &models.HisOrder{
1013
+			UserOrgId:          adminUser.CurrentOrgId,
1014
+			HisPatientId:       his.ID,
1015
+			PatientId:          his.PatientId,
1016
+			SettleAccountsDate: recordDateTime,
1017
+			Ctime:              time.Now().Unix(),
1018
+			Mtime:              time.Now().Unix(),
1019
+			Status:             1,
1020
+			Number:             chrg_bchno,
1021
+			Infcode:            res.Infcode,
1022
+			WarnMsg:            res.WarnMsg,
1023
+			Cainfo:             res.Cainfo,
1024
+			ErrMsg:             res.ErrMsg,
1025
+			RespondTime:        res.RefmsgTime,
1026
+			InfRefmsgid:        res.InfRefmsgid,
1027
+			OrderStatus:        1,
945 1028
 		}
946
-		defer resp.Body.Close()
947
-		body, ioErr := ioutil.ReadAll(resp.Body)
948
-		if ioErr != nil {
949
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
950
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1029
+
1030
+		err = service.CreateOrder(order)
1031
+		if err != nil {
1032
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
951 1033
 			return
952 1034
 		}
953
-		var respJSON map[string]interface{}
954
-		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
955
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
956
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
957
-			return
1035
+
1036
+		for _, item := range res.Output.Result {
1037
+			temp := strings.Split(item.FeedetlSn, "-")
1038
+			var advice_id int64 = 0
1039
+			var project_id int64 = 0
1040
+			var types int64 = 0
1041
+
1042
+			id, _ := strconv.ParseInt(temp[2], 10, 64)
1043
+			types, _ = strconv.ParseInt(temp[1], 10, 64)
1044
+
1045
+			if temp[1] == "1" {
1046
+				advice_id = id
1047
+				project_id = 0
1048
+			} else if temp[1] == "2" {
1049
+				advice_id = 0
1050
+				project_id = id
1051
+			}
1052
+
1053
+			info := &models.HisOrderInfo{
1054
+				OrderNumber:      order.Number,
1055
+				FeedetlSn:        item.FeedetlSn,
1056
+				UploadDate:       time.Now().Unix(),
1057
+				AdviceId:         advice_id,
1058
+				DetItemFeeSumamt: item.DetItemFeeSumamt,
1059
+				Cnt:              item.Cnt,
1060
+				Pric:             float64(item.Pric),
1061
+				PatientId:        his.PatientId,
1062
+				PricUplmtAmt:     item.PricUplmtAmt,
1063
+				SelfpayProp:      item.SelfpayProp,
1064
+				FulamtOwnpayAmt:  item.FulamtOwnpayAmt,
1065
+				OverlmtAmt:       item.OverlmtAmt,
1066
+				PreselfpayAmt:    item.PreselfpayAmt,
1067
+				BasMednFlag:      item.BasMednFlag,
1068
+				MedChrgitmType:   item.MedChrgitmType,
1069
+				HiNegoDrugFlag:   item.HiNegoDrugFlag,
1070
+				Status:           1,
1071
+				Memo:             item.Memo,
1072
+				Mtime:            time.Now().Unix(),
1073
+				InscpScpAmt:      item.InscpScpAmt,
1074
+				DrtReimFlag:      item.DrtReimFlag,
1075
+				Ctime:            time.Now().Unix(),
1076
+				ListSpItemFlag:   item.ListSpItemFlag,
1077
+				ChldMedcFlag:     item.ChldMedcFlag,
1078
+				LmtUsedFlag:      item.LmtUsedFlag,
1079
+				ChrgitmLv:        item.ChrgitmLv,
1080
+				UserOrgId:        adminUser.CurrentOrgId,
1081
+				HisPatientId:     his.ID,
1082
+				OrderId:          order.ID,
1083
+				ProjectId:        project_id,
1084
+				Type:             types,
1085
+			}
1086
+			service.CreateOrderInfo(info)
958 1087
 		}
959
-		fmt.Println(respJSON)
960
-		respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
961
-		userJSONBytes, _ := json.Marshal(respJSON)
962
-		var res ResultFour
963
-		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
964
-			utils.ErrorLog("解析失败:%v", err)
965
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
966
-			return
1088
+
1089
+		var total float64
1090
+		for _, item := range prescriptions {
1091
+			if item.Type == 1 { //药品
1092
+				for _, subItem := range item.HisDoctorAdviceInfo {
1093
+					total = total + (subItem.Price * subItem.PrescribingNumber)
1094
+				}
1095
+			}
1096
+			if item.Type == 2 { //项目
1097
+				for _, subItem := range item.HisPrescriptionProject {
1098
+					total = total + (subItem.Price * float64(subItem.Count))
1099
+				}
1100
+			}
967 1101
 		}
968 1102
 
1103
+		allTotal := fmt.Sprintf("%.2f", total)
1104
+		if res.Infcode == 0 {
1105
+			var rf []*ResultFive
1106
+			json.Unmarshal([]byte(his.Iinfo), &rf)
1107
+			psn_no := his.PsnNo
1108
+			mdtrt_id := his.Number
1109
+			chrg_bchno := chrg_bchno
1110
+			cert_no := his.Certno
1111
+			insutype := rf[0].Insutype
1112
+			api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
1113
+				insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
1114
+				"&total=" + allTotal
1115
+			resp, requestErr := http.Get(api)
1116
+
1117
+			if requestErr != nil {
1118
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1119
+				return
1120
+			}
1121
+			defer resp.Body.Close()
1122
+			body, ioErr := ioutil.ReadAll(resp.Body)
1123
+			if ioErr != nil {
1124
+				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1125
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1126
+				return
1127
+			}
1128
+			var respJSON map[string]interface{}
1129
+			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
1130
+				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1131
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1132
+				return
1133
+			}
1134
+			fmt.Println(respJSON)
1135
+			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1136
+			userJSONBytes, _ := json.Marshal(respJSON)
1137
+			var res ResultFour
1138
+			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1139
+				utils.ErrorLog("解析失败:%v", err)
1140
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1141
+				return
1142
+			}
1143
+		} else {
1144
+
1145
+		}
969 1146
 	} else {
970 1147
 
1148
+		c.ServeSuccessJSON(map[string]interface{}{
1149
+			"msg": res.ErrMsg,
1150
+		})
1151
+
971 1152
 	}
972 1153
 }

+ 4 - 0
enums/error_code.go View File

@@ -218,6 +218,8 @@ const ( // ErrorCode
218 218
 	ErrorCodeRegisterOneException = 20066
219 219
 
220 220
 	ErrorCodeRegisterTwoException = 20067
221
+
222
+	ErrorCodeCreateOrderException = 20068
221 223
 )
222 224
 
223 225
 var ErrCodeMsgs = map[int]string{
@@ -426,6 +428,8 @@ var ErrCodeMsgs = map[int]string{
426 428
 	ErrorCodeRegisterOneException: "无参保信息",
427 429
 
428 430
 	ErrorCodeRegisterTwoException: "挂号失败",
431
+
432
+	ErrorCodeCreateOrderException: "创建预结算订单失败",
429 433
 }
430 434
 
431 435
 type SGJError struct {

+ 15 - 8
models/his_models.go View File

@@ -193,6 +193,7 @@ type HisDoctorAdviceInfo struct {
193 193
 	Price                 float64 `gorm:"column:price" json:"price" form:"price"`
194 194
 	PrescriptionId        int64   `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
195 195
 	MedListCodg           string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
196
+	FeedetlSn             string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
196 197
 }
197 198
 
198 199
 func (HisDoctorAdviceInfo) TableName() string {
@@ -249,10 +250,10 @@ type HisPrescriptionInfo struct {
249 250
 	Creator      int64  `gorm:"column:creator" json:"creator" form:"creator"`
250 251
 	Modifier     int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
251 252
 	Diagnosis    string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
252
-	SickType     string `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
253
-	PType        string `gorm:"column:p_type" json:"p_type" form:"p_type"`
254
-	SickHistory  string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
253
+	RegisterType int64  `gorm:"column:register_type" json:"register_type" form:"register_type"`
254
+	Doctor       int64  `gorm:"column:doctor" json:"doctor" form:"doctor"`
255 255
 	Departments  int64  `gorm:"column:departments" json:"departments" form:"departments"`
256
+	SickHistory  string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
256 257
 }
257 258
 
258 259
 func (HisPrescriptionInfo) TableName() string {
@@ -273,6 +274,8 @@ type HisPrescription struct {
273 274
 	Doctor                 int64                     `gorm:"column:doctor" json:"doctor" form:"doctor"`
274 275
 	Creator                int64                     `gorm:"column:creator" json:"creator" form:"creator"`
275 276
 	Modifier               int64                     `gorm:"column:modifier" json:"modifier" form:"modifier"`
277
+	IsFinish               int64                     `gorm:"column:is_finish" json:"is_finish" form:"is_finish"`
278
+	BatchNumber            string                    `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
276 279
 	HisDoctorAdviceInfo    []*HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"advices"`
277 280
 	HisPrescriptionProject []*HisPrescriptionProject `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"project"`
278 281
 }
@@ -418,6 +421,8 @@ type HisPrescriptionProject struct {
418 421
 	PrescriptionId int64       `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
419 422
 	Count          int64       `gorm:"column:count" json:"count" form:"count"`
420 423
 	HisProject     *HisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
424
+	FeedetlSn      string      `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
425
+	MedListCodg    string      `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
421 426
 }
422 427
 
423 428
 func (HisPrescriptionProject) TableName() string {
@@ -510,7 +515,7 @@ type HisOrder struct {
510 515
 	Ctime              int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
511 516
 	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
512 517
 	Status             int64  `gorm:"column:status" json:"status" form:"status"`
513
-	Number             int64  `gorm:"column:number" json:"number" form:"number"`
518
+	Number             string `gorm:"column:number" json:"number" form:"number"`
514 519
 	PatientId          int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
515 520
 	Infcode            int64  `gorm:"column:infcode" json:"infcode" form:"infcode"`
516 521
 	WarnMsg            string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
@@ -518,6 +523,7 @@ type HisOrder struct {
518 523
 	ErrMsg             string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
519 524
 	RespondTime        string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
520 525
 	InfRefmsgid        string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
526
+	OrderStatus        int64  `gorm:"column:order_status" json:"order_status" form:"order_status"`
521 527
 }
522 528
 
523 529
 func (HisOrder) TableName() string {
@@ -526,12 +532,11 @@ func (HisOrder) TableName() string {
526 532
 
527 533
 type HisOrderInfo struct {
528 534
 	ID               int64   `gorm:"column:id" json:"id" form:"id"`
529
-	OrderNumber      int64   `gorm:"column:order_number" json:"order_number" form:"order_number"`
530
-	FeedtlSn         int64   `gorm:"column:feedtl_sn" json:"feedtl_sn" form:"feedtl_sn"`
535
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
531 536
 	UploadDate       int64   `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
532 537
 	AdviceId         int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
533
-	DetItemFeeSumamt int64   `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
534
-	Cnt              int64   `gorm:"column:cnt" json:"cnt" form:"cnt"`
538
+	DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
539
+	Cnt              float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
535 540
 	Pric             float64 `gorm:"column:pric" json:"pric" form:"pric"`
536 541
 	PatientId        int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
537 542
 	PricUplmtAmt     float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
@@ -556,6 +561,8 @@ type HisOrderInfo struct {
556 561
 	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
557 562
 	HisPatientId     int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
558 563
 	OrderId          int64   `gorm:"column:order_id" json:"order_id" form:"order_id"`
564
+	ProjectId        int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
565
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
559 566
 }
560 567
 
561 568
 func (HisOrderInfo) TableName() string {

+ 8 - 8
service/gdyb_service.go View File

@@ -219,7 +219,7 @@ func Gdyb2203(psnNo string, mdtrtId string) string {
219 219
 	inputMessage["infno"] = "2203"        // 交易编码
220 220
 	inputData["mdtrt_id"] = mdtrtId       // 就诊 ID(来自2201接口返回)
221 221
 	inputData["psn_no"] = psnNo           // 人员编号 (来自1101接口返回)
222
-	inputData["med_type"] = "11"          // 医疗类别
222
+	inputData["med_type"] = "11"          // 医疗类别 16门诊特殊病
223 223
 	inputData["begntime"] = timeFormatOne // 开始时间
224 224
 	inputData["main_cond_dscr"] = ""      // 主要病情描述
225 225
 	inputData["dise_codg"] = ""           // 病种编码
@@ -341,7 +341,7 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
341 341
 	timestamp := time.Now().Unix()
342 342
 	signature := setSignature(timestamp, nonce)
343 343
 	tempTime := time.Unix(timestamp, 0)
344
-	timeFormat := tempTime.Format("20060102150405")
344
+	//timeFormat := tempTime.Format("20060102150405")
345 345
 	timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
346 346
 	//chrgBchno := rand.Intn(100000) + 10000
347 347
 
@@ -351,12 +351,12 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
351 351
 		if item.Type == 1 { //药品
352 352
 			for _, subItem := range item.HisDoctorAdviceInfo {
353 353
 
354
-				var randNum int
355
-				randNum = rand.Intn(10000) + 1000
354
+				//var randNum int
355
+				//randNum = rand.Intn(10000) + 1000
356 356
 				cus := &Custom{
357 357
 					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
358 358
 					Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
359
-					FeedetlSn:        timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(subItem.DrugId, 10),
359
+					FeedetlSn:        subItem.FeedetlSn,
360 360
 					Price:            fmt.Sprintf("%.2f", subItem.Price),
361 361
 					MedListCodg:      subItem.MedListCodg,
362 362
 				}
@@ -367,12 +367,12 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
367 367
 
368 368
 		if item.Type == 2 { //项目
369 369
 			for _, subItem := range item.HisPrescriptionProject {
370
-				var randNum int
371
-				randNum = rand.Intn(10000) + 1000
370
+				//var randNum int
371
+				//randNum = rand.Intn(10000) + 1000
372 372
 				cus := &Custom{
373 373
 					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
374 374
 					Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
375
-					FeedetlSn:        timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(subItem.ID, 10),
375
+					FeedetlSn:        subItem.FeedetlSn,
376 376
 					Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
377 377
 				}
378 378
 				fmt.Println(cus.FeedetlSn)

+ 50 - 4
service/his_service.go View File

@@ -3,6 +3,7 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6
+	"time"
6 7
 )
7 8
 
8 9
 type HisPatient struct {
@@ -15,7 +16,7 @@ type HisPatient struct {
15 16
 	RecordDate      int64              `gorm:"column:record_date" json:"record_date" form:"record_date"`
16 17
 	HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
17 18
 	PatientId       int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
18
-	Number          string             `gorm:"column:name" json:"name" form:"name"`
19
+	Number          string             `gorm:"column:number" json:"number" form:"number"`
19 20
 }
20 21
 
21 22
 func (HisPatient) TableName() string {
@@ -112,7 +113,26 @@ func SaveHisPatientCaseHistory(caseHistory models.HisPatientCaseHistory) (err er
112 113
 }
113 114
 
114 115
 func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
115
-	err = writeDb.Create(&prescription).Error
116
+	err = writeDb.Save(&prescription).Error
117
+	return
118
+}
119
+
120
+func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
121
+	err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
122
+	err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
123
+	err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
124
+	return
125
+}
126
+
127
+func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
128
+	err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
129
+
130
+	return
131
+}
132
+
133
+func DelelteProject(id int64, user_org_id int64) (err error) {
134
+	err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
135
+
116 136
 	return
117 137
 }
118 138
 
@@ -155,12 +175,17 @@ func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err
155 175
 }
156 176
 
157 177
 func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
158
-	err = writeDb.Create(s).Error
178
+	err = writeDb.Save(s).Error
159 179
 	return
160 180
 }
161 181
 
162 182
 func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
163
-	err = writeDb.Create(project).Error
183
+	err = writeDb.Save(project).Error
184
+	return
185
+}
186
+
187
+func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
188
+	err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
164 189
 	return
165 190
 }
166 191
 
@@ -173,3 +198,24 @@ func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (inf
173 198
 	err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
174 199
 	return
175 200
 }
201
+
202
+func CreateOrder(order *models.HisOrder) (err error) {
203
+	err = writeDb.Create(&order).Error
204
+	return
205
+}
206
+
207
+func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
208
+	err = writeDb.Create(&order).Error
209
+	return
210
+}
211
+
212
+func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
213
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
214
+	return
215
+
216
+}
217
+func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
218
+	err = writeDb.Save(&info).Error
219
+	return
220
+
221
+}