gdyb_service.go 55KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. package service
  2. import (
  3. "XT_New/models"
  4. //"/models"
  5. "bytes"
  6. "crypto/sha256"
  7. "encoding/hex"
  8. "encoding/json"
  9. "fmt"
  10. "io"
  11. "io/ioutil"
  12. "math/rand"
  13. "mime/multipart"
  14. "net/http"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. _ "unsafe"
  21. )
  22. const (
  23. SceretKey = "RhaDw4H0RUbWYyTxmRKM1eSeN0qyGLds" // secretKey 私钥
  24. )
  25. // 人员基本信息
  26. func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  27. // 生成签名
  28. nonce := GetRandomString(32)
  29. timestamp := time.Now().Unix()
  30. signature := setSignature(timestamp, nonce, secret_key)
  31. // 生成输入报文
  32. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  33. input := make(map[string]interface{})
  34. inputData := make(map[string]interface{})
  35. inputMessage["infno"] = "1101" // 交易编码
  36. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  37. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  38. inputData["card_sn"] = "" // 卡识别码
  39. inputData["begntime"] = "" // 开始时间
  40. inputData["psn_cert_type"] = "1" // 人员证件类型
  41. inputData["certno"] = certNo // 证件号码
  42. inputData["psn_name"] = "" // 人员姓名
  43. input["data"] = inputData
  44. inputMessage["input"] = input //交易输入
  45. bytesData, err := json.Marshal(inputMessage)
  46. fmt.Println(string(bytesData))
  47. if err != nil {
  48. fmt.Println(err.Error())
  49. return err.Error()
  50. }
  51. reader := bytes.NewReader(bytesData)
  52. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  53. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  54. request, err := http.NewRequest("POST", url, reader)
  55. if err != nil {
  56. fmt.Println(err.Error())
  57. return err.Error()
  58. }
  59. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  60. request.Header.Set("x-tif-paasid", "sg03_prd")
  61. request.Header.Set("x-tif-signature", signature)
  62. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  63. request.Header.Set("x-tif-nonce", nonce)
  64. client := http.Client{}
  65. resp, err := client.Do(request)
  66. if err != nil {
  67. fmt.Println(err.Error())
  68. return err.Error()
  69. }
  70. respBytes, err := ioutil.ReadAll(resp.Body)
  71. if err != nil {
  72. fmt.Println(err.Error())
  73. return err.Error()
  74. }
  75. fmt.Println(string(respBytes))
  76. str := string(respBytes)
  77. return str
  78. }
  79. // 门诊挂号
  80. func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor 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) string {
  81. // 生成签名
  82. nonce := GetRandomString(32)
  83. timestamp := time.Now().Unix()
  84. signature := setSignature(timestamp, nonce, secret_key)
  85. tempTime := time.Unix(timestamp, 0)
  86. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  87. // 生成输入报文
  88. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  89. input := make(map[string]interface{})
  90. inputData := make(map[string]interface{})
  91. inputMessage["infno"] = "2201" // 交易编码
  92. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  93. inputData["insutype"] = insutype // 险种类型(来自1101接口返回)
  94. inputData["begntime"] = timeFormatOne // 开始时间
  95. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  96. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  97. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  98. inputData["atddr_no"] = doctor_id // 医师编码
  99. inputData["dr_name"] = doctor // 医师姓名
  100. inputData["dept_code"] = dept_code // 科室编码
  101. inputData["dept_name"] = dept // 科室名称
  102. inputData["caty"] = "A03.06" // 科别
  103. input["data"] = inputData
  104. inputMessage["input"] = input //交易输入
  105. bytesData, err := json.Marshal(inputMessage)
  106. fmt.Println(string(bytesData))
  107. if err != nil {
  108. fmt.Println(err.Error())
  109. return err.Error()
  110. }
  111. reader := bytes.NewReader(bytesData)
  112. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201"
  113. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2201"
  114. request, err := http.NewRequest("POST", url, reader)
  115. if err != nil {
  116. fmt.Println(err.Error())
  117. return err.Error()
  118. }
  119. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  120. request.Header.Set("x-tif-paasid", "sg03_prd")
  121. request.Header.Set("x-tif-signature", signature)
  122. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  123. request.Header.Set("x-tif-nonce", nonce)
  124. client := http.Client{}
  125. resp, err := client.Do(request)
  126. if err != nil {
  127. fmt.Println(err.Error())
  128. return err.Error()
  129. }
  130. respBytes, err := ioutil.ReadAll(resp.Body)
  131. if err != nil {
  132. fmt.Println(err.Error())
  133. return err.Error()
  134. }
  135. str := string(respBytes)
  136. fmt.Println(str)
  137. return str
  138. }
  139. // 门诊挂号撤销
  140. func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  141. // 生成签名
  142. nonce := GetRandomString(32)
  143. timestamp := time.Now().Unix()
  144. signature := setSignature(timestamp, nonce, secret_key)
  145. // 生成输入报文
  146. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", insuplc_admdvs, mdtrtarea_admvs)
  147. input := make(map[string]interface{})
  148. inputData := make(map[string]interface{})
  149. inputMessage["infno"] = "2202" // 交易编码
  150. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  151. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  152. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  153. input["data"] = inputData
  154. inputMessage["input"] = input //交易输入
  155. bytesData, err := json.Marshal(inputMessage)
  156. fmt.Println(string(bytesData))
  157. if err != nil {
  158. fmt.Println(err.Error())
  159. return err.Error()
  160. }
  161. reader := bytes.NewReader(bytesData)
  162. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2202"
  163. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  164. request, err := http.NewRequest("POST", url, reader)
  165. if err != nil {
  166. fmt.Println(err.Error())
  167. return err.Error()
  168. }
  169. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  170. //request.Header.Set("x-tif-paasid", "test_hosp")
  171. request.Header.Set("x-tif-paasid", "sg03_prd")
  172. request.Header.Set("x-tif-signature", signature)
  173. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  174. request.Header.Set("x-tif-nonce", nonce)
  175. client := http.Client{}
  176. resp, err := client.Do(request)
  177. if err != nil {
  178. fmt.Println(err.Error())
  179. return err.Error()
  180. }
  181. respBytes, err := ioutil.ReadAll(resp.Body)
  182. if err != nil {
  183. fmt.Println(err.Error())
  184. return err.Error()
  185. }
  186. str := string(respBytes)
  187. fmt.Println(str)
  188. return str
  189. }
  190. // 门诊就诊信息上传
  191. func Gdyb2203(psnNo string, mdtrtId 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) string {
  192. // 生成签名
  193. nonce := GetRandomString(32)
  194. timestamp := time.Now().Unix()
  195. signature := setSignature(timestamp, nonce, secret_key)
  196. tempTime := time.Unix(timestamp, 0)
  197. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  198. // 生成输入报文
  199. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  200. input := make(map[string]interface{})
  201. inputData := make(map[string]interface{})
  202. diseinfo := make([]map[string]interface{}, 0)
  203. inputMessage["infno"] = "2203" // 交易编码
  204. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  205. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  206. inputData["med_type"] = med_type // 医疗类别 16门诊特殊病
  207. inputData["begntime"] = timeFormatOne // 开始时间
  208. inputData["main_cond_dscr"] = "" // 主要病情描述
  209. inputData["dise_codg"] = "" // 病种编码
  210. inputData["dise_name"] = "" // 病种名称
  211. inputData["birctrl_type"] = "" // 计划生育手术类别
  212. inputData["birctrl_matn_date"] = "" // 计划生育手术或生育日期
  213. diseinfo_sun := make(map[string]interface{})
  214. diseinfo_sun["diag_type"] = "1" // 诊断类别
  215. diseinfo_sun["diag_srt_no"] = "1" // 诊断排序号
  216. diseinfo_sun["diag_code"] = diag_code // 诊断代码
  217. diseinfo_sun["diag_name"] = diag // 诊断名称
  218. diseinfo_sun["diag_dept"] = department // 诊断科室
  219. diseinfo_sun["dise_dor_no"] = doctor_id // 诊断医生编码
  220. diseinfo_sun["dise_dor_name"] = doctor // 诊断医生姓名
  221. diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间
  222. diseinfo_sun["vali_flag"] = "1" // 有效标志
  223. diseinfo = append(diseinfo, diseinfo_sun)
  224. input["diseinfo"] = diseinfo
  225. input["mdtrtinfo"] = inputData
  226. inputMessage["input"] = input //交易输入
  227. bytesData, err := json.Marshal(inputMessage)
  228. fmt.Println(string(bytesData))
  229. if err != nil {
  230. fmt.Println(err.Error())
  231. return err.Error()
  232. }
  233. reader := bytes.NewReader(bytesData)
  234. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2203"
  235. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203"
  236. request, err := http.NewRequest("POST", url, reader)
  237. if err != nil {
  238. fmt.Println(err.Error())
  239. return err.Error()
  240. }
  241. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  242. request.Header.Set("x-tif-paasid", "sg03_prd")
  243. request.Header.Set("x-tif-signature", signature)
  244. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  245. request.Header.Set("x-tif-nonce", nonce)
  246. client := http.Client{}
  247. resp, err := client.Do(request)
  248. if err != nil {
  249. fmt.Println(err.Error())
  250. return err.Error()
  251. }
  252. respBytes, err := ioutil.ReadAll(resp.Body)
  253. if err != nil {
  254. fmt.Println(err.Error())
  255. return err.Error()
  256. }
  257. str := string(respBytes)
  258. fmt.Println(str)
  259. return str
  260. }
  261. type Custom struct {
  262. DetItemFeeSumamt string
  263. Cut string
  264. FeedetlSn string
  265. Price string
  266. MedListCodg string
  267. }
  268. type RequestResult struct {
  269. Output Output `json:"output" form:"output"`
  270. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  271. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  272. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  273. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  274. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  275. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  276. }
  277. type Output struct {
  278. Result Result `json:"result" form:"result"`
  279. }
  280. type Result struct {
  281. BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"`
  282. MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"`
  283. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  284. HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  285. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  286. FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"`
  287. UploadDate int64 `json:"upload_date" form:"upload_date"`
  288. AdviceId int64 `json:"advice_id" form:"advice_id"`
  289. Cnt int64 `json:"cnt" form:"cnt"`
  290. Pric float64 `json:"pric" form:"pric"`
  291. PatientId int64 `json:"patient_id" form:"patient_id"`
  292. PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  293. SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"`
  294. OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"`
  295. PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"`
  296. Status int64 `json:"status" form:"status"`
  297. Memo string `json:"memo" form:"memo"`
  298. FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"`
  299. Mtime int64 `json:"mtime" form:"mtime"`
  300. InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"`
  301. DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"`
  302. Ctime int64 `json:"ctime" form:"ctime"`
  303. ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"`
  304. ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"`
  305. LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"`
  306. ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"`
  307. UserOrgId int64 `json:"user_org_id" form:"user_org_id"`
  308. HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"`
  309. OrderId int64 `json:"order_id" form:"order_id"`
  310. }
  311. // 门诊费用明细信息上传
  312. func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  313. // 生成签名
  314. nonce := GetRandomString(32)
  315. timestamp := time.Now().Unix()
  316. signature := setSignature(timestamp, nonce, secret_key)
  317. tempTime := time.Unix(timestamp, 0)
  318. //timeFormat := tempTime.Format("20060102150405")
  319. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  320. //chrgBchno := rand.Intn(100000) + 10000
  321. var customs []*Custom
  322. for _, item := range hisPrescription {
  323. if item.Type == 1 { //药品
  324. for _, subItem := range item.HisDoctorAdviceInfo {
  325. if len(subItem.MedListCodg) > 0 {
  326. //var randNum int
  327. //randNum = rand.Intn(10000) + 1000
  328. cus := &Custom{
  329. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  330. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  331. FeedetlSn: subItem.FeedetlSn,
  332. Price: fmt.Sprintf("%.2f", subItem.Price),
  333. MedListCodg: subItem.MedListCodg,
  334. }
  335. customs = append(customs, cus)
  336. }
  337. }
  338. }
  339. if item.Type == 2 { //项目
  340. for _, subItem := range item.HisPrescriptionProject {
  341. //var randNum int
  342. //randNum = rand.Intn(10000) + 1000
  343. if len(subItem.MedListCodg) > 0 {
  344. cut, _ := strconv.ParseFloat(subItem.Count, 64)
  345. cus := &Custom{
  346. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cut),
  347. Cut: fmt.Sprintf("%.2f", cut),
  348. FeedetlSn: subItem.FeedetlSn,
  349. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  350. MedListCodg: subItem.MedListCodg,
  351. }
  352. customs = append(customs, cus)
  353. }
  354. }
  355. }
  356. for _, subItem := range item.HisAdditionalCharge {
  357. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  358. cus := &Custom{
  359. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  360. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  361. FeedetlSn: subItem.FeedetlSn,
  362. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  363. MedListCodg: subItem.XtHisAddtionConfig.Code,
  364. }
  365. customs = append(customs, cus)
  366. }
  367. }
  368. }
  369. // 生成输入报文
  370. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  371. input := make(map[string]interface{})
  372. feedetail := make([]map[string]interface{}, 0)
  373. inputMessage["infno"] = "2204" // 交易编码
  374. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  375. for _, item := range customs {
  376. feedetailInfo := make(map[string]interface{})
  377. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  378. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  379. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  380. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  381. feedetailInfo["dise_codg"] = "" // 病种编码
  382. feedetailInfo["rxno"] = "" // 处方号
  383. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  384. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  385. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  386. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  387. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  388. feedetailInfo["cnt"] = item.Cut // 数量
  389. feedetailInfo["pric"] = item.Price // 单价
  390. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  391. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  392. feedetailInfo["prd_days"] = "0" // 周期天数
  393. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  394. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  395. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  396. feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码
  397. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  398. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  399. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  400. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  401. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  402. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  403. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  404. feedetailInfo["etip_flag"] = "" // 外检标志
  405. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  406. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  407. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  408. feedetail = append(feedetail, feedetailInfo)
  409. }
  410. input["feedetail"] = feedetail
  411. inputMessage["input"] = input //交易输入
  412. bytesData, err := json.Marshal(inputMessage)
  413. fmt.Println("----------")
  414. fmt.Println(string(bytesData))
  415. fmt.Println("----------")
  416. if err != nil {
  417. fmt.Println(err.Error())
  418. return ""
  419. }
  420. reader := bytes.NewReader(bytesData)
  421. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2204"
  422. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  423. request, err := http.NewRequest("POST", url, reader)
  424. if err != nil {
  425. fmt.Println(err.Error())
  426. return ""
  427. }
  428. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  429. request.Header.Set("x-tif-paasid", "sg03_prd")
  430. request.Header.Set("x-tif-signature", signature)
  431. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  432. request.Header.Set("x-tif-nonce", nonce)
  433. client := http.Client{}
  434. resp, err := client.Do(request)
  435. if err != nil {
  436. fmt.Println(err.Error())
  437. return ""
  438. }
  439. respBytes, err := ioutil.ReadAll(resp.Body)
  440. if err != nil {
  441. fmt.Println(err.Error())
  442. return ""
  443. }
  444. return string(respBytes)
  445. //var result RequestResult
  446. //json.Unmarshal(respBytes, &result)
  447. //return &result
  448. }
  449. // 门诊费用明细信息撤销
  450. func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) string {
  451. // 生成签名
  452. nonce := GetRandomString(32)
  453. timestamp := time.Now().Unix()
  454. signature := setSignature(timestamp, nonce, secret_key)
  455. // 生成输入报文
  456. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  457. input := make(map[string]interface{})
  458. inputData := make(map[string]interface{})
  459. inputMessage["infno"] = "2205" // 交易编码
  460. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  461. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  462. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  463. input["data"] = inputData
  464. inputMessage["input"] = input //交易输入
  465. bytesData, err := json.Marshal(inputMessage)
  466. fmt.Println(string(bytesData))
  467. if err != nil {
  468. fmt.Println(err.Error())
  469. return err.Error()
  470. }
  471. reader := bytes.NewReader(bytesData)
  472. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2205"
  473. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  474. request, err := http.NewRequest("POST", url, reader)
  475. fmt.Println(err)
  476. fmt.Println(request)
  477. if err != nil {
  478. fmt.Println(err.Error())
  479. return err.Error()
  480. }
  481. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  482. request.Header.Set("x-tif-paasid", "sg03_prd")
  483. request.Header.Set("x-tif-signature", signature)
  484. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  485. request.Header.Set("x-tif-nonce", nonce)
  486. client := http.Client{}
  487. resp, err := client.Do(request)
  488. if err != nil {
  489. fmt.Println(err.Error())
  490. return err.Error()
  491. }
  492. respBytes, err := ioutil.ReadAll(resp.Body)
  493. if err != nil {
  494. fmt.Println(err.Error())
  495. return err.Error()
  496. }
  497. str := string(respBytes)
  498. fmt.Println(str)
  499. return str
  500. }
  501. // 门诊预结算
  502. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string {
  503. // 生成签名
  504. nonce := GetRandomString(32)
  505. timestamp := time.Now().Unix()
  506. signature := setSignature(timestamp, nonce, secret_key)
  507. // 生成输入报文
  508. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "")
  509. input := make(map[string]interface{})
  510. inputData := make(map[string]interface{})
  511. inputMessage["infno"] = "2206" // 交易编码
  512. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  513. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  514. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  515. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  516. inputData["medfee_sumamt"] = total // 医疗费总额
  517. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  518. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  519. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  520. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  521. inputData["insutype"] = insutype // 险种类型
  522. input["data"] = inputData
  523. inputMessage["input"] = input //交易输入
  524. bytesData, err := json.Marshal(inputMessage)
  525. fmt.Println(string(bytesData))
  526. if err != nil {
  527. fmt.Println(err.Error())
  528. return err.Error()
  529. }
  530. reader := bytes.NewReader(bytesData)
  531. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2206"
  532. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  533. request, err := http.NewRequest("POST", url, reader)
  534. if err != nil {
  535. fmt.Println(err.Error())
  536. return err.Error()
  537. }
  538. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  539. request.Header.Set("x-tif-paasid", "sg03_prd")
  540. request.Header.Set("x-tif-signature", signature)
  541. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  542. request.Header.Set("x-tif-nonce", nonce)
  543. client := http.Client{}
  544. resp, err := client.Do(request)
  545. if err != nil {
  546. fmt.Println(err.Error())
  547. return err.Error()
  548. }
  549. respBytes, err := ioutil.ReadAll(resp.Body)
  550. if err != nil {
  551. fmt.Println(err.Error())
  552. return err.Error()
  553. }
  554. str := string(respBytes)
  555. fmt.Println(str)
  556. return str
  557. }
  558. // 门诊结算
  559. func Gdyb2207(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  560. // 生成签名
  561. nonce := GetRandomString(32)
  562. timestamp := time.Now().Unix()
  563. signature := setSignature(timestamp, nonce, secret_key)
  564. // 生成输入报文
  565. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  566. input := make(map[string]interface{})
  567. inputData := make(map[string]interface{})
  568. inputMessage["infno"] = "2207" // 交易编码
  569. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  570. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  571. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  572. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  573. inputData["medfee_sumamt"] = total // 医疗费总额
  574. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  575. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  576. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  577. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  578. inputData["insutype"] = insutype // 险种类型
  579. inputData["invono"] = "" // 发票号
  580. input["data"] = inputData
  581. inputMessage["input"] = input //交易输入
  582. bytesData, err := json.Marshal(inputMessage)
  583. fmt.Println(string(bytesData))
  584. if err != nil {
  585. fmt.Println(err.Error())
  586. return err.Error()
  587. }
  588. reader := bytes.NewReader(bytesData)
  589. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  590. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  591. request, err := http.NewRequest("POST", url, reader)
  592. if err != nil {
  593. fmt.Println(err.Error())
  594. return err.Error()
  595. }
  596. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  597. request.Header.Set("x-tif-paasid", "sg03_prd")
  598. request.Header.Set("x-tif-signature", signature)
  599. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  600. request.Header.Set("x-tif-nonce", nonce)
  601. client := http.Client{}
  602. resp, err := client.Do(request)
  603. if err != nil {
  604. fmt.Println(err.Error())
  605. return err.Error()
  606. }
  607. respBytes, err := ioutil.ReadAll(resp.Body)
  608. if err != nil {
  609. fmt.Println(err.Error())
  610. return err.Error()
  611. }
  612. str := string(respBytes)
  613. fmt.Println(str)
  614. return str
  615. }
  616. // 门诊结算撤销
  617. func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string {
  618. // 生成签名
  619. nonce := GetRandomString(32)
  620. timestamp := time.Now().Unix()
  621. signature := setSignature(timestamp, nonce, secret_key)
  622. // 生成输入报文
  623. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  624. input := make(map[string]interface{})
  625. inputData := make(map[string]interface{})
  626. inputMessage["infno"] = "2208" // 交易编码
  627. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  628. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  629. inputData["setl_id"] = setlId // 结算 ID
  630. input["data"] = inputData
  631. inputMessage["input"] = input //交易输入
  632. bytesData, err := json.Marshal(inputMessage)
  633. fmt.Println(string(bytesData))
  634. if err != nil {
  635. fmt.Println(err.Error())
  636. return err.Error()
  637. }
  638. reader := bytes.NewReader(bytesData)
  639. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2208"
  640. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  641. request, err := http.NewRequest("POST", url, reader)
  642. if err != nil {
  643. fmt.Println(err.Error())
  644. return err.Error()
  645. }
  646. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  647. request.Header.Set("x-tif-paasid", "sg03_prd")
  648. request.Header.Set("x-tif-signature", signature)
  649. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  650. request.Header.Set("x-tif-nonce", nonce)
  651. client := http.Client{}
  652. resp, err := client.Do(request)
  653. if err != nil {
  654. fmt.Println(err.Error())
  655. return err.Error()
  656. }
  657. respBytes, err := ioutil.ReadAll(resp.Body)
  658. if err != nil {
  659. fmt.Println(err.Error())
  660. return err.Error()
  661. }
  662. str := string(respBytes)
  663. fmt.Println(str)
  664. return str
  665. }
  666. // 医药机构费用结算对总账 func Gdyb3201( org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string {
  667. func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  668. fmt.Println("11222333-----")
  669. fmt.Println(baseParams)
  670. fmt.Println(businessParams)
  671. // 生成签名
  672. nonce := GetRandomString(32)
  673. timestamp := time.Now().Unix()
  674. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  675. // 生成输入报文
  676. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  677. input := make(map[string]interface{})
  678. inputData := make(map[string]interface{})
  679. inputMessage["infno"] = "3201" // 交易编码
  680. inputData["insutype"] = businessParams.Insutype // 险种
  681. inputData["clr_type"] = businessParams.ClrType // 就诊 ID(来自2201接口返回)
  682. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  683. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  684. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  685. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  686. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  687. inputData["acct_pay"] = businessParams.AcctPay //个人账户支付金额
  688. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  689. input["data"] = inputData
  690. inputMessage["input"] = input //交易输入
  691. bytesData, err := json.Marshal(inputMessage)
  692. fmt.Println(string(bytesData))
  693. if err != nil {
  694. fmt.Println(err.Error())
  695. return err.Error()
  696. }
  697. reader := bytes.NewReader(bytesData)
  698. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3201"
  699. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3201"
  700. request, err := http.NewRequest("POST", url, reader)
  701. if err != nil {
  702. fmt.Println(err.Error())
  703. return err.Error()
  704. }
  705. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  706. request.Header.Set("x-tif-paasid", "sg03_prd")
  707. request.Header.Set("x-tif-signature", signature)
  708. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  709. request.Header.Set("x-tif-nonce", nonce)
  710. client := http.Client{}
  711. resp, err := client.Do(request)
  712. if err != nil {
  713. fmt.Println(err.Error())
  714. return err.Error()
  715. }
  716. respBytes, err := ioutil.ReadAll(resp.Body)
  717. if err != nil {
  718. fmt.Println(err.Error())
  719. return err.Error()
  720. }
  721. str := string(respBytes)
  722. fmt.Println(str)
  723. return str
  724. }
  725. type Params struct {
  726. FileName string `json:"file_name"` //产品ID
  727. In []byte `json:"in"` //
  728. FixmedinsCode string `json:"fixmedins_code"` //调用环境生产为1 沙盒2
  729. }
  730. //文件上传
  731. //文件上传
  732. func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string {
  733. // 生成签名
  734. nonce := GetRandomString(32)
  735. timestamp := time.Now().Unix()
  736. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  737. buf := new(bytes.Buffer)
  738. buf.ReadFrom(strings.NewReader(string(file_byte)))
  739. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  740. input := make(map[string]interface{})
  741. inputData := make(map[string]interface{})
  742. inputMessage["infno"] = "9101" // 交易编码
  743. inputData["file_name"] = file_name //文件名
  744. inputData["in"] = bytes.NewBuffer(file_byte).Bytes() //文件数据
  745. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  746. input["fsUploadIn"] = inputData
  747. inputMessage["input"] = input //交易输入
  748. bytesData, err := json.Marshal(inputMessage)
  749. fmt.Println(string(bytesData))
  750. if err != nil {
  751. fmt.Println(err.Error())
  752. return err.Error()
  753. }
  754. reader := bytes.NewReader(bytesData)
  755. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9101"
  756. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9101"
  757. request, err := http.NewRequest("POST", url, reader)
  758. if err != nil {
  759. fmt.Println(err.Error())
  760. return err.Error()
  761. }
  762. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  763. request.Header.Set("x-tif-paasid", "sg03_prd")
  764. request.Header.Set("x-tif-signature", signature)
  765. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  766. request.Header.Set("x-tif-nonce", nonce)
  767. client := http.Client{}
  768. resp, err := client.Do(request)
  769. if err != nil {
  770. fmt.Println(err.Error())
  771. return err.Error()
  772. }
  773. respBytes, err := ioutil.ReadAll(resp.Body)
  774. if err != nil {
  775. fmt.Println(err.Error())
  776. return err.Error()
  777. }
  778. str := string(respBytes)
  779. fmt.Println(str)
  780. return str
  781. }
  782. func Gdyb9102(baseParams models.BaseParams, file_name string, file_qury_no string) string {
  783. // 生成签名
  784. nonce := GetRandomString(32)
  785. timestamp := time.Now().Unix()
  786. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  787. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  788. input := make(map[string]interface{})
  789. inputData := make(map[string]interface{})
  790. inputMessage["infno"] = "9102" // 交易编码
  791. inputData["file_name"] = file_name //文件名
  792. inputData["file_qury_no"] = "fsi/H44022900158/" + file_qury_no //文件数据
  793. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  794. input["fsDownloadIn"] = inputData
  795. inputMessage["input"] = input //交易输入
  796. bytesData, err := json.Marshal(inputMessage)
  797. fmt.Println(string(bytesData))
  798. if err != nil {
  799. fmt.Println(err.Error())
  800. return err.Error()
  801. }
  802. reader := bytes.NewReader(bytesData)
  803. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9102"
  804. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9102"
  805. request, err := http.NewRequest("POST", url, reader)
  806. if err != nil {
  807. fmt.Println(err.Error())
  808. return err.Error()
  809. }
  810. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  811. request.Header.Set("x-tif-paasid", "sg03_prd")
  812. request.Header.Set("x-tif-signature", signature)
  813. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  814. request.Header.Set("x-tif-nonce", nonce)
  815. client := http.Client{}
  816. resp, err := client.Do(request)
  817. if err != nil {
  818. fmt.Println(err.Error())
  819. return err.Error()
  820. }
  821. respBytes, err := ioutil.ReadAll(resp.Body)
  822. if err != nil {
  823. fmt.Println(err.Error())
  824. return err.Error()
  825. }
  826. str := string(respBytes)
  827. fmt.Println(str)
  828. return str
  829. }
  830. func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  831. // 生成签名
  832. nonce := GetRandomString(32)
  833. timestamp := time.Now().Unix()
  834. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  835. // 生成输入报文
  836. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  837. input := make(map[string]interface{})
  838. inputData := make(map[string]interface{})
  839. inputMessage["infno"] = "3202" // 交易编码
  840. inputData["file_qury_no"] = "fsi/H44022900158/" + businessParams.FileQuryNo // 险种
  841. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  842. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  843. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  844. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  845. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  846. inputData["cash_payamt"] = businessParams.CashPayamt //现金支付金额
  847. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  848. input["data"] = inputData
  849. inputMessage["input"] = input //交易输入
  850. bytesData, err := json.Marshal(inputMessage)
  851. fmt.Println(string(bytesData))
  852. if err != nil {
  853. fmt.Println(err.Error())
  854. return err.Error()
  855. }
  856. reader := bytes.NewReader(bytesData)
  857. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3202"
  858. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3202"
  859. request, err := http.NewRequest("POST", url, reader)
  860. if err != nil {
  861. fmt.Println(err.Error())
  862. return err.Error()
  863. }
  864. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  865. request.Header.Set("x-tif-paasid", "sg03_prd")
  866. request.Header.Set("x-tif-signature", signature)
  867. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  868. request.Header.Set("x-tif-nonce", nonce)
  869. client := http.Client{}
  870. resp, err := client.Do(request)
  871. if err != nil {
  872. fmt.Println(err.Error())
  873. return err.Error()
  874. }
  875. respBytes, err := ioutil.ReadAll(resp.Body)
  876. if err != nil {
  877. fmt.Println(err.Error())
  878. return err.Error()
  879. }
  880. str := string(respBytes)
  881. fmt.Println(str)
  882. return str
  883. }
  884. func Gdyb5203(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  885. // 生成签名
  886. nonce := GetRandomString(32)
  887. timestamp := time.Now().Unix()
  888. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  889. // 生成输入报文
  890. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  891. input := make(map[string]interface{})
  892. inputData := make(map[string]interface{})
  893. inputMessage["infno"] = "5203" // 交易编码
  894. inputData["psn_no"] = businessParams.PsnNo
  895. inputData["setl_id"] = businessParams.SetlId
  896. inputData["mdtrt_id"] = businessParams.MdtrtId
  897. input["data"] = inputData
  898. inputMessage["input"] = input //交易输入
  899. bytesData, err := json.Marshal(inputMessage)
  900. fmt.Println(string(bytesData))
  901. if err != nil {
  902. fmt.Println(err.Error())
  903. return err.Error()
  904. }
  905. reader := bytes.NewReader(bytesData)
  906. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5203"
  907. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203"
  908. request, err := http.NewRequest("POST", url, reader)
  909. if err != nil {
  910. fmt.Println(err.Error())
  911. return err.Error()
  912. }
  913. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  914. request.Header.Set("x-tif-paasid", "sg03_prd")
  915. request.Header.Set("x-tif-signature", signature)
  916. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  917. request.Header.Set("x-tif-nonce", nonce)
  918. client := http.Client{}
  919. resp, err := client.Do(request)
  920. if err != nil {
  921. fmt.Println(err.Error())
  922. return err.Error()
  923. }
  924. respBytes, err := ioutil.ReadAll(resp.Body)
  925. if err != nil {
  926. fmt.Println(err.Error())
  927. return err.Error()
  928. }
  929. str := string(respBytes)
  930. fmt.Println(str)
  931. return str
  932. }
  933. // 门诊结算撤销
  934. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  935. // // 生成签名
  936. // nonce := GetRandomString(32)
  937. // timestamp := time.Now().Unix()
  938. // signature := setSignature(timestamp, nonce)
  939. //
  940. // // 生成输入报文
  941. // inputMessage := SetInputMessage(nonce, timestamp)
  942. // input := make(map[string]interface{})
  943. // inputData := make(map[string]interface{})
  944. // inputMessage["infno"] = "4101" // 交易编码
  945. //
  946. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  947. // inputData["setl_id"] = setlId // 结算 ID 必填
  948. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  949. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  950. // inputData["hi_setl_lv"] = "" // 医保结算等级
  951. // inputData["hi_no"] = "" // 医保编号
  952. // inputData["medcasno"] = "" // 病案号 必填
  953. // inputData["dcla_time"] = "" // 申报时间 必填
  954. // inputData["psn_name"] = "" // 人员姓名 必填
  955. // inputData["gend"] = "" // 性别 必填
  956. // inputData["brdy"] = "" // 出生日期 必填
  957. // inputData["age"] = "" // 年龄 必填
  958. // inputData["ntly"] = "" // 国籍 必填
  959. // inputData["nwb_age"] = "" // 年龄 必填
  960. // inputData["naty"] = "" // 民族 必填
  961. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  962. // inputData["certno"] = "" // 证件号码 必填
  963. // inputData["prfs"] = "" // 职业 必填
  964. // inputData["curr_addr"] = "" // 现住址 必填
  965. // inputData["emp_name"] = "" // 单位名称 必填
  966. // inputData["emp_addr"] = "" // 单位地址 必填
  967. // inputData["emp_tel"] = "" // 单位电话 必填
  968. // inputData["poscode"] = "" // 邮编 必填
  969. // inputData["coner_name"] = "" // 联系人姓名 必填
  970. // inputData["patn_rlts"] = "" // 与患者关系 必填
  971. // inputData["coner_addr"] = "" // 联系人地址 必填
  972. // inputData["coner_tel"] = "" // 联系人电话 必填
  973. // inputData["hi_type"] = "" // 医保类型 必填
  974. // inputData["insuplc"] = "" // 参保地 必填
  975. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  976. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  977. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  978. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  979. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  980. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  981. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  982. // inputData["adm_way"] = "" // 入院途径 必填
  983. // inputData["trt_type"] = "" // 治疗类别 必填
  984. // inputData["adm_time"] = "" // 入院时间 必填
  985. // inputData["adm_caty"] = "" // 入院科别 必填
  986. // inputData["refldept_dept"] = "" // 转科科别 必填
  987. // inputData["dscg_time"] = "" // 出院时间 必填
  988. // inputData["dscg_caty"] = "" // 出院科别 必填
  989. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  990. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  991. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  992. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  993. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  994. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  995. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  996. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  997. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  998. // inputData["bld_cat"] = "" // 输血品种 必填
  999. // inputData["bld_amt"] = "" // 输血量 必填
  1000. // inputData["bld_unt"] = "" // 输血计量单位 必填
  1001. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  1002. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  1003. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  1004. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  1005. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  1006. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  1007. // inputData["bill_code"] = "" // 票据代码 必填
  1008. // inputData["bill_no"] = "" // 票据号码 必填
  1009. // inputData["biz_sn"] = "" // 业务流水号 必填
  1010. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  1011. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  1012. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  1013. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  1014. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  1015. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  1016. // inputData["psn_selfpay"] = "" // 个人自付 必填
  1017. // inputData["psn_ownpay"] = "" // 个人自费 必填
  1018. // inputData["acct_pay"] = "" // 个人账户支出 必填
  1019. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  1020. // inputData["hsorg"] = "" // 医保机构 必填
  1021. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  1022. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  1023. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  1024. //
  1025. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  1026. // payinfotemp := make(map[string]interface{})
  1027. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  1028. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  1029. // payinfo = append(payinfo,payinfotemp)
  1030. //
  1031. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  1032. // opspdiseinfotemp := make(map[string]interface{})
  1033. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  1034. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  1035. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1036. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1037. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  1038. //
  1039. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  1040. // diseinfotemp := make(map[string]interface{})
  1041. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  1042. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  1043. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  1044. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  1045. // diseinfo = append(diseinfo,diseinfotemp)
  1046. //
  1047. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  1048. // iteminfotemp := make(map[string]interface{})
  1049. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  1050. // iteminfotemp["amt"] = "" // 金额 必填
  1051. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  1052. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  1053. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  1054. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  1055. // iteminfo = append(iteminfo,iteminfotemp)
  1056. //
  1057. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  1058. // oprninfotemp := make(map[string]interface{})
  1059. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  1060. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1061. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1062. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  1063. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  1064. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  1065. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  1066. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  1067. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  1068. // oprninfo = append(oprninfo,iteminfotemp)
  1069. //
  1070. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  1071. // icuinfotemp := make(map[string]interface{})
  1072. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  1073. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  1074. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  1075. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  1076. // icuinfo = append(icuinfo,iteminfotemp)
  1077. //
  1078. //
  1079. //
  1080. //
  1081. // input["setlinfo"] = inputData
  1082. // input["payinfo"] = payinfo
  1083. // input["opspdiseinfo"] = opspdiseinfo
  1084. // input["diseinfo"] = diseinfo
  1085. // input["iteminfo"] = iteminfo
  1086. // input["oprninfo"] = oprninfo
  1087. // input["icuinfo"] = icuinfo
  1088. // inputMessage["input"] = input //交易输入
  1089. //
  1090. // bytesData, err := json.Marshal(inputMessage)
  1091. // fmt.Println(string(bytesData))
  1092. // if err != nil {
  1093. // fmt.Println(err.Error())
  1094. // return err.Error()
  1095. // }
  1096. // reader := bytes.NewReader(bytesData)
  1097. //
  1098. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  1099. // request, err := http.NewRequest("POST", url, reader)
  1100. // if err != nil {
  1101. // fmt.Println(err.Error())
  1102. // return err.Error()
  1103. // }
  1104. //
  1105. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1106. // request.Header.Set("x-tif-paasid", "test_hosp")
  1107. // request.Header.Set("x-tif-signature", signature)
  1108. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1109. // request.Header.Set("x-tif-nonce", nonce)
  1110. //
  1111. // client := http.Client{}
  1112. // resp, err := client.Do(request)
  1113. // if err != nil {
  1114. // fmt.Println(err.Error())
  1115. // return err.Error()
  1116. // }
  1117. // respBytes, err := ioutil.ReadAll(resp.Body)
  1118. // if err != nil {
  1119. // fmt.Println(err.Error())
  1120. // return err.Error()
  1121. // }
  1122. // str := string(respBytes)
  1123. // fmt.Println(str)
  1124. // return str
  1125. //}
  1126. // 生成签名
  1127. func setSignature(timestamp int64, nonce string, secret_key string) string {
  1128. str := strconv.FormatInt(timestamp, 10) + secret_key + nonce + strconv.FormatInt(timestamp, 10)
  1129. hash := sha256.New()
  1130. //输入数据
  1131. hash.Write([]byte(str))
  1132. //计算哈希值
  1133. bytes := hash.Sum(nil)
  1134. //将字符串编码为16进制格式,返回字符串
  1135. hashCode := hex.EncodeToString(bytes)
  1136. //返回哈希值
  1137. return hashCode
  1138. }
  1139. // 生成随机字符串
  1140. func GetRandomString(l int) string {
  1141. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1142. bytes := []byte(str)
  1143. result := []byte{}
  1144. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  1145. for i := 0; i < l; i++ {
  1146. result = append(result, bytes[r.Intn(len(bytes))])
  1147. }
  1148. return string(result)
  1149. }
  1150. // 生成基础报文
  1151. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} {
  1152. // 生成签名
  1153. tempTime := time.Unix(timestamp, 0)
  1154. timeFormat := tempTime.Format("20060102150405")
  1155. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1156. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  1157. // 生成输入报文
  1158. inputMessage := make(map[string]interface{})
  1159. inputMessage["infno"] = "1101" // 交易编码
  1160. inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  1161. inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs // 就医地医保区划
  1162. inputMessage["insuplc_admdvs"] = insuplc_admdvs // 参保地医保区划
  1163. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  1164. inputMessage["dev_no"] = "" // 设备编号
  1165. inputMessage["dev_safe_info"] = "" // 设备安全信息
  1166. inputMessage["cainfo"] = "" // 数字签名信息
  1167. inputMessage["signtype"] = "" // 签名类型
  1168. inputMessage["infver"] = "V1.1" // 接收方系统代码
  1169. inputMessage["opter_type"] = "1" // 经办人类别
  1170. inputMessage["opter"] = doctor // 经办人
  1171. inputMessage["opter_name"] = doctor // 经办人姓名
  1172. inputMessage["inf_time"] = timeFormatOne // 交易时间
  1173. inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号
  1174. inputMessage["fixmedins_name"] = org_name //定点医药机构名称
  1175. inputMessage["sign_no"] = "" //交易签到流水号
  1176. return inputMessage
  1177. }
  1178. func postFile(filename string, target_url string) (*http.Response, error) {
  1179. body_buf := bytes.NewBufferString("")
  1180. body_writer := multipart.NewWriter(body_buf)
  1181. // use the body_writer to write the Part headers to the buffer
  1182. _, err := body_writer.CreateFormFile("userfile", filename)
  1183. if err != nil {
  1184. fmt.Println("error writing to buffer")
  1185. return nil, err
  1186. }
  1187. // the file data will be the second part of the body
  1188. fh, err := os.Open(filename)
  1189. if err != nil {
  1190. fmt.Println("error opening file")
  1191. return nil, err
  1192. }
  1193. // need to know the boundary to properly close the part myself.
  1194. boundary := body_writer.Boundary()
  1195. //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
  1196. close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
  1197. // use multi-reader to defer the reading of the file data until
  1198. // writing to the socket buffer.
  1199. request_reader := io.MultiReader(body_buf, fh, close_buf)
  1200. fi, err := fh.Stat()
  1201. if err != nil {
  1202. fmt.Printf("Error Stating file: %s", filename)
  1203. return nil, err
  1204. }
  1205. req, err := http.NewRequest("POST", target_url, request_reader)
  1206. if err != nil {
  1207. return nil, err
  1208. }
  1209. // Set headers for multipart, and Content Length
  1210. req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary)
  1211. req.ContentLength = fi.Size() + int64(body_buf.Len()) + int64(close_buf.Len())
  1212. return http.DefaultClient.Do(req)
  1213. }
  1214. //func Gdyb1201(psnNo string, org_name string, doctor string) string {
  1215. // // 生成签名
  1216. // nonce := GetRandomString(32)
  1217. // timestamp := time.Now().Unix()
  1218. // signature := setSignature(timestamp, nonce)
  1219. //
  1220. // // 生成输入报文
  1221. // inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  1222. // input := make(map[string]interface{})
  1223. // inputData := make(map[string]interface{})
  1224. // inputMessage["infno"] = "1201" // 交易编码
  1225. // inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  1226. // inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回)
  1227. // inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  1228. //
  1229. // input["medinsinfo"] = inputData
  1230. // inputMessage["input"] = input //交易输入
  1231. //
  1232. // bytesData, err := json.Marshal(inputMessage)
  1233. // fmt.Println(string(bytesData))
  1234. // if err != nil {
  1235. // fmt.Println(err.Error())
  1236. // return err.Error()
  1237. // }
  1238. // reader := bytes.NewReader(bytesData)
  1239. //
  1240. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  1241. // request, err := http.NewRequest("POST", url, reader)
  1242. // if err != nil {
  1243. // fmt.Println(err.Error())
  1244. // return err.Error()
  1245. // }
  1246. //
  1247. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1248. // request.Header.Set("x-tif-paasid", "test_hosp")
  1249. // request.Header.Set("x-tif-signature", signature)
  1250. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1251. // request.Header.Set("x-tif-nonce", nonce)
  1252. //
  1253. // client := http.Client{}
  1254. // resp, err := client.Do(request)
  1255. // if err != nil {
  1256. // fmt.Println(err.Error())
  1257. // return err.Error()
  1258. // }
  1259. // respBytes, err := ioutil.ReadAll(resp.Body)
  1260. // if err != nil {
  1261. // fmt.Println(err.Error())
  1262. // return err.Error()
  1263. // }
  1264. // str := string(respBytes)
  1265. // fmt.Println(str)
  1266. // return str
  1267. //}
  1268. func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
  1269. file, err := os.Open(path)
  1270. if err != nil {
  1271. return nil, err
  1272. }
  1273. defer file.Close()
  1274. body := &bytes.Buffer{}
  1275. writer := multipart.NewWriter(body)
  1276. part, err := writer.CreateFormFile(paramName, filepath.Base(path))
  1277. if err != nil {
  1278. return nil, err
  1279. }
  1280. _, err = io.Copy(part, file)
  1281. for key, val := range params {
  1282. _ = writer.WriteField(key, val)
  1283. }
  1284. err = writer.Close()
  1285. if err != nil {
  1286. return nil, err
  1287. }
  1288. req, err := http.NewRequest("POST", uri, body)
  1289. req.Header.Set("Content-Type", writer.FormDataContentType())
  1290. return req, err
  1291. }