his_api_controller.go 75KB

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