his_api_controller.go 80KB

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