Browse Source

Merge branch 'master' of http://git.shengws.com/csx/gdyb

csx 3 years ago
parent
commit
70eed6709f
4 changed files with 160 additions and 64 deletions
  1. 36 17
      controllers/js/jsyb_controller.go
  2. 71 42
      controllers/sg/his_api_controller.go
  3. 5 5
      main.go
  4. 48 0
      service/jsyb_service.go

+ 36 - 17
controllers/js/jsyb_controller.go View File

@@ -467,16 +467,35 @@ func (c *JSybController) PostTen() {
467 467
 	})
468 468
 }
469 469
 
470
-//var initFlag int64 = 0
471
-
472 470
 func (c *JSybController) ReadCard() {
473 471
 	fixmedins_code := c.GetString("fixmedins_code")
474 472
 	secret_key := c.GetString("secret_key")
475 473
 	ak := c.GetString("ak")
476
-
474
+	org_name := c.GetString("org_name")
475
+	doctor := c.GetString("doctor")
476
+	insuplc_admdvs := c.GetString("insuplc_admdvs")
477
+	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
478
+	url := c.GetString("url")
477 479
 	c.TestGetBasBaseInit(fixmedins_code, secret_key, ak)
478
-	basStr := c.GetBasBaseInfo()
479
-	fmt.Println(basStr)
480
+	pCardInfo, pBusiCardInfo := c.GetBasBaseInfo()
481
+	bas := strings.Split(pCardInfo, "|")
482
+	basNumber := bas[2]
483
+	card_sn := bas[3]
484
+	if len(pCardInfo) > 0 && len(pBusiCardInfo) > 0 {
485
+		result, _ := service.Jsyb1101A(basNumber, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, 1, card_sn, "1", url, ak, pBusiCardInfo)
486
+		fmt.Println(result)
487
+		c.ServeSuccessJSON(map[string]interface{}{
488
+			"status":         "0",
489
+			"card_info":      pCardInfo,
490
+			"busi_card_info": pBusiCardInfo,
491
+			"result":         result,
492
+		})
493
+	} else {
494
+		c.ServeSuccessJSON(map[string]interface{}{
495
+			"status": "-1",
496
+		})
497
+
498
+	}
480 499
 
481 500
 }
482 501
 
@@ -519,24 +538,24 @@ func (c *JSybController) TestGetBasBaseInit(code string, secret_key string, ak s
519 538
 	//initFlag = 1
520 539
 	return
521 540
 }
522
-func (c *JSybController) GetBasBaseInfo() string {
541
+func (c *JSybController) GetBasBaseInfo() (string, string) {
523 542
 	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
524 543
 	readCard := DllDef.MustFindProc("ReadCardBas")
525 544
 	fmt.Println(readCard)
526 545
 	fmt.Println("!!!!!")
527
-	str := make([]byte, 2048)
528
-	str1 := make([]byte, 8192)
529
-	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), (uintptr)(unsafe.Pointer(&str1[0])))
530
-	fmt.Println(ret2)
531
-	//str = strings.Replace(str, " ", "", -1)
532
-	fmt.Println(string(strings.Replace(string(str1), " ", "", -1)))
533
-	fmt.Println(string(strings.Replace(string(str), " ", "", -1)))
534
-	fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
535
-	fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
546
+	pCardInfo := make([]byte, 2048)
547
+	pBusiCardInfo := make([]byte, 8192)
548
+	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&pCardInfo[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
549
+	//fmt.Println(ret2)
550
+	////str = strings.Replace(str, " ", "", -1)
551
+	//fmt.Println(string(strings.Replace(string(pCardInfo), " ", "", -1)))
552
+	//fmt.Println(string(strings.Replace(string(str), " ", "", -1)))
553
+	//fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
554
+	//fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
536 555
 	if ret2 != 0 {
537
-		return ""
556
+		return "", ""
538 557
 	}
539
-	return string(str)
558
+	return strings.Replace(string(pCardInfo), " ", "", -1), strings.Replace(string(pBusiCardInfo), " ", "", -1)
540 559
 }
541 560
 
542 561
 func IntPtr(n int) uintptr {

+ 71 - 42
controllers/sg/his_api_controller.go View File

@@ -268,6 +268,7 @@ func (c *HisApiController) ReadCard() {
268 268
 			api := "http://192.168.124.4:9532/" + "hbyb/1101?cert_no=" + "" +
269 269
 				"&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
270 270
 				"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(certificates, 10)
271
+
271 272
 			resp, requestErr := http.Get(api)
272 273
 			if requestErr != nil {
273 274
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -340,11 +341,9 @@ func (c *HisApiController) ReadCard() {
340 341
 			}
341 342
 
342 343
 		} else if miConfig.MdtrtareaAdmvs == "320921" {
343
-			DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
344
-			Iinit := DllDef.MustFindProc("Init")
345
-			fmt.Println(Iinit)
346
-			var res ResultTwo
347
-			api := "http://192.168.3.111:9532/" + "jsyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&ak=" + miConfig.ChannelNumber
344
+
345
+			api := "http://192.168.3.111:9532/" + "jsyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&ak=" + miConfig.ChannelNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
346
+				"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url
348 347
 
349 348
 			resp, requestErr := http.Get(api)
350 349
 			if requestErr != nil {
@@ -364,57 +363,87 @@ func (c *HisApiController) ReadCard() {
364 363
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
365 364
 				return
366 365
 			}
367
-
368
-			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
366
+			var status string
367
+			respJSON = respJSON["data"].(map[string]interface{})["status"].(map[string]interface{})
369 368
 			result, _ := json.Marshal(respJSON)
370
-			fmt.Println("log")
371
-			fmt.Println(string(result))
372
-
373
-			if err := json.Unmarshal([]byte(result), &res); err != nil {
369
+			if err := json.Unmarshal([]byte(result), &status); err != nil {
374 370
 				utils.ErrorLog("解析失败:%v", err)
375 371
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
376 372
 				return
377 373
 			}
374
+			if status == "0" { //读卡成功
375
+				var card_info string //卡信息
376
+				var busi_card_info string
377
+				var res ResultTwo //1101结果
378 378
 
379
-			if res.Infcode == 0 {
380
-				patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
381
-				if err == gorm.ErrRecordNotFound {
382
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
379
+				respJSON = respJSON["data"].(map[string]interface{})["card_info"].(map[string]interface{})
380
+				card_info_result, _ := json.Marshal(respJSON)
381
+
382
+				respJSON = respJSON["data"].(map[string]interface{})["busi_card_info"].(map[string]interface{})
383
+				busi_card_info_result, _ := json.Marshal(respJSON)
384
+
385
+				respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
386
+				result, _ := json.Marshal(respJSON)
387
+
388
+				if err := json.Unmarshal([]byte(result), &res); err != nil {
389
+					utils.ErrorLog("解析失败:%v", err)
390
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
383 391
 					return
384
-				} else if err != nil {
385
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
392
+				}
393
+				if err := json.Unmarshal([]byte(card_info_result), &card_info); err != nil {
394
+					utils.ErrorLog("解析失败:%v", err)
395
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
386 396
 					return
397
+				}
398
+				if err := json.Unmarshal([]byte(busi_card_info_result), &busi_card_info); err != nil {
399
+					utils.ErrorLog("解析失败:%v", err)
400
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
401
+					return
402
+				}
387 403
 
388
-				} else {
404
+				if res.Infcode == 0 {
405
+					patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
406
+					if err == gorm.ErrRecordNotFound {
407
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
408
+						return
409
+					} else if err != nil {
410
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
411
+						return
389 412
 
390
-					Iinfos, _ := json.Marshal(res.Output.Iinfo)
391
-					Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
392
-					infoStr := string(Iinfos)
393
-					idetinfoStr := string(Idetinfos)
394
-					psn := &models.HisPsn{
395
-						PsnNo:       res.Output.Baseinfo.PsnNo,
396
-						Age:         res.Output.Baseinfo.Age,
397
-						PatientId:   patient.ID,
398
-						Certno:      res.Output.Baseinfo.Certno,
399
-						Brdy:        res.Output.Baseinfo.Brdy,
400
-						Gend:        res.Output.Baseinfo.Gend,
401
-						Naty:        res.Output.Baseinfo.Naty,
402
-						PsnCertType: res.Output.Baseinfo.PsnCertType,
403
-						PsnName:     res.Output.Baseinfo.PsnName,
404
-						Idetinfo:    idetinfoStr,
405
-						Insuinfo:    infoStr,
406
-						UserOrgId:   c.GetAdminUserInfo().CurrentOrgId,
407
-					}
408
-					service.CreateHisPsn(psn)
413
+					} else {
409 414
 
410
-					c.ServeSuccessJSON(map[string]interface{}{
411
-						"patient": patient,
412
-						"number":  res.Output.Baseinfo.Certno,
413
-					})
415
+						Iinfos, _ := json.Marshal(res.Output.Iinfo)
416
+						Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
417
+						infoStr := string(Iinfos)
418
+						idetinfoStr := string(Idetinfos)
419
+						psn := &models.HisPsn{
420
+							PsnNo:       res.Output.Baseinfo.PsnNo,
421
+							Age:         res.Output.Baseinfo.Age,
422
+							PatientId:   patient.ID,
423
+							Certno:      res.Output.Baseinfo.Certno,
424
+							Brdy:        res.Output.Baseinfo.Brdy,
425
+							Gend:        res.Output.Baseinfo.Gend,
426
+							Naty:        res.Output.Baseinfo.Naty,
427
+							PsnCertType: res.Output.Baseinfo.PsnCertType,
428
+							PsnName:     res.Output.Baseinfo.PsnName,
429
+							Idetinfo:    idetinfoStr,
430
+							Insuinfo:    infoStr,
431
+							UserOrgId:   c.GetAdminUserInfo().CurrentOrgId,
432
+						}
433
+						service.CreateHisPsn(psn)
434
+						c.ServeSuccessJSON(map[string]interface{}{
435
+							"patient": patient,
436
+							"number":  res.Output.Baseinfo.Certno,
437
+						})
438
+					}
439
+				} else {
440
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
441
+					return
414 442
 				}
415
-			} else {
443
+			} else { //读卡失败
416 444
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
417 445
 				return
446
+
418 447
 			}
419 448
 
420 449
 		} else {

+ 5 - 5
main.go View File

@@ -15,11 +15,11 @@ import (
15 15
 )
16 16
 
17 17
 func init() {
18
-	//service.ConnectDB()
19
-	//org_id, _ := beego.AppConfig.Int64("org_id")
20
-	//miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
21
-	//CreateLog(miConfig)
22
-	//UploadLog(miConfig)
18
+	service.ConnectDB()
19
+	org_id, _ := beego.AppConfig.Int64("org_id")
20
+	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
21
+	CreateLog(miConfig)
22
+	UploadLog(miConfig)
23 23
 
24 24
 }
25 25
 func main() {

+ 48 - 0
service/jsyb_service.go View File

@@ -57,6 +57,54 @@ func Jsyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
57 57
 	return HttpRequest(request_url, access_key, secret_key, timestamp, string(bytesData)), inputLog
58 58
 }
59 59
 
60
+//人员基本信息版本2
61
+func Jsyb1101A(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, certificates string, request_url string, access_key string, pBusiCardInfo string) (string, string) {
62
+	timestamp := time.Now().Unix()
63
+	//生成输入报文
64
+	inputMessage := SetJSInputMessage(timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
65
+
66
+	input := make(map[string]interface{})
67
+	inputData := make(map[string]interface{})
68
+	inputMessage["infno"] = "1101" // 交易编码
69
+
70
+	if certificates == "3" {
71
+		inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
72
+		inputData["certno"] = certNo        // 证件号码
73
+		inputData["psn_cert_type"] = "99"   // 人员证件类型
74
+
75
+	} else {
76
+		if id_card_type == 1 {
77
+			inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
78
+			inputData["card_sn"] = card_sn      // 卡识别码
79
+			inputData["certno"] = certNo        // 证件号码
80
+			inputData["psn_cert_type"] = "01"   // 人员证件类型
81
+
82
+		} else {
83
+			inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
84
+			inputData["card_sn"] = ""           // 卡识别码
85
+			inputData["certno"] = certNo        // 证件号码
86
+			inputData["psn_cert_type"] = "01"   // 人员证件类型
87
+		}
88
+	}
89
+
90
+	inputData["mdtrt_cert_no"] = certNo + "|" + pBusiCardInfo // 就诊凭证编号
91
+	inputData["begntime"] = ""                                // 开始时间
92
+	inputData["psn_name"] = ""                                // 人员姓名
93
+	input["data"] = inputData
94
+	inputMessage["input"] = input //交易输入
95
+
96
+	var inputLog string
97
+	bytesData, _ := json.Marshal(inputMessage)
98
+	inputLog = string(bytesData)
99
+	fmt.Println(string(bytesData))
100
+	if err != nil {
101
+		fmt.Println(err.Error())
102
+		return err.Error(), ""
103
+	}
104
+	request_url = request_url + "1101"
105
+	return HttpRequest(request_url, access_key, secret_key, timestamp, string(bytesData)), inputLog
106
+}
107
+
60 108
 // 门诊挂号
61 109
 func Jsyb2201(psnNo string, insutype string, certNo string, org_name string, opera string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, doctor_name string, request_url string, access_key string) (string, string) {
62 110
 	fmt.Println(opera)