his_api_controller.go 76KB

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