csx 4 年之前
父節點
當前提交
4f293ac480
共有 2 個文件被更改,包括 260 次插入0 次删除
  1. 119 0
      controllers/his_api_controller.go
  2. 141 0
      service/gdyb_service.go

+ 119 - 0
controllers/his_api_controller.go 查看文件

@@ -46,6 +46,9 @@ func HisManagerApiRegistRouters() {
46 46
 
47 47
 	beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
48 48
 
49
+	beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
50
+	beego.Router("/api/returnrecord/put", &HisApiController{}, "get:ReturnRecord")
51
+
49 52
 }
50 53
 
51 54
 func (c *HisApiController) Sscard() {
@@ -2043,6 +2046,122 @@ func (c *HisApiController) CheckTreatment() {
2043 2046
 
2044 2047
 }
2045 2048
 
2049
+func (c *HisApiController) PutRecord() {
2050
+	id, _ := c.GetInt64("id")
2051
+	record_time := c.GetString("record_time")
2052
+	timeLayout := "2006-01-02"
2053
+	loc, _ := time.LoadLocation("Local")
2054
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
2055
+	if err != nil {
2056
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2057
+		return
2058
+	}
2059
+	recordDateTime := theTime.Unix()
2060
+
2061
+	adminInfo := c.GetAdminUserInfo()
2062
+	patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
2063
+	patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
2064
+
2065
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
2066
+
2067
+	fmt.Println(miConfig.SecretKey)
2068
+
2069
+	if patient == nil {
2070
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
2071
+		return
2072
+	}
2073
+	if len(patient.IdCardNo) == 0 {
2074
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
2075
+		return
2076
+	}
2077
+	config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
2078
+	if config.IsOpen == 1 {
2079
+		api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
2080
+		resp, requestErr := http.Get(api)
2081
+		if requestErr != nil {
2082
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2083
+			return
2084
+		}
2085
+		defer resp.Body.Close()
2086
+		body, ioErr := ioutil.ReadAll(resp.Body)
2087
+		if ioErr != nil {
2088
+			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2089
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2090
+			return
2091
+		}
2092
+		var respJSON map[string]interface{}
2093
+
2094
+		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2095
+			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2096
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2097
+			return
2098
+		}
2099
+
2100
+		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2101
+		userJSONBytes, _ := json.Marshal(userJSON)
2102
+		var res ResultTwo
2103
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2104
+			utils.ErrorLog("解析失败:%v", err)
2105
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2106
+			return
2107
+		}
2108
+		Iinfos, _ := json.Marshal(res.Output.Iinfo)
2109
+		Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
2110
+		infoStr := string(Iinfos)
2111
+		idetinfoStr := string(Idetinfos)
2112
+
2113
+		if res.Infcode == 0 {
2114
+			his := models.VMHisPatient{
2115
+				Status:      1,
2116
+				Ctime:       time.Now().Unix(),
2117
+				Mtime:       time.Now().Unix(),
2118
+				PsnNo:       res.Output.Baseinfo.PsnNo,
2119
+				PsnCertType: res.Output.Baseinfo.PsnCertType,
2120
+				Certno:      res.Output.Baseinfo.Certno,
2121
+				PsnName:     res.Output.Baseinfo.PsnName,
2122
+				Gend:        res.Output.Baseinfo.Gend,
2123
+				Naty:        res.Output.Baseinfo.Naty,
2124
+				Brdy:        res.Output.Baseinfo.Brdy,
2125
+				Age:         res.Output.Baseinfo.Age,
2126
+				Iinfo:       infoStr,
2127
+				Idetinfo:    idetinfoStr,
2128
+				PatientId:   patient.ID,
2129
+				RecordDate:  theTime.Unix(),
2130
+				UserOrgId:   adminInfo.CurrentOrgId,
2131
+				AdminUserId: adminInfo.AdminUser.Id,
2132
+				IsReturn:    1,
2133
+			}
2134
+
2135
+			doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
2136
+			result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
2137
+
2138
+			var dat map[string]interface{}
2139
+			if err := json.Unmarshal([]byte(result), &dat); err == nil {
2140
+				fmt.Println(dat)
2141
+			} else {
2142
+				fmt.Println(err)
2143
+			}
2144
+
2145
+		} else {
2146
+			adminUser := c.GetAdminUserInfo()
2147
+			errlog := &models.HisOrderError{
2148
+				UserOrgId:  adminUser.CurrentOrgId,
2149
+				Ctime:      time.Now().Unix(),
2150
+				Mtime:      time.Now().Unix(),
2151
+				ErrMsg:     res.ErrMsg,
2152
+				Status:     1,
2153
+				PatientId:  id,
2154
+				RecordTime: recordDateTime,
2155
+				Stage:      1,
2156
+			}
2157
+			service.CreateErrMsgLog(errlog)
2158
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
2159
+			return
2160
+		}
2161
+	}
2162
+
2163
+}
2164
+
2046 2165
 func PathExists(path string) (bool, error) {
2047 2166
 	_, err := os.Stat(path)
2048 2167
 	if err == nil {

+ 141 - 0
service/gdyb_service.go 查看文件

@@ -1155,6 +1155,147 @@ func Gdyb2001(baseParams models.BaseParams, psn_no string, insutype string, med_
1155 1155
 	return str
1156 1156
 }
1157 1157
 
1158
+//func Gdyb2503(psnNo string, doctor string, department string, diag string, org_name string, med_type string, doctor_id int64, fixmedins_code string, diag_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_code string, sick_name string) string {
1159
+//	// 生成签名
1160
+//	nonce := GetRandomString(32)
1161
+//	timestamp := time.Now().Unix()
1162
+//	signature := setSignature(timestamp, nonce, secret_key)
1163
+//	tempTime := time.Unix(timestamp, 0)
1164
+//	timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
1165
+//
1166
+//	// 生成输入报文
1167
+//	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
1168
+//	input := make(map[string]interface{})
1169
+//	inputData := make(map[string]interface{})
1170
+//	diseinfo := make([]map[string]interface{}, 0)
1171
+//
1172
+//	inputMessage["infno"] = "2203"        // 交易编码
1173
+//	inputData["mdtrt_id"] = mdtrtId       // 就诊 ID(来自2201接口返回)
1174
+//	inputData["psn_no"] = psnNo           // 人员编号 (来自1101接口返回)
1175
+//	inputData["med_type"] = med_type      // 医疗类别 16门诊特殊病
1176
+//	inputData["begntime"] = timeFormatOne // 开始时间
1177
+//	inputData["main_cond_dscr"] = ""      // 主要病情描述
1178
+//	inputData["dise_codg"] = sick_code    // 病种编码
1179
+//	inputData["dise_name"] = sick_name    // 病种名称
1180
+//	inputData["birctrl_type"] = ""        // 计划生育手术类别
1181
+//	inputData["birctrl_matn_date"] = ""   // 计划生育手术或生育日期
1182
+//
1183
+//	diseinfo_sun := make(map[string]interface{})
1184
+//	diseinfo_sun["diag_type"] = "1"           // 诊断类别
1185
+//	diseinfo_sun["diag_srt_no"] = "1"         // 诊断排序号
1186
+//	diseinfo_sun["diag_code"] = diag_code     // 诊断代码
1187
+//	diseinfo_sun["diag_name"] = diag          // 诊断名称
1188
+//	diseinfo_sun["diag_dept"] = department    // 诊断科室
1189
+//	diseinfo_sun["dise_dor_no"] = doctor_id   // 诊断医生编码
1190
+//	diseinfo_sun["dise_dor_name"] = doctor    // 诊断医生姓名
1191
+//	diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间
1192
+//	diseinfo_sun["vali_flag"] = "1"           // 有效标志
1193
+//
1194
+//	diseinfo = append(diseinfo, diseinfo_sun)
1195
+//	input["diseinfo"] = diseinfo
1196
+//	input["mdtrtinfo"] = inputData
1197
+//	inputMessage["input"] = input //交易输入
1198
+//
1199
+//	bytesData, err := json.Marshal(inputMessage)
1200
+//	fmt.Println(string(bytesData))
1201
+//	if err != nil {
1202
+//		fmt.Println(err.Error())
1203
+//		return err.Error()
1204
+//	}
1205
+//	reader := bytes.NewReader(bytesData)
1206
+//
1207
+//	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2203"
1208
+//
1209
+//	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203"
1210
+//	request, err := http.NewRequest("POST", url, reader)
1211
+//	if err != nil {
1212
+//		fmt.Println(err.Error())
1213
+//		return err.Error()
1214
+//	}
1215
+//
1216
+//	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
1217
+//	request.Header.Set("x-tif-paasid", "sg03_prd")
1218
+//	request.Header.Set("x-tif-signature", signature)
1219
+//	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
1220
+//	request.Header.Set("x-tif-nonce", nonce)
1221
+//
1222
+//	client := http.Client{}
1223
+//	resp, err := client.Do(request)
1224
+//	if err != nil {
1225
+//		fmt.Println(err.Error())
1226
+//		return err.Error()
1227
+//	}
1228
+//	respBytes, err := ioutil.ReadAll(resp.Body)
1229
+//	if err != nil {
1230
+//		fmt.Println(err.Error())
1231
+//		return err.Error()
1232
+//	}
1233
+//	str := string(respBytes)
1234
+//	fmt.Println(str)
1235
+//	return str
1236
+//}
1237
+func Gdyb2503(psnNo string, insutype string, org_name string, doctor string, fixmedins_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_name string, sick_code string) string {
1238
+	// 生成签名
1239
+	nonce := GetRandomString(32)
1240
+	timestamp := time.Now().Unix()
1241
+	signature := setSignature(timestamp, nonce, secret_key)
1242
+	tempTime := time.Unix(timestamp, 0)
1243
+	timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
1244
+
1245
+	// 生成输入报文
1246
+	inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
1247
+	input := make(map[string]interface{})
1248
+	inputData := make(map[string]interface{})
1249
+	inputMessage["infno"] = "2503"                 // 交易编码
1250
+	inputData["psn_no"] = psnNo                    // 人员编号 (来自1101接口返回)
1251
+	inputData["insutype"] = insutype               // 险种类型(来自1101接口返回)
1252
+	inputData["opsp_dise_code"] = sick_code        // 险种类型(来自1101接口返回)
1253
+	inputData["opsp_dise_name"] = sick_name        // 险种类型(来自1101接口返回)
1254
+	inputData["insu_optins"] = mdtrtarea_admvs     // 险种类型(来自1101接口返回)
1255
+	inputData["ide_fixmedins_no"] = fixmedins_code // 险种类型(来自1101接口返回)
1256
+	inputData["ide_fixmedins_name"] = org_name     // 险种类型(来自1101接口返回)
1257
+	inputData["hosp_ide_date"] = timeFormatOne     // 险种类型(来自1101接口返回)
1258
+	inputData["diag_dr_codg"] = doctor_id          // 开始时间
1259
+	inputData["diag_dr_name"] = doctor             // 开始时间
1260
+	inputData["begndate"] = timeFormatOne          // 医师编码
1261
+	input["data"] = inputData
1262
+	inputMessage["input"] = input //交易输入
1263
+	bytesData, err := json.Marshal(inputMessage)
1264
+	fmt.Println(string(bytesData))
1265
+	if err != nil {
1266
+		fmt.Println(err.Error())
1267
+		return err.Error()
1268
+	}
1269
+	reader := bytes.NewReader(bytesData)
1270
+	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2503"
1271
+	request, err := http.NewRequest("POST", url, reader)
1272
+	if err != nil {
1273
+		fmt.Println(err.Error())
1274
+		return err.Error()
1275
+	}
1276
+
1277
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
1278
+	request.Header.Set("x-tif-paasid", "sg03_prd")
1279
+	request.Header.Set("x-tif-signature", signature)
1280
+	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
1281
+	request.Header.Set("x-tif-nonce", nonce)
1282
+
1283
+	client := http.Client{}
1284
+	resp, err := client.Do(request)
1285
+	if err != nil {
1286
+		fmt.Println(err.Error())
1287
+		return err.Error()
1288
+	}
1289
+	respBytes, err := ioutil.ReadAll(resp.Body)
1290
+	if err != nil {
1291
+		fmt.Println(err.Error())
1292
+		return err.Error()
1293
+	}
1294
+	str := string(respBytes)
1295
+	fmt.Println(str)
1296
+	return str
1297
+}
1298
+
1158 1299
 //  门诊结算撤销
1159 1300
 //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
1160 1301
 //	// 生成签名