his_api_controller.go 86KB

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