his_api_controller.go 65KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  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. if patient == nil {
  372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  373. return
  374. }
  375. if len(patient.IdCardNo) == 0 {
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  377. return
  378. }
  379. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  380. if config.IsOpen == 1 {
  381. 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
  382. resp, requestErr := http.Get(api)
  383. if requestErr != nil {
  384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  385. return
  386. }
  387. defer resp.Body.Close()
  388. body, ioErr := ioutil.ReadAll(resp.Body)
  389. if ioErr != nil {
  390. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  392. return
  393. }
  394. var respJSON map[string]interface{}
  395. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  396. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  398. return
  399. }
  400. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  401. userJSONBytes, _ := json.Marshal(userJSON)
  402. var res ResultTwo
  403. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  404. utils.ErrorLog("解析失败:%v", err)
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  406. return
  407. }
  408. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  409. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  410. infoStr := string(Iinfos)
  411. idetinfoStr := string(Idetinfos)
  412. if res.Infcode == 0 {
  413. his := models.VMHisPatient{
  414. Name: name,
  415. Gender: gender,
  416. Birthday: birthUnix,
  417. MedicalTreatmentType: medical_care,
  418. IdType: certificates,
  419. IdCardNo: id_card,
  420. BalanceAccountsType: settlementValue,
  421. SocialType: social_type,
  422. MedicalInsuranceNumber: medical_insurance_card,
  423. RegisterType: register_type,
  424. RegisterCost: registration_fee,
  425. TreatmentCost: medical_expenses,
  426. Status: 1,
  427. Ctime: time.Now().Unix(),
  428. Mtime: time.Now().Unix(),
  429. PsnNo: res.Output.Baseinfo.PsnNo,
  430. PsnCertType: res.Output.Baseinfo.PsnCertType,
  431. Certno: res.Output.Baseinfo.Certno,
  432. PsnName: res.Output.Baseinfo.PsnName,
  433. Gend: res.Output.Baseinfo.Gend,
  434. Naty: res.Output.Baseinfo.Naty,
  435. Brdy: res.Output.Baseinfo.Brdy,
  436. Age: res.Output.Baseinfo.Age,
  437. Iinfo: infoStr,
  438. Idetinfo: idetinfoStr,
  439. PatientId: patient.ID,
  440. RecordDate: theTime.Unix(),
  441. UserOrgId: adminInfo.CurrentOrgId,
  442. AdminUserId: adminInfo.AdminUser.Id,
  443. IsReturn: 1,
  444. }
  445. timestamp := time.Now().Unix()
  446. tempTime := time.Unix(timestamp, 0)
  447. timeFormat := tempTime.Format("20060102150405")
  448. chrgBchno := rand.Intn(100000) + 10000
  449. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  450. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  451. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  452. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  453. if count <= 0 {
  454. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  455. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  456. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  457. "&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
  458. resp, requestErr := http.Get(api)
  459. if requestErr != nil {
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  461. return
  462. }
  463. defer resp.Body.Close()
  464. body, ioErr := ioutil.ReadAll(resp.Body)
  465. if ioErr != nil {
  466. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  468. return
  469. }
  470. var respJSON map[string]interface{}
  471. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  472. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  474. return
  475. }
  476. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  477. userJSONBytes, _ := json.Marshal(respJSON)
  478. var res ResultThree
  479. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  480. utils.ErrorLog("解析失败:%v", err)
  481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  482. return
  483. }
  484. if res.Infcode == -1 {
  485. adminUser := c.GetAdminUserInfo()
  486. errlog := &models.HisOrderError{
  487. UserOrgId: adminUser.CurrentOrgId,
  488. Ctime: time.Now().Unix(),
  489. Mtime: time.Now().Unix(),
  490. ErrMsg: res.ErrMsg,
  491. Status: 1,
  492. PatientId: id,
  493. RecordTime: recordDateTime,
  494. Stage: 2,
  495. }
  496. service.CreateErrMsgLog(errlog)
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  498. return
  499. }
  500. his.Number = res.Output.Data.MdtrtID
  501. his.PsnNo = res.Output.Data.PsnNo
  502. his.IptOtpNo = res.Output.Data.IptOtpNo
  503. his.IdCardNo = patient.IdCardNo
  504. his.PhoneNumber = patient.Phone
  505. his.UserOrgId = adminInfo.CurrentOrgId
  506. his.Ctime = time.Now().Unix()
  507. his.Mtime = time.Now().Unix()
  508. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  509. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  510. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  511. "&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 +
  512. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  513. resp2, requestErr2 := http.Get(api2)
  514. if requestErr2 != nil {
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  516. return
  517. }
  518. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  519. if ioErr2 != nil {
  520. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  522. return
  523. }
  524. var respJSON2 map[string]interface{}
  525. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  526. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  528. return
  529. }
  530. respJSON2 = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  531. userJSONBytes2, _ := json.Marshal(respJSON2)
  532. fmt.Println(respJSON2)
  533. fmt.Println(userJSONBytes2)
  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. }