Преглед на файлове

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

csx преди 1 година
родител
ревизия
de9d3b4a6f
променени са 2 файла, в които са добавени 171 реда и са изтрити 13 реда
  1. 83 3
      controllers/sg/his_api_controller.go
  2. 88 10
      service/gdyb_service.go

+ 83 - 3
controllers/sg/his_api_controller.go Целия файл

@@ -1090,6 +1090,22 @@ func (c *HisApiController) CheckCardPWDTwo() {
1090 1090
 
1091 1091
 }
1092 1092
 
1093
+type ELeCertData struct {
1094
+	Data struct {
1095
+		Extra       string `json:"extra"`
1096
+		IDNo        string `json:"idNo"`
1097
+		IDType      string `json:"idType"`
1098
+		EcToken     string `json:"ecToken"`
1099
+		InsuOrg     string `json:"insuOrg"`
1100
+		UserName    string `json:"userName"`
1101
+		EcIndexNo   string `json:"ecIndexNo"`
1102
+		Gender      string `json:"gender"`
1103
+		Birthday    string `json:"birthday"`
1104
+		Nationality string `json:"nationality"`
1105
+		Email       string `json:"email"`
1106
+	} `json:"OutData"`
1107
+}
1108
+
1093 1109
 func (c *HisApiController) ReadCard() {
1094 1110
 	id_card_type, _ := c.GetInt64("id_card_type")
1095 1111
 	admin_user_id, _ := c.GetInt64("admin_user_id")
@@ -1936,7 +1952,65 @@ func (c *HisApiController) ReadCard() {
1936 1952
 				return
1937 1953
 			}
1938 1954
 		} else if miConfig.MdtrtareaAdmvs == "440300" || miConfig.MdtrtareaAdmvs == "440305" {
1939
-			service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
1955
+			result, requestLog := service.Gdyb6101(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
1956
+			saveLog(result, requestLog, "6101", "电子凭证")
1957
+			var ele ELeCertData
1958
+			err := json.Unmarshal([]byte(result), &ele)
1959
+			if err != nil {
1960
+				utils.ErrorLog("解析失败:%v", err)
1961
+			}
1962
+			result2, requestLog2 := service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, ele.Data.EcToken)
1963
+			saveLog(result2, requestLog2, "1101", "获取人员信息")
1964
+
1965
+			var res ResultTwo
1966
+			if err := json.Unmarshal([]byte(result2), &res); err != nil {
1967
+				utils.ErrorLog("解析失败:%v", err)
1968
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1969
+				return
1970
+			}
1971
+
1972
+			if res.Infcode == 0 {
1973
+				patient, err := service.GetPatientByNumber(ele.Data.IDNo, c.GetAdminUserInfo().CurrentOrgId)
1974
+				if err == gorm.ErrRecordNotFound {
1975
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
1976
+					return
1977
+				} else if err != nil {
1978
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1979
+					return
1980
+
1981
+				} else {
1982
+					Iinfos, _ := json.Marshal(res.Output.Iinfo)
1983
+					Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
1984
+					infoStr := string(Iinfos)
1985
+					idetinfoStr := string(Idetinfos)
1986
+					psn := &models.HisPsn{
1987
+						PsnNo:        res.Output.Baseinfo.PsnNo,
1988
+						Age:          res.Output.Baseinfo.Age,
1989
+						PatientId:    patient.ID,
1990
+						Certno:       res.Output.Baseinfo.Certno,
1991
+						Brdy:         res.Output.Baseinfo.Brdy,
1992
+						Gend:         res.Output.Baseinfo.Gend,
1993
+						Naty:         res.Output.Baseinfo.Naty,
1994
+						PsnCertType:  res.Output.Baseinfo.PsnCertType,
1995
+						PsnName:      res.Output.Baseinfo.PsnName,
1996
+						Idetinfo:     idetinfoStr,
1997
+						Insuinfo:     infoStr,
1998
+						UserOrgId:    c.GetAdminUserInfo().CurrentOrgId,
1999
+						CardInfo:     "",
2000
+						VerifyNumber: ele.Data.EcToken,
2001
+					}
2002
+					service.CreateHisPsn(psn)
2003
+
2004
+					c.ServeSuccessJSON(map[string]interface{}{
2005
+						"patient": patient,
2006
+						"number":  ele.Data.EcToken,
2007
+					})
2008
+				}
2009
+			} else {
2010
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
2011
+				return
2012
+			}
2013
+
1940 2014
 		}
1941 2015
 		break
1942 2016
 	}
@@ -5170,7 +5244,12 @@ func (c *HisApiController) GetRegisterInfo() {
5170 5244
 			var result string
5171 5245
 			var requestLog string
5172 5246
 			if miConfig.UserOrgId == 10138 {
5173
-				result, requestLog = service.Gdyb1101D(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10), name, record_time)
5247
+				if id_card_type == 4 {
5248
+					psn_info, _ := service.GetPsnByPatientId(id)
5249
+					result, requestLog = service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_info.VerifyNumber)
5250
+				} else {
5251
+					result, requestLog = service.Gdyb1101D(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10), name, record_time)
5252
+				}
5174 5253
 			} else {
5175 5254
 				result, requestLog = service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10), name)
5176 5255
 			}
@@ -5469,7 +5548,8 @@ func (c *HisApiController) GetRegisterInfo() {
5469 5548
 				}
5470 5549
 				infocode, _ = strconv.ParseInt(resThree10265.Infcode, 10, 64)
5471 5550
 			} else {
5472
-				result, requestLog := service.Gdyb2201A(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, insuplc_admdvs_temp, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, doctor_info.UserName, record_time)
5551
+				psn_info, _ := service.GetPsnByPatientId(id)
5552
+				result, requestLog := service.Gdyb2201A(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, insuplc_admdvs_temp, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, doctor_info.UserName, record_time, psn_info.VerifyNumber)
5473 5553
 				saveLog(result, requestLog, "2201A", "挂号")
5474 5554
 				if miConfig.Code == "H15049901371" {
5475 5555
 

+ 88 - 10
service/gdyb_service.go Целия файл

@@ -354,7 +354,7 @@ func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, ope
354 354
 
355 355
 }
356 356
 
357
-func Gdyb2201A(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, record_time string) (string, string) {
357
+func Gdyb2201A(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, record_time string, token string) (string, string) {
358 358
 	fmt.Println(opera)
359 359
 
360 360
 	// 生成签名
@@ -376,6 +376,10 @@ func Gdyb2201A(psnNo string, insutype string, certNo string, org_name string, op
376 376
 	if id_card_type == 1 {
377 377
 		inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
378 378
 		inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
379
+	} else if id_card_type == 4 {
380
+
381
+		inputData["mdtrt_cert_type"] = "01" // 就诊凭证类型
382
+		inputData["mdtrt_cert_no"] = token  // 就诊凭证编号
379 383
 	} else {
380 384
 		inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
381 385
 		inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
@@ -3829,7 +3833,7 @@ func Gdyb1101G(certNo string, org_name string, doctor string, fixmedins_code str
3829 3833
 	return str
3830 3834
 }
3831 3835
 
3832
-func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
3836
+func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, token string) (string, string) {
3833 3837
 	//生成签名
3834 3838
 	nonce := GetRandomString(32)
3835 3839
 	timestamp := time.Now().Unix()
@@ -3845,9 +3849,9 @@ func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, i
3845 3849
 	inputData["certno"] = ""            // 证件号码
3846 3850
 	inputData["psn_cert_type"] = "01"   // 人员证件类型
3847 3851
 
3848
-	inputData["mdtrt_cert_no"] = "" // 就诊凭证编号
3849
-	inputData["begntime"] = ""      // 开始时间
3850
-	inputData["psn_name"] = ""      // 人员姓名
3852
+	inputData["mdtrt_cert_no"] = token // 就诊凭证编号
3853
+	inputData["begntime"] = ""         // 开始时间
3854
+	inputData["psn_name"] = ""         // 人员姓名
3851 3855
 	input["data"] = inputData
3852 3856
 	inputMessage["input"] = input //交易输入
3853 3857
 
@@ -3855,7 +3859,7 @@ func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, i
3855 3859
 	fmt.Println(string(bytesData))
3856 3860
 	if err != nil {
3857 3861
 		fmt.Println(err.Error())
3858
-		return err.Error()
3862
+		return err.Error(), ""
3859 3863
 	}
3860 3864
 	reader := bytes.NewReader(bytesData)
3861 3865
 	gdyb_url := beego.AppConfig.String("gdyb_url")
@@ -3877,7 +3881,7 @@ func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, i
3877 3881
 	request, err := http.NewRequest("POST", url, reader)
3878 3882
 	if err != nil {
3879 3883
 		fmt.Println(err.Error())
3880
-		return err.Error()
3884
+		return err.Error(), ""
3881 3885
 	}
3882 3886
 
3883 3887
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -3890,16 +3894,90 @@ func Gdyb1101ForEleCert(org_name string, doctor string, fixmedins_code string, i
3890 3894
 	resp, err := client.Do(request)
3891 3895
 	if err != nil {
3892 3896
 		fmt.Println(err.Error())
3893
-		return err.Error()
3897
+		return err.Error(), ""
3894 3898
 	}
3895 3899
 	respBytes, err := ioutil.ReadAll(resp.Body)
3896 3900
 	if err != nil {
3897 3901
 		fmt.Println(err.Error())
3898
-		return err.Error()
3902
+		return err.Error(), ""
3899 3903
 	}
3900 3904
 	fmt.Println(string(respBytes))
3901 3905
 	str := string(respBytes)
3902
-	return str
3906
+	return str, string(bytesData)
3907
+
3908
+}
3909
+
3910
+func Gdyb6101(org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) (string, string) {
3911
+	//生成签名
3912
+	nonce := GetRandomString(32)
3913
+	timestamp := time.Now().Unix()
3914
+	signature := setSignature(timestamp, nonce, secret_key)
3915
+	//生成输入报文
3916
+	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
3917
+	input := make(map[string]interface{})
3918
+	inputData := make(map[string]interface{})
3919
+	inputMessage["infno"] = "6101" // 交易编码
3920
+
3921
+	inputData["orgId"] = fixmedins_code  // 就诊凭证类型
3922
+	inputData["businessType"] = "01101"  // 卡识别码
3923
+	inputData["businessInfo"] = ""       // 证件号码
3924
+	inputData["operateorId"] = "01"      // 人员证件类型
3925
+	inputData["operateornName"] = doctor // 就诊凭证编号
3926
+	inputData["officeId"] = "01"         // 开始时间
3927
+	inputData["officeName"] = "血透"       // 人员姓名
3928
+	inputData["deviceType"] = ""         // 人员姓名
3929
+	input["InData"] = inputData
3930
+	inputMessage["input"] = input //交易输入
3931
+
3932
+	bytesData, err := json.Marshal(inputMessage)
3933
+	fmt.Println(string(bytesData))
3934
+	if err != nil {
3935
+		fmt.Println(err.Error())
3936
+		return err.Error(), ""
3937
+	}
3938
+	reader := bytes.NewReader(bytesData)
3939
+	gdyb_url := beego.AppConfig.String("gdyb_url")
3940
+	gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
3941
+
3942
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
3943
+	//url := gdyb_url + "1101"
3944
+	var url string
3945
+	if fixmedins_code == "H15049901371" {
3946
+		url = gdyb_url
3947
+	} else {
3948
+		url = gdyb_url + "1101"
3949
+	}
3950
+
3951
+	fmt.Println(url)
3952
+	fmt.Println(gdyb_paasid)
3953
+	fmt.Println(secret_key)
3954
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
3955
+	request, err := http.NewRequest("POST", url, reader)
3956
+	if err != nil {
3957
+		fmt.Println(err.Error())
3958
+		return err.Error(), ""
3959
+	}
3960
+
3961
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
3962
+	request.Header.Set("x-tif-paasid", gdyb_paasid)
3963
+	request.Header.Set("x-tif-signature", signature)
3964
+	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
3965
+	request.Header.Set("x-tif-nonce", nonce)
3966
+
3967
+	client := http.Client{}
3968
+	resp, err := client.Do(request)
3969
+	if err != nil {
3970
+		fmt.Println(err.Error())
3971
+		return err.Error(), ""
3972
+	}
3973
+	respBytes, err := ioutil.ReadAll(resp.Body)
3974
+	if err != nil {
3975
+		fmt.Println(err.Error())
3976
+		return err.Error(), ""
3977
+	}
3978
+	fmt.Println(string(respBytes))
3979
+	str := string(respBytes)
3980
+	return str, string(bytesData)
3903 3981
 
3904 3982
 }
3905 3983