gdyb_service.go 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. package service
  2. import (
  3. "XT_New/models"
  4. "bytes"
  5. "crypto/sha256"
  6. "encoding/hex"
  7. "encoding/json"
  8. "fmt"
  9. "io/ioutil"
  10. "math/rand"
  11. "net/http"
  12. "strconv"
  13. "time"
  14. _ "unsafe"
  15. )
  16. const (
  17. SceretKey = "RhaDw4H0RUbWYyTxmRKM1eSeN0qyGLds" // secretKey 私钥
  18. FixmedinsCOde = "H44022900158" // 定点医药机构编号
  19. )
  20. // 人员基本信息
  21. func Gdyb1101(certNo string, org_name string, doctor string) string {
  22. // 生成签名
  23. nonce := GetRandomString(32)
  24. timestamp := time.Now().Unix()
  25. signature := setSignature(timestamp, nonce)
  26. // 生成输入报文
  27. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  28. input := make(map[string]interface{})
  29. inputData := make(map[string]interface{})
  30. inputMessage["infno"] = "1101" // 交易编码
  31. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  32. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  33. inputData["card_sn"] = "" // 卡识别码
  34. inputData["begntime"] = "" // 开始时间
  35. inputData["psn_cert_type"] = "" // 人员证件类型
  36. inputData["certno"] = "" // 证件号码
  37. inputData["psn_name"] = "" // 人员姓名
  38. input["data"] = inputData
  39. inputMessage["input"] = input //交易输入
  40. bytesData, err := json.Marshal(inputMessage)
  41. fmt.Println(string(bytesData))
  42. if err != nil {
  43. fmt.Println(err.Error())
  44. return err.Error()
  45. }
  46. reader := bytes.NewReader(bytesData)
  47. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  48. request, err := http.NewRequest("POST", url, reader)
  49. if err != nil {
  50. fmt.Println(err.Error())
  51. return err.Error()
  52. }
  53. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  54. request.Header.Set("x-tif-paasid", "test_hosp")
  55. request.Header.Set("x-tif-signature", signature)
  56. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  57. request.Header.Set("x-tif-nonce", nonce)
  58. client := http.Client{}
  59. resp, err := client.Do(request)
  60. if err != nil {
  61. fmt.Println(err.Error())
  62. return err.Error()
  63. }
  64. respBytes, err := ioutil.ReadAll(resp.Body)
  65. if err != nil {
  66. fmt.Println(err.Error())
  67. return err.Error()
  68. }
  69. fmt.Println(string(respBytes))
  70. str := string(respBytes)
  71. return str
  72. }
  73. // 门诊挂号
  74. func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string) string {
  75. // 生成签名
  76. nonce := GetRandomString(32)
  77. timestamp := time.Now().Unix()
  78. signature := setSignature(timestamp, nonce)
  79. tempTime := time.Unix(timestamp, 0)
  80. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  81. // 生成输入报文
  82. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  83. input := make(map[string]interface{})
  84. inputData := make(map[string]interface{})
  85. inputMessage["infno"] = "2201" // 交易编码
  86. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  87. inputData["insutype"] = insutype // 险种类型(来自1101接口返回)
  88. inputData["begntime"] = timeFormatOne // 开始时间
  89. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  90. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  91. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  92. inputData["atddr_no"] = "1002" // 医师编码
  93. inputData["dr_name"] = doctor // 医师姓名
  94. inputData["dept_code"] = "3002" // 科室编码
  95. inputData["dept_name"] = dept // 科室名称
  96. inputData["caty"] = "A03.06" // 科别
  97. input["data"] = inputData
  98. inputMessage["input"] = input //交易输入
  99. bytesData, err := json.Marshal(inputMessage)
  100. fmt.Println(string(bytesData))
  101. if err != nil {
  102. fmt.Println(err.Error())
  103. return err.Error()
  104. }
  105. reader := bytes.NewReader(bytesData)
  106. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2201"
  107. request, err := http.NewRequest("POST", url, reader)
  108. if err != nil {
  109. fmt.Println(err.Error())
  110. return err.Error()
  111. }
  112. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  113. request.Header.Set("x-tif-paasid", "test_hosp")
  114. request.Header.Set("x-tif-signature", signature)
  115. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  116. request.Header.Set("x-tif-nonce", nonce)
  117. client := http.Client{}
  118. resp, err := client.Do(request)
  119. if err != nil {
  120. fmt.Println(err.Error())
  121. return err.Error()
  122. }
  123. respBytes, err := ioutil.ReadAll(resp.Body)
  124. if err != nil {
  125. fmt.Println(err.Error())
  126. return err.Error()
  127. }
  128. str := string(respBytes)
  129. fmt.Println(str)
  130. return str
  131. }
  132. // 门诊挂号撤销
  133. func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string) string {
  134. // 生成签名
  135. nonce := GetRandomString(32)
  136. timestamp := time.Now().Unix()
  137. signature := setSignature(timestamp, nonce)
  138. // 生成输入报文
  139. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  140. input := make(map[string]interface{})
  141. inputData := make(map[string]interface{})
  142. inputMessage["infno"] = "2202" // 交易编码
  143. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  144. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  145. inputData["ipt_otp_no"] = ipt_otp_no // 住院/门诊号
  146. input["data"] = inputData
  147. inputMessage["input"] = input //交易输入
  148. bytesData, err := json.Marshal(inputMessage)
  149. fmt.Println(string(bytesData))
  150. if err != nil {
  151. fmt.Println(err.Error())
  152. return err.Error()
  153. }
  154. reader := bytes.NewReader(bytesData)
  155. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  156. request, err := http.NewRequest("POST", url, reader)
  157. if err != nil {
  158. fmt.Println(err.Error())
  159. return err.Error()
  160. }
  161. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  162. request.Header.Set("x-tif-paasid", "test_hosp")
  163. request.Header.Set("x-tif-signature", signature)
  164. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  165. request.Header.Set("x-tif-nonce", nonce)
  166. client := http.Client{}
  167. resp, err := client.Do(request)
  168. if err != nil {
  169. fmt.Println(err.Error())
  170. return err.Error()
  171. }
  172. respBytes, err := ioutil.ReadAll(resp.Body)
  173. if err != nil {
  174. fmt.Println(err.Error())
  175. return err.Error()
  176. }
  177. str := string(respBytes)
  178. fmt.Println(str)
  179. return str
  180. }
  181. // 门诊就诊信息上传
  182. func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, diag string, org_name string) string {
  183. // 生成签名
  184. nonce := GetRandomString(32)
  185. timestamp := time.Now().Unix()
  186. signature := setSignature(timestamp, nonce)
  187. tempTime := time.Unix(timestamp, 0)
  188. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  189. // 生成输入报文
  190. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  191. input := make(map[string]interface{})
  192. inputData := make(map[string]interface{})
  193. diseinfo := make([]map[string]interface{}, 0)
  194. inputMessage["infno"] = "2203" // 交易编码
  195. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  196. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  197. inputData["med_type"] = "11" // 医疗类别 16门诊特殊病
  198. inputData["begntime"] = timeFormatOne // 开始时间
  199. inputData["main_cond_dscr"] = "" // 主要病情描述
  200. inputData["dise_codg"] = "" // 病种编码
  201. inputData["dise_name"] = "" // 病种名称
  202. inputData["birctrl_type"] = "" // 计划生育手术类别
  203. inputData["birctrl_matn_date"] = "" // 计划生育手术或生育日期
  204. diseinfo_sun := make(map[string]interface{})
  205. diseinfo_sun["diag_type"] = "1" // 诊断类别
  206. diseinfo_sun["diag_srt_no"] = "1" // 诊断排序号
  207. diseinfo_sun["diag_code"] = "A04.902" // 诊断代码
  208. diseinfo_sun["diag_name"] = diag // 诊断名称
  209. diseinfo_sun["diag_dept"] = department // 诊断科室
  210. diseinfo_sun["dise_dor_no"] = "1002" // 诊断医生编码
  211. diseinfo_sun["dise_dor_name"] = doctor // 诊断医生姓名
  212. diseinfo_sun["diag_time"] = timeFormatOne // 诊断时间
  213. diseinfo_sun["vali_flag"] = "1" // 有效标志
  214. diseinfo = append(diseinfo, diseinfo_sun)
  215. input["diseinfo"] = diseinfo
  216. input["mdtrtinfo"] = inputData
  217. inputMessage["input"] = input //交易输入
  218. bytesData, err := json.Marshal(inputMessage)
  219. fmt.Println(string(bytesData))
  220. if err != nil {
  221. fmt.Println(err.Error())
  222. return err.Error()
  223. }
  224. reader := bytes.NewReader(bytesData)
  225. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2203"
  226. request, err := http.NewRequest("POST", url, reader)
  227. if err != nil {
  228. fmt.Println(err.Error())
  229. return err.Error()
  230. }
  231. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  232. request.Header.Set("x-tif-paasid", "test_hosp")
  233. request.Header.Set("x-tif-signature", signature)
  234. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  235. request.Header.Set("x-tif-nonce", nonce)
  236. client := http.Client{}
  237. resp, err := client.Do(request)
  238. if err != nil {
  239. fmt.Println(err.Error())
  240. return err.Error()
  241. }
  242. respBytes, err := ioutil.ReadAll(resp.Body)
  243. if err != nil {
  244. fmt.Println(err.Error())
  245. return err.Error()
  246. }
  247. str := string(respBytes)
  248. fmt.Println(str)
  249. return str
  250. }
  251. type Custom struct {
  252. DetItemFeeSumamt string
  253. Cut string
  254. FeedetlSn string
  255. Price string
  256. MedListCodg string
  257. }
  258. type RequestResult struct {
  259. Output Output `json:"output" form:"output"`
  260. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  261. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  262. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  263. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  264. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  265. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  266. }
  267. type Output struct {
  268. Result Result `json:"result" form:"result"`
  269. }
  270. type Result struct {
  271. BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"`
  272. MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"`
  273. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  274. HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  275. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  276. FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"`
  277. UploadDate int64 `json:"upload_date" form:"upload_date"`
  278. AdviceId int64 `json:"advice_id" form:"advice_id"`
  279. Cnt int64 `json:"cnt" form:"cnt"`
  280. Pric float64 `json:"pric" form:"pric"`
  281. PatientId int64 `json:"patient_id" form:"patient_id"`
  282. PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  283. SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"`
  284. OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"`
  285. PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"`
  286. Status int64 `json:"status" form:"status"`
  287. Memo string `json:"memo" form:"memo"`
  288. FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"`
  289. Mtime int64 `json:"mtime" form:"mtime"`
  290. InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"`
  291. DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"`
  292. Ctime int64 `json:"ctime" form:"ctime"`
  293. ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"`
  294. ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"`
  295. LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"`
  296. ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"`
  297. UserOrgId int64 `json:"user_org_id" form:"user_org_id"`
  298. HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"`
  299. OrderId int64 `json:"order_id" form:"order_id"`
  300. }
  301. // 门诊费用明细信息上传
  302. func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string) string {
  303. // 生成签名
  304. nonce := GetRandomString(32)
  305. timestamp := time.Now().Unix()
  306. signature := setSignature(timestamp, nonce)
  307. tempTime := time.Unix(timestamp, 0)
  308. //timeFormat := tempTime.Format("20060102150405")
  309. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  310. //chrgBchno := rand.Intn(100000) + 10000
  311. var customs []*Custom
  312. for _, item := range hisPrescription {
  313. if item.Type == 1 { //药品
  314. for _, subItem := range item.HisDoctorAdviceInfo {
  315. //var randNum int
  316. //randNum = rand.Intn(10000) + 1000
  317. cus := &Custom{
  318. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  319. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  320. FeedetlSn: subItem.FeedetlSn,
  321. Price: fmt.Sprintf("%.2f", subItem.Price),
  322. MedListCodg: subItem.MedListCodg,
  323. }
  324. customs = append(customs, cus)
  325. }
  326. }
  327. if item.Type == 2 { //项目
  328. for _, subItem := range item.HisPrescriptionProject {
  329. //var randNum int
  330. //randNum = rand.Intn(10000) + 1000
  331. cus := &Custom{
  332. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  333. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  334. FeedetlSn: subItem.FeedetlSn,
  335. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  336. MedListCodg: subItem.MedListCodg,
  337. }
  338. fmt.Println(cus.FeedetlSn)
  339. customs = append(customs, cus)
  340. }
  341. }
  342. }
  343. fmt.Println(customs)
  344. // 生成输入报文
  345. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  346. input := make(map[string]interface{})
  347. feedetail := make([]map[string]interface{}, 0)
  348. inputMessage["infno"] = "2204" // 交易编码
  349. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  350. for _, item := range customs {
  351. feedetailInfo := make(map[string]interface{})
  352. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  353. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  354. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  355. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  356. feedetailInfo["dise_codg"] = "" // 病种编码
  357. feedetailInfo["rxno"] = "" // 处方号
  358. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  359. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  360. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  361. feedetailInfo["medins_list_codg"] = FixmedinsCOde // 医药机构目录编码
  362. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  363. feedetailInfo["cnt"] = item.Cut // 数量
  364. feedetailInfo["pric"] = item.Price // 单价
  365. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  366. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  367. feedetailInfo["prd_days"] = "0" // 周期天数
  368. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  369. feedetailInfo["bilg_dept_codg"] = "3002" // 开单科室编码
  370. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  371. feedetailInfo["bilg_dr_codg"] = "1002" // 开单医生编码
  372. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  373. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  374. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  375. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  376. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  377. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  378. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  379. feedetailInfo["etip_flag"] = "" // 外检标志
  380. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  381. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  382. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  383. feedetail = append(feedetail, feedetailInfo)
  384. }
  385. input["feedetail"] = feedetail
  386. inputMessage["input"] = input //交易输入
  387. bytesData, err := json.Marshal(inputMessage)
  388. fmt.Println("----------")
  389. fmt.Println(string(bytesData))
  390. fmt.Println("----------")
  391. if err != nil {
  392. fmt.Println(err.Error())
  393. return ""
  394. }
  395. reader := bytes.NewReader(bytesData)
  396. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  397. request, err := http.NewRequest("POST", url, reader)
  398. if err != nil {
  399. fmt.Println(err.Error())
  400. return ""
  401. }
  402. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  403. request.Header.Set("x-tif-paasid", "test_hosp")
  404. request.Header.Set("x-tif-signature", signature)
  405. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  406. request.Header.Set("x-tif-nonce", nonce)
  407. client := http.Client{}
  408. resp, err := client.Do(request)
  409. if err != nil {
  410. fmt.Println(err.Error())
  411. return ""
  412. }
  413. respBytes, err := ioutil.ReadAll(resp.Body)
  414. if err != nil {
  415. fmt.Println(err.Error())
  416. return ""
  417. }
  418. return string(respBytes)
  419. //var result RequestResult
  420. //json.Unmarshal(respBytes, &result)
  421. //return &result
  422. }
  423. // 门诊费用明细信息撤销
  424. func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string) string {
  425. // 生成签名
  426. nonce := GetRandomString(32)
  427. timestamp := time.Now().Unix()
  428. signature := setSignature(timestamp, nonce)
  429. // 生成输入报文
  430. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  431. input := make(map[string]interface{})
  432. inputData := make(map[string]interface{})
  433. inputMessage["infno"] = "2205" // 交易编码
  434. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  435. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  436. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  437. input["data"] = inputData
  438. inputMessage["input"] = input //交易输入
  439. bytesData, err := json.Marshal(inputMessage)
  440. fmt.Println(string(bytesData))
  441. if err != nil {
  442. fmt.Println(err.Error())
  443. return err.Error()
  444. }
  445. reader := bytes.NewReader(bytesData)
  446. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  447. request, err := http.NewRequest("POST", url, reader)
  448. fmt.Println(err)
  449. fmt.Println(request)
  450. if err != nil {
  451. fmt.Println(err.Error())
  452. return err.Error()
  453. }
  454. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  455. request.Header.Set("x-tif-paasid", "test_hosp")
  456. request.Header.Set("x-tif-signature", signature)
  457. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  458. request.Header.Set("x-tif-nonce", nonce)
  459. client := http.Client{}
  460. resp, err := client.Do(request)
  461. if err != nil {
  462. fmt.Println(err.Error())
  463. return err.Error()
  464. }
  465. respBytes, err := ioutil.ReadAll(resp.Body)
  466. if err != nil {
  467. fmt.Println(err.Error())
  468. return err.Error()
  469. }
  470. str := string(respBytes)
  471. fmt.Println(str)
  472. return str
  473. }
  474. // 门诊预结算
  475. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string) string {
  476. // 生成签名
  477. nonce := GetRandomString(32)
  478. timestamp := time.Now().Unix()
  479. signature := setSignature(timestamp, nonce)
  480. // 生成输入报文
  481. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  482. input := make(map[string]interface{})
  483. inputData := make(map[string]interface{})
  484. inputMessage["infno"] = "2206" // 交易编码
  485. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  486. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  487. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  488. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  489. inputData["medfee_sumamt"] = total // 医疗费总额
  490. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  491. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  492. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  493. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  494. inputData["insutype"] = insutype // 险种类型
  495. input["data"] = inputData
  496. inputMessage["input"] = input //交易输入
  497. bytesData, err := json.Marshal(inputMessage)
  498. fmt.Println(string(bytesData))
  499. if err != nil {
  500. fmt.Println(err.Error())
  501. return err.Error()
  502. }
  503. reader := bytes.NewReader(bytesData)
  504. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  505. request, err := http.NewRequest("POST", url, reader)
  506. if err != nil {
  507. fmt.Println(err.Error())
  508. return err.Error()
  509. }
  510. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  511. request.Header.Set("x-tif-paasid", "test_hosp")
  512. request.Header.Set("x-tif-signature", signature)
  513. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  514. request.Header.Set("x-tif-nonce", nonce)
  515. client := http.Client{}
  516. resp, err := client.Do(request)
  517. if err != nil {
  518. fmt.Println(err.Error())
  519. return err.Error()
  520. }
  521. respBytes, err := ioutil.ReadAll(resp.Body)
  522. if err != nil {
  523. fmt.Println(err.Error())
  524. return err.Error()
  525. }
  526. str := string(respBytes)
  527. fmt.Println(str)
  528. return str
  529. }
  530. // 门诊结算
  531. func Gdyb2207(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string) string {
  532. // 生成签名
  533. nonce := GetRandomString(32)
  534. timestamp := time.Now().Unix()
  535. signature := setSignature(timestamp, nonce)
  536. // 生成输入报文
  537. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  538. input := make(map[string]interface{})
  539. inputData := make(map[string]interface{})
  540. inputMessage["infno"] = "2207" // 交易编码
  541. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  542. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  543. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  544. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  545. inputData["medfee_sumamt"] = total // 医疗费总额
  546. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  547. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  548. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  549. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  550. inputData["insutype"] = insutype // 险种类型
  551. inputData["invono"] = "" // 发票号
  552. input["data"] = inputData
  553. inputMessage["input"] = input //交易输入
  554. bytesData, err := json.Marshal(inputMessage)
  555. fmt.Println(string(bytesData))
  556. if err != nil {
  557. fmt.Println(err.Error())
  558. return err.Error()
  559. }
  560. reader := bytes.NewReader(bytesData)
  561. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  562. request, err := http.NewRequest("POST", url, reader)
  563. if err != nil {
  564. fmt.Println(err.Error())
  565. return err.Error()
  566. }
  567. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  568. request.Header.Set("x-tif-paasid", "test_hosp")
  569. request.Header.Set("x-tif-signature", signature)
  570. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  571. request.Header.Set("x-tif-nonce", nonce)
  572. client := http.Client{}
  573. resp, err := client.Do(request)
  574. if err != nil {
  575. fmt.Println(err.Error())
  576. return err.Error()
  577. }
  578. respBytes, err := ioutil.ReadAll(resp.Body)
  579. if err != nil {
  580. fmt.Println(err.Error())
  581. return err.Error()
  582. }
  583. str := string(respBytes)
  584. fmt.Println(str)
  585. return str
  586. }
  587. // 门诊结算撤销
  588. func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doctor string) string {
  589. // 生成签名
  590. nonce := GetRandomString(32)
  591. timestamp := time.Now().Unix()
  592. signature := setSignature(timestamp, nonce)
  593. // 生成输入报文
  594. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  595. input := make(map[string]interface{})
  596. inputData := make(map[string]interface{})
  597. inputMessage["infno"] = "2208" // 交易编码
  598. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  599. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  600. inputData["setl_id"] = setlId // 结算 ID
  601. input["data"] = inputData
  602. inputMessage["input"] = input //交易输入
  603. bytesData, err := json.Marshal(inputMessage)
  604. fmt.Println(string(bytesData))
  605. if err != nil {
  606. fmt.Println(err.Error())
  607. return err.Error()
  608. }
  609. reader := bytes.NewReader(bytesData)
  610. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  611. request, err := http.NewRequest("POST", url, reader)
  612. if err != nil {
  613. fmt.Println(err.Error())
  614. return err.Error()
  615. }
  616. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  617. request.Header.Set("x-tif-paasid", "test_hosp")
  618. request.Header.Set("x-tif-signature", signature)
  619. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  620. request.Header.Set("x-tif-nonce", nonce)
  621. client := http.Client{}
  622. resp, err := client.Do(request)
  623. if err != nil {
  624. fmt.Println(err.Error())
  625. return err.Error()
  626. }
  627. respBytes, err := ioutil.ReadAll(resp.Body)
  628. if err != nil {
  629. fmt.Println(err.Error())
  630. return err.Error()
  631. }
  632. str := string(respBytes)
  633. fmt.Println(str)
  634. return str
  635. }
  636. // 门诊结算撤销
  637. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  638. // // 生成签名
  639. // nonce := GetRandomString(32)
  640. // timestamp := time.Now().Unix()
  641. // signature := setSignature(timestamp, nonce)
  642. //
  643. // // 生成输入报文
  644. // inputMessage := SetInputMessage(nonce, timestamp)
  645. // input := make(map[string]interface{})
  646. // inputData := make(map[string]interface{})
  647. // inputMessage["infno"] = "4101" // 交易编码
  648. //
  649. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  650. // inputData["setl_id"] = setlId // 结算 ID 必填
  651. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  652. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  653. // inputData["hi_setl_lv"] = "" // 医保结算等级
  654. // inputData["hi_no"] = "" // 医保编号
  655. // inputData["medcasno"] = "" // 病案号 必填
  656. // inputData["dcla_time"] = "" // 申报时间 必填
  657. // inputData["psn_name"] = "" // 人员姓名 必填
  658. // inputData["gend"] = "" // 性别 必填
  659. // inputData["brdy"] = "" // 出生日期 必填
  660. // inputData["age"] = "" // 年龄 必填
  661. // inputData["ntly"] = "" // 国籍 必填
  662. // inputData["nwb_age"] = "" // 年龄 必填
  663. // inputData["naty"] = "" // 民族 必填
  664. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  665. // inputData["certno"] = "" // 证件号码 必填
  666. // inputData["prfs"] = "" // 职业 必填
  667. // inputData["curr_addr"] = "" // 现住址 必填
  668. // inputData["emp_name"] = "" // 单位名称 必填
  669. // inputData["emp_addr"] = "" // 单位地址 必填
  670. // inputData["emp_tel"] = "" // 单位电话 必填
  671. // inputData["poscode"] = "" // 邮编 必填
  672. // inputData["coner_name"] = "" // 联系人姓名 必填
  673. // inputData["patn_rlts"] = "" // 与患者关系 必填
  674. // inputData["coner_addr"] = "" // 联系人地址 必填
  675. // inputData["coner_tel"] = "" // 联系人电话 必填
  676. // inputData["hi_type"] = "" // 医保类型 必填
  677. // inputData["insuplc"] = "" // 参保地 必填
  678. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  679. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  680. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  681. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  682. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  683. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  684. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  685. // inputData["adm_way"] = "" // 入院途径 必填
  686. // inputData["trt_type"] = "" // 治疗类别 必填
  687. // inputData["adm_time"] = "" // 入院时间 必填
  688. // inputData["adm_caty"] = "" // 入院科别 必填
  689. // inputData["refldept_dept"] = "" // 转科科别 必填
  690. // inputData["dscg_time"] = "" // 出院时间 必填
  691. // inputData["dscg_caty"] = "" // 出院科别 必填
  692. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  693. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  694. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  695. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  696. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  697. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  698. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  699. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  700. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  701. // inputData["bld_cat"] = "" // 输血品种 必填
  702. // inputData["bld_amt"] = "" // 输血量 必填
  703. // inputData["bld_unt"] = "" // 输血计量单位 必填
  704. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  705. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  706. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  707. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  708. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  709. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  710. // inputData["bill_code"] = "" // 票据代码 必填
  711. // inputData["bill_no"] = "" // 票据号码 必填
  712. // inputData["biz_sn"] = "" // 业务流水号 必填
  713. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  714. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  715. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  716. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  717. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  718. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  719. // inputData["psn_selfpay"] = "" // 个人自付 必填
  720. // inputData["psn_ownpay"] = "" // 个人自费 必填
  721. // inputData["acct_pay"] = "" // 个人账户支出 必填
  722. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  723. // inputData["hsorg"] = "" // 医保机构 必填
  724. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  725. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  726. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  727. //
  728. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  729. // payinfotemp := make(map[string]interface{})
  730. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  731. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  732. // payinfo = append(payinfo,payinfotemp)
  733. //
  734. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  735. // opspdiseinfotemp := make(map[string]interface{})
  736. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  737. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  738. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  739. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  740. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  741. //
  742. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  743. // diseinfotemp := make(map[string]interface{})
  744. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  745. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  746. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  747. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  748. // diseinfo = append(diseinfo,diseinfotemp)
  749. //
  750. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  751. // iteminfotemp := make(map[string]interface{})
  752. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  753. // iteminfotemp["amt"] = "" // 金额 必填
  754. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  755. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  756. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  757. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  758. // iteminfo = append(iteminfo,iteminfotemp)
  759. //
  760. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  761. // oprninfotemp := make(map[string]interface{})
  762. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  763. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  764. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  765. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  766. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  767. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  768. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  769. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  770. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  771. // oprninfo = append(oprninfo,iteminfotemp)
  772. //
  773. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  774. // icuinfotemp := make(map[string]interface{})
  775. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  776. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  777. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  778. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  779. // icuinfo = append(icuinfo,iteminfotemp)
  780. //
  781. //
  782. //
  783. //
  784. // input["setlinfo"] = inputData
  785. // input["payinfo"] = payinfo
  786. // input["opspdiseinfo"] = opspdiseinfo
  787. // input["diseinfo"] = diseinfo
  788. // input["iteminfo"] = iteminfo
  789. // input["oprninfo"] = oprninfo
  790. // input["icuinfo"] = icuinfo
  791. // inputMessage["input"] = input //交易输入
  792. //
  793. // bytesData, err := json.Marshal(inputMessage)
  794. // fmt.Println(string(bytesData))
  795. // if err != nil {
  796. // fmt.Println(err.Error())
  797. // return err.Error()
  798. // }
  799. // reader := bytes.NewReader(bytesData)
  800. //
  801. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  802. // request, err := http.NewRequest("POST", url, reader)
  803. // if err != nil {
  804. // fmt.Println(err.Error())
  805. // return err.Error()
  806. // }
  807. //
  808. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  809. // request.Header.Set("x-tif-paasid", "test_hosp")
  810. // request.Header.Set("x-tif-signature", signature)
  811. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  812. // request.Header.Set("x-tif-nonce", nonce)
  813. //
  814. // client := http.Client{}
  815. // resp, err := client.Do(request)
  816. // if err != nil {
  817. // fmt.Println(err.Error())
  818. // return err.Error()
  819. // }
  820. // respBytes, err := ioutil.ReadAll(resp.Body)
  821. // if err != nil {
  822. // fmt.Println(err.Error())
  823. // return err.Error()
  824. // }
  825. // str := string(respBytes)
  826. // fmt.Println(str)
  827. // return str
  828. //}
  829. // 生成签名
  830. func setSignature(timestamp int64, nonce string) string {
  831. str := strconv.FormatInt(timestamp, 10) + SceretKey + nonce + strconv.FormatInt(timestamp, 10)
  832. hash := sha256.New()
  833. //输入数据
  834. hash.Write([]byte(str))
  835. //计算哈希值
  836. bytes := hash.Sum(nil)
  837. //将字符串编码为16进制格式,返回字符串
  838. hashCode := hex.EncodeToString(bytes)
  839. //返回哈希值
  840. return hashCode
  841. }
  842. // 生成随机字符串
  843. func GetRandomString(l int) string {
  844. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  845. bytes := []byte(str)
  846. result := []byte{}
  847. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  848. for i := 0; i < l; i++ {
  849. result = append(result, bytes[r.Intn(len(bytes))])
  850. }
  851. return string(result)
  852. }
  853. // 生成基础报文
  854. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string) map[string]interface{} {
  855. // 生成签名
  856. tempTime := time.Unix(timestamp, 0)
  857. timeFormat := tempTime.Format("20060102150405")
  858. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  859. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  860. // 生成输入报文
  861. inputMessage := make(map[string]interface{})
  862. inputMessage["infno"] = "1101" // 交易编码
  863. inputMessage["msgid"] = "H44022900158" + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  864. inputMessage["mdtrtarea_admvs"] = "440200" // 就医地医保区划
  865. inputMessage["insuplc_admdvs"] = "440200" // 参保地医保区划
  866. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  867. inputMessage["dev_no"] = "" // 设备编号
  868. inputMessage["dev_safe_info"] = "" // 设备安全信息
  869. inputMessage["cainfo"] = "" // 数字签名信息
  870. inputMessage["signtype"] = "" // 签名类型
  871. inputMessage["infver"] = "V1.1" // 接收方系统代码
  872. inputMessage["opter_type"] = "1" // 经办人类别
  873. inputMessage["opter"] = "mockuser" // 经办人
  874. inputMessage["opter_name"] = doctor // 经办人姓名
  875. inputMessage["inf_time"] = timeFormatOne // 交易时间
  876. inputMessage["fixmedins_code"] = FixmedinsCOde // 定点医药机构编号
  877. inputMessage["fixmedins_name"] = "" //定点医药机构名称
  878. inputMessage["sign_no"] = "" //交易签到流水号
  879. return inputMessage
  880. }
  881. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  882. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  883. return
  884. }
  885. func Gdyb1201(psnNo string, org_name string, doctor string) string {
  886. // 生成签名
  887. nonce := GetRandomString(32)
  888. timestamp := time.Now().Unix()
  889. signature := setSignature(timestamp, nonce)
  890. // 生成输入报文
  891. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor)
  892. input := make(map[string]interface{})
  893. inputData := make(map[string]interface{})
  894. inputMessage["infno"] = "1201" // 交易编码
  895. inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  896. inputData["fixmedins_name"] = "翁源沅胜血液透析中心" // 人员编号 (来自1101接口返回)
  897. inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  898. input["medinsinfo"] = inputData
  899. inputMessage["input"] = input //交易输入
  900. bytesData, err := json.Marshal(inputMessage)
  901. fmt.Println(string(bytesData))
  902. if err != nil {
  903. fmt.Println(err.Error())
  904. return err.Error()
  905. }
  906. reader := bytes.NewReader(bytesData)
  907. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  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", "test_hosp")
  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. }