gdyb_service.go 55KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. package service
  2. import (
  3. "Xcx_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. cus := &Custom{
  345. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  346. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  347. FeedetlSn: subItem.FeedetlSn,
  348. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  349. MedListCodg: subItem.MedListCodg,
  350. }
  351. customs = append(customs, cus)
  352. }
  353. }
  354. }
  355. for _, subItem := range item.HisAdditionalCharge {
  356. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  357. cus := &Custom{
  358. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  359. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  360. FeedetlSn: subItem.FeedetlSn,
  361. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  362. MedListCodg: subItem.XtHisAddtionConfig.Code,
  363. }
  364. customs = append(customs, cus)
  365. }
  366. }
  367. }
  368. // 生成输入报文
  369. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  370. input := make(map[string]interface{})
  371. feedetail := make([]map[string]interface{}, 0)
  372. inputMessage["infno"] = "2204" // 交易编码
  373. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  374. for _, item := range customs {
  375. feedetailInfo := make(map[string]interface{})
  376. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  377. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  378. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  379. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  380. feedetailInfo["dise_codg"] = "" // 病种编码
  381. feedetailInfo["rxno"] = "" // 处方号
  382. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  383. feedetailInfo["fee_ocur_time"] = timeFormatOne // 费用发生时间
  384. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  385. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  386. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  387. feedetailInfo["cnt"] = item.Cut // 数量
  388. feedetailInfo["pric"] = item.Price // 单价
  389. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  390. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  391. feedetailInfo["prd_days"] = "0" // 周期天数
  392. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  393. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  394. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  395. feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码
  396. feedetailInfo["bilg_dr_name"] = doctor // 开单医师姓名
  397. feedetailInfo["acord_dept_codg"] = "" // 受单科室编码
  398. feedetailInfo["acord_dept_name"] = "" // 受单科室名称
  399. feedetailInfo["orders_dr_code"] = "" // 受单医生编码
  400. feedetailInfo["orders_dr_name"] = "" // 受单医生姓名
  401. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  402. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  403. feedetailInfo["etip_flag"] = "" // 外检标志
  404. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  405. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  406. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  407. feedetail = append(feedetail, feedetailInfo)
  408. }
  409. input["feedetail"] = feedetail
  410. inputMessage["input"] = input //交易输入
  411. bytesData, err := json.Marshal(inputMessage)
  412. fmt.Println("----------")
  413. fmt.Println(string(bytesData))
  414. fmt.Println("----------")
  415. if err != nil {
  416. fmt.Println(err.Error())
  417. return ""
  418. }
  419. reader := bytes.NewReader(bytesData)
  420. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2204"
  421. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2204"
  422. request, err := http.NewRequest("POST", url, reader)
  423. if err != nil {
  424. fmt.Println(err.Error())
  425. return ""
  426. }
  427. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  428. request.Header.Set("x-tif-paasid", "sg03_prd")
  429. request.Header.Set("x-tif-signature", signature)
  430. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  431. request.Header.Set("x-tif-nonce", nonce)
  432. client := http.Client{}
  433. resp, err := client.Do(request)
  434. if err != nil {
  435. fmt.Println(err.Error())
  436. return ""
  437. }
  438. respBytes, err := ioutil.ReadAll(resp.Body)
  439. if err != nil {
  440. fmt.Println(err.Error())
  441. return ""
  442. }
  443. return string(respBytes)
  444. //var result RequestResult
  445. //json.Unmarshal(respBytes, &result)
  446. //return &result
  447. }
  448. // 门诊费用明细信息撤销
  449. 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 {
  450. // 生成签名
  451. nonce := GetRandomString(32)
  452. timestamp := time.Now().Unix()
  453. signature := setSignature(timestamp, nonce, secret_key)
  454. // 生成输入报文
  455. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  456. input := make(map[string]interface{})
  457. inputData := make(map[string]interface{})
  458. inputMessage["infno"] = "2205" // 交易编码
  459. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  460. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  461. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  462. input["data"] = inputData
  463. inputMessage["input"] = input //交易输入
  464. bytesData, err := json.Marshal(inputMessage)
  465. fmt.Println(string(bytesData))
  466. if err != nil {
  467. fmt.Println(err.Error())
  468. return err.Error()
  469. }
  470. reader := bytes.NewReader(bytesData)
  471. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2205"
  472. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  473. request, err := http.NewRequest("POST", url, reader)
  474. fmt.Println(err)
  475. fmt.Println(request)
  476. if err != nil {
  477. fmt.Println(err.Error())
  478. return err.Error()
  479. }
  480. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  481. request.Header.Set("x-tif-paasid", "sg03_prd")
  482. request.Header.Set("x-tif-signature", signature)
  483. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  484. request.Header.Set("x-tif-nonce", nonce)
  485. client := http.Client{}
  486. resp, err := client.Do(request)
  487. if err != nil {
  488. fmt.Println(err.Error())
  489. return err.Error()
  490. }
  491. respBytes, err := ioutil.ReadAll(resp.Body)
  492. if err != nil {
  493. fmt.Println(err.Error())
  494. return err.Error()
  495. }
  496. str := string(respBytes)
  497. fmt.Println(str)
  498. return str
  499. }
  500. // 门诊预结算
  501. func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string {
  502. // 生成签名
  503. nonce := GetRandomString(32)
  504. timestamp := time.Now().Unix()
  505. signature := setSignature(timestamp, nonce, secret_key)
  506. // 生成输入报文
  507. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "", "", "")
  508. input := make(map[string]interface{})
  509. inputData := make(map[string]interface{})
  510. inputMessage["infno"] = "2206" // 交易编码
  511. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  512. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型,
  513. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  514. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  515. inputData["medfee_sumamt"] = total // 医疗费总额
  516. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  517. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  518. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  519. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  520. inputData["insutype"] = insutype // 险种类型
  521. input["data"] = inputData
  522. inputMessage["input"] = input //交易输入
  523. bytesData, err := json.Marshal(inputMessage)
  524. fmt.Println(string(bytesData))
  525. if err != nil {
  526. fmt.Println(err.Error())
  527. return err.Error()
  528. }
  529. reader := bytes.NewReader(bytesData)
  530. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2206"
  531. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2206"
  532. request, err := http.NewRequest("POST", url, reader)
  533. if err != nil {
  534. fmt.Println(err.Error())
  535. return err.Error()
  536. }
  537. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  538. request.Header.Set("x-tif-paasid", "sg03_prd")
  539. request.Header.Set("x-tif-signature", signature)
  540. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  541. request.Header.Set("x-tif-nonce", nonce)
  542. client := http.Client{}
  543. resp, err := client.Do(request)
  544. if err != nil {
  545. fmt.Println(err.Error())
  546. return err.Error()
  547. }
  548. respBytes, err := ioutil.ReadAll(resp.Body)
  549. if err != nil {
  550. fmt.Println(err.Error())
  551. return err.Error()
  552. }
  553. str := string(respBytes)
  554. fmt.Println(str)
  555. return str
  556. }
  557. // 门诊结算
  558. 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 {
  559. // 生成签名
  560. nonce := GetRandomString(32)
  561. timestamp := time.Now().Unix()
  562. signature := setSignature(timestamp, nonce, secret_key)
  563. // 生成输入报文
  564. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  565. input := make(map[string]interface{})
  566. inputData := make(map[string]interface{})
  567. inputMessage["infno"] = "2207" // 交易编码
  568. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  569. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  570. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  571. inputData["med_type"] = "11" // 医疗类别 11 普通门诊 12 门诊挂号
  572. inputData["medfee_sumamt"] = total // 医疗费总额
  573. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  574. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  575. inputData["chrg_bchno"] = chrgBchno // 收费批次号(来自2204生成的)
  576. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  577. inputData["insutype"] = insutype // 险种类型
  578. inputData["invono"] = "" // 发票号
  579. input["data"] = inputData
  580. inputMessage["input"] = input //交易输入
  581. bytesData, err := json.Marshal(inputMessage)
  582. fmt.Println(string(bytesData))
  583. if err != nil {
  584. fmt.Println(err.Error())
  585. return err.Error()
  586. }
  587. reader := bytes.NewReader(bytesData)
  588. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  589. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  590. request, err := http.NewRequest("POST", url, reader)
  591. if err != nil {
  592. fmt.Println(err.Error())
  593. return err.Error()
  594. }
  595. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  596. request.Header.Set("x-tif-paasid", "sg03_prd")
  597. request.Header.Set("x-tif-signature", signature)
  598. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  599. request.Header.Set("x-tif-nonce", nonce)
  600. client := http.Client{}
  601. resp, err := client.Do(request)
  602. if err != nil {
  603. fmt.Println(err.Error())
  604. return err.Error()
  605. }
  606. respBytes, err := ioutil.ReadAll(resp.Body)
  607. if err != nil {
  608. fmt.Println(err.Error())
  609. return err.Error()
  610. }
  611. str := string(respBytes)
  612. fmt.Println(str)
  613. return str
  614. }
  615. // 门诊结算撤销
  616. 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 {
  617. // 生成签名
  618. nonce := GetRandomString(32)
  619. timestamp := time.Now().Unix()
  620. signature := setSignature(timestamp, nonce, secret_key)
  621. // 生成输入报文
  622. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  623. input := make(map[string]interface{})
  624. inputData := make(map[string]interface{})
  625. inputMessage["infno"] = "2208" // 交易编码
  626. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  627. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  628. inputData["setl_id"] = setlId // 结算 ID
  629. input["data"] = inputData
  630. inputMessage["input"] = input //交易输入
  631. bytesData, err := json.Marshal(inputMessage)
  632. fmt.Println(string(bytesData))
  633. if err != nil {
  634. fmt.Println(err.Error())
  635. return err.Error()
  636. }
  637. reader := bytes.NewReader(bytesData)
  638. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2208"
  639. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  640. request, err := http.NewRequest("POST", url, reader)
  641. if err != nil {
  642. fmt.Println(err.Error())
  643. return err.Error()
  644. }
  645. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  646. request.Header.Set("x-tif-paasid", "sg03_prd")
  647. request.Header.Set("x-tif-signature", signature)
  648. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  649. request.Header.Set("x-tif-nonce", nonce)
  650. client := http.Client{}
  651. resp, err := client.Do(request)
  652. if err != nil {
  653. fmt.Println(err.Error())
  654. return err.Error()
  655. }
  656. respBytes, err := ioutil.ReadAll(resp.Body)
  657. if err != nil {
  658. fmt.Println(err.Error())
  659. return err.Error()
  660. }
  661. str := string(respBytes)
  662. fmt.Println(str)
  663. return str
  664. }
  665. // 医药机构费用结算对总账 func Gdyb3201( org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) string {
  666. func Gdyb3201(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  667. fmt.Println("11222333-----")
  668. fmt.Println(baseParams)
  669. fmt.Println(businessParams)
  670. // 生成签名
  671. nonce := GetRandomString(32)
  672. timestamp := time.Now().Unix()
  673. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  674. // 生成输入报文
  675. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  676. input := make(map[string]interface{})
  677. inputData := make(map[string]interface{})
  678. inputMessage["infno"] = "3201" // 交易编码
  679. inputData["insutype"] = businessParams.Insutype // 险种
  680. inputData["clr_type"] = businessParams.ClrType // 就诊 ID(来自2201接口返回)
  681. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  682. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  683. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  684. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  685. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  686. inputData["acct_pay"] = businessParams.AcctPay //个人账户支付金额
  687. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  688. input["data"] = inputData
  689. inputMessage["input"] = input //交易输入
  690. bytesData, err := json.Marshal(inputMessage)
  691. fmt.Println(string(bytesData))
  692. if err != nil {
  693. fmt.Println(err.Error())
  694. return err.Error()
  695. }
  696. reader := bytes.NewReader(bytesData)
  697. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3201"
  698. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3201"
  699. request, err := http.NewRequest("POST", url, reader)
  700. if err != nil {
  701. fmt.Println(err.Error())
  702. return err.Error()
  703. }
  704. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  705. request.Header.Set("x-tif-paasid", "sg03_prd")
  706. request.Header.Set("x-tif-signature", signature)
  707. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  708. request.Header.Set("x-tif-nonce", nonce)
  709. client := http.Client{}
  710. resp, err := client.Do(request)
  711. if err != nil {
  712. fmt.Println(err.Error())
  713. return err.Error()
  714. }
  715. respBytes, err := ioutil.ReadAll(resp.Body)
  716. if err != nil {
  717. fmt.Println(err.Error())
  718. return err.Error()
  719. }
  720. str := string(respBytes)
  721. fmt.Println(str)
  722. return str
  723. }
  724. type Params struct {
  725. FileName string `json:"file_name"` //产品ID
  726. In []byte `json:"in"` //
  727. FixmedinsCode string `json:"fixmedins_code"` //调用环境生产为1 沙盒2
  728. }
  729. //文件上传
  730. //文件上传
  731. func Gdyb9101(baseParams models.BaseParams, file_name string, file_byte []byte) string {
  732. // 生成签名
  733. nonce := GetRandomString(32)
  734. timestamp := time.Now().Unix()
  735. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  736. buf := new(bytes.Buffer)
  737. buf.ReadFrom(strings.NewReader(string(file_byte)))
  738. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  739. input := make(map[string]interface{})
  740. inputData := make(map[string]interface{})
  741. inputMessage["infno"] = "9101" // 交易编码
  742. inputData["file_name"] = file_name //文件名
  743. inputData["in"] = bytes.NewBuffer(file_byte).Bytes() //文件数据
  744. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  745. input["fsUploadIn"] = inputData
  746. inputMessage["input"] = input //交易输入
  747. bytesData, err := json.Marshal(inputMessage)
  748. fmt.Println(string(bytesData))
  749. if err != nil {
  750. fmt.Println(err.Error())
  751. return err.Error()
  752. }
  753. reader := bytes.NewReader(bytesData)
  754. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9101"
  755. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9101"
  756. request, err := http.NewRequest("POST", url, reader)
  757. if err != nil {
  758. fmt.Println(err.Error())
  759. return err.Error()
  760. }
  761. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  762. request.Header.Set("x-tif-paasid", "sg03_prd")
  763. request.Header.Set("x-tif-signature", signature)
  764. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  765. request.Header.Set("x-tif-nonce", nonce)
  766. client := http.Client{}
  767. resp, err := client.Do(request)
  768. if err != nil {
  769. fmt.Println(err.Error())
  770. return err.Error()
  771. }
  772. respBytes, err := ioutil.ReadAll(resp.Body)
  773. if err != nil {
  774. fmt.Println(err.Error())
  775. return err.Error()
  776. }
  777. str := string(respBytes)
  778. fmt.Println(str)
  779. return str
  780. }
  781. func Gdyb9102(baseParams models.BaseParams, file_name string, file_qury_no string) string {
  782. // 生成签名
  783. nonce := GetRandomString(32)
  784. timestamp := time.Now().Unix()
  785. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  786. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  787. input := make(map[string]interface{})
  788. inputData := make(map[string]interface{})
  789. inputMessage["infno"] = "9102" // 交易编码
  790. inputData["file_name"] = file_name //文件名
  791. inputData["file_qury_no"] = "fsi/H44022900158/" + file_qury_no //文件数据
  792. inputData["fixmedins_code"] = baseParams.FixmedinsCode //编码
  793. input["fsDownloadIn"] = inputData
  794. inputMessage["input"] = input //交易输入
  795. bytesData, err := json.Marshal(inputMessage)
  796. fmt.Println(string(bytesData))
  797. if err != nil {
  798. fmt.Println(err.Error())
  799. return err.Error()
  800. }
  801. reader := bytes.NewReader(bytesData)
  802. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/9102"
  803. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/9102"
  804. request, err := http.NewRequest("POST", url, reader)
  805. if err != nil {
  806. fmt.Println(err.Error())
  807. return err.Error()
  808. }
  809. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  810. request.Header.Set("x-tif-paasid", "sg03_prd")
  811. request.Header.Set("x-tif-signature", signature)
  812. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  813. request.Header.Set("x-tif-nonce", nonce)
  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. func Gdyb3202(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  830. // 生成签名
  831. nonce := GetRandomString(32)
  832. timestamp := time.Now().Unix()
  833. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  834. // 生成输入报文
  835. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  836. input := make(map[string]interface{})
  837. inputData := make(map[string]interface{})
  838. inputMessage["infno"] = "3202" // 交易编码
  839. inputData["file_qury_no"] = "fsi/H44022900158/" + businessParams.FileQuryNo // 险种
  840. inputData["setl_optins"] = baseParams.OrgName // 结算经办机构
  841. inputData["stmt_begndate"] = businessParams.StmtBegndate // 对帐开始时间
  842. inputData["stmt_enddate"] = businessParams.StmtEnddate //对帐结束时间
  843. inputData["medfee_sumamt"] = businessParams.MedfeeSumamt //医疗费总额
  844. inputData["fund_pay_sumamt"] = businessParams.FundPaySumamt //基金支付总额
  845. inputData["cash_payamt"] = businessParams.CashPayamt //现金支付金额
  846. inputData["fixmedins_setl_cnt"] = businessParams.FixmedinsSetlCnt //定点医药机构结算笔数
  847. input["data"] = inputData
  848. inputMessage["input"] = input //交易输入
  849. bytesData, err := json.Marshal(inputMessage)
  850. fmt.Println(string(bytesData))
  851. if err != nil {
  852. fmt.Println(err.Error())
  853. return err.Error()
  854. }
  855. reader := bytes.NewReader(bytesData)
  856. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/3202"
  857. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/3202"
  858. request, err := http.NewRequest("POST", url, reader)
  859. if err != nil {
  860. fmt.Println(err.Error())
  861. return err.Error()
  862. }
  863. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  864. request.Header.Set("x-tif-paasid", "sg03_prd")
  865. request.Header.Set("x-tif-signature", signature)
  866. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  867. request.Header.Set("x-tif-nonce", nonce)
  868. client := http.Client{}
  869. resp, err := client.Do(request)
  870. if err != nil {
  871. fmt.Println(err.Error())
  872. return err.Error()
  873. }
  874. respBytes, err := ioutil.ReadAll(resp.Body)
  875. if err != nil {
  876. fmt.Println(err.Error())
  877. return err.Error()
  878. }
  879. str := string(respBytes)
  880. fmt.Println(str)
  881. return str
  882. }
  883. func Gdyb5203(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  884. // 生成签名
  885. nonce := GetRandomString(32)
  886. timestamp := time.Now().Unix()
  887. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  888. // 生成输入报文
  889. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  890. input := make(map[string]interface{})
  891. inputData := make(map[string]interface{})
  892. inputMessage["infno"] = "5203" // 交易编码
  893. inputData["psn_no"] = businessParams.PsnNo
  894. inputData["setl_id"] = businessParams.SetlId
  895. inputData["mdtrt_id"] = businessParams.MdtrtId
  896. input["data"] = inputData
  897. inputMessage["input"] = input //交易输入
  898. bytesData, err := json.Marshal(inputMessage)
  899. fmt.Println(string(bytesData))
  900. if err != nil {
  901. fmt.Println(err.Error())
  902. return err.Error()
  903. }
  904. reader := bytes.NewReader(bytesData)
  905. url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5203"
  906. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203"
  907. request, err := http.NewRequest("POST", url, reader)
  908. if err != nil {
  909. fmt.Println(err.Error())
  910. return err.Error()
  911. }
  912. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  913. request.Header.Set("x-tif-paasid", "sg03_prd")
  914. request.Header.Set("x-tif-signature", signature)
  915. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  916. request.Header.Set("x-tif-nonce", nonce)
  917. client := http.Client{}
  918. resp, err := client.Do(request)
  919. if err != nil {
  920. fmt.Println(err.Error())
  921. return err.Error()
  922. }
  923. respBytes, err := ioutil.ReadAll(resp.Body)
  924. if err != nil {
  925. fmt.Println(err.Error())
  926. return err.Error()
  927. }
  928. str := string(respBytes)
  929. fmt.Println(str)
  930. return str
  931. }
  932. // 门诊结算撤销
  933. //func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
  934. // // 生成签名
  935. // nonce := GetRandomString(32)
  936. // timestamp := time.Now().Unix()
  937. // signature := setSignature(timestamp, nonce)
  938. //
  939. // // 生成输入报文
  940. // inputMessage := SetInputMessage(nonce, timestamp)
  941. // input := make(map[string]interface{})
  942. // inputData := make(map[string]interface{})
  943. // inputMessage["infno"] = "4101" // 交易编码
  944. //
  945. // inputData["mdtrt_id"] = mdtrtId // 就诊 ID 必填(来自2201接口返回)
  946. // inputData["setl_id"] = setlId // 结算 ID 必填
  947. // inputData["fixmedins_name"] = "" // 定点医药机构名称 必填
  948. // inputData["fixmedins_code"] = "" // 定点医药机构编码 必填
  949. // inputData["hi_setl_lv"] = "" // 医保结算等级
  950. // inputData["hi_no"] = "" // 医保编号
  951. // inputData["medcasno"] = "" // 病案号 必填
  952. // inputData["dcla_time"] = "" // 申报时间 必填
  953. // inputData["psn_name"] = "" // 人员姓名 必填
  954. // inputData["gend"] = "" // 性别 必填
  955. // inputData["brdy"] = "" // 出生日期 必填
  956. // inputData["age"] = "" // 年龄 必填
  957. // inputData["ntly"] = "" // 国籍 必填
  958. // inputData["nwb_age"] = "" // 年龄 必填
  959. // inputData["naty"] = "" // 民族 必填
  960. // inputData["patn_cert_type"] = "" // 患者证件类别 必填
  961. // inputData["certno"] = "" // 证件号码 必填
  962. // inputData["prfs"] = "" // 职业 必填
  963. // inputData["curr_addr"] = "" // 现住址 必填
  964. // inputData["emp_name"] = "" // 单位名称 必填
  965. // inputData["emp_addr"] = "" // 单位地址 必填
  966. // inputData["emp_tel"] = "" // 单位电话 必填
  967. // inputData["poscode"] = "" // 邮编 必填
  968. // inputData["coner_name"] = "" // 联系人姓名 必填
  969. // inputData["patn_rlts"] = "" // 与患者关系 必填
  970. // inputData["coner_addr"] = "" // 联系人地址 必填
  971. // inputData["coner_tel"] = "" // 联系人电话 必填
  972. // inputData["hi_type"] = "" // 医保类型 必填
  973. // inputData["insuplc"] = "" // 参保地 必填
  974. // inputData["sp_psn_type"] = "" // 特殊人员类型 必填
  975. // inputData["nwb_adm_type"] = "" // 新生儿入院类型 必填
  976. // inputData["nwb_bir_wt"] = "" // 新生儿出生体重 必填
  977. // inputData["nwb_adm_wt"] = "" // 新生儿入院体重 必填
  978. // inputData["opsp_diag_caty"] = "" // 门诊慢特病诊断 必填
  979. // inputData["opsp_mdtrt_date"] = "" // 门诊慢特病就诊日期 必填
  980. // inputData["ipt_med_type"] = "" // 住院医疗类型 必填
  981. // inputData["adm_way"] = "" // 入院途径 必填
  982. // inputData["trt_type"] = "" // 治疗类别 必填
  983. // inputData["adm_time"] = "" // 入院时间 必填
  984. // inputData["adm_caty"] = "" // 入院科别 必填
  985. // inputData["refldept_dept"] = "" // 转科科别 必填
  986. // inputData["dscg_time"] = "" // 出院时间 必填
  987. // inputData["dscg_caty"] = "" // 出院科别 必填
  988. // inputData["act_ipt_days"] = "" // 实际住院天数 必填
  989. // inputData["otp_wm_dise"] = "" // 门(急) 诊西医诊断 必填
  990. // inputData["wm_dise_code"] = "" // 门(急) 诊中医诊断 必填
  991. // inputData["otp_tcm_dise"] = "" // 西医诊断疾病代码 必填
  992. // inputData["tcm_dise_code"] = "" // 中医诊断代码 必填
  993. // inputData["oprn_oprt_code_cnt"] = "" // 手术操作代码计数 必填
  994. // inputData["vent_used_dura"] = "" // 呼吸机使用时长 必填
  995. // inputData["pwcry_bfadm_coma_dura"] = "" // 颅脑损伤患者入院前昏迷时长 必填
  996. // inputData["pwcry_afadm_coma_dura"] = "" // 颅脑损伤患者入院后昏迷时长 必填
  997. // inputData["bld_cat"] = "" // 输血品种 必填
  998. // inputData["bld_amt"] = "" // 输血量 必填
  999. // inputData["bld_unt"] = "" // 输血计量单位 必填
  1000. // inputData["spga_nurscare_days"] = "" // 特级护理天数 必填
  1001. // inputData["lv1_nurscare_days"] = "" // 一级护理天数 必填
  1002. // inputData["scd_nurscare_days"] = "" // 二级护理天数 必填
  1003. // inputData["lv3_nurscare_days"] = "" // 三级护理天数 必填
  1004. // inputData["acp_medins_name"] = "" // 拟接收机构名称 必填
  1005. // inputData["acp_optins_code"] = "" // 拟接收机构代码 必填
  1006. // inputData["bill_code"] = "" // 票据代码 必填
  1007. // inputData["bill_no"] = "" // 票据号码 必填
  1008. // inputData["biz_sn"] = "" // 业务流水号 必填
  1009. // inputData["days_rinp_flag_31"] = "" // 出院 31 天内再住院计划标志 必填
  1010. // inputData["days_rinp_pup_31"] = "" // 出院 31 天内再住院目的 必填
  1011. // inputData["chfpdr_name"] = "" // 主诊医师姓名 必填
  1012. // inputData["chfpdr_code"] = "" // 主诊医师代码 必填
  1013. // inputData["setl_begn_date"] = "" // 结算开始日期 必填
  1014. // inputData["setl_end_date"] = "" // 结算结束日期 必填
  1015. // inputData["psn_selfpay"] = "" // 个人自付 必填
  1016. // inputData["psn_ownpay"] = "" // 个人自费 必填
  1017. // inputData["acct_pay"] = "" // 个人账户支出 必填
  1018. // inputData["hi_paymtd"] = "" // 医保支付方式 必填
  1019. // inputData["hsorg"] = "" // 医保机构 必填
  1020. // inputData["hsorg_opter"] = "" // 医保机构经办人 必填
  1021. // inputData["medins_fill_dept"] = "" // 医疗机构填报部门 必填
  1022. // inputData["medins_fill_psn"] = "" // 医疗机构填报人 必填
  1023. //
  1024. // payinfo := make([]map[string]interface{},0) // 基金支付信息
  1025. // payinfotemp := make(map[string]interface{})
  1026. // payinfotemp["fund_pay_type"] = "" // 基金支付类型 必填
  1027. // payinfotemp["fund_payamt"] = "" // 基金支付金额
  1028. // payinfo = append(payinfo,payinfotemp)
  1029. //
  1030. // opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
  1031. // opspdiseinfotemp := make(map[string]interface{})
  1032. // opspdiseinfotemp["diag_name"] = "" // 诊断名称 必填
  1033. // opspdiseinfotemp["diag_code"] = "" // 诊断代码 必填
  1034. // opspdiseinfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1035. // opspdiseinfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1036. // opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
  1037. //
  1038. // diseinfo := make([]map[string]interface{},0) // 住院诊断信息
  1039. // diseinfotemp := make(map[string]interface{})
  1040. // diseinfotemp["diag_type"] = "" // 诊断类别 必填
  1041. // diseinfotemp["diag_code"] = "" // 诊断代码 必填
  1042. // diseinfotemp["diag_name"] = "" // 诊断名称 必填
  1043. // diseinfotemp["adm_cond_type"] = "" // 入院病情类型 必填
  1044. // diseinfo = append(diseinfo,diseinfotemp)
  1045. //
  1046. // iteminfo := make([]map[string]interface{},0) // 住院诊断信息
  1047. // iteminfotemp := make(map[string]interface{})
  1048. // iteminfotemp["med_chrgitm"] = "" // 医疗收费项目 必填
  1049. // iteminfotemp["amt"] = "" // 金额 必填
  1050. // iteminfotemp["claa_sumfee"] = "" // 甲类费用合计 必填
  1051. // iteminfotemp["clab_amt"] = "" // 乙类金额 必填
  1052. // iteminfotemp["fulamt_ownpay_amt"] = "" // 全自费金额 必填
  1053. // iteminfotemp["oth_amt"] = "" // 其他金额 必填
  1054. // iteminfo = append(iteminfo,iteminfotemp)
  1055. //
  1056. // oprninfo := make([]map[string]interface{},0) // 手术操作信息
  1057. // oprninfotemp := make(map[string]interface{})
  1058. // oprninfotemp["oprn_oprt_type"] = "" // 手术操作类别 必填
  1059. // oprninfotemp["oprn_oprt_name"] = "" // 手术操作名称 必填
  1060. // oprninfotemp["oprn_oprt_code"] = "" // 手术操作代码 必填
  1061. // oprninfotemp["oprn_oprt_date"] = "" // 手术操作日期 必填
  1062. // oprninfotemp["anst_way"] = "" // 麻醉方式 必填
  1063. // oprninfotemp["oper_dr_name"] = "" // 术者医师姓名 必填
  1064. // oprninfotemp["oper_dr_code"] = "" // 术者医师代码 必填
  1065. // oprninfotemp["anst_dr_name"] = "" // 麻醉医师姓名 必填
  1066. // oprninfotemp["anst_dr_code"] = "" // 麻醉医师代码 必填
  1067. // oprninfo = append(oprninfo,iteminfotemp)
  1068. //
  1069. // icuinfo := make([]map[string]interface{},0) // 重症监护信息
  1070. // icuinfotemp := make(map[string]interface{})
  1071. // icuinfotemp["scs_cutd_ward_type"] = "" // 重症监护病房类型 必填
  1072. // icuinfotemp["scs_cutd_inpool_time"] = "" // 重症监护进入时间 必填
  1073. // icuinfotemp["scs_cutd_exit_time"] = "" // 重症监护退出时间 必填
  1074. // icuinfotemp["scs_cutd_sum_dura"] = "" // 重症监护合计时长 必填
  1075. // icuinfo = append(icuinfo,iteminfotemp)
  1076. //
  1077. //
  1078. //
  1079. //
  1080. // input["setlinfo"] = inputData
  1081. // input["payinfo"] = payinfo
  1082. // input["opspdiseinfo"] = opspdiseinfo
  1083. // input["diseinfo"] = diseinfo
  1084. // input["iteminfo"] = iteminfo
  1085. // input["oprninfo"] = oprninfo
  1086. // input["icuinfo"] = icuinfo
  1087. // inputMessage["input"] = input //交易输入
  1088. //
  1089. // bytesData, err := json.Marshal(inputMessage)
  1090. // fmt.Println(string(bytesData))
  1091. // if err != nil {
  1092. // fmt.Println(err.Error())
  1093. // return err.Error()
  1094. // }
  1095. // reader := bytes.NewReader(bytesData)
  1096. //
  1097. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
  1098. // request, err := http.NewRequest("POST", url, reader)
  1099. // if err != nil {
  1100. // fmt.Println(err.Error())
  1101. // return err.Error()
  1102. // }
  1103. //
  1104. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1105. // request.Header.Set("x-tif-paasid", "test_hosp")
  1106. // request.Header.Set("x-tif-signature", signature)
  1107. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1108. // request.Header.Set("x-tif-nonce", nonce)
  1109. //
  1110. // client := http.Client{}
  1111. // resp, err := client.Do(request)
  1112. // if err != nil {
  1113. // fmt.Println(err.Error())
  1114. // return err.Error()
  1115. // }
  1116. // respBytes, err := ioutil.ReadAll(resp.Body)
  1117. // if err != nil {
  1118. // fmt.Println(err.Error())
  1119. // return err.Error()
  1120. // }
  1121. // str := string(respBytes)
  1122. // fmt.Println(str)
  1123. // return str
  1124. //}
  1125. // 生成签名
  1126. func setSignature(timestamp int64, nonce string, secret_key string) string {
  1127. str := strconv.FormatInt(timestamp, 10) + secret_key + nonce + strconv.FormatInt(timestamp, 10)
  1128. hash := sha256.New()
  1129. //输入数据
  1130. hash.Write([]byte(str))
  1131. //计算哈希值
  1132. bytes := hash.Sum(nil)
  1133. //将字符串编码为16进制格式,返回字符串
  1134. hashCode := hex.EncodeToString(bytes)
  1135. //返回哈希值
  1136. return hashCode
  1137. }
  1138. // 生成随机字符串
  1139. func GetRandomString(l int) string {
  1140. str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1141. bytes := []byte(str)
  1142. result := []byte{}
  1143. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  1144. for i := 0; i < l; i++ {
  1145. result = append(result, bytes[r.Intn(len(bytes))])
  1146. }
  1147. return string(result)
  1148. }
  1149. // 生成基础报文
  1150. func SetInputMessage(nonce string, timestamp int64, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) map[string]interface{} {
  1151. // 生成签名
  1152. tempTime := time.Unix(timestamp, 0)
  1153. timeFormat := tempTime.Format("20060102150405")
  1154. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1155. randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  1156. // 生成输入报文
  1157. inputMessage := make(map[string]interface{})
  1158. inputMessage["infno"] = "1101" // 交易编码
  1159. inputMessage["msgid"] = fixmedins_code + timeFormat + strconv.FormatInt(int64(randNum), 10) // 发送方报文 ID
  1160. inputMessage["mdtrtarea_admvs"] = mdtrtarea_admvs // 就医地医保区划
  1161. inputMessage["insuplc_admdvs"] = insuplc_admdvs // 参保地医保区划
  1162. inputMessage["recer_sys_code"] = "01" // 接收方系统代码
  1163. inputMessage["dev_no"] = "" // 设备编号
  1164. inputMessage["dev_safe_info"] = "" // 设备安全信息
  1165. inputMessage["cainfo"] = "" // 数字签名信息
  1166. inputMessage["signtype"] = "" // 签名类型
  1167. inputMessage["infver"] = "V1.1" // 接收方系统代码
  1168. inputMessage["opter_type"] = "1" // 经办人类别
  1169. inputMessage["opter"] = doctor // 经办人
  1170. inputMessage["opter_name"] = doctor // 经办人姓名
  1171. inputMessage["inf_time"] = timeFormatOne // 交易时间
  1172. inputMessage["fixmedins_code"] = fixmedins_code // 定点医药机构编号
  1173. inputMessage["fixmedins_name"] = org_name //定点医药机构名称
  1174. inputMessage["sign_no"] = "" //交易签到流水号
  1175. return inputMessage
  1176. }
  1177. func postFile(filename string, target_url string) (*http.Response, error) {
  1178. body_buf := bytes.NewBufferString("")
  1179. body_writer := multipart.NewWriter(body_buf)
  1180. // use the body_writer to write the Part headers to the buffer
  1181. _, err := body_writer.CreateFormFile("userfile", filename)
  1182. if err != nil {
  1183. fmt.Println("error writing to buffer")
  1184. return nil, err
  1185. }
  1186. // the file data will be the second part of the body
  1187. fh, err := os.Open(filename)
  1188. if err != nil {
  1189. fmt.Println("error opening file")
  1190. return nil, err
  1191. }
  1192. // need to know the boundary to properly close the part myself.
  1193. boundary := body_writer.Boundary()
  1194. //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
  1195. close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
  1196. // use multi-reader to defer the reading of the file data until
  1197. // writing to the socket buffer.
  1198. request_reader := io.MultiReader(body_buf, fh, close_buf)
  1199. fi, err := fh.Stat()
  1200. if err != nil {
  1201. fmt.Printf("Error Stating file: %s", filename)
  1202. return nil, err
  1203. }
  1204. req, err := http.NewRequest("POST", target_url, request_reader)
  1205. if err != nil {
  1206. return nil, err
  1207. }
  1208. // Set headers for multipart, and Content Length
  1209. req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary)
  1210. req.ContentLength = fi.Size() + int64(body_buf.Len()) + int64(close_buf.Len())
  1211. return http.DefaultClient.Do(req)
  1212. }
  1213. //func Gdyb1201(psnNo string, org_name string, doctor string) string {
  1214. // // 生成签名
  1215. // nonce := GetRandomString(32)
  1216. // timestamp := time.Now().Unix()
  1217. // signature := setSignature(timestamp, nonce)
  1218. //
  1219. // // 生成输入报文
  1220. // inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, "")
  1221. // input := make(map[string]interface{})
  1222. // inputData := make(map[string]interface{})
  1223. // inputMessage["infno"] = "1201" // 交易编码
  1224. // inputData["fixmedins_type"] = psnNo // 人员编号 (来自1101接口返回)
  1225. // inputData["fixmedins_name"] = org_name // 人员编号 (来自1101接口返回)
  1226. // inputData["fixmedins_code"] = "" // 人员编号 (来自1101接口返回)
  1227. //
  1228. // input["medinsinfo"] = inputData
  1229. // inputMessage["input"] = input //交易输入
  1230. //
  1231. // bytesData, err := json.Marshal(inputMessage)
  1232. // fmt.Println(string(bytesData))
  1233. // if err != nil {
  1234. // fmt.Println(err.Error())
  1235. // return err.Error()
  1236. // }
  1237. // reader := bytes.NewReader(bytesData)
  1238. //
  1239. // url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1201"
  1240. // request, err := http.NewRequest("POST", url, reader)
  1241. // if err != nil {
  1242. // fmt.Println(err.Error())
  1243. // return err.Error()
  1244. // }
  1245. //
  1246. // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1247. // request.Header.Set("x-tif-paasid", "test_hosp")
  1248. // request.Header.Set("x-tif-signature", signature)
  1249. // request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1250. // request.Header.Set("x-tif-nonce", nonce)
  1251. //
  1252. // client := http.Client{}
  1253. // resp, err := client.Do(request)
  1254. // if err != nil {
  1255. // fmt.Println(err.Error())
  1256. // return err.Error()
  1257. // }
  1258. // respBytes, err := ioutil.ReadAll(resp.Body)
  1259. // if err != nil {
  1260. // fmt.Println(err.Error())
  1261. // return err.Error()
  1262. // }
  1263. // str := string(respBytes)
  1264. // fmt.Println(str)
  1265. // return str
  1266. //}
  1267. func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
  1268. file, err := os.Open(path)
  1269. if err != nil {
  1270. return nil, err
  1271. }
  1272. defer file.Close()
  1273. body := &bytes.Buffer{}
  1274. writer := multipart.NewWriter(body)
  1275. part, err := writer.CreateFormFile(paramName, filepath.Base(path))
  1276. if err != nil {
  1277. return nil, err
  1278. }
  1279. _, err = io.Copy(part, file)
  1280. for key, val := range params {
  1281. _ = writer.WriteField(key, val)
  1282. }
  1283. err = writer.Close()
  1284. if err != nil {
  1285. return nil, err
  1286. }
  1287. req, err := http.NewRequest("POST", uri, body)
  1288. req.Header.Set("Content-Type", writer.FormDataContentType())
  1289. return req, err
  1290. }