csx 4 years ago
parent
commit
cd040a5833

+ 2 - 1
controllers/gdyb_controller.go View File

75
 	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
75
 	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
76
 
76
 
77
 	secret_key := c.GetString("secret_key")
77
 	secret_key := c.GetString("secret_key")
78
+	id_card_type, _ := c.GetInt64("id_card_type")
78
 
79
 
79
-	result := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key)
80
+	result := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type)
80
 
81
 
81
 	var dat map[string]interface{}
82
 	var dat map[string]interface{}
82
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {
83
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {

+ 234 - 33
controllers/his_api_controller.go View File

42
 	beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
42
 	beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
43
 	beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
43
 	beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
44
 	beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
44
 	beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
45
+
46
+	beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
47
+
48
+}
49
+
50
+func (c *HisApiController) GetHisPatientInfo() {
51
+
52
+	medical_insurance_card := c.GetString("medical_insurance_card")
53
+	id_card_type, _ := c.GetInt64("id_card_type")
54
+	id_card := c.GetString("id_card")
55
+
56
+	adminInfo := c.GetAdminUserInfo()
57
+	config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
58
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
59
+
60
+	appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
61
+
62
+	IdCardNo := ""
63
+
64
+	if id_card_type == 1 {
65
+		IdCardNo = medical_insurance_card
66
+	} else if id_card_type == 2 {
67
+		IdCardNo = id_card
68
+	}
69
+
70
+	if config.IsOpen == 1 {
71
+
72
+		api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
73
+		resp, requestErr := http.Get(api)
74
+		if requestErr != nil {
75
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
76
+			return
77
+		}
78
+		defer resp.Body.Close()
79
+		body, ioErr := ioutil.ReadAll(resp.Body)
80
+		if ioErr != nil {
81
+			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
82
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
83
+			return
84
+		}
85
+		var respJSON map[string]interface{}
86
+
87
+		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
88
+			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
89
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
90
+			return
91
+		}
92
+
93
+		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
94
+		userJSONBytes, _ := json.Marshal(userJSON)
95
+		var res ResultTwo
96
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
97
+			utils.ErrorLog("解析失败:%v", err)
98
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
99
+			return
100
+		}
101
+		Iinfos, _ := json.Marshal(res.Output.Iinfo)
102
+		Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
103
+		infoStr := string(Iinfos)
104
+		idetinfoStr := string(Idetinfos)
105
+
106
+		if res.Infcode == 0 {
107
+			his := models.VMHisPatient{
108
+				Status:      1,
109
+				Ctime:       time.Now().Unix(),
110
+				Mtime:       time.Now().Unix(),
111
+				PsnNo:       res.Output.Baseinfo.PsnNo,
112
+				PsnCertType: res.Output.Baseinfo.PsnCertType,
113
+				Certno:      res.Output.Baseinfo.Certno,
114
+				PsnName:     res.Output.Baseinfo.PsnName,
115
+				Gend:        res.Output.Baseinfo.Gend,
116
+				Naty:        res.Output.Baseinfo.Naty,
117
+				Brdy:        res.Output.Baseinfo.Brdy,
118
+				Age:         res.Output.Baseinfo.Age,
119
+				Iinfo:       infoStr,
120
+				Idetinfo:    idetinfoStr,
121
+				UserOrgId:   adminInfo.CurrentOrgId,
122
+				IsReturn:    1,
123
+				IdCardType:  id_card_type,
124
+			}
125
+			c.ServeSuccessJSON(map[string]interface{}{
126
+				"info": his,
127
+			})
128
+		} else {
129
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
130
+			return
131
+		}
132
+	}
133
+
45
 }
134
 }
46
 
135
 
47
 func (c *HisApiController) Sscard() {
136
 func (c *HisApiController) Sscard() {
48
 	id_card_type, _ := c.GetInt64("id_card_type")
137
 	id_card_type, _ := c.GetInt64("id_card_type")
49
 	adminUser := c.GetAdminUserInfo()
138
 	adminUser := c.GetAdminUserInfo()
139
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
140
+
50
 	r := CardInit()
141
 	r := CardInit()
51
 	if r == 0 {
142
 	if r == 0 {
52
 		switch id_card_type {
143
 		switch id_card_type {
53
 		case 1:
144
 		case 1:
54
 			basStr, err := GetBasBaseInfo()
145
 			basStr, err := GetBasBaseInfo()
55
-			fmt.Println("~~~~~")
56
-			fmt.Println(basStr)
57
-			fmt.Println("~~~~~")
58
 
146
 
59
 			if err != nil {
147
 			if err != nil {
60
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
148
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
61
 				return
149
 				return
62
 
150
 
63
 			} else {
151
 			} else {
152
+
64
 				bas := strings.Split(basStr, "|")
153
 				bas := strings.Split(basStr, "|")
65
 				basNumber := bas[1]
154
 				basNumber := bas[1]
66
-				patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
67
-				if err == gorm.ErrRecordNotFound {
68
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
155
+
156
+				appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
157
+
158
+				api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
159
+				resp, requestErr := http.Get(api)
160
+				if requestErr != nil {
161
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
69
 					return
162
 					return
163
+				}
164
+				defer resp.Body.Close()
165
+				body, ioErr := ioutil.ReadAll(resp.Body)
166
+				if ioErr != nil {
167
+					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
168
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
169
+					return
170
+				}
171
+				var respJSON map[string]interface{}
70
 
172
 
71
-				} else if err != nil {
72
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
173
+				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
174
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
175
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
176
+					return
177
+				}
178
+
179
+				userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
180
+				userJSONBytes, _ := json.Marshal(userJSON)
181
+				var res ResultTwo
182
+				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
183
+					utils.ErrorLog("解析失败:%v", err)
184
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
73
 					return
185
 					return
186
+				}
187
+				Iinfos, _ := json.Marshal(res.Output.Iinfo)
188
+				Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
189
+				infoStr := string(Iinfos)
190
+				idetinfoStr := string(Idetinfos)
191
+
192
+				if res.Infcode == 0 {
193
+					his := models.VMHisPatient{
194
+						Status:      1,
195
+						Ctime:       time.Now().Unix(),
196
+						Mtime:       time.Now().Unix(),
197
+						PsnNo:       res.Output.Baseinfo.PsnNo,
198
+						PsnCertType: res.Output.Baseinfo.PsnCertType,
199
+						Certno:      res.Output.Baseinfo.Certno,
200
+						PsnName:     res.Output.Baseinfo.PsnName,
201
+						Gend:        res.Output.Baseinfo.Gend,
202
+						Naty:        res.Output.Baseinfo.Naty,
203
+						Brdy:        res.Output.Baseinfo.Brdy,
204
+						Age:         res.Output.Baseinfo.Age,
205
+						Iinfo:       infoStr,
206
+						Idetinfo:    idetinfoStr,
207
+						UserOrgId:   adminUser.CurrentOrgId,
208
+						IsReturn:    1,
209
+						IdCardType:  id_card_type,
210
+					}
74
 
211
 
212
+					patient, err := service.GetPatientByNumber(his.Certno, adminUser.CurrentOrgId)
213
+					if err == gorm.ErrRecordNotFound {
214
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
215
+						return
216
+
217
+					} else if err != nil {
218
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
219
+						return
220
+
221
+					} else {
222
+						c.ServeSuccessJSON(map[string]interface{}{
223
+							"patient": patient,
224
+							"info":    his,
225
+							"number":  basNumber,
226
+						})
227
+					}
75
 				} else {
228
 				} else {
76
-					c.ServeSuccessJSON(map[string]interface{}{
77
-						"patient": patient,
78
-						"number":  basNumber,
79
-					})
229
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
230
+					return
80
 				}
231
 				}
81
 
232
 
82
 			}
233
 			}
84
 			break
235
 			break
85
 		case 2:
236
 		case 2:
86
 			SFZStr, err := GetSFZBaseInfo()
237
 			SFZStr, err := GetSFZBaseInfo()
87
-			fmt.Println("~~~~~----")
88
-			fmt.Println(SFZStr)
89
-			fmt.Println("~~~~~---")
90
 			if err != nil {
238
 			if err != nil {
91
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
239
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
92
 				return
240
 				return
95
 
243
 
96
 				id_card_str := strings.Split(SFZStr, "^")
244
 				id_card_str := strings.Split(SFZStr, "^")
97
 				id_card_number := id_card_str[0]
245
 				id_card_number := id_card_str[0]
98
-				patient, err := service.GetPatientByIDCard(id_card_number, adminUser.CurrentOrgId)
99
-				if err == gorm.ErrRecordNotFound {
100
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
246
+				appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
247
+
248
+				api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
249
+				resp, requestErr := http.Get(api)
250
+				if requestErr != nil {
251
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
101
 					return
252
 					return
253
+				}
254
+				defer resp.Body.Close()
255
+				body, ioErr := ioutil.ReadAll(resp.Body)
256
+				if ioErr != nil {
257
+					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
258
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
259
+					return
260
+				}
261
+				var respJSON map[string]interface{}
102
 
262
 
103
-				} else if err != nil {
104
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
263
+				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
264
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
265
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
266
+					return
267
+				}
268
+
269
+				userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
270
+				userJSONBytes, _ := json.Marshal(userJSON)
271
+				var res ResultTwo
272
+				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
273
+					utils.ErrorLog("解析失败:%v", err)
274
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
105
 					return
275
 					return
276
+				}
277
+				Iinfos, _ := json.Marshal(res.Output.Iinfo)
278
+				Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
279
+				infoStr := string(Iinfos)
280
+				idetinfoStr := string(Idetinfos)
281
+
282
+				if res.Infcode == 0 {
283
+					his := models.VMHisPatient{
284
+						Status:      1,
285
+						Ctime:       time.Now().Unix(),
286
+						Mtime:       time.Now().Unix(),
287
+						PsnNo:       res.Output.Baseinfo.PsnNo,
288
+						PsnCertType: res.Output.Baseinfo.PsnCertType,
289
+						Certno:      res.Output.Baseinfo.Certno,
290
+						PsnName:     res.Output.Baseinfo.PsnName,
291
+						Gend:        res.Output.Baseinfo.Gend,
292
+						Naty:        res.Output.Baseinfo.Naty,
293
+						Brdy:        res.Output.Baseinfo.Brdy,
294
+						Age:         res.Output.Baseinfo.Age,
295
+						Iinfo:       infoStr,
296
+						Idetinfo:    idetinfoStr,
297
+						UserOrgId:   adminUser.CurrentOrgId,
298
+						IsReturn:    1,
299
+						IdCardType:  id_card_type,
300
+					}
106
 
301
 
302
+					patient, err := service.GetPatientByNumber(his.Certno, adminUser.CurrentOrgId)
303
+					if err == gorm.ErrRecordNotFound {
304
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
305
+						return
306
+
307
+					} else if err != nil {
308
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
309
+						return
310
+
311
+					} else {
312
+						c.ServeSuccessJSON(map[string]interface{}{
313
+							"patient": patient,
314
+							"info":    his,
315
+							"number":  id_card_number,
316
+						})
317
+					}
107
 				} else {
318
 				} else {
108
-					c.ServeSuccessJSON(map[string]interface{}{
109
-						"patient": patient,
110
-					})
319
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
320
+					return
111
 				}
321
 				}
112
 
322
 
113
 			}
323
 			}
114
 			break
324
 			break
115
 		case 3:
325
 		case 3:
116
-			//QRStr, err :=GetQRBaseInfo()
117
-			//if err != nil{
118
-			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
119
-			//	return
120
-			//
121
-			//}else{
122
-			//
123
-			//
124
-			//
125
-			//}
326
+
126
 			break
327
 			break
127
 
328
 
128
 		}
329
 		}

+ 5 - 1
enums/error_code.go View File

234
 	ErrorCodeReadCardException = 20074
234
 	ErrorCodeReadCardException = 20074
235
 
235
 
236
 	ErrorCodeNoPateintException = 20075
236
 	ErrorCodeNoPateintException = 20075
237
+
238
+	ErrorCodeHisFailedException = 20076
237
 )
239
 )
238
 
240
 
239
 var ErrCodeMsgs = map[int]string{
241
 var ErrCodeMsgs = map[int]string{
450
 	ErrorCodeAmountAccountException:  "结算失败",
452
 	ErrorCodeAmountAccountException:  "结算失败",
451
 
453
 
452
 	ErrorCodeReadCardException:  "读卡失败",
454
 	ErrorCodeReadCardException:  "读卡失败",
453
-	ErrorCodeNoPateintException: "该患者不存在血透系统中,请在血透系统中添加该患者",
455
+	ErrorCodeNoPateintException: "读卡失败!请先在系统录入患者信息或检查患者身份证信息是否正确,再重新读卡",
456
+
457
+	ErrorCodeHisFailedException: "获取人员信息失败",
454
 }
458
 }
455
 
459
 
456
 type SGJError struct {
460
 type SGJError struct {

+ 9 - 3
service/gdyb_service.go View File

25
 )
25
 )
26
 
26
 
27
 // 人员基本信息
27
 // 人员基本信息
28
-func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
28
+func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64) string {
29
 	// 生成签名
29
 	// 生成签名
30
 	nonce := GetRandomString(32)
30
 	nonce := GetRandomString(32)
31
 	timestamp := time.Now().Unix()
31
 	timestamp := time.Now().Unix()
35
 	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
35
 	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
36
 	input := make(map[string]interface{})
36
 	input := make(map[string]interface{})
37
 	inputData := make(map[string]interface{})
37
 	inputData := make(map[string]interface{})
38
-	inputMessage["infno"] = "1101"      // 交易编码
39
-	inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
38
+	inputMessage["infno"] = "1101" // 交易编码
39
+
40
+	if id_card_type == 1 {
41
+		inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
42
+	} else if id_card_type == 2 {
43
+		inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
44
+	}
45
+
40
 	inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
46
 	inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
41
 	inputData["card_sn"] = ""           // 卡识别码
47
 	inputData["card_sn"] = ""           // 卡识别码
42
 	inputData["begntime"] = ""          // 开始时间
48
 	inputData["begntime"] = ""          // 开始时间

+ 7 - 1
service/his_service.go View File

927
 }
927
 }
928
 
928
 
929
 func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
929
 func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
930
-	err = readDb.Model(&Patients{}).Where("health_care_no = ? AND user_org_id = ?", number, user_org_id).First(&patient).Error
930
+	err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?)  AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
931
 	return
931
 	return
932
 }
932
 }
933
 
933
 
940
 	err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
940
 	err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
941
 	return
941
 	return
942
 }
942
 }
943
+
944
+func GetAppRole(orgID int64) (models.App_Role, error) {
945
+	var appRole models.App_Role
946
+	err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
947
+	return appRole, err
948
+}