his_api_controller.go 65KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  32. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  33. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  34. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  35. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  36. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  37. }
  38. func (c *HisApiController) Sscard() {
  39. r := CardInit()
  40. if r == 0 {
  41. GetBaseInfo()
  42. }
  43. c.ServeSuccessJSON(map[string]interface{}{
  44. "list": "11",
  45. })
  46. }
  47. func GetBaseInfo() error {
  48. //handle := syscall.MustLoadDLL("SSCard.dll")
  49. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  50. //
  51. //str := make([]byte, 256)
  52. //str1 := make([]byte, 256)
  53. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  54. //if ferr != nil {
  55. // fmt.Println("ReadCardBas 报错", ferr.Error())
  56. // return ferr
  57. //}
  58. //
  59. //fmt.Println(string(str))
  60. //
  61. //fmt.Println(r)
  62. return nil
  63. }
  64. func CardInit() int {
  65. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  66. //add := DllTestDef.MustFindProc("Init")
  67. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  68. //if err != nil {
  69. // fmt.Println("SSCard的运算结果为:", ret)
  70. //}
  71. //result := int(ret)
  72. return 0
  73. }
  74. func IntPtr(n int) uintptr {
  75. return uintptr(n)
  76. }
  77. func StrPtr(s string) uintptr {
  78. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  79. }
  80. type ResultTwo struct {
  81. ErrMsg string `json:"err_msg"`
  82. InfRefmsgid string `json:"inf_refmsgid"`
  83. Infcode int64 `json:"infcode"`
  84. Output struct {
  85. Baseinfo struct {
  86. Age float64 `json:"age"`
  87. Brdy string `json:"brdy"`
  88. Certno string `json:"certno"`
  89. Gend string `json:"gend"`
  90. Naty string `json:"naty"`
  91. PsnCertType string `json:"psn_cert_type"`
  92. PsnName string `json:"psn_name"`
  93. PsnNo string `json:"psn_no"`
  94. } `json:"baseinfo"`
  95. Idetinfo []interface{} `json:"idetinfo"`
  96. Iinfo []struct {
  97. Balc int64 `json:"balc"`
  98. CvlservFlag string `json:"cvlserv_flag"`
  99. EmpName string `json:"emp_name"`
  100. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  101. Insutype string `json:"insutype"`
  102. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  103. PausInsuDate interface{} `json:"paus_insu_date"`
  104. PsnInsuDate string `json:"psn_insu_date"`
  105. PsnInsuStas string `json:"psn_insu_stas"`
  106. PsnType string `json:"psn_type"`
  107. } `json:"insuinfo"`
  108. } `json:"output"`
  109. RefmsgTime string `json:"refmsg_time"`
  110. RespondTime string `json:"respond_time"`
  111. Signtype interface{} `json:"signtype"`
  112. WarnInfo interface{} `json:"warn_info"`
  113. }
  114. type ResultThree struct {
  115. Cainfo interface{} `json:"cainfo"`
  116. ErrMsg string `json:"err_msg"`
  117. InfRefmsgid string `json:"inf_refmsgid"`
  118. Infcode int64 `json:"infcode"`
  119. Output struct {
  120. Data struct {
  121. IptOtpNo string `json:"ipt_otp_no"`
  122. MdtrtID string `json:"mdtrt_id"`
  123. PsnNo string `json:"psn_no"`
  124. } `json:"data"`
  125. } `json:"output"`
  126. RefmsgTime string `json:"refmsg_time"`
  127. RespondTime string `json:"respond_time"`
  128. Signtype interface{} `json:"signtype"`
  129. WarnMsg interface{} `json:"warn_msg"`
  130. }
  131. type ResultFour struct {
  132. Cainfo string `json:"cainfo"`
  133. ErrMsg string `json:"err_msg"`
  134. InfRefmsgid string `json:"inf_refmsgid"`
  135. Infcode int64 `json:"infcode"`
  136. Output struct {
  137. Result []struct {
  138. BasMednFlag string `json:"bas_medn_flag"`
  139. ChldMedcFlag string `json:"chld_medc_flag"`
  140. ChrgitmLv string `json:"chrgitm_lv"`
  141. Cnt float64 `json:"cnt"`
  142. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  143. DrtReimFlag string `json:"drt_reim_flag"`
  144. FeedetlSn string `json:"feedetl_sn"`
  145. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  146. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  147. InscpScpAmt float64 `json:"inscp_scp_amt"`
  148. ListSpItemFlag string `json:"list_sp_item_flag"`
  149. LmtUsedFlag string `json:"lmt_used_flag"`
  150. MedChrgitmType string `json:"med_chrgitm_type"`
  151. Memo string `json:"memo"`
  152. OverlmtAmt float64 `json:"overlmt_amt"`
  153. PreselfpayAmt float64 `json:"preselfpay_amt"`
  154. Pric float64 `json:"pric"`
  155. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  156. SelfpayProp float64 `json:"selfpay_prop"`
  157. } `json:"result"`
  158. } `json:"output"`
  159. RefmsgTime string `json:"refmsg_time"`
  160. RespondTime string `json:"respond_time"`
  161. Signtype string `json:"signtype"`
  162. WarnMsg string `json:"warn_msg"`
  163. }
  164. type ResultFive struct {
  165. Insutype string `json:"insutype"`
  166. }
  167. type ResultSix struct {
  168. Cainfo interface{} `json:"cainfo"`
  169. ErrMsg string `json:"err_msg"`
  170. InfRefmsgid string `json:"inf_refmsgid"`
  171. Infcode int64 `json:"infcode"`
  172. Output struct {
  173. } `json:"output"`
  174. RefmsgTime string `json:"refmsg_time"`
  175. RespondTime string `json:"respond_time"`
  176. Signtype interface{} `json:"signtype"`
  177. WarnMsg interface{} `json:"warn_msg"`
  178. }
  179. type ResultSeven struct {
  180. Cainfo string `json:"cainfo"`
  181. ErrMsg string `json:"err_msg"`
  182. InfRefmsgid string `json:"inf_refmsgid"`
  183. Infcode int64 `json:"infcode"`
  184. Output struct {
  185. Setldetail []interface{} `json:"setldetail"`
  186. Setlinfo struct {
  187. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  188. AcctPay float64 `json:"acct_pay"`
  189. ActPayDedc float64 `json:"act_pay_dedc"`
  190. Age float64 `json:"age"`
  191. Balc float64 `json:"balc"`
  192. Brdy string `json:"brdy"`
  193. Certno string `json:"certno"`
  194. ClrOptins string `json:"clr_optins"`
  195. ClrType string `json:"clr_type"`
  196. ClrWay string `json:"clr_way"`
  197. CvlservFlag string `json:"cvlserv_flag"`
  198. CvlservPay float64 `json:"cvlserv_pay"`
  199. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  200. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  201. Gend string `json:"gend"`
  202. HifesPay float64 `json:"hifes_pay"`
  203. HifmiPay float64 `json:"hifmi_pay"`
  204. HifpPay float64 `json:"hifp_pay"`
  205. HospPartAmt float64 `json:"hosp_part_amt"`
  206. InscpScpAmt float64 `json:"inscp_scp_amt"`
  207. Insutype string `json:"insutype"`
  208. MafPay float64 `json:"maf_pay"`
  209. MdtrtCertType string `json:"mdtrt_cert_type"`
  210. HifobPay float64 `json:"hifob_pay"`
  211. MdtrtID string `json:"mdtrt_id"`
  212. MedType string `json:"med_type"`
  213. MedfeeSumamt float64 `json:"medfee_sumamt"`
  214. MedinsSetlID string `json:"medins_setl_id"`
  215. Naty string `json:"naty"`
  216. OthPay float64 `json:"oth_pay"`
  217. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  218. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  219. PreselfpayAmt float64 `json:"preselfpay_amt"`
  220. PsnCashPay float64 `json:"psn_cash_pay"`
  221. PsnCertType string `json:"psn_cert_type"`
  222. PsnName string `json:"psn_name"`
  223. PsnNo string `json:"psn_no"`
  224. PsnPartAmt float64 `json:"psn_part_amt"`
  225. PsnType string `json:"psn_type"`
  226. SetlID string `json:"setl_id"`
  227. SetlTime string `json:"setl_time"`
  228. } `json:"setlinfo"`
  229. } `json:"output"`
  230. RefmsgTime string `json:"refmsg_time"`
  231. RespondTime string `json:"respond_time"`
  232. Signtype interface{} `json:"signtype"`
  233. WarnMsg interface{} `json:"warn_msg"`
  234. }
  235. type ResultEight struct {
  236. Cainfo string `json:"cainfo"`
  237. ErrMsg string `json:"err_msg"`
  238. InfRefmsgid string `json:"inf_refmsgid"`
  239. Infcode int64 `json:"infcode"`
  240. Output struct {
  241. Stmtinfo struct {
  242. SetlOptins string `json:"setl_optins"`
  243. StmtRslt string `json:"stmt_rslt"`
  244. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  245. } `json:"stmtinfo"`
  246. } `json:"output"`
  247. RefmsgTime string `json:"refmsg_time"`
  248. RespondTime string `json:"respond_time"`
  249. Signtype interface{} `json:"signtype"`
  250. WarnMsg interface{} `json:"warn_msg"`
  251. }
  252. type ResultNine struct {
  253. Cainfo string `json:"cainfo"`
  254. ErrMsg string `json:"err_msg"`
  255. InfRefmsgid string `json:"inf_refmsgid"`
  256. Infcode int64 `json:"infcode"`
  257. Output struct {
  258. FileQuryNo string `json:"file_qury_no"`
  259. } `json:"output"`
  260. RefmsgTime string `json:"refmsg_time"`
  261. RespondTime string `json:"respond_time"`
  262. Signtype interface{} `json:"signtype"`
  263. WarnMsg interface{} `json:"warn_msg"`
  264. }
  265. type ResultTen struct {
  266. Cainfo string `json:"cainfo"`
  267. ErrMsg string `json:"err_msg"`
  268. InfRefmsgid string `json:"inf_refmsgid"`
  269. Infcode int64 `json:"infcode"`
  270. Output struct {
  271. DldEndtime string `json:"dld_endtime"`
  272. FileQuryNo string `json:"file_qury_no"`
  273. Filename string `json:"filename"`
  274. } `json:"output"`
  275. RefmsgTime string `json:"refmsg_time"`
  276. RespondTime string `json:"respond_time"`
  277. Signtype interface{} `json:"signtype"`
  278. WarnMsg interface{} `json:"warn_msg"`
  279. }
  280. type ResultEleven struct {
  281. Cainfo string `json:"cainfo"`
  282. ErrMsg string `json:"err_msg"`
  283. InfRefmsgid string `json:"inf_refmsgid"`
  284. Infcode int64 `json:"infcode"`
  285. Output struct {
  286. Setlinfo struct {
  287. FixmedinsName string `json:"fixmedins_name"`
  288. FixmedinsCode string `json:"fixmedins_code"`
  289. PsnNo string `json:"psn_no"`
  290. PsnName string `json:"psn_name"`
  291. HifobPay float64 `json:"hifob_pay"`
  292. Gend string `json:"gend"`
  293. Brdy string `json:"brdy"`
  294. PsnCertType string `json:"psn_cert_type"`
  295. PsnType string `json:"psn_type"`
  296. EmpName string `json:"emp_name"`
  297. Certno string `json:"certno"`
  298. Insutype string `json:"insutype"`
  299. MedfeeSumamt float64 `json:"medfee_sumamt"`
  300. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  301. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  302. PreselfpayAmt float64 `json:"preselfpay_amt"`
  303. InscpScpAmt float64 `json:"inscp_scp_amt"`
  304. ActPayDedc float64 `json:"act_pay_dedc"`
  305. HifpPay float64 `json:"hifp_pay"`
  306. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  307. CvlservPay float64 `json:"cvlserv_pay"`
  308. HifesPay float64 `json:"hifes_pay"`
  309. HifmiPay float64 `json:"hifmi_pay"`
  310. MafPay float64 `json:"maf_pay"`
  311. OthPay float64 `json:"oth_pay"`
  312. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  313. PsnPay float64 `json:"psn_pay"`
  314. AcctPay float64 `json:"acct_pay"`
  315. CashPayamt float64 `json:"cash_payamt"`
  316. Balc float64 `json:"balc"`
  317. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  318. MedinsSetlId string `json:"medins_setl_id"`
  319. RefdSetlFlag string `json:"refd_setl_flag"`
  320. SetlTime string `json:"setl_time"`
  321. } `json:"setlinfo"`
  322. } `json:"output"`
  323. RefmsgTime string `json:"refmsg_time"`
  324. RespondTime string `json:"respond_time"`
  325. Signtype interface{} `json:"signtype"`
  326. WarnMsg interface{} `json:"warn_msg"`
  327. }
  328. type Custom struct {
  329. DetItemFeeSumamt string
  330. Cut string
  331. FeedetlSn string
  332. Price string
  333. MedListCodg string
  334. Type int64
  335. AdviceId int64
  336. ProjectId int64
  337. ItemId int64
  338. }
  339. //获取个人信息----挂号-----上传就诊信息
  340. func (c *HisApiController) GetRegisterInfo() {
  341. id, _ := c.GetInt64("id")
  342. record_time := c.GetString("record_time")
  343. name := c.GetString("name")
  344. gender, _ := c.GetInt64("gender")
  345. age, _ := c.GetInt64("age")
  346. birthday := c.GetString("birthday")
  347. phone := c.GetString("phone")
  348. medical_care, _ := c.GetInt64("medical_care")
  349. id_card := c.GetString("id_card")
  350. register_type, _ := c.GetInt64("register_type")
  351. registration_fee, _ := c.GetFloat("registration_fee")
  352. medical_expenses, _ := c.GetFloat("medical_expenses")
  353. certificates, _ := c.GetInt64("certificates")
  354. settlementValue, _ := c.GetInt64("settlement_value")
  355. social_type, _ := c.GetInt64("social_type")
  356. medical_insurance_card := c.GetString("medical_insurance_card")
  357. timeLayout := "2006-01-02"
  358. loc, _ := time.LoadLocation("Local")
  359. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  360. birthUnix := birthdays.Unix()
  361. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  362. if err != nil {
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. recordDateTime := theTime.Unix()
  367. adminInfo := c.GetAdminUserInfo()
  368. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  369. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  370. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  371. fmt.Println(miConfig.SecretKey)
  372. if patient == nil {
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  374. return
  375. }
  376. if len(patient.IdCardNo) == 0 {
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  378. return
  379. }
  380. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  381. if config.IsOpen == 1 {
  382. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  383. resp, requestErr := http.Get(api)
  384. if requestErr != nil {
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  386. return
  387. }
  388. defer resp.Body.Close()
  389. body, ioErr := ioutil.ReadAll(resp.Body)
  390. if ioErr != nil {
  391. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  393. return
  394. }
  395. var respJSON map[string]interface{}
  396. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  397. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  399. return
  400. }
  401. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  402. userJSONBytes, _ := json.Marshal(userJSON)
  403. var res ResultTwo
  404. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  405. utils.ErrorLog("解析失败:%v", err)
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  407. return
  408. }
  409. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  410. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  411. infoStr := string(Iinfos)
  412. idetinfoStr := string(Idetinfos)
  413. if res.Infcode == 0 {
  414. his := models.VMHisPatient{
  415. Name: name,
  416. Gender: gender,
  417. Birthday: birthUnix,
  418. MedicalTreatmentType: medical_care,
  419. IdType: certificates,
  420. IdCardNo: id_card,
  421. BalanceAccountsType: settlementValue,
  422. SocialType: social_type,
  423. MedicalInsuranceNumber: medical_insurance_card,
  424. RegisterType: register_type,
  425. RegisterCost: registration_fee,
  426. TreatmentCost: medical_expenses,
  427. Status: 1,
  428. Ctime: time.Now().Unix(),
  429. Mtime: time.Now().Unix(),
  430. PsnNo: res.Output.Baseinfo.PsnNo,
  431. PsnCertType: res.Output.Baseinfo.PsnCertType,
  432. Certno: res.Output.Baseinfo.Certno,
  433. PsnName: res.Output.Baseinfo.PsnName,
  434. Gend: res.Output.Baseinfo.Gend,
  435. Naty: res.Output.Baseinfo.Naty,
  436. Brdy: res.Output.Baseinfo.Brdy,
  437. Age: res.Output.Baseinfo.Age,
  438. Iinfo: infoStr,
  439. Idetinfo: idetinfoStr,
  440. PatientId: patient.ID,
  441. RecordDate: theTime.Unix(),
  442. UserOrgId: adminInfo.CurrentOrgId,
  443. AdminUserId: adminInfo.AdminUser.Id,
  444. IsReturn: 1,
  445. }
  446. timestamp := time.Now().Unix()
  447. tempTime := time.Unix(timestamp, 0)
  448. timeFormat := tempTime.Format("20060102150405")
  449. chrgBchno := rand.Intn(100000) + 10000
  450. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  451. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  452. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  453. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  454. fmt.Println(miConfig.SecretKey)
  455. if count <= 0 {
  456. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  457. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  458. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  459. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  460. resp, requestErr := http.Get(api)
  461. if requestErr != nil {
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  463. return
  464. }
  465. defer resp.Body.Close()
  466. body, ioErr := ioutil.ReadAll(resp.Body)
  467. if ioErr != nil {
  468. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  470. return
  471. }
  472. var respJSON map[string]interface{}
  473. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  474. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  476. return
  477. }
  478. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  479. userJSONBytes, _ := json.Marshal(respJSON)
  480. var res ResultThree
  481. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  482. utils.ErrorLog("解析失败:%v", err)
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  484. return
  485. }
  486. if res.Infcode == -1 {
  487. adminUser := c.GetAdminUserInfo()
  488. errlog := &models.HisOrderError{
  489. UserOrgId: adminUser.CurrentOrgId,
  490. Ctime: time.Now().Unix(),
  491. Mtime: time.Now().Unix(),
  492. ErrMsg: res.ErrMsg,
  493. Status: 1,
  494. PatientId: id,
  495. RecordTime: recordDateTime,
  496. Stage: 2,
  497. }
  498. service.CreateErrMsgLog(errlog)
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  500. return
  501. }
  502. his.Number = res.Output.Data.MdtrtID
  503. his.PsnNo = res.Output.Data.PsnNo
  504. his.IptOtpNo = res.Output.Data.IptOtpNo
  505. his.IdCardNo = patient.IdCardNo
  506. his.PhoneNumber = patient.Phone
  507. his.UserOrgId = adminInfo.CurrentOrgId
  508. his.Ctime = time.Now().Unix()
  509. his.Mtime = time.Now().Unix()
  510. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  511. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  512. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  513. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  514. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  515. resp2, requestErr2 := http.Get(api2)
  516. if requestErr2 != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. return
  519. }
  520. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  521. if ioErr2 != nil {
  522. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. var respJSON2 map[string]interface{}
  527. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  528. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  530. return
  531. }
  532. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  533. userJSONBytes2, _ := json.Marshal(respJSON2)
  534. var res2 ResultSix
  535. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  536. utils.ErrorLog("解析失败:%v", err)
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  538. return
  539. }
  540. if res2.Infcode == -1 {
  541. adminUser := c.GetAdminUserInfo()
  542. errlog := &models.HisOrderError{
  543. UserOrgId: adminUser.CurrentOrgId,
  544. Ctime: time.Now().Unix(),
  545. Mtime: time.Now().Unix(),
  546. ErrMsg: res2.ErrMsg,
  547. Status: 1,
  548. PatientId: id,
  549. RecordTime: recordDateTime,
  550. Stage: 3,
  551. }
  552. service.CreateErrMsgLog(errlog)
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  554. return
  555. }
  556. his.Status = 1
  557. service.CreateHisPatientTwo(&his)
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "his_info": his,
  560. })
  561. } else {
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  563. return
  564. }
  565. } else {
  566. adminUser := c.GetAdminUserInfo()
  567. errlog := &models.HisOrderError{
  568. UserOrgId: adminUser.CurrentOrgId,
  569. Ctime: time.Now().Unix(),
  570. Mtime: time.Now().Unix(),
  571. ErrMsg: res.ErrMsg,
  572. Status: 1,
  573. PatientId: id,
  574. RecordTime: recordDateTime,
  575. Stage: 1,
  576. }
  577. service.CreateErrMsgLog(errlog)
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  579. return
  580. }
  581. } else {
  582. timeStr := time.Now().Format("2006-01-02")
  583. timeArr := strings.Split(timeStr, "-")
  584. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  585. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  586. var hisPatient models.XtHisPatient
  587. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  588. hisPatient = models.XtHisPatient{
  589. Name: name,
  590. Age: age,
  591. Gender: gender,
  592. Birthday: birthUnix,
  593. Phone: phone,
  594. MedicalTreatmentType: medical_care,
  595. IdType: certificates,
  596. IdCardNo: id_card,
  597. BalanceAccountsType: settlementValue,
  598. SocialType: social_type,
  599. MedicalInsuranceNumber: medical_insurance_card,
  600. RegisterType: register_type,
  601. RegisterCost: registration_fee,
  602. TreatmentCost: medical_expenses,
  603. AdminUserId: adminInfo.AdminUser.Id,
  604. UserOrgId: adminInfo.CurrentOrgId,
  605. Status: 1,
  606. RecordDate: recordDateTime,
  607. IsReturn: 1,
  608. PatientId: patient.ID,
  609. Ctime: time.Now().Unix(),
  610. Mtime: time.Now().Unix(),
  611. Number: str,
  612. }
  613. service.CreateHisPatient(&hisPatient)
  614. }
  615. c.ServeSuccessJSON(map[string]interface{}{
  616. "his_info": hisPatient,
  617. })
  618. }
  619. }
  620. //上传明细----结算
  621. func (c *HisApiController) GetUploadInfo() {
  622. id, _ := c.GetInt64("id")
  623. record_time := c.GetString("record_time")
  624. pay_way, _ := c.GetInt64("pay_way")
  625. pay_price, _ := c.GetFloat("pay_price")
  626. pay_card_no := c.GetString("pay_card_no")
  627. discount_price, _ := c.GetFloat("discount_price")
  628. preferential_price, _ := c.GetFloat("preferential_price")
  629. reality_price, _ := c.GetFloat("reality_price")
  630. found_price, _ := c.GetFloat("found_price")
  631. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  632. private_price, _ := c.GetFloat("private_price")
  633. timeLayout := "2006-01-02"
  634. loc, _ := time.LoadLocation("Local")
  635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  636. if err != nil {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  638. return
  639. }
  640. recordDateTime := theTime.Unix()
  641. adminUser := c.GetAdminUserInfo()
  642. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  643. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  644. timestamp := time.Now().Unix()
  645. tempTime := time.Unix(timestamp, 0)
  646. timeFormat := tempTime.Format("20060102150405")
  647. chrgBchno := rand.Intn(100000) + 10000
  648. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  649. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  650. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  651. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  652. strconv.FormatInt(his.PatientId, 10)
  653. client := &http.Client{}
  654. data := make(map[string]interface{})
  655. data["psn_no"] = his.PsnNo
  656. data["mdtrt_id"] = his.Number
  657. data["pre"] = prescriptions
  658. data["chrg_bchno"] = chrg_bchno
  659. data["org_name"] = miConfig.OrgName
  660. data["doctor"] = patientPrescription.Doctor
  661. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  662. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  663. data["fixmedins_code"] = miConfig.Code
  664. data["dept_code"] = department.Number
  665. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  666. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  667. data["secret_key"] = miConfig.SecretKey
  668. var ids []int64
  669. for _, item := range prescriptions {
  670. ids = append(ids, item.ID)
  671. }
  672. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  673. if config.IsOpen == 1 { //对接了医保,走医保流程
  674. bytesData, _ := json.Marshal(data)
  675. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  676. resp, _ := client.Do(req)
  677. defer resp.Body.Close()
  678. body, ioErr := ioutil.ReadAll(resp.Body)
  679. if ioErr != nil {
  680. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  682. return
  683. }
  684. var respJSON map[string]interface{}
  685. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  686. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  688. return
  689. }
  690. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  691. userJSONBytes, _ := json.Marshal(respJSON)
  692. var res ResultFour
  693. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  694. utils.ErrorLog("解析失败:%v", err)
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  696. return
  697. }
  698. if res.Infcode == 0 {
  699. order := &models.HisOrder{
  700. UserOrgId: adminUser.CurrentOrgId,
  701. HisPatientId: his.ID,
  702. PatientId: his.PatientId,
  703. SettleAccountsDate: recordDateTime,
  704. Ctime: time.Now().Unix(),
  705. Mtime: time.Now().Unix(),
  706. Status: 1,
  707. Number: chrg_bchno,
  708. Infcode: res.Infcode,
  709. WarnMsg: res.WarnMsg,
  710. Cainfo: res.Cainfo,
  711. ErrMsg: res.ErrMsg,
  712. RespondTime: res.RefmsgTime,
  713. InfRefmsgid: res.InfRefmsgid,
  714. OrderStatus: 1,
  715. PayWay: pay_way,
  716. PayPrice: pay_price,
  717. PayCardNo: pay_card_no,
  718. DiscountPrice: discount_price,
  719. PreferentialPrice: preferential_price,
  720. RealityPrice: reality_price,
  721. FoundPrice: found_price,
  722. MedicalInsurancePrice: medical_insurance_price,
  723. PrivatePrice: private_price,
  724. IsMedicineInsurance: 1,
  725. }
  726. err = service.CreateOrder(order)
  727. if err != nil {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  729. return
  730. }
  731. for _, item := range res.Output.Result {
  732. temp := strings.Split(item.FeedetlSn, "-")
  733. var advice_id int64 = 0
  734. var project_id int64 = 0
  735. var types int64 = 0
  736. id, _ := strconv.ParseInt(temp[2], 10, 64)
  737. types, _ = strconv.ParseInt(temp[1], 10, 64)
  738. if temp[1] == "1" {
  739. advice_id = id
  740. project_id = 0
  741. } else if temp[1] == "2" {
  742. advice_id = 0
  743. project_id = id
  744. }
  745. info := &models.HisOrderInfo{
  746. OrderNumber: order.Number,
  747. FeedetlSn: item.FeedetlSn,
  748. UploadDate: time.Now().Unix(),
  749. AdviceId: advice_id,
  750. DetItemFeeSumamt: item.DetItemFeeSumamt,
  751. Cnt: item.Cnt,
  752. Pric: float64(item.Pric),
  753. PatientId: his.PatientId,
  754. PricUplmtAmt: item.PricUplmtAmt,
  755. SelfpayProp: item.SelfpayProp,
  756. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  757. OverlmtAmt: item.OverlmtAmt,
  758. PreselfpayAmt: item.PreselfpayAmt,
  759. BasMednFlag: item.BasMednFlag,
  760. MedChrgitmType: item.MedChrgitmType,
  761. HiNegoDrugFlag: item.HiNegoDrugFlag,
  762. Status: 1,
  763. Memo: item.Memo,
  764. Mtime: time.Now().Unix(),
  765. InscpScpAmt: item.InscpScpAmt,
  766. DrtReimFlag: item.DrtReimFlag,
  767. Ctime: time.Now().Unix(),
  768. ListSpItemFlag: item.ListSpItemFlag,
  769. ChldMedcFlag: item.ChldMedcFlag,
  770. LmtUsedFlag: item.LmtUsedFlag,
  771. ChrgitmLv: item.ChrgitmLv,
  772. UserOrgId: adminUser.CurrentOrgId,
  773. HisPatientId: his.ID,
  774. OrderId: order.ID,
  775. ProjectId: project_id,
  776. Type: types,
  777. }
  778. service.CreateOrderInfo(info)
  779. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  780. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  781. var total float64
  782. for _, item := range prescriptions {
  783. if item.Type == 1 { //药品
  784. for _, subItem := range item.HisDoctorAdviceInfo {
  785. total = total + (subItem.Price * subItem.PrescribingNumber)
  786. }
  787. }
  788. if item.Type == 2 { //项目
  789. for _, subItem := range item.HisPrescriptionProject {
  790. total = total + (subItem.Price * float64(subItem.Count))
  791. }
  792. }
  793. }
  794. allTotal := fmt.Sprintf("%.2f", total)
  795. if res.Infcode == 0 {
  796. var rf []*ResultFive
  797. json.Unmarshal([]byte(his.Iinfo), &rf)
  798. psn_no := his.PsnNo
  799. mdtrt_id := his.Number
  800. chrg_bchno := chrg_bchno
  801. cert_no := his.Certno
  802. insutype := rf[0].Insutype
  803. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  804. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  805. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  806. resp, requestErr := http.Get(api)
  807. if requestErr != nil {
  808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  809. return
  810. }
  811. defer resp.Body.Close()
  812. body, ioErr := ioutil.ReadAll(resp.Body)
  813. if ioErr != nil {
  814. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  816. return
  817. }
  818. var respJSON map[string]interface{}
  819. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  820. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  822. return
  823. }
  824. fmt.Println(respJSON)
  825. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  826. userJSONBytes, _ := json.Marshal(respJSON)
  827. var res ResultSeven
  828. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  829. utils.ErrorLog("解析失败:%v", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  831. return
  832. }
  833. if res.Infcode == -1 {
  834. errlog := &models.HisOrderError{
  835. UserOrgId: adminUser.CurrentOrgId,
  836. Ctime: time.Now().Unix(),
  837. Mtime: time.Now().Unix(),
  838. Number: chrg_bchno,
  839. ErrMsg: res.ErrMsg,
  840. Status: 1,
  841. PatientId: id,
  842. RecordTime: recordDateTime,
  843. Stage: 7,
  844. }
  845. service.CreateErrMsgLog(errlog)
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  847. return
  848. } else {
  849. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  850. order.OrderStatus = 2
  851. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  852. order.SetlId = res.Output.Setlinfo.SetlID
  853. order.PsnNo = res.Output.Setlinfo.PsnNo
  854. order.PsnName = res.Output.Setlinfo.PsnName
  855. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  856. order.Certno = res.Output.Setlinfo.Certno
  857. order.Gend = res.Output.Setlinfo.Gend
  858. order.Naty = res.Output.Setlinfo.Naty
  859. order.Age = res.Output.Setlinfo.Age
  860. order.Insutype = res.Output.Setlinfo.Insutype
  861. order.PsnType = res.Output.Setlinfo.PsnType
  862. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  863. order.SetlTime = res.Output.Setlinfo.SetlTime
  864. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  865. order.MedType = res.Output.Setlinfo.MedType
  866. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  867. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  868. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  869. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  870. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  871. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  872. order.HifpPay = res.Output.Setlinfo.HifpPay
  873. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  874. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  875. order.HifesPay = res.Output.Setlinfo.HifesPay
  876. order.HifobPay = res.Output.Setlinfo.HifobPay
  877. order.MafPay = res.Output.Setlinfo.MafPay
  878. order.OthPay = res.Output.Setlinfo.OthPay
  879. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  880. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  881. order.AcctPay = res.Output.Setlinfo.AcctPay
  882. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  883. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  884. order.Balc = res.Output.Setlinfo.Balc
  885. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  886. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  887. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  888. order.ClrWay = res.Output.Setlinfo.ClrWay
  889. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  890. detailStr := string(setlDetail)
  891. order.SetlDetail = detailStr
  892. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  893. err = service.UpDateOrder(order)
  894. if err == nil {
  895. c.ServeSuccessJSON(map[string]interface{}{
  896. "msg": "结算成功",
  897. })
  898. } else {
  899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  900. return
  901. }
  902. }
  903. } else {
  904. adminUser := c.GetAdminUserInfo()
  905. errlog := &models.HisOrderError{
  906. UserOrgId: adminUser.CurrentOrgId,
  907. Ctime: time.Now().Unix(),
  908. Mtime: time.Now().Unix(),
  909. ErrMsg: res.ErrMsg,
  910. Status: 1,
  911. PatientId: id,
  912. RecordTime: recordDateTime,
  913. Stage: 5,
  914. }
  915. service.CreateErrMsgLog(errlog)
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  917. return
  918. }
  919. }
  920. } else {
  921. adminUser := c.GetAdminUserInfo()
  922. errlog := &models.HisOrderError{
  923. UserOrgId: adminUser.CurrentOrgId,
  924. Ctime: time.Now().Unix(),
  925. Mtime: time.Now().Unix(),
  926. ErrMsg: res.ErrMsg,
  927. Status: 1,
  928. PatientId: id,
  929. RecordTime: recordDateTime,
  930. Stage: 4,
  931. }
  932. service.CreateErrMsgLog(errlog)
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  934. return
  935. }
  936. } else {
  937. var total float64
  938. for _, item := range prescriptions {
  939. if item.Type == 1 { //药品
  940. for _, subItem := range item.HisDoctorAdviceInfo {
  941. total = total + (subItem.Price * subItem.PrescribingNumber)
  942. }
  943. }
  944. if item.Type == 2 { //项目
  945. for _, subItem := range item.HisPrescriptionProject {
  946. total = total + (subItem.Price * float64(subItem.Count))
  947. }
  948. }
  949. for _, subItem := range item.HisAdditionalCharge {
  950. total = total + (subItem.Price * float64(subItem.Count))
  951. }
  952. }
  953. allTotal := fmt.Sprintf("%.2f", total)
  954. totals, _ := strconv.ParseFloat(allTotal, 64)
  955. order := &models.HisOrder{
  956. UserOrgId: adminUser.CurrentOrgId,
  957. HisPatientId: his.ID,
  958. PatientId: id,
  959. SettleAccountsDate: recordDateTime,
  960. Ctime: time.Now().Unix(),
  961. Mtime: time.Now().Unix(),
  962. Status: 1,
  963. OrderStatus: 2,
  964. Number: chrg_bchno,
  965. MedfeeSumamt: totals,
  966. PayWay: pay_way,
  967. PayPrice: pay_price,
  968. PayCardNo: pay_card_no,
  969. DiscountPrice: discount_price,
  970. PreferentialPrice: preferential_price,
  971. RealityPrice: reality_price,
  972. FoundPrice: found_price,
  973. MedicalInsurancePrice: medical_insurance_price,
  974. PrivatePrice: private_price,
  975. }
  976. err = service.CreateOrder(order)
  977. if err != nil {
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  979. return
  980. }
  981. var customs []*Custom
  982. for _, item := range prescriptions {
  983. if item.Type == 1 { //药品
  984. for _, subItem := range item.HisDoctorAdviceInfo {
  985. cus := &Custom{
  986. AdviceId: subItem.ID,
  987. ProjectId: 0,
  988. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  989. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  990. FeedetlSn: subItem.FeedetlSn,
  991. Price: fmt.Sprintf("%.2f", subItem.Price),
  992. MedListCodg: subItem.MedListCodg,
  993. Type: 1,
  994. }
  995. customs = append(customs, cus)
  996. }
  997. }
  998. if item.Type == 2 { //项目
  999. for _, subItem := range item.HisPrescriptionProject {
  1000. cus := &Custom{
  1001. AdviceId: 0,
  1002. ProjectId: subItem.ID,
  1003. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1004. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1005. FeedetlSn: subItem.FeedetlSn,
  1006. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1007. MedListCodg: subItem.MedListCodg,
  1008. Type: 2,
  1009. }
  1010. customs = append(customs, cus)
  1011. }
  1012. }
  1013. for _, item := range item.HisAdditionalCharge {
  1014. cus := &Custom{
  1015. ItemId: item.ID,
  1016. AdviceId: 0,
  1017. ProjectId: 0,
  1018. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1019. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1020. FeedetlSn: item.FeedetlSn,
  1021. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1022. MedListCodg: item.XtHisAddtionConfig.Code,
  1023. Type: 3,
  1024. }
  1025. customs = append(customs, cus)
  1026. }
  1027. }
  1028. for _, item := range customs {
  1029. var advice_id int64 = 0
  1030. var project_id int64 = 0
  1031. var item_id int64 = 0
  1032. var types int64 = 0
  1033. if item.Type == 1 {
  1034. advice_id = item.AdviceId
  1035. project_id = 0
  1036. item_id = 0
  1037. } else if item.Type == 2 {
  1038. advice_id = 0
  1039. item_id = 0
  1040. project_id = item.ProjectId
  1041. } else if item.Type == 3 {
  1042. advice_id = 0
  1043. item_id = item.ItemId
  1044. project_id = 0
  1045. }
  1046. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1047. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1048. pric, _ := strconv.ParseFloat(item.Price, 32)
  1049. info := &models.HisOrderInfo{
  1050. OrderNumber: order.Number,
  1051. UploadDate: time.Now().Unix(),
  1052. AdviceId: advice_id,
  1053. DetItemFeeSumamt: detItemFeeSumamt,
  1054. Cnt: cut,
  1055. Pric: pric,
  1056. PatientId: id,
  1057. Status: 1,
  1058. Mtime: time.Now().Unix(),
  1059. Ctime: time.Now().Unix(),
  1060. UserOrgId: adminUser.CurrentOrgId,
  1061. HisPatientId: his.ID,
  1062. OrderId: order.ID,
  1063. ProjectId: project_id,
  1064. Type: types,
  1065. ItemId: item_id,
  1066. }
  1067. service.CreateOrderInfo(info)
  1068. }
  1069. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1070. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1071. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1072. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1073. if err == nil {
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "msg": "结算成功",
  1076. })
  1077. } else {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1079. return
  1080. }
  1081. }
  1082. }
  1083. //退款
  1084. func (c *HisApiController) Refund() {
  1085. order_id, _ := c.GetInt64("order_id")
  1086. number := c.GetString("number")
  1087. record_time := c.GetString("record_time")
  1088. patient_id, _ := c.GetInt64("patient_id")
  1089. timeLayout := "2006-01-02"
  1090. loc, _ := time.LoadLocation("Local")
  1091. adminUser := c.GetAdminUserInfo()
  1092. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1093. fmt.Println(err)
  1094. if err != nil {
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1096. return
  1097. }
  1098. recordDateTime := theTime.Unix()
  1099. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1100. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1101. order, _ := service.GetHisOrderByID(order_id)
  1102. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1103. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1104. if config.IsOpen == 1 { //对接了医保,走医保流程
  1105. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1106. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1107. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1108. resp, requestErr := http.Get(api)
  1109. if requestErr != nil {
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1111. return
  1112. }
  1113. body, ioErr := ioutil.ReadAll(resp.Body)
  1114. if ioErr != nil {
  1115. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. return
  1118. }
  1119. var respJSON map[string]interface{}
  1120. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1121. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1123. return
  1124. }
  1125. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1126. userJSONBytes, _ := json.Marshal(respJSON)
  1127. fmt.Println(respJSON)
  1128. fmt.Println(userJSONBytes)
  1129. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1130. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1131. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1132. resp2, requestErr2 := http.Get(api2)
  1133. if requestErr2 != nil {
  1134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1135. return
  1136. }
  1137. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1138. if ioErr2 != nil {
  1139. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. var respJSON2 map[string]interface{}
  1144. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1145. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1147. return
  1148. }
  1149. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1150. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1151. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1152. resp3, requestErr3 := http.Get(api3)
  1153. if requestErr3 != nil {
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1155. return
  1156. }
  1157. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1158. if ioErr3 != nil {
  1159. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1161. return
  1162. }
  1163. var respJSON3 map[string]interface{}
  1164. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1165. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1167. return
  1168. }
  1169. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1170. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1171. if err == nil {
  1172. c.ServeSuccessJSON(map[string]interface{}{
  1173. "msg": "退费成功",
  1174. })
  1175. } else {
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1177. return
  1178. }
  1179. } else {
  1180. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1181. if err == nil {
  1182. c.ServeSuccessJSON(map[string]interface{}{
  1183. "msg": "退费成功",
  1184. })
  1185. } else {
  1186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1187. return
  1188. }
  1189. }
  1190. }
  1191. //对账
  1192. func (c *HisApiController) GetCheckAccount() {
  1193. start_time := c.GetString("start_time")
  1194. end_time := c.GetString("end_time")
  1195. insutype := c.GetString("insutype")
  1196. clr_type := c.GetString("clr_type")
  1197. adminUser := c.GetAdminUserInfo()
  1198. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1199. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1203. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1204. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1205. decimal.DivisionPrecision = 2
  1206. var medfee_sumamt float64
  1207. var acct_pay float64
  1208. var fund_pay_sumamt float64
  1209. fixmedins_setl_cnt := int64(len(orders))
  1210. for _, item := range orders {
  1211. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1212. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1213. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1214. }
  1215. var user_name string
  1216. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1217. if role.ID == 0 {
  1218. user_name = "xxx"
  1219. } else {
  1220. user_name = role.UserName
  1221. }
  1222. if config.IsOpen == 1 {
  1223. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1224. "insutype=" + insutype +
  1225. "&clr_type=" + clr_type +
  1226. "&setl_optins=" + miConfig.OrgName +
  1227. "&stmt_begndate=" + start_time +
  1228. "&stm_enddate=" + end_time +
  1229. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1230. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1231. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1232. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1233. "&fixmedins_code=" + miConfig.Code +
  1234. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1235. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1236. "&secret_key=" + miConfig.SecretKey +
  1237. "&org_name=" + miConfig.OrgName +
  1238. "&doctor=" + user_name
  1239. fmt.Println(api)
  1240. resp, requestErr := http.Get(api)
  1241. if requestErr != nil {
  1242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1243. return
  1244. }
  1245. body, ioErr := ioutil.ReadAll(resp.Body)
  1246. fmt.Println(body)
  1247. if ioErr != nil {
  1248. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1250. return
  1251. }
  1252. var respJSON map[string]interface{}
  1253. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1254. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1256. return
  1257. }
  1258. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1259. userJSONBytes, _ := json.Marshal(respJSON)
  1260. var res ResultEight
  1261. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1262. utils.ErrorLog("解析失败:%v", err)
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1264. return
  1265. }
  1266. if res.Infcode == 0 {
  1267. c.ServeSuccessJSON(map[string]interface{}{
  1268. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1269. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1270. })
  1271. } else {
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1273. }
  1274. }
  1275. }
  1276. //对账明细
  1277. func (c *HisApiController) GetCheckDetailAccount() {
  1278. start_time := c.GetString("start_time")
  1279. end_time := c.GetString("end_time")
  1280. adminUser := c.GetAdminUserInfo()
  1281. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1282. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1283. timeLayout := "2006-01-02"
  1284. loc, _ := time.LoadLocation("Local")
  1285. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1286. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1287. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1288. Mkdir(miConfig.OrgName)
  1289. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1290. file_name := file + ".txt"
  1291. zip_name := file + ".zip"
  1292. zip_path := miConfig.OrgName + "/" + zip_name
  1293. file_path := miConfig.OrgName + "/" + file_name
  1294. decimal.DivisionPrecision = 2
  1295. var medfee_sumamt float64
  1296. var psn_cash_pay float64
  1297. var fund_pay_sumamt float64
  1298. fixmedins_setl_cnt := int64(len(orders))
  1299. for _, item := range orders {
  1300. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1301. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1302. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1303. }
  1304. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1305. defer f.Close()
  1306. if err != nil {
  1307. fmt.Println(err.Error())
  1308. } else {
  1309. for _, item := range orders {
  1310. var refd_setl_flag string
  1311. if item.OrderStatus == 2 {
  1312. refd_setl_flag = "0"
  1313. }
  1314. if item.OrderStatus == 3 {
  1315. refd_setl_flag = "1"
  1316. }
  1317. var str string
  1318. str = item.SetlId + " " +
  1319. item.MdtrtId + " " +
  1320. item.PsnNo + " " +
  1321. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1322. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1323. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1324. _, err = f.Write([]byte(str))
  1325. }
  1326. }
  1327. Zip(file_path, zip_path)
  1328. fmt.Println(ReadFile(zip_path))
  1329. fmt.Println(string(ReadFile(zip_path)))
  1330. if config.IsOpen == 1 {
  1331. var user_name string
  1332. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1333. if role.ID == 0 {
  1334. user_name = "xxx"
  1335. } else {
  1336. user_name = role.UserName
  1337. }
  1338. baseParams := models.BaseParams{
  1339. SecretKey: miConfig.SecretKey,
  1340. FixmedinsCode: miConfig.Code,
  1341. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1342. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1343. OrgName: miConfig.OrgName,
  1344. Doctor: user_name,
  1345. }
  1346. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1347. var dat map[string]interface{}
  1348. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1349. fmt.Println(dat)
  1350. } else {
  1351. fmt.Println(err)
  1352. }
  1353. userJSONBytes, _ := json.Marshal(dat)
  1354. var res ResultNine
  1355. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1356. utils.ErrorLog("解析失败:%v", err)
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1358. return
  1359. }
  1360. if res.Infcode == 0 {
  1361. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1362. "file_qury_no=" + res.Output.FileQuryNo +
  1363. "&setl_optins=" + miConfig.OrgName +
  1364. "&stmt_begndate=" + start_time +
  1365. "&stm_enddate=" + end_time +
  1366. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1367. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1368. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1369. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1370. "&fixmedins_code=" + miConfig.Code +
  1371. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1372. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1373. "&secret_key=" + miConfig.SecretKey +
  1374. "&org_name=" + miConfig.OrgName +
  1375. "&doctor=" + user_name
  1376. resp, requestErr := http.Get(api)
  1377. if requestErr != nil {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1379. return
  1380. }
  1381. body, ioErr := ioutil.ReadAll(resp.Body)
  1382. if ioErr != nil {
  1383. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1385. return
  1386. }
  1387. var respJSON map[string]interface{}
  1388. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1389. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1391. return
  1392. }
  1393. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1394. userJSONBytes, _ := json.Marshal(respJSON)
  1395. var res ResultTen
  1396. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1397. utils.ErrorLog("解析失败:%v", err)
  1398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1399. return
  1400. }
  1401. if res.Infcode == 0 {
  1402. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1403. c.ServeSuccessJSON(map[string]interface{}{
  1404. "msg": "明细对账成功",
  1405. })
  1406. }
  1407. } else {
  1408. }
  1409. }
  1410. }
  1411. func (c *HisApiController) GetSettleAccounts() {
  1412. //id, _ := c.GetInt64("id")
  1413. //record_time := c.GetString("record_time")
  1414. order_id, _ := c.GetInt64("order_id")
  1415. //timeLayout := "2006-01-02"
  1416. //loc, _ := time.LoadLocation("Local")
  1417. //
  1418. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1419. //if err != nil {
  1420. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. // return
  1422. //}
  1423. //recordDateTime := theTime.Unix()
  1424. adminUser := c.GetAdminUserInfo()
  1425. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1426. order, _ := service.GetHisOrderByID(order_id)
  1427. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1428. var bedCostTotal float64 = 0 //床位总费
  1429. var bedCostSelfTotal float64 = 0 //床位自费
  1430. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1431. var operationCostTotal float64 = 0 //手术费
  1432. var operationCostSelfTotal float64 = 0 //手术费
  1433. var operationCostPartSelfTotal float64 = 0 //手术费
  1434. var otherCostTotal float64 = 0 //其他费用
  1435. var otherCostSelfTotal float64 = 0 //其他费用
  1436. var otherCostPartSelfTotal float64 = 0 //其他费用
  1437. var materialCostTotal float64 = 0 //材料费
  1438. var materialCostSelfTotal float64 = 0 //材料费
  1439. var materialCostPartSelfTotal float64 = 0 //材料费
  1440. var westernMedicineCostTotal float64 = 0 //西药费
  1441. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1442. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1443. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1444. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1445. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1446. var checkCostTotal float64 = 0 //检查费
  1447. var checkCostSelfTotal float64 = 0 //检查费
  1448. var checkCostPartSelfTotal float64 = 0 //检查费
  1449. var laboratoryCostTotal float64 = 0 //化验费
  1450. var laboratoryCostSelfTotal float64 = 0 //化验费
  1451. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1452. var treatCostTotal float64 = 0 //治疗费用
  1453. var treatCostSelfTotal float64 = 0 //治疗费用
  1454. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1455. decimal.DivisionPrecision = 2
  1456. for _, item := range orderInfos {
  1457. if item.MedChrgitmType == "01" { //床位费
  1458. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1459. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1460. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1461. }
  1462. if item.MedChrgitmType == "03" { //检查费
  1463. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1464. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1465. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1466. }
  1467. if item.MedChrgitmType == "04" { //化验费
  1468. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1469. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1470. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1471. }
  1472. if item.MedChrgitmType == "05" { //治疗费
  1473. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1474. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1475. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1476. }
  1477. if item.MedChrgitmType == "06" { //手术费
  1478. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1479. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1480. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1481. }
  1482. if item.MedChrgitmType == "08" { //材料费
  1483. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1484. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1485. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1486. }
  1487. if item.MedChrgitmType == "09" { //西药费
  1488. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1489. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1490. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1491. }
  1492. if item.MedChrgitmType == "11" { //中成费
  1493. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1494. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1495. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1496. }
  1497. if item.MedChrgitmType == "14" { //其他费
  1498. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1499. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1500. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1501. }
  1502. }
  1503. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1504. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1505. var user_name string
  1506. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1507. if role.ID == 0 {
  1508. user_name = "xxx"
  1509. } else {
  1510. user_name = role.UserName
  1511. }
  1512. baseParams := models.BaseParams{
  1513. SecretKey: miConfig.SecretKey,
  1514. FixmedinsCode: miConfig.Code,
  1515. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1516. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1517. OrgName: miConfig.OrgName,
  1518. Doctor: user_name,
  1519. }
  1520. businessParams := models.BusinessParams{
  1521. PsnNo: order.PsnNo,
  1522. MdtrtId: order.MdtrtId,
  1523. SetlId: order.SetlId,
  1524. }
  1525. if config.IsOpen == 1 {
  1526. result := service.Gdyb5203(baseParams, businessParams)
  1527. var dat map[string]interface{}
  1528. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1529. fmt.Println(dat)
  1530. } else {
  1531. fmt.Println(err)
  1532. }
  1533. userJSONBytes, _ := json.Marshal(dat)
  1534. var res ResultEleven
  1535. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1536. utils.ErrorLog("解析失败:%v", err)
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1538. return
  1539. }
  1540. if res.Infcode == 0 {
  1541. c.ServeSuccessJSON(map[string]interface{}{
  1542. "info": res.Output.Setlinfo,
  1543. "bedCostTotal": bedCostTotal,
  1544. "bedCostSelfTotal": bedCostSelfTotal,
  1545. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1546. "operationCostTotal": operationCostTotal,
  1547. "operationCostSelfTotal": operationCostSelfTotal,
  1548. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1549. "otherCostTotal": otherCostTotal,
  1550. "otherCostSelfTotal": otherCostSelfTotal,
  1551. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1552. "materialCostTotal": materialCostTotal,
  1553. "materialCostSelfTotal": materialCostSelfTotal,
  1554. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1555. "westernMedicineCostTotal": westernMedicineCostTotal,
  1556. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1557. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1558. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1559. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1560. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1561. "checkCostTotal": checkCostTotal,
  1562. "checkCostSelfTotal": checkCostSelfTotal,
  1563. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1564. "laboratoryCostTotal": laboratoryCostTotal,
  1565. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1566. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1567. "treatCostTotal": treatCostTotal,
  1568. "treatCostSelfTotal": treatCostSelfTotal,
  1569. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1570. })
  1571. }
  1572. }
  1573. }
  1574. func PathExists(path string) (bool, error) {
  1575. _, err := os.Stat(path)
  1576. if err == nil {
  1577. return true, nil
  1578. }
  1579. if os.IsNotExist(err) {
  1580. return false, nil
  1581. }
  1582. return false, err
  1583. }
  1584. //创建文件夹
  1585. func Mkdir(dir string) {
  1586. // 创建文件夹
  1587. exist, err := PathExists(dir)
  1588. if err != nil {
  1589. fmt.Println(err.Error())
  1590. } else {
  1591. if exist {
  1592. fmt.Println(dir + "文件夹已存在!")
  1593. } else {
  1594. // 文件夹名称,权限
  1595. err := os.Mkdir(dir, os.ModePerm)
  1596. if err != nil {
  1597. fmt.Println(dir+"文件夹创建失败:", err.Error())
  1598. } else {
  1599. fmt.Println(dir + "文件夹创建成功!")
  1600. }
  1601. }
  1602. }
  1603. }
  1604. //压缩文件
  1605. func Zip(srcFile string, destZip string) error {
  1606. zipfile, err := os.Create(destZip)
  1607. if err != nil {
  1608. return err
  1609. }
  1610. defer zipfile.Close()
  1611. archive := zip.NewWriter(zipfile)
  1612. defer archive.Close()
  1613. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  1614. if err != nil {
  1615. return err
  1616. }
  1617. header, err := zip.FileInfoHeader(info)
  1618. if err != nil {
  1619. return err
  1620. }
  1621. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  1622. // header.Name = path
  1623. if info.IsDir() {
  1624. header.Name += "/"
  1625. } else {
  1626. header.Method = zip.Deflate
  1627. }
  1628. writer, err := archive.CreateHeader(header)
  1629. if err != nil {
  1630. return err
  1631. }
  1632. if !info.IsDir() {
  1633. file, err := os.Open(path)
  1634. if err != nil {
  1635. return err
  1636. }
  1637. defer file.Close()
  1638. _, err = io.Copy(writer, file)
  1639. }
  1640. return err
  1641. })
  1642. return err
  1643. }
  1644. func ReadFile(filePath string) []byte {
  1645. f, err := os.Open(filePath)
  1646. if err != nil {
  1647. fmt.Println("read file fail", err)
  1648. return nil
  1649. }
  1650. defer f.Close()
  1651. fd, err := ioutil.ReadAll(f)
  1652. if err != nil {
  1653. fmt.Println("read to fd fail", err)
  1654. return nil
  1655. }
  1656. return fd
  1657. }