zh_his_service.go 56KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. package service
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/models"
  7. "github.com/astaxie/beego"
  8. "github.com/jinzhu/gorm"
  9. "io/ioutil"
  10. "net/http"
  11. "strconv"
  12. "time"
  13. _ "unsafe"
  14. )
  15. // 人员基本信息
  16. func ZHGdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, certificates int64, name string) (string, string, string) {
  17. //生成签名
  18. var requestLog string
  19. var resultLog string
  20. nonce := GetRandomString(32)
  21. timestamp := time.Now().Unix()
  22. signature := setSignature(timestamp, nonce, secret_key)
  23. //生成输入报文
  24. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  25. input := make(map[string]interface{})
  26. inputData := make(map[string]interface{})
  27. inputMessage["infno"] = "1101" // 交易编码
  28. if certificates == 3 {
  29. inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
  30. inputData["certno"] = certNo // 证件号码
  31. inputData["psn_cert_type"] = "99" // 人员证件类型
  32. } else {
  33. if id_card_type == 1 {
  34. inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
  35. inputData["card_sn"] = card_sn // 卡识别码
  36. inputData["certno"] = certNo // 证件号码
  37. inputData["psn_cert_type"] = "01" // 人员证件类型
  38. } else {
  39. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  40. inputData["card_sn"] = "" // 卡识别码
  41. inputData["certno"] = certNo // 证件号码
  42. inputData["psn_cert_type"] = "01" // 人员证件类型
  43. }
  44. }
  45. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  46. inputData["begntime"] = "" // 开始时间
  47. inputData["psn_name"] = name // 人员姓名
  48. input["data"] = inputData
  49. inputMessage["input"] = input //交易输入
  50. bytesData, err := json.Marshal(inputMessage)
  51. fmt.Println(string(bytesData))
  52. requestLog = string(bytesData)
  53. if err != nil {
  54. fmt.Println(err.Error())
  55. return err.Error(), "", ""
  56. }
  57. reader := bytes.NewReader(bytesData)
  58. gdyb_url := beego.AppConfig.String("gdyb_url")
  59. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  60. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  61. url := gdyb_url + "1101"
  62. if mdtrtarea_admvs == "150499" {
  63. url = gdyb_url
  64. }
  65. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  66. request, err := http.NewRequest("POST", url, reader)
  67. if err != nil {
  68. fmt.Println(err.Error())
  69. return err.Error(), "", ""
  70. }
  71. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  72. request.Header.Set("x-tif-paasid", gdyb_paasid)
  73. request.Header.Set("x-tif-signature", signature)
  74. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  75. request.Header.Set("x-tif-nonce", nonce)
  76. client := http.Client{}
  77. resp, err := client.Do(request)
  78. if err != nil {
  79. fmt.Println(err.Error())
  80. return err.Error(), "", ""
  81. }
  82. respBytes, err := ioutil.ReadAll(resp.Body)
  83. if err != nil {
  84. fmt.Println(err.Error())
  85. return err.Error(), "", ""
  86. }
  87. fmt.Println(string(respBytes))
  88. str := string(respBytes)
  89. resultLog = str
  90. return str, requestLog, resultLog
  91. }
  92. func ZHGdyb1101B(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, certificates int64, name string) (string, string) {
  93. //生成签名
  94. var requestLog string
  95. nonce := GetRandomString(32)
  96. timestamp := time.Now().Unix()
  97. signature := setSignature(timestamp, nonce, secret_key)
  98. //生成输入报文
  99. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  100. input := make(map[string]interface{})
  101. inputData := make(map[string]interface{})
  102. inputMessage["infno"] = "1101" // 交易编码
  103. if certificates == 3 {
  104. inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
  105. inputData["certno"] = certNo // 证件号码
  106. inputData["psn_cert_type"] = "99" // 人员证件类型
  107. } else {
  108. if id_card_type == 1 {
  109. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  110. inputData["card_sn"] = "" // 卡识别码
  111. inputData["certno"] = certNo // 证件号码
  112. inputData["psn_cert_type"] = "01" // 人员证件类型
  113. } else {
  114. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  115. inputData["card_sn"] = "" // 卡识别码
  116. inputData["certno"] = certNo // 证件号码
  117. inputData["psn_cert_type"] = "01" // 人员证件类型
  118. }
  119. }
  120. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  121. inputData["begntime"] = "" // 开始时间
  122. inputData["psn_name"] = "" // 人员姓名
  123. input["data"] = inputData
  124. inputMessage["input"] = input //交易输入
  125. bytesData, err := json.Marshal(inputMessage)
  126. fmt.Println(string(bytesData))
  127. requestLog = string(bytesData)
  128. if err != nil {
  129. fmt.Println(err.Error())
  130. return err.Error(), ""
  131. }
  132. reader := bytes.NewReader(bytesData)
  133. gdyb_url := beego.AppConfig.String("gdyb_url")
  134. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  135. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  136. url := gdyb_url + "1101"
  137. if mdtrtarea_admvs == "150499" {
  138. url = gdyb_url
  139. }
  140. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
  141. request, err := http.NewRequest("POST", url, reader)
  142. if err != nil {
  143. fmt.Println(err.Error())
  144. return err.Error(), ""
  145. }
  146. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  147. request.Header.Set("x-tif-paasid", gdyb_paasid)
  148. request.Header.Set("x-tif-signature", signature)
  149. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  150. request.Header.Set("x-tif-nonce", nonce)
  151. client := http.Client{}
  152. resp, err := client.Do(request)
  153. if err != nil {
  154. fmt.Println(err.Error())
  155. return err.Error(), ""
  156. }
  157. respBytes, err := ioutil.ReadAll(resp.Body)
  158. if err != nil {
  159. fmt.Println(err.Error())
  160. return err.Error(), ""
  161. }
  162. fmt.Println(string(respBytes))
  163. str := string(respBytes)
  164. return str, requestLog
  165. }
  166. type DiseinfoStruct struct {
  167. PsnNo string
  168. DiagType string
  169. MaindiagFlag string
  170. DiagSrtNo string
  171. DiagCode string
  172. DiagName string
  173. DiagDept string
  174. DiseDorNo string
  175. DiseDorName string
  176. DiagTime string
  177. }
  178. type Struct2401 struct {
  179. PsnNo string
  180. Insutype string
  181. MdtrtCertType string
  182. MdtrtCertNo string
  183. MedType string
  184. IptNo string
  185. AtddrNo string
  186. ChfpdrName string
  187. AdmDiagDscr string
  188. AdmDeptCodg string
  189. AdmDeptName string
  190. AdmBed string
  191. DscgMaindiagCode string
  192. DscgMaindiagName string
  193. Diseinfo []DiseinfoStruct
  194. Begntime string
  195. DiseCodg string
  196. DiseName string
  197. }
  198. // 住院登记
  199. func ZHGdyb2401(struct2401 Struct2401, secret_key string, org_name string, fixmedins_code string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string) (string, string) {
  200. // 生成签名
  201. nonce := GetRandomString(32)
  202. timestamp := time.Now().Unix()
  203. signature := setSignature(timestamp, nonce, secret_key)
  204. //tempTime := time.Unix(timestamp, 0)
  205. //timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  206. // 生成输入报文
  207. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  208. input := make(map[string]interface{})
  209. inputData := make(map[string]interface{})
  210. inputMessage["infno"] = "2401" // 交易编码
  211. inputData["psn_no"] = struct2401.PsnNo // 人员编号 (来自1101接口返回)
  212. inputData["insutype"] = struct2401.Insutype // 险种类型(来自1101接口返回)
  213. inputData["tel"] = ""
  214. inputData["coner_name"] = ""
  215. inputData["begntime"] = struct2401.Begntime // 开始时间
  216. inputData["mdtrt_cert_type"] = struct2401.MdtrtCertType // 就诊凭证类型
  217. inputData["mdtrt_cert_no"] = struct2401.MdtrtCertNo // 就诊凭证编号
  218. inputData["med_type"] = struct2401.MedType // 就诊凭证编号
  219. inputData["ipt_no"] = struct2401.IptNo // 住院/门诊号
  220. inputData["medrcdno"] = ""
  221. inputData["atddr_no"] = struct2401.AtddrNo
  222. inputData["chfpdr_name"] = struct2401.ChfpdrName
  223. inputData["adm_diag_dscr"] = struct2401.AdmDiagDscr
  224. inputData["adm_dept_codg"] = struct2401.AdmDeptCodg
  225. inputData["adm_dept_name"] = struct2401.AdmDeptName
  226. inputData["adm_bed"] = struct2401.AdmBed
  227. inputData["dscg_maindiag_code"] = struct2401.DscgMaindiagCode
  228. inputData["dscg_maindiag_name"] = struct2401.DscgMaindiagName
  229. inputData["main_cond_dscr"] = ""
  230. inputData["dise_codg"] = struct2401.DiseCodg
  231. inputData["dise_name"] = struct2401.DiseName
  232. inputData["oprn_oprt_code"] = ""
  233. inputData["oprn_oprt_name"] = ""
  234. inputData["fpsc_no"] = ""
  235. inputData["matn_type"] = ""
  236. inputData["birctrl_type"] = ""
  237. inputData["latechb_flag"] = ""
  238. inputData["geso_val"] = ""
  239. inputData["fetts"] = ""
  240. inputData["fetus_cnt"] = ""
  241. inputData["pret_flag"] = ""
  242. inputData["birctrl_matn_date"] = ""
  243. inputData["dise_type_code"] = ""
  244. inputDataArr := make([]map[string]interface{}, 0)
  245. for _, item := range struct2401.Diseinfo {
  246. inputDataTwo := make(map[string]interface{})
  247. inputDataTwo["psn_no"] = item.PsnNo
  248. inputDataTwo["diag_type"] = item.DiagType
  249. inputDataTwo["maindiag_flag"] = item.MaindiagFlag
  250. inputDataTwo["diag_srt_no"] = item.DiagSrtNo
  251. inputDataTwo["diag_code"] = item.DiagCode
  252. inputDataTwo["diag_name"] = item.DiagName
  253. inputDataTwo["adm_cond"] = ""
  254. inputDataTwo["diag_dept"] = item.DiagDept
  255. inputDataTwo["dise_dor_no"] = item.DiseDorNo
  256. inputDataTwo["dise_dor_name"] = item.DiseDorName
  257. inputDataTwo["diag_time"] = item.DiagTime
  258. inputDataArr = append(inputDataArr, inputDataTwo)
  259. }
  260. input["mdtrtinfo"] = inputData
  261. input["diseinfo"] = inputDataArr
  262. inputMessage["input"] = input //交易输入
  263. bytesData, err := json.Marshal(inputMessage)
  264. fmt.Println(string(bytesData))
  265. requestLog := string(bytesData)
  266. if err != nil {
  267. fmt.Println(err.Error())
  268. return err.Error(), ""
  269. }
  270. reader := bytes.NewReader(bytesData)
  271. gdyb_url := beego.AppConfig.String("gdyb_url")
  272. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  273. url := gdyb_url + "2401"
  274. if mdtrtarea_admvs == "150499" {
  275. url = gdyb_url
  276. }
  277. request, err := http.NewRequest("POST", url, reader)
  278. if err != nil {
  279. fmt.Println(err.Error())
  280. return err.Error(), ""
  281. }
  282. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  283. request.Header.Set("x-tif-paasid", gdyb_paasid)
  284. request.Header.Set("x-tif-signature", signature)
  285. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  286. request.Header.Set("x-tif-nonce", nonce)
  287. client := http.Client{}
  288. resp, err := client.Do(request)
  289. if err != nil {
  290. fmt.Println(err.Error())
  291. return err.Error(), ""
  292. }
  293. respBytes, err := ioutil.ReadAll(resp.Body)
  294. if err != nil {
  295. fmt.Println(err.Error())
  296. return err.Error(), ""
  297. }
  298. str := string(respBytes)
  299. fmt.Println(str)
  300. return str, requestLog
  301. }
  302. //住院撤销
  303. func ZHGdyb2404(mdtrt_id string, psn_no string, secret_key string, org_name string, fixmedins_code string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string) (string, string) {
  304. // 生成签名
  305. nonce := GetRandomString(32)
  306. timestamp := time.Now().Unix()
  307. signature := setSignature(timestamp, nonce, secret_key)
  308. // 生成输入报文
  309. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  310. input := make(map[string]interface{})
  311. inputData := make(map[string]interface{})
  312. inputMessage["infno"] = "2404" // 交易编码
  313. inputData["mdtrt_id"] = mdtrt_id // 人员编号 (来自1101接口返回)
  314. inputData["psn_no"] = psn_no // 人员编号 (来自1101接口返回)
  315. input["data"] = inputData
  316. inputMessage["input"] = input //交易输入
  317. bytesData, err := json.Marshal(inputMessage)
  318. fmt.Println(string(bytesData))
  319. requestLog := string(bytesData)
  320. if err != nil {
  321. fmt.Println(err.Error())
  322. return err.Error(), ""
  323. }
  324. reader := bytes.NewReader(bytesData)
  325. gdyb_url := beego.AppConfig.String("gdyb_url")
  326. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  327. url := gdyb_url + "2404"
  328. if mdtrtarea_admvs == "150499" {
  329. url = gdyb_url
  330. }
  331. request, err := http.NewRequest("POST", url, reader)
  332. if err != nil {
  333. fmt.Println(err.Error())
  334. return err.Error(), ""
  335. }
  336. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  337. request.Header.Set("x-tif-paasid", gdyb_paasid)
  338. request.Header.Set("x-tif-signature", signature)
  339. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  340. request.Header.Set("x-tif-nonce", nonce)
  341. client := http.Client{}
  342. resp, err := client.Do(request)
  343. if err != nil {
  344. fmt.Println(err.Error())
  345. return err.Error(), ""
  346. }
  347. respBytes, err := ioutil.ReadAll(resp.Body)
  348. if err != nil {
  349. fmt.Println(err.Error())
  350. return err.Error(), ""
  351. }
  352. str := string(respBytes)
  353. fmt.Println(str)
  354. return str, requestLog
  355. }
  356. //出院撤销
  357. func ZHGdyb2405(mdtrt_id string, psn_no string, secret_key string, org_name string, fixmedins_code string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string) (string, string) {
  358. // 生成签名
  359. nonce := GetRandomString(32)
  360. timestamp := time.Now().Unix()
  361. signature := setSignature(timestamp, nonce, secret_key)
  362. // 生成输入报文
  363. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  364. input := make(map[string]interface{})
  365. inputData := make(map[string]interface{})
  366. inputMessage["infno"] = "2405" // 交易编码
  367. inputData["mdtrt_id"] = mdtrt_id // 人员编号 (来自1101接口返回)
  368. inputData["psn_no"] = psn_no // 人员编号 (来自1101接口返回)
  369. input["data"] = inputData
  370. inputMessage["input"] = input //交易输入
  371. bytesData, err := json.Marshal(inputMessage)
  372. fmt.Println(string(bytesData))
  373. requestLog := string(bytesData)
  374. if err != nil {
  375. fmt.Println(err.Error())
  376. return err.Error(), ""
  377. }
  378. reader := bytes.NewReader(bytesData)
  379. gdyb_url := beego.AppConfig.String("gdyb_url")
  380. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  381. url := gdyb_url + "2405"
  382. if mdtrtarea_admvs == "150499" {
  383. url = gdyb_url
  384. }
  385. request, err := http.NewRequest("POST", url, reader)
  386. if err != nil {
  387. fmt.Println(err.Error())
  388. return err.Error(), ""
  389. }
  390. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  391. request.Header.Set("x-tif-paasid", gdyb_paasid)
  392. request.Header.Set("x-tif-signature", signature)
  393. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  394. request.Header.Set("x-tif-nonce", nonce)
  395. client := http.Client{}
  396. resp, err := client.Do(request)
  397. if err != nil {
  398. fmt.Println(err.Error())
  399. return err.Error(), ""
  400. }
  401. respBytes, err := ioutil.ReadAll(resp.Body)
  402. if err != nil {
  403. fmt.Println(err.Error())
  404. return err.Error(), ""
  405. }
  406. str := string(respBytes)
  407. fmt.Println(str)
  408. return str, requestLog
  409. }
  410. type Diseinfo2402Struct struct {
  411. MdtrtId string
  412. PsnNo string
  413. DiagType string
  414. MaindiagFlag string
  415. DiagSrtNo string
  416. DiagCode string
  417. DiagName string
  418. DiagDept string
  419. DiseDorNo string
  420. DiseDorName string
  421. DiagTime string
  422. }
  423. type Struct2402 struct {
  424. MdtrtId string
  425. PsnNo string
  426. Insutype string
  427. Endtime string
  428. DscgDeptCodg string
  429. DscgDeptName string
  430. DscgWay string
  431. Diseinfo []Diseinfo2402Struct
  432. DiseName string
  433. DiseCode string
  434. }
  435. // 出院
  436. func ZHGdyb2402(struct2402 Struct2402, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) (string, string) {
  437. // 生成签名
  438. nonce := GetRandomString(32)
  439. timestamp := time.Now().Unix()
  440. signature := setSignature(timestamp, nonce, secret_key)
  441. //tempTime := time.Unix(timestamp, 0)
  442. //timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  443. // 生成输入报文
  444. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  445. input := make(map[string]interface{})
  446. inputData := make(map[string]interface{})
  447. inputMessage["infno"] = "2402" // 交易编码
  448. inputData["mdtrt_id"] = struct2402.MdtrtId // 人员编号 (来自1101接口返回)
  449. inputData["psn_no"] = struct2402.PsnNo // 人员编号 (来自1101接口返回)
  450. inputData["insutype"] = struct2402.Insutype // 险种类型(来自1101接口返回)
  451. inputData["endtime"] = struct2402.Endtime // 结束时间
  452. inputData["dise_codg"] = struct2402.DiseCode // 就诊凭证类型
  453. inputData["dise_name"] = struct2402.DiseName // 就诊凭证类型
  454. inputData["oprn_oprt_code"] = "" // 就诊凭证类型
  455. inputData["oprn_oprt_name"] = "" // 就诊凭证类型
  456. inputData["fpsc_no"] = "" // 就诊凭证类型
  457. inputData["matn_type"] = "" // 就诊凭证类型
  458. inputData["birctrl_type"] = "" // 就诊凭证类型
  459. inputData["latechb_flag"] = "" // 就诊凭证类型
  460. inputData["geso_val"] = ""
  461. inputData["fetts"] = ""
  462. inputData["fetus_cnt"] = ""
  463. inputData["pret_flag"] = ""
  464. inputData["birctrl_matn_date"] = ""
  465. inputData["cop_flag"] = ""
  466. inputData["dscg_dept_codg"] = struct2402.DscgDeptCodg
  467. inputData["dscg_dept_name"] = struct2402.DscgDeptName
  468. inputData["dscg_bed"] = "待定"
  469. inputData["dscg_way"] = struct2402.DscgWay
  470. inputData["die_date"] = ""
  471. inputDataArr := make([]map[string]interface{}, 0)
  472. for _, item := range struct2402.Diseinfo {
  473. inputDataTwo := make(map[string]interface{})
  474. inputDataTwo["psn_no"] = item.PsnNo
  475. inputDataTwo["mdtrt_id"] = item.MdtrtId
  476. inputDataTwo["diag_type"] = item.DiagType
  477. inputDataTwo["maindiag_flag"] = item.MaindiagFlag
  478. inputDataTwo["diag_srt_no"] = item.DiagSrtNo
  479. inputDataTwo["diag_code"] = item.DiagCode
  480. inputDataTwo["diag_name"] = item.DiagName
  481. inputDataTwo["diag_dept"] = item.DiagDept
  482. inputDataTwo["dise_dor_no"] = item.DiseDorNo
  483. inputDataTwo["dise_dor_name"] = item.DiseDorName
  484. inputDataTwo["diag_time"] = item.DiagTime
  485. inputDataArr = append(inputDataArr, inputDataTwo)
  486. }
  487. input["dscginfo"] = inputData
  488. input["diseinfo"] = inputDataArr
  489. inputMessage["input"] = input //交易输入
  490. bytesData, err := json.Marshal(inputMessage)
  491. fmt.Println(string(bytesData))
  492. request_log := string(bytesData)
  493. if err != nil {
  494. fmt.Println(err.Error())
  495. return err.Error(), ""
  496. }
  497. reader := bytes.NewReader(bytesData)
  498. gdyb_url := beego.AppConfig.String("gdyb_url")
  499. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  500. url := gdyb_url + "2402"
  501. if mdtrtarea_admvs == "150499" {
  502. url = gdyb_url
  503. }
  504. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2202"
  505. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  506. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2202"
  507. request, err := http.NewRequest("POST", url, reader)
  508. if err != nil {
  509. fmt.Println(err.Error())
  510. return err.Error(), ""
  511. }
  512. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  513. //request.Header.Set("x-tif-paasid", "test_hosp")
  514. request.Header.Set("x-tif-paasid", gdyb_paasid)
  515. request.Header.Set("x-tif-signature", signature)
  516. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  517. request.Header.Set("x-tif-nonce", nonce)
  518. client := http.Client{}
  519. resp, err := client.Do(request)
  520. if err != nil {
  521. fmt.Println(err.Error())
  522. return err.Error(), ""
  523. }
  524. respBytes, err := ioutil.ReadAll(resp.Body)
  525. if err != nil {
  526. fmt.Println(err.Error())
  527. return err.Error(), ""
  528. }
  529. str := string(respBytes)
  530. fmt.Println(str)
  531. return str, request_log
  532. }
  533. type ZHCustom struct {
  534. DetItemFeeSumamt string
  535. Cut string
  536. FeedetlSn string
  537. Price string
  538. MedListCodg string
  539. LmtUsedFlag int64
  540. HospApprFlag int64
  541. }
  542. type ZHRequestResult struct {
  543. Output ZHOutput `json:"output" form:"output"`
  544. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  545. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  546. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  547. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  548. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  549. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  550. }
  551. type ZHOutput struct {
  552. Result Result `json:"result" form:"result"`
  553. }
  554. type ZHResult struct {
  555. BasMednFlag string `json:"bas_medn_flag" form:"bas_medn_flag"`
  556. MedChrgitmType string `json:"med_chrgitm_type" form:"med_chrgitm_type"`
  557. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  558. HiNegoDrugFlag string `json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
  559. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  560. FeedtlSn int64 `json:"feedtl_sn" form:"feedtl_sn"`
  561. UploadDate int64 `json:"upload_date" form:"upload_date"`
  562. AdviceId int64 `json:"advice_id" form:"advice_id"`
  563. Cnt int64 `json:"cnt" form:"cnt"`
  564. Pric float64 `json:"pric" form:"pric"`
  565. PatientId int64 `json:"patient_id" form:"patient_id"`
  566. PricUplmtAmt float64 `json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
  567. SelfpayProp float64 `json:"selfpay_prop" form:"selfpay_prop"`
  568. OverlmtAmt float64 `json:"overlmt_amt" form:"overlmt_amt"`
  569. PreselfpayAmt float64 `json:"preselfpay_amt" form:"preselfpay_amt"`
  570. Status int64 `json:"status" form:"status"`
  571. Memo string `json:"memo" form:"memo"`
  572. FeedetlSn string `json:"feedetl_sn" form:"feedetl_sn"`
  573. Mtime int64 `json:"mtime" form:"mtime"`
  574. InscpScpAmt float64 `json:"inscp_scp_amt" form:"inscp_scp_amt"`
  575. DrtReimFlag string `json:"drt_reim_flag" form:"drt_reim_flag"`
  576. Ctime int64 `json:"ctime" form:"ctime"`
  577. ListSpItemFlag string `json:"list_sp_item_flag" form:"list_sp_item_flag"`
  578. ChldMedcFlag string `json:"chld_medc_flag" form:"chld_medc_flag"`
  579. LmtUsedFlag string `json:"lmt_used_flag" form:"lmt_used_flag"`
  580. ChrgitmLv string `json:"chrgitm_lv" form:"chrgitm_lv"`
  581. UserOrgId int64 `json:"user_org_id" form:"user_org_id"`
  582. HisPatientId int64 `json:"his_patient_id" form:"his_patient_id"`
  583. OrderId int64 `json:"order_id" form:"order_id"`
  584. }
  585. // 住院费用明细信息上传
  586. func ZHGdyb2301(psnNo string, mdtrtId string, hisPrescription []*models.NewCustom, 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, med_type string, doctor_name string, doctor_number string) (string, string) {
  587. // 生成签名
  588. nonce := GetRandomString(32)
  589. timestamp := time.Now().Unix()
  590. signature := setSignature(timestamp, nonce, secret_key)
  591. //tempTime := time.Unix(timestamp, 0)
  592. //timeFormat := tempTime.Format("20060102150405")
  593. //timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  594. //chrgBchno := rand.Intn(100000) + 10000
  595. var customs []*models.NewCustom
  596. customs = hisPrescription
  597. // 生成输入报文
  598. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  599. input := make(map[string]interface{})
  600. feedetail := make([]map[string]interface{}, 0)
  601. inputMessage["infno"] = "2301" // 交易编码
  602. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  603. for _, item := range customs {
  604. org_id, _ := beego.AppConfig.Int64("org_id")
  605. doctor_info, _ := GetAdminUserInfoByID(org_id, item.DoctorId)
  606. feedetailInfo := make(map[string]interface{})
  607. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  608. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  609. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  610. feedetailInfo["med_type"] = med_type
  611. feedetailInfo["fee_ocur_time"] = item.FeeOcurTime // 费用发生时间
  612. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  613. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  614. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  615. feedetailInfo["cnt"] = item.Cut // 数量
  616. feedetailInfo["pric"] = item.Price // 单价
  617. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  618. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  619. feedetailInfo["bilg_dr_codg"] = doctor_info.DoctorNumber // 开单医生编码
  620. feedetailInfo["bilg_dr_name"] = doctor_info.UserName
  621. feedetailInfo["acord_dept_codg"] = dept_code // 受单科室编码
  622. feedetailInfo["acord_dept_name"] = dept // 受单科室名称
  623. feedetailInfo["orders_dr_code"] = doctor_info.DoctorNumber // 受单医生编码
  624. feedetailInfo["orders_dr_name"] = doctor_info.UserName // 受单医生姓名
  625. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  626. feedetailInfo["dise_codg"] = "" // 病种编码
  627. feedetailInfo["rxno"] = "" // 处方号
  628. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  629. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  630. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  631. feedetailInfo["prd_days"] = "0" // 周期天数
  632. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  633. // 开单医师姓名
  634. if item.HospApprFlag != -1 {
  635. if item.HospApprFlag == 1 {
  636. feedetailInfo["hosp_appr_flag"] = "0" // 医院审批标志
  637. } else if item.HospApprFlag == 2 {
  638. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  639. } else if item.HospApprFlag == 3 {
  640. feedetailInfo["hosp_appr_flag"] = "2" // 医院审批标志
  641. } else {
  642. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  643. }
  644. } else {
  645. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  646. }
  647. //feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  648. feedetailInfo["etip_flag"] = "" // 外检标志
  649. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  650. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  651. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  652. feedetail = append(feedetail, feedetailInfo)
  653. }
  654. input["feedetail"] = feedetail
  655. inputMessage["input"] = input //交易输入
  656. bytesData, err := json.Marshal(inputMessage)
  657. fmt.Println("----------")
  658. fmt.Println(string(bytesData))
  659. fmt.Println("----------")
  660. requestLog := string(bytesData)
  661. if err != nil {
  662. fmt.Println(err.Error())
  663. return "", ""
  664. }
  665. reader := bytes.NewReader(bytesData)
  666. gdyb_url := beego.AppConfig.String("gdyb_url")
  667. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  668. url := gdyb_url + "2301"
  669. if mdtrtarea_admvs == "150499" {
  670. url = gdyb_url
  671. }
  672. request, err := http.NewRequest("POST", url, reader)
  673. if err != nil {
  674. fmt.Println(err.Error())
  675. return "", ""
  676. }
  677. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  678. request.Header.Set("x-tif-paasid", gdyb_paasid)
  679. request.Header.Set("x-tif-signature", signature)
  680. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  681. request.Header.Set("x-tif-nonce", nonce)
  682. client := http.Client{}
  683. resp, err := client.Do(request)
  684. if err != nil {
  685. fmt.Println(err.Error())
  686. return "", ""
  687. }
  688. respBytes, err := ioutil.ReadAll(resp.Body)
  689. if err != nil {
  690. fmt.Println(err.Error())
  691. return "", ""
  692. }
  693. return string(respBytes), requestLog
  694. }
  695. func ZHGdyb2301A(psnNo string, mdtrtId string, hisPrescription []*models.NewCustom, 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, med_type string, opertor string) (string, string) {
  696. // 生成签名
  697. nonce := GetRandomString(32)
  698. timestamp := time.Now().Unix()
  699. signature := setSignature(timestamp, nonce, secret_key)
  700. //tempTime := time.Unix(timestamp, 0)
  701. //timeFormat := tempTime.Format("20060102150405")
  702. //timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  703. //chrgBchno := rand.Intn(100000) + 10000
  704. var customs []*models.NewCustom
  705. customs = hisPrescription
  706. // 生成输入报文
  707. inputMessage := SetInputMessage(nonce, timestamp, org_name, opertor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  708. input := make(map[string]interface{})
  709. feedetail := make([]map[string]interface{}, 0)
  710. inputMessage["infno"] = "2301" // 交易编码
  711. //chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  712. for _, item := range customs {
  713. feedetailInfo := make(map[string]interface{})
  714. feedetailInfo["feedetl_sn"] = item.FeedetlSn
  715. feedetailInfo["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  716. feedetailInfo["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  717. feedetailInfo["med_type"] = ""
  718. feedetailInfo["fee_ocur_time"] = item.FeeOcurTime // 费用发生时间
  719. feedetailInfo["med_list_codg"] = item.MedListCodg // 医疗目录编码
  720. feedetailInfo["medins_list_codg"] = fixmedins_code // 医药机构目录编码
  721. feedetailInfo["det_item_fee_sumamt"] = item.DetItemFeeSumamt // 明细项目费用总额
  722. feedetailInfo["cnt"] = item.Cut // 数量
  723. feedetailInfo["pric"] = item.Price // 单价
  724. feedetailInfo["bilg_dept_codg"] = dept_code // 开单科室编码
  725. feedetailInfo["bilg_dept_name"] = dept // 开单科室名称
  726. feedetailInfo["bilg_dr_codg"] = doctor_id // 开单医生编码
  727. feedetailInfo["bilg_dr_name"] = doctor
  728. feedetailInfo["acord_dept_codg"] = dept_code // 受单科室编码
  729. feedetailInfo["acord_dept_name"] = dept // 受单科室名称
  730. feedetailInfo["orders_dr_code"] = doctor_id // 受单医生编码
  731. feedetailInfo["orders_dr_name"] = doctor // 受单医生姓名
  732. feedetailInfo["chrg_bchno"] = chrg_bchno // 收费批次号
  733. feedetailInfo["dise_codg"] = "" // 病种编码
  734. feedetailInfo["rxno"] = "" // 处方号
  735. feedetailInfo["rx_circ_flag"] = "0" // 外购处方标志
  736. feedetailInfo["sin_dos_dscr"] = "" // 单次剂量描述
  737. feedetailInfo["used_frqu_dscr"] = "" // 使用频次描述
  738. feedetailInfo["prd_days"] = "0" // 周期天数
  739. feedetailInfo["medc_way_dscr"] = "" // 用药途径描述
  740. // 开单医师姓名
  741. if item.HospApprFlag != -1 {
  742. if item.HospApprFlag == 1 {
  743. feedetailInfo["hosp_appr_flag"] = "0" // 医院审批标志
  744. } else if item.HospApprFlag == 2 {
  745. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  746. } else if item.HospApprFlag == 3 {
  747. feedetailInfo["hosp_appr_flag"] = "2" // 医院审批标志
  748. } else {
  749. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  750. }
  751. } else {
  752. feedetailInfo["hosp_appr_flag"] = "1" // 医院审批标志
  753. }
  754. feedetailInfo["tcmdrug_used_way"] = "" // 中药使用方式
  755. feedetailInfo["etip_flag"] = "" // 外检标志
  756. feedetailInfo["etip_hosp_code"] = "" // 外检医院编码
  757. feedetailInfo["dscg_tkdrug_flag"] = "" // 出院带药标志
  758. feedetailInfo["matn_fee_flag"] = "" // 生育费用标志
  759. feedetail = append(feedetail, feedetailInfo)
  760. }
  761. input["feedetail"] = feedetail
  762. inputMessage["input"] = input //交易输入
  763. bytesData, err := json.Marshal(inputMessage)
  764. fmt.Println("----------")
  765. fmt.Println(string(bytesData))
  766. fmt.Println("----------")
  767. requestLog := string(bytesData)
  768. if err != nil {
  769. fmt.Println(err.Error())
  770. return "", ""
  771. }
  772. reader := bytes.NewReader(bytesData)
  773. gdyb_url := beego.AppConfig.String("gdyb_url")
  774. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  775. url := gdyb_url + "2301"
  776. if mdtrtarea_admvs == "150499" {
  777. url = gdyb_url
  778. }
  779. request, err := http.NewRequest("POST", url, reader)
  780. if err != nil {
  781. fmt.Println(err.Error())
  782. return "", ""
  783. }
  784. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  785. request.Header.Set("x-tif-paasid", gdyb_paasid)
  786. request.Header.Set("x-tif-signature", signature)
  787. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  788. request.Header.Set("x-tif-nonce", nonce)
  789. client := http.Client{}
  790. resp, err := client.Do(request)
  791. if err != nil {
  792. fmt.Println(err.Error())
  793. return "", ""
  794. }
  795. respBytes, err := ioutil.ReadAll(resp.Body)
  796. if err != nil {
  797. fmt.Println(err.Error())
  798. return "", ""
  799. }
  800. return string(respBytes), requestLog
  801. }
  802. // 住院费用明细信息撤销
  803. func Gdyb2302(psnNo string, mdtrtId string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string, number string, refund_type int64) (string, string) {
  804. // 生成签名
  805. nonce := GetRandomString(32)
  806. timestamp := time.Now().Unix()
  807. signature := setSignature(timestamp, nonce, secret_key)
  808. // 生成输入报文
  809. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  810. input := make(map[string]interface{})
  811. inputData := make(map[string]interface{})
  812. inputMessage["infno"] = "2302" // 交易编码
  813. if refund_type == 1 {
  814. inputData["feedetl_sn"] = number //
  815. } else {
  816. inputData["feedetl_sn"] = "0000" //
  817. }
  818. inputData["mdtrt_id"] = mdtrtId // 就诊 ID
  819. inputData["psn_no"] = psnNo // 人员编号
  820. input["data"] = inputData
  821. inputMessage["input"] = input //交易输入
  822. bytesData, err := json.Marshal(inputMessage)
  823. fmt.Println(string(bytesData))
  824. requestLog := string(bytesData)
  825. if err != nil {
  826. fmt.Println(err.Error())
  827. return err.Error(), ""
  828. }
  829. reader := bytes.NewReader(bytesData)
  830. gdyb_url := beego.AppConfig.String("gdyb_url")
  831. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  832. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  833. url := gdyb_url + "2302"
  834. if mdtrtarea_admvs == "150499" {
  835. url = gdyb_url
  836. }
  837. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2205"
  838. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  839. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2205"
  840. request, err := http.NewRequest("POST", url, reader)
  841. fmt.Println(err)
  842. fmt.Println(request)
  843. if err != nil {
  844. fmt.Println(err.Error())
  845. return err.Error(), ""
  846. }
  847. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  848. request.Header.Set("x-tif-paasid", gdyb_paasid)
  849. request.Header.Set("x-tif-signature", signature)
  850. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  851. request.Header.Set("x-tif-nonce", nonce)
  852. client := http.Client{}
  853. resp, err := client.Do(request)
  854. if err != nil {
  855. fmt.Println(err.Error())
  856. return err.Error(), ""
  857. }
  858. respBytes, err := ioutil.ReadAll(resp.Body)
  859. if err != nil {
  860. fmt.Println(err.Error())
  861. return err.Error(), ""
  862. }
  863. str := string(respBytes)
  864. fmt.Println(str)
  865. return str, requestLog
  866. }
  867. func ZHGdyb2303(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, mid_setl_flag string, id_card_type int64, fulamt_ownpay_amt float64, overlmt_selfpay float64, preselfpay_amt float64, inscp_scp_amt float64, certificates int64) (string, string) {
  868. // 生成签名
  869. nonce := GetRandomString(32)
  870. timestamp := time.Now().Unix()
  871. signature := setSignature(timestamp, nonce, secret_key)
  872. // 生成输入报文
  873. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  874. input := make(map[string]interface{})
  875. inputData := make(map[string]interface{})
  876. inputMessage["infno"] = "2303" // 交易编码
  877. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  878. if certificates == 3 {
  879. inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
  880. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  881. } else {
  882. if id_card_type == 1 {
  883. inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
  884. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  885. } else {
  886. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  887. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  888. }
  889. }
  890. inputData["mdtrt_cert_sn"] = ""
  891. inputData["mid_setl_flag"] = mid_setl_flag // 中途退费标志
  892. inputData["medfee_sumamt"] = total // 医疗费总额
  893. inputData["psn_setlway"] = "02" // 个人结算方式 01 按项目结 02 按定额结算
  894. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  895. inputData["acct_used_flag"] = "1" // 个人账户使用标志 0否 1是
  896. inputData["insutype"] = insutype // 险种类型
  897. inputData["invono"] = "" // 发票号
  898. inputData["dise_codg"] = "M07803" // 发票号
  899. input["data"] = inputData
  900. inputMessage["input"] = input //交易输入
  901. bytesData, err := json.Marshal(inputMessage)
  902. fmt.Println(string(bytesData))
  903. if err != nil {
  904. fmt.Println(err.Error())
  905. return err.Error(), ""
  906. }
  907. reader := bytes.NewReader(bytesData)
  908. gdyb_url := beego.AppConfig.String("gdyb_url")
  909. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  910. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  911. url := gdyb_url + "2303"
  912. if mdtrtarea_admvs == "150499" {
  913. url = gdyb_url
  914. }
  915. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  916. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  917. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  918. request, err := http.NewRequest("POST", url, reader)
  919. if err != nil {
  920. fmt.Println(err.Error())
  921. return err.Error(), ""
  922. }
  923. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  924. request.Header.Set("x-tif-paasid", gdyb_paasid)
  925. request.Header.Set("x-tif-signature", signature)
  926. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  927. request.Header.Set("x-tif-nonce", nonce)
  928. client := http.Client{}
  929. resp, err := client.Do(request)
  930. if err != nil {
  931. fmt.Println(err.Error())
  932. return err.Error(), ""
  933. }
  934. respBytes, err := ioutil.ReadAll(resp.Body)
  935. if err != nil {
  936. fmt.Println(err.Error())
  937. return err.Error(), ""
  938. }
  939. str := string(respBytes)
  940. fmt.Println(str)
  941. mjson, _ := json.Marshal(inputMessage)
  942. str2 := string(mjson)
  943. return str, str2
  944. }
  945. // 住院结算
  946. func ZHGdyb2304(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, mid_setl_flag string, id_card_type int64, fulamt_ownpay_amt float64, overlmt_selfpay float64, preselfpay_amt float64, inscp_scp_amt float64, certificates int64, fapiao_number string, acct_used_flag string) (string, string) {
  947. // 生成签名
  948. nonce := GetRandomString(32)
  949. timestamp := time.Now().Unix()
  950. signature := setSignature(timestamp, nonce, secret_key)
  951. // 生成输入报文
  952. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  953. input := make(map[string]interface{})
  954. inputData := make(map[string]interface{})
  955. inputMessage["infno"] = "2304" // 交易编码
  956. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  957. if certificates == 3 {
  958. inputData["mdtrt_cert_type"] = "99" // 就诊凭证类型
  959. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  960. } else {
  961. if id_card_type == 1 {
  962. inputData["mdtrt_cert_type"] = "03" // 就诊凭证类型
  963. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  964. } else {
  965. inputData["mdtrt_cert_type"] = "02" // 就诊凭证类型
  966. inputData["mdtrt_cert_no"] = certNo // 就诊凭证编号
  967. }
  968. }
  969. inputData["mdtrt_cert_sn"] = ""
  970. inputData["mid_setl_flag"] = mid_setl_flag // 中途退费标志
  971. inputData["medfee_sumamt"] = total // 医疗费总额
  972. inputData["psn_setlway"] = "01" // 个人结算方式 01 按项目结 02 按定额结算
  973. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  974. inputData["acct_used_flag"] = acct_used_flag // 个人账户使用标志 0否 1是
  975. inputData["insutype"] = insutype // 险种类型
  976. inputData["invono"] = fapiao_number // 发票号
  977. input["data"] = inputData
  978. inputMessage["input"] = input //交易输入
  979. bytesData, err := json.Marshal(inputMessage)
  980. fmt.Println(string(bytesData))
  981. if err != nil {
  982. fmt.Println(err.Error())
  983. return err.Error(), ""
  984. }
  985. reader := bytes.NewReader(bytesData)
  986. gdyb_url := beego.AppConfig.String("gdyb_url")
  987. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  988. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  989. url := gdyb_url + "2304"
  990. if mdtrtarea_admvs == "150499" {
  991. url = gdyb_url
  992. }
  993. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2207"
  994. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  995. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2207"
  996. request, err := http.NewRequest("POST", url, reader)
  997. if err != nil {
  998. fmt.Println(err.Error())
  999. return err.Error(), ""
  1000. }
  1001. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1002. request.Header.Set("x-tif-paasid", gdyb_paasid)
  1003. request.Header.Set("x-tif-signature", signature)
  1004. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1005. request.Header.Set("x-tif-nonce", nonce)
  1006. client := http.Client{}
  1007. resp, err := client.Do(request)
  1008. if err != nil {
  1009. fmt.Println(err.Error())
  1010. return err.Error(), ""
  1011. }
  1012. respBytes, err := ioutil.ReadAll(resp.Body)
  1013. if err != nil {
  1014. fmt.Println(err.Error())
  1015. return err.Error(), ""
  1016. }
  1017. str := string(respBytes)
  1018. fmt.Println(str)
  1019. mjson, _ := json.Marshal(inputMessage)
  1020. str2 := string(mjson)
  1021. return str, str2
  1022. }
  1023. func Gdyb26011(psnNo string, omsgid string, oinfno string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
  1024. // 生成签名
  1025. nonce := GetRandomString(32)
  1026. timestamp := time.Now().Unix()
  1027. signature := setSignature(timestamp, nonce, secret_key)
  1028. // 生成输入报文
  1029. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  1030. input := make(map[string]interface{})
  1031. inputData := make(map[string]interface{})
  1032. inputMessage["infno"] = "2601" // 交易编码
  1033. inputData["psn_no"] = psnNo
  1034. inputData["omsgid"] = omsgid
  1035. inputData["oinfno"] = oinfno
  1036. input["data"] = inputData
  1037. inputMessage["input"] = input //交易输入
  1038. bytesData, err := json.Marshal(inputMessage)
  1039. fmt.Println(string(bytesData))
  1040. if err != nil {
  1041. fmt.Println(err.Error())
  1042. return err.Error()
  1043. }
  1044. reader := bytes.NewReader(bytesData)
  1045. gdyb_url := beego.AppConfig.String("gdyb_url")
  1046. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  1047. url := gdyb_url + "2601"
  1048. if mdtrtarea_admvs == "150499" {
  1049. url = gdyb_url
  1050. }
  1051. request, err := http.NewRequest("POST", url, reader)
  1052. if err != nil {
  1053. fmt.Println(err.Error())
  1054. return err.Error()
  1055. }
  1056. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1057. request.Header.Set("x-tif-paasid", gdyb_paasid)
  1058. request.Header.Set("x-tif-signature", signature)
  1059. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1060. request.Header.Set("x-tif-nonce", nonce)
  1061. client := http.Client{}
  1062. resp, err := client.Do(request)
  1063. if err != nil {
  1064. fmt.Println(err.Error())
  1065. return err.Error()
  1066. }
  1067. respBytes, err := ioutil.ReadAll(resp.Body)
  1068. if err != nil {
  1069. fmt.Println(err.Error())
  1070. return err.Error()
  1071. }
  1072. str := string(respBytes)
  1073. fmt.Println(str)
  1074. return str
  1075. }
  1076. // 住院结算撤销
  1077. func Gdyb2305(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) (string, string) {
  1078. // 生成签名
  1079. nonce := GetRandomString(32)
  1080. timestamp := time.Now().Unix()
  1081. signature := setSignature(timestamp, nonce, secret_key)
  1082. // 生成输入报文
  1083. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  1084. input := make(map[string]interface{})
  1085. inputData := make(map[string]interface{})
  1086. inputMessage["infno"] = "2305" // 交易编码
  1087. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  1088. inputData["mdtrt_id"] = mdtrtId // 就诊 ID(来自2201接口返回)
  1089. inputData["setl_id"] = setlId // 结算 ID
  1090. input["data"] = inputData
  1091. inputMessage["input"] = input //交易输入
  1092. bytesData, err := json.Marshal(inputMessage)
  1093. fmt.Println(string(bytesData))
  1094. if err != nil {
  1095. fmt.Println(err.Error())
  1096. return err.Error(), ""
  1097. }
  1098. reader := bytes.NewReader(bytesData)
  1099. gdyb_url := beego.AppConfig.String("gdyb_url")
  1100. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  1101. url := gdyb_url + "2305"
  1102. if mdtrtarea_admvs == "150499" {
  1103. url = gdyb_url
  1104. }
  1105. request, err := http.NewRequest("POST", url, reader)
  1106. if err != nil {
  1107. fmt.Println(err.Error())
  1108. return err.Error(), ""
  1109. }
  1110. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1111. request.Header.Set("x-tif-paasid", gdyb_paasid)
  1112. request.Header.Set("x-tif-signature", signature)
  1113. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1114. request.Header.Set("x-tif-nonce", nonce)
  1115. client := http.Client{}
  1116. resp, err := client.Do(request)
  1117. if err != nil {
  1118. fmt.Println(err.Error())
  1119. return err.Error(), ""
  1120. }
  1121. respBytes, err := ioutil.ReadAll(resp.Body)
  1122. if err != nil {
  1123. fmt.Println(err.Error())
  1124. return err.Error(), ""
  1125. }
  1126. str := string(respBytes)
  1127. fmt.Println(str)
  1128. mjson, _ := json.Marshal(inputMessage)
  1129. str2 := string(mjson)
  1130. return str, str2
  1131. }
  1132. func Gdyb90306(psnNo string, mdtrtId string, setlId string, org_name string, doctor string, secret_key string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string) (string, string) {
  1133. // 生成签名
  1134. nonce := GetRandomString(32)
  1135. timestamp := time.Now().Unix()
  1136. signature := setSignature(timestamp, nonce, secret_key)
  1137. // 生成输入报文
  1138. inputMessage := SetInputMessage(nonce, timestamp, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs)
  1139. input := make(map[string]interface{})
  1140. inputData := make(map[string]interface{})
  1141. inputMessage["infno"] = "90306" // 交易编码
  1142. inputData["psn_no"] = psnNo // 人员编号 (来自1101接口返回)
  1143. inputData["setl_id"] = setlId // 结算 ID
  1144. input["data"] = inputData
  1145. inputMessage["input"] = input //交易输入
  1146. bytesData, err := json.Marshal(inputMessage)
  1147. fmt.Println(string(bytesData))
  1148. if err != nil {
  1149. fmt.Println(err.Error())
  1150. return err.Error(), ""
  1151. }
  1152. reader := bytes.NewReader(bytesData)
  1153. gdyb_url := beego.AppConfig.String("gdyb_url")
  1154. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  1155. url := gdyb_url + "90306"
  1156. if mdtrtarea_admvs == "150499" {
  1157. url = gdyb_url
  1158. }
  1159. request, err := http.NewRequest("POST", url, reader)
  1160. if err != nil {
  1161. fmt.Println(err.Error())
  1162. return err.Error(), ""
  1163. }
  1164. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1165. request.Header.Set("x-tif-paasid", gdyb_paasid)
  1166. request.Header.Set("x-tif-signature", signature)
  1167. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1168. request.Header.Set("x-tif-nonce", nonce)
  1169. client := http.Client{}
  1170. resp, err := client.Do(request)
  1171. if err != nil {
  1172. fmt.Println(err.Error())
  1173. return err.Error(), ""
  1174. }
  1175. respBytes, err := ioutil.ReadAll(resp.Body)
  1176. if err != nil {
  1177. fmt.Println(err.Error())
  1178. return err.Error(), ""
  1179. }
  1180. str := string(respBytes)
  1181. fmt.Println(str)
  1182. mjson, _ := json.Marshal(inputMessage)
  1183. str2 := string(mjson)
  1184. return str, str2
  1185. }
  1186. func CreateHospitalRecord(record *models.HisHospitalCheckRecord) (err error) {
  1187. err = writeDb.Save(&record).Error
  1188. return
  1189. }
  1190. func GetInHospitalRecord(id int64) (record models.HisHospitalCheckRecord, err error) {
  1191. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1", id).First(&record).Error
  1192. return
  1193. }
  1194. func GetInHospitalRecordByNumber(number string) (record models.HisHospitalCheckRecord, err error) {
  1195. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("number = ? AND status = 1", number).First(&record).Error
  1196. return
  1197. }
  1198. func GetLastHospitalRecord(id int64, user_org_id int64) (record models.HisHospitalCheckRecord, err error) {
  1199. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1 AND user_org_id = ?", id, user_org_id).Last(&record).Error
  1200. return
  1201. }
  1202. func GetZHHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1203. err = readDb.Model(&models.HisPrescription{}).
  1204. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1205. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1206. }).
  1207. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1208. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1209. }).
  1210. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1211. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
  1212. }).
  1213. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND p_type = 1", org_id, record_date, patient_id).
  1214. Find(&prescription).Error
  1215. return
  1216. }
  1217. func GetZHMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  1218. err = readDb.Model(&models.HisPrescription{}).
  1219. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1220. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1221. }).
  1222. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1223. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1224. }).
  1225. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1226. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
  1227. }).
  1228. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
  1229. Find(&prescription).Error
  1230. return
  1231. }
  1232. func GetZHHisUploadPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1233. err = readDb.Model(&models.HisPrescription{}).
  1234. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1235. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1236. }).
  1237. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1238. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1239. }).
  1240. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1241. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1242. }).
  1243. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 4 AND p_type = 1", org_id, record_date, patient_id).
  1244. Find(&prescription).Error
  1245. return
  1246. }
  1247. func GetZHMonthHisUploadPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  1248. err = readDb.Model(&models.HisPrescription{}).
  1249. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1250. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1251. }).
  1252. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1253. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1254. }).
  1255. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1257. }).
  1258. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status == 4 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
  1259. Find(&prescription).Error
  1260. return
  1261. }
  1262. func GetZHHisUploadOrderInfo(org_id int64, patient_id int64, record_date int64, record_end_date int64, number string) (infos []*models.HisOrderInfo, err error) {
  1263. err = readDb.Model(&models.HisOrderInfo{}).
  1264. Where("user_org_id = ? AND status = 1 AND upload_date <= ? AND upload_date >= ? AND patient_id = ? AND order_number = ? ", org_id, record_end_date, record_date, patient_id, number).
  1265. Find(&infos).Error
  1266. return
  1267. }
  1268. func UpDateOrderInfoStatus(patient_id int64, record_date int64, org_id int64, record_two_date int64) (err error) {
  1269. err = writeDb.Model(&models.HisOrderInfo{}).Where("user_org_id = ? AND status = 1 AND upload_date <= ? AND upload_date >= ? AND patient_id = ?", org_id, record_two_date, record_date, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  1270. return
  1271. }
  1272. func UpDatePrescriptionOrderStatusTwo(patient_id int64, record_date int64, org_id int64) (err error) {
  1273. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 1", org_id, record_date, patient_id).Updates(map[string]interface{}{"order_status": 1}).Error
  1274. return
  1275. }
  1276. //func GetAllOrderInfoByNumber(number string) (infos []*models.HisOrderInfo, err error){
  1277. //
  1278. // err = readDb.Model(&models.HisOrderInfo{}).Where("user_org_id = ? AND ")
  1279. //}
  1280. func GetZHSettleMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  1281. err = readDb.Model(&models.HisPrescription{}).
  1282. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1283. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1284. }).
  1285. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1286. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1287. }).
  1288. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1289. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
  1290. }).
  1291. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
  1292. Find(&prescription).Error
  1293. return
  1294. }
  1295. func ZHyb5203(baseParams models.BaseParams, businessParams models.BusinessParams) string {
  1296. fmt.Println("~~~~~~1")
  1297. fmt.Println(baseParams)
  1298. fmt.Println(businessParams)
  1299. // 生成签名
  1300. nonce := GetRandomString(32)
  1301. timestamp := time.Now().Unix()
  1302. signature := setSignature(timestamp, nonce, baseParams.SecretKey)
  1303. fmt.Println("~~~~~~2")
  1304. // 生成输入报文
  1305. inputMessage := SetInputMessage(nonce, timestamp, baseParams.OrgName, baseParams.Doctor, baseParams.FixmedinsCode, baseParams.InsuplcAdmdvs, baseParams.MdtrtareaAdmvs)
  1306. input := make(map[string]interface{})
  1307. inputData := make(map[string]interface{})
  1308. inputMessage["infno"] = "5203" // 交易编码
  1309. inputData["psn_no"] = businessParams.PsnNo
  1310. inputData["setl_id"] = businessParams.SetlId
  1311. inputData["mdtrt_id"] = businessParams.MdtrtId
  1312. input["data"] = inputData
  1313. inputMessage["input"] = input //交易输入
  1314. bytesData, err := json.Marshal(inputMessage)
  1315. fmt.Println(string(bytesData))
  1316. fmt.Println("~~~~~~")
  1317. fmt.Println("~~~~~~")
  1318. fmt.Println(string(bytesData))
  1319. if err != nil {
  1320. fmt.Println(err.Error())
  1321. return err.Error()
  1322. }
  1323. reader := bytes.NewReader(bytesData)
  1324. gdyb_url := beego.AppConfig.String("gdyb_url")
  1325. gdyb_paasid := beego.AppConfig.String("gdyb_paasid")
  1326. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/1101"
  1327. //url := gdyb_url + "5203"
  1328. var url string
  1329. if baseParams.FixmedinsCode == "H15049901371" {
  1330. url = gdyb_url
  1331. } else {
  1332. url = gdyb_url + "5203"
  1333. }
  1334. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/5203"
  1335. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203"
  1336. //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/5203"
  1337. request, err := http.NewRequest("POST", url, reader)
  1338. if err != nil {
  1339. fmt.Println(err.Error())
  1340. return err.Error()
  1341. }
  1342. request.Header.Set("Content-Type", "application/json;charset=UTF-8")
  1343. request.Header.Set("x-tif-paasid", gdyb_paasid)
  1344. request.Header.Set("x-tif-signature", signature)
  1345. request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
  1346. request.Header.Set("x-tif-nonce", nonce)
  1347. client := http.Client{}
  1348. resp, err := client.Do(request)
  1349. if err != nil {
  1350. fmt.Println(err.Error())
  1351. return err.Error()
  1352. }
  1353. respBytes, err := ioutil.ReadAll(resp.Body)
  1354. if err != nil {
  1355. fmt.Println(err.Error())
  1356. return err.Error()
  1357. }
  1358. str := string(respBytes)
  1359. fmt.Println(str)
  1360. return str
  1361. }