his_api_controller.go 150KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  32. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  35. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  36. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  37. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  38. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  39. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  40. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  41. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  42. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  43. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  44. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  45. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  46. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  47. beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo")
  48. beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  49. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  50. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  51. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  52. //备案撤销相关接口
  53. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  54. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  55. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  56. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  57. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  58. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  59. }
  60. //func (c *HisApiController) TestPay() {
  61. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  62. // readCards := DllDef2.MustFindProc("BankTrans")
  63. // inputData := make(map[string]interface{})
  64. // inputData["transId"] = "05"
  65. // inputData["amount"] = "0.01"
  66. // inputData["traceNo"] = "20210227093601325405377"
  67. // inputData["cardNo"] = "F36084348"
  68. // inputData["id"] = "44022919620927046X"
  69. // //jsonStr := `
  70. // // {
  71. // // "transId": "05",
  72. // // "amount":"1.00",
  73. // // "traceNo":"20210227093601325405377",
  74. // // "cardNo":"F36084348",
  75. // // "id":"44022919620927046X"
  76. // //
  77. // // }
  78. // //`
  79. //
  80. // bytes_arr, _ := json.Marshal(inputData)
  81. // str3 := make([]byte, 256)
  82. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  83. // fmt.Println(":", string(str3))
  84. //
  85. // if err4 != nil {
  86. // fmt.Println("SSCard的运算结果为:", ret4)
  87. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  88. // return
  89. // }
  90. //
  91. //}
  92. //func (c *HisApiController) TestGetBasBaseInfo() {
  93. //
  94. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  95. // //fmt.Println(result)
  96. // //cs1 := C.CString("")
  97. // //cs2 := C.CString("")
  98. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  99. // //fmt.Println(cs1)
  100. // //fmt.Println(cs2)
  101. // //C.free(unsafe.Pointer(cs1))
  102. // //C.free(unsafe.Pointer(cs2))
  103. //
  104. // //
  105. //
  106. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  107. // Iinit := DllDef.MustFindProc("Init")
  108. // readCard := DllDef.MustFindProc("ReadCardBas")
  109. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  110. // if ret != 0 {
  111. // fmt.Println("SSCard的报错原因:", err)
  112. // fmt.Println("SSCard的运算结果为:", ret)
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  114. // return
  115. // }
  116. //
  117. // result := int(ret)
  118. // fmt.Println("SSCard的运算结果为1:", result)
  119. //
  120. // //path := ""
  121. // //bytePath := []byte( "\x00")
  122. // //bytePath2 := []byte( "\x00")
  123. // //ssss
  124. //
  125. // str := make([]byte, 256)
  126. // str1 := make([]byte, 256)
  127. // s2 := []byte(string(str))
  128. // s3 := []byte(string(str1))
  129. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  130. // fmt.Println(" Add(4,5)的结果为:", ret2)
  131. // fmt.Println(" str:", s2)
  132. // fmt.Println(" str1:", s3)
  133. // if err2 != nil {
  134. // fmt.Println("SSCard的运算结果为:", ret2)
  135. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  136. // return
  137. // }
  138. //
  139. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  140. //
  141. //}
  142. func (c *HisApiController) GetOrgInfo() {
  143. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  144. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  145. }
  146. func (c *HisApiController) GetHisPatientInfo() {
  147. medical_insurance_card := c.GetString("medical_insurance_card")
  148. id_card_type, _ := c.GetInt64("id_card_type")
  149. id_card := c.GetString("id_card")
  150. adminInfo := c.GetAdminUserInfo()
  151. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  152. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  153. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  154. IdCardNo := ""
  155. if id_card_type == 1 {
  156. IdCardNo = medical_insurance_card
  157. } else if id_card_type == 2 {
  158. IdCardNo = id_card
  159. }
  160. if config.IsOpen == 1 {
  161. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  162. resp, requestErr := http.Get(api)
  163. if requestErr != nil {
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  165. return
  166. }
  167. defer resp.Body.Close()
  168. body, ioErr := ioutil.ReadAll(resp.Body)
  169. if ioErr != nil {
  170. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  172. return
  173. }
  174. var respJSON map[string]interface{}
  175. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  176. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  178. return
  179. }
  180. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  181. userJSONBytes, _ := json.Marshal(userJSON)
  182. var res ResultTwo
  183. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  184. utils.ErrorLog("解析失败:%v", err)
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  186. return
  187. }
  188. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  189. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  190. infoStr := string(Iinfos)
  191. idetinfoStr := string(Idetinfos)
  192. if res.Infcode == 0 {
  193. his := models.VMHisPatient{
  194. Status: 1,
  195. Ctime: time.Now().Unix(),
  196. Mtime: time.Now().Unix(),
  197. PsnNo: res.Output.Baseinfo.PsnNo,
  198. PsnCertType: res.Output.Baseinfo.PsnCertType,
  199. Certno: res.Output.Baseinfo.Certno,
  200. PsnName: res.Output.Baseinfo.PsnName,
  201. Gend: res.Output.Baseinfo.Gend,
  202. Naty: res.Output.Baseinfo.Naty,
  203. Brdy: res.Output.Baseinfo.Brdy,
  204. Age: res.Output.Baseinfo.Age,
  205. Iinfo: infoStr,
  206. Idetinfo: idetinfoStr,
  207. UserOrgId: adminInfo.CurrentOrgId,
  208. IsReturn: 1,
  209. IdCardType: id_card_type,
  210. }
  211. c.ServeSuccessJSON(map[string]interface{}{
  212. "info": his,
  213. })
  214. } else {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  216. return
  217. }
  218. }
  219. }
  220. //func (c *HisApiController) Sscard() {
  221. // //id_card_type, _ := c.GetInt64("id_card_type")
  222. // //adminUser := c.GetAdminUserInfo()
  223. // //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  224. // id_card_type := 1
  225. // r := CardInit()
  226. // fmt.Println(r)
  227. // //if r == 0 {
  228. // switch id_card_type {
  229. // case 1:
  230. // defer GetBasBaseInfo()
  231. //
  232. // //if err != nil {
  233. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  234. // // return
  235. // //
  236. // //} else {
  237. // // fmt.Println(basStr)
  238. // //
  239. // // bas := strings.Split(basStr, "|")
  240. // //
  241. // // basNumber := bas[1]
  242. // //
  243. // // //basNumber := bas[2]
  244. // // card_sn := bas[3]
  245. // //
  246. // // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  247. // //
  248. // // api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  249. // // resp, requestErr := http.Get(api)
  250. // // if requestErr != nil {
  251. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. // // return
  253. // // }
  254. // // defer resp.Body.Close()
  255. // // body, ioErr := ioutil.ReadAll(resp.Body)
  256. // // if ioErr != nil {
  257. // // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  258. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  259. // // return
  260. // // }
  261. // // var respJSON map[string]interface{}
  262. // //
  263. // // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  264. // // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  265. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  266. // // return
  267. // // }
  268. // //
  269. // // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  270. // // userJSONBytes, _ := json.Marshal(userJSON)
  271. // // var res ResultTwo
  272. // // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  273. // // utils.ErrorLog("解析失败:%v", err)
  274. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  275. // // return
  276. // // }
  277. // // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  278. // // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  279. // // infoStr := string(Iinfos)
  280. // // idetinfoStr := string(Idetinfos)
  281. // //
  282. // // if res.Infcode == 0 {
  283. // // his := models.VMHisPatient{
  284. // // Status: 1,
  285. // // Ctime: time.Now().Unix(),
  286. // // Mtime: time.Now().Unix(),
  287. // // PsnNo: res.Output.Baseinfo.PsnNo,
  288. // // PsnCertType: res.Output.Baseinfo.PsnCertType,
  289. // // Certno: res.Output.Baseinfo.Certno,
  290. // // PsnName: res.Output.Baseinfo.PsnName,
  291. // // Gend: res.Output.Baseinfo.Gend,
  292. // // Naty: res.Output.Baseinfo.Naty,
  293. // // Brdy: res.Output.Baseinfo.Brdy,
  294. // // Age: res.Output.Baseinfo.Age,
  295. // // Iinfo: infoStr,
  296. // // Idetinfo: idetinfoStr,
  297. // // UserOrgId: adminUser.CurrentOrgId,
  298. // // IsReturn: 1,
  299. // // IdCardType: id_card_type,
  300. // // }
  301. // //
  302. // // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  303. // // if err == gorm.ErrRecordNotFound {
  304. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  305. // // return
  306. // //
  307. // // } else if err != nil {
  308. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  309. // // return
  310. // //
  311. // // } else {
  312. // // c.ServeSuccessJSON(map[string]interface{}{
  313. // // "patient": patient,
  314. // // "his": his,
  315. // // "number": basNumber,
  316. // // })
  317. // // }
  318. // // } else {
  319. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  320. // // return
  321. // // }
  322. // //
  323. // //}
  324. //
  325. // break
  326. // case 2:
  327. // ////SFZStr, err := GetSFZBaseInfo()
  328. // //if err != nil {
  329. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  330. // // return
  331. // //
  332. // //} else {
  333. // //
  334. // // id_card_str := strings.Split(SFZStr, "^")
  335. // // id_card_number := id_card_str[0]
  336. // //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  337. // //
  338. // //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  339. // //resp, requestErr := http.Get(api)
  340. // //if requestErr != nil {
  341. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  342. // // return
  343. // //}
  344. // //defer resp.Body.Close()
  345. // //body, ioErr := ioutil.ReadAll(resp.Body)
  346. // //if ioErr != nil {
  347. // // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  348. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. // // return
  350. // //}
  351. // //var respJSON map[string]interface{}
  352. // //
  353. // //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  354. // // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  355. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  356. // // return
  357. // //}
  358. // //
  359. // //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  360. // //userJSONBytes, _ := json.Marshal(userJSON)
  361. // //var res ResultTwo
  362. // //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  363. // // utils.ErrorLog("解析失败:%v", err)
  364. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  365. // // return
  366. // //}
  367. // //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  368. // //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  369. // //infoStr := string(Iinfos)
  370. // //idetinfoStr := string(Idetinfos)
  371. // //
  372. // //if res.Infcode == 0 {
  373. // // his := models.VMHisPatient{
  374. // // Status: 1,
  375. // // Ctime: time.Now().Unix(),
  376. // // Mtime: time.Now().Unix(),
  377. // // PsnNo: res.Output.Baseinfo.PsnNo,
  378. // // PsnCertType: res.Output.Baseinfo.PsnCertType,
  379. // // Certno: res.Output.Baseinfo.Certno,
  380. // // PsnName: res.Output.Baseinfo.PsnName,
  381. // // Gend: res.Output.Baseinfo.Gend,
  382. // // Naty: res.Output.Baseinfo.Naty,
  383. // // Brdy: res.Output.Baseinfo.Brdy,
  384. // // Age: res.Output.Baseinfo.Age,
  385. // // Iinfo: infoStr,
  386. // // Idetinfo: idetinfoStr,
  387. // // UserOrgId: adminUser.CurrentOrgId,
  388. // // IsReturn: 1,
  389. // // IdCardType: id_card_type,
  390. // // }
  391. //
  392. // // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  393. // // if err == gorm.ErrRecordNotFound {
  394. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  395. // // return
  396. // //
  397. // // } else if err != nil {
  398. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  399. // // return
  400. // //
  401. // // } else {
  402. // // c.ServeSuccessJSON(map[string]interface{}{
  403. // // "patient": patient,
  404. // // "number": id_card_number,
  405. // // })
  406. // // }
  407. // //}
  408. // break
  409. // case 3:
  410. //
  411. // break
  412. //
  413. // }
  414. //}
  415. //func GetBasBaseInfo() (jsonStr string, err error) {
  416. //
  417. // handle := syscall.NewLazyDLL("SSCard.dll")
  418. // add := handle.NewProc("ReadCardBas")
  419. // str := make([]byte, 1024)
  420. // str1 := make([]byte, 1024)
  421. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  422. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  423. //
  424. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  425. //
  426. // fmt.Println("> Add(4,5)的结果为:", ret)
  427. // handle.Release()
  428. //
  429. // return "", nil
  430. //
  431. //}
  432. //func GetSFZBaseInfo() (jsonStr string, err error) {
  433. // //handle := syscall.MustLoadDLL("SSCard.dll")
  434. //
  435. // str := make([]byte, 256)
  436. // str1 := make([]byte, 256)
  437. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  438. //
  439. // fmt.Println(r)
  440. // return string(str), nil
  441. //}
  442. //func GetQRBaseInfo() (jsonStr string, err error) {
  443. // handle := syscall.LoadDLL("SSCard.dll")
  444. // ReadCardBas := handle.FindProc("GetQRBase")
  445. //
  446. // str := make([]byte, 256)
  447. // str1 := make([]byte, 256)
  448. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  449. //
  450. // fmt.Println(string(str))
  451. // fmt.Println(r)
  452. // return string(str), nil
  453. //}
  454. //func CardInit() int {
  455. // DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  456. // add := DllTestDef.MustFindProc("Init")
  457. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  458. // if err != nil {
  459. // fmt.Println("SSCard的运算结果为:", ret)
  460. // }
  461. // result := int(ret)
  462. // return result
  463. //}
  464. //func CardInit() int {
  465. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  466. // if err != nil {
  467. // fmt.Println("SSCard的运算结果为:", ret)
  468. // }
  469. // fmt.Println(err)
  470. // result := int(ret)
  471. // return result
  472. //}
  473. func IntPtr(n int) uintptr {
  474. return uintptr(n)
  475. }
  476. func StrPtr(s string) uintptr {
  477. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  478. }
  479. type ResultTwo struct {
  480. ErrMsg string `json:"err_msg"`
  481. InfRefmsgid string `json:"inf_refmsgid"`
  482. Infcode int64 `json:"infcode"`
  483. Output struct {
  484. Baseinfo struct {
  485. Age float64 `json:"age"`
  486. Brdy string `json:"brdy"`
  487. Certno string `json:"certno"`
  488. Gend string `json:"gend"`
  489. Naty string `json:"naty"`
  490. PsnCertType string `json:"psn_cert_type"`
  491. PsnName string `json:"psn_name"`
  492. PsnNo string `json:"psn_no"`
  493. } `json:"baseinfo"`
  494. Idetinfo []interface{} `json:"idetinfo"`
  495. Iinfo []struct {
  496. Balc float64 `json:"balc"`
  497. CvlservFlag string `json:"cvlserv_flag"`
  498. EmpName string `json:"emp_name"`
  499. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  500. Insutype string `json:"insutype"`
  501. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  502. PausInsuDate string `json:"paus_insu_date"`
  503. PsnInsuDate string `json:"psn_insu_date"`
  504. PsnInsuStas string `json:"psn_insu_stas"`
  505. PsnType string `json:"psn_type"`
  506. } `json:"insuinfo"`
  507. } `json:"output"`
  508. RefmsgTime string `json:"refmsg_time"`
  509. RespondTime string `json:"respond_time"`
  510. Signtype interface{} `json:"signtype"`
  511. WarnInfo interface{} `json:"warn_info"`
  512. }
  513. type ResultThree struct {
  514. Cainfo interface{} `json:"cainfo"`
  515. ErrMsg string `json:"err_msg"`
  516. InfRefmsgid string `json:"inf_refmsgid"`
  517. Infcode int64 `json:"infcode"`
  518. Output struct {
  519. Data struct {
  520. IptOtpNo string `json:"ipt_otp_no"`
  521. MdtrtID string `json:"mdtrt_id"`
  522. PsnNo string `json:"psn_no"`
  523. } `json:"data"`
  524. } `json:"output"`
  525. RefmsgTime string `json:"refmsg_time"`
  526. RespondTime string `json:"respond_time"`
  527. Signtype interface{} `json:"signtype"`
  528. WarnMsg interface{} `json:"warn_msg"`
  529. }
  530. type ResultFour struct {
  531. Cainfo string `json:"cainfo"`
  532. ErrMsg string `json:"err_msg"`
  533. InfRefmsgid string `json:"inf_refmsgid"`
  534. Infcode int64 `json:"infcode"`
  535. Output struct {
  536. Result []struct {
  537. BasMednFlag string `json:"bas_medn_flag"`
  538. ChldMedcFlag string `json:"chld_medc_flag"`
  539. ChrgitmLv string `json:"chrgitm_lv"`
  540. Cnt float64 `json:"cnt"`
  541. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  542. DrtReimFlag string `json:"drt_reim_flag"`
  543. FeedetlSn string `json:"feedetl_sn"`
  544. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  545. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  546. InscpScpAmt float64 `json:"inscp_scp_amt"`
  547. ListSpItemFlag string `json:"list_sp_item_flag"`
  548. LmtUsedFlag string `json:"lmt_used_flag"`
  549. MedChrgitmType string `json:"med_chrgitm_type"`
  550. Memo string `json:"memo"`
  551. OverlmtAmt float64 `json:"overlmt_amt"`
  552. PreselfpayAmt float64 `json:"preselfpay_amt"`
  553. Pric float64 `json:"pric"`
  554. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  555. SelfpayProp float64 `json:"selfpay_prop"`
  556. } `json:"result"`
  557. } `json:"output"`
  558. RefmsgTime string `json:"refmsg_time"`
  559. RespondTime string `json:"respond_time"`
  560. Signtype string `json:"signtype"`
  561. WarnMsg string `json:"warn_msg"`
  562. }
  563. type ResultFive struct {
  564. Balc float64 `json:"balc"`
  565. CvlservFlag string `json:"cvlserv_flag"`
  566. EmpName string `json:"emp_name"`
  567. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  568. Insutype string `json:"insutype"`
  569. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  570. PausInsuDate string `json:"paus_insu_date"`
  571. PsnInsuDate string `json:"psn_insu_date"`
  572. PsnInsuStas string `json:"psn_insu_stas"`
  573. PsnType string `json:"psn_type"`
  574. }
  575. type ResultSix struct {
  576. Cainfo interface{} `json:"cainfo"`
  577. ErrMsg string `json:"err_msg"`
  578. InfRefmsgid string `json:"inf_refmsgid"`
  579. Infcode int64 `json:"infcode"`
  580. Output struct {
  581. } `json:"output"`
  582. RefmsgTime string `json:"refmsg_time"`
  583. RespondTime string `json:"respond_time"`
  584. Signtype interface{} `json:"signtype"`
  585. WarnMsg interface{} `json:"warn_msg"`
  586. }
  587. type ResultSeven struct {
  588. Cainfo string `json:"cainfo"`
  589. ErrMsg string `json:"err_msg"`
  590. InfRefmsgid string `json:"inf_refmsgid"`
  591. Infcode int64 `json:"infcode"`
  592. Output struct {
  593. Setldetail []interface{} `json:"setldetail"`
  594. Setlinfo struct {
  595. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  596. AcctPay float64 `json:"acct_pay"`
  597. ActPayDedc float64 `json:"act_pay_dedc"`
  598. Age float64 `json:"age"`
  599. Balc float64 `json:"balc"`
  600. Brdy string `json:"brdy"`
  601. Certno string `json:"certno"`
  602. ClrOptins string `json:"clr_optins"`
  603. ClrType string `json:"clr_type"`
  604. ClrWay string `json:"clr_way"`
  605. CvlservFlag string `json:"cvlserv_flag"`
  606. CvlservPay float64 `json:"cvlserv_pay"`
  607. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  608. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  609. Gend string `json:"gend"`
  610. HifesPay float64 `json:"hifes_pay"`
  611. HifmiPay float64 `json:"hifmi_pay"`
  612. HifpPay float64 `json:"hifp_pay"`
  613. HospPartAmt float64 `json:"hosp_part_amt"`
  614. InscpScpAmt float64 `json:"inscp_scp_amt"`
  615. Insutype string `json:"insutype"`
  616. MafPay float64 `json:"maf_pay"`
  617. MdtrtCertType string `json:"mdtrt_cert_type"`
  618. HifobPay float64 `json:"hifob_pay"`
  619. MdtrtID string `json:"mdtrt_id"`
  620. MedType string `json:"med_type"`
  621. MedfeeSumamt float64 `json:"medfee_sumamt"`
  622. MedinsSetlID string `json:"medins_setl_id"`
  623. Naty string `json:"naty"`
  624. OthPay float64 `json:"oth_pay"`
  625. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  626. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  627. PreselfpayAmt float64 `json:"preselfpay_amt"`
  628. PsnCashPay float64 `json:"psn_cash_pay"`
  629. PsnCertType string `json:"psn_cert_type"`
  630. PsnName string `json:"psn_name"`
  631. PsnNo string `json:"psn_no"`
  632. PsnPartAmt float64 `json:"psn_part_amt"`
  633. PsnType string `json:"psn_type"`
  634. SetlID string `json:"setl_id"`
  635. SetlTime string `json:"setl_time"`
  636. } `json:"setlinfo"`
  637. } `json:"output"`
  638. RefmsgTime string `json:"refmsg_time"`
  639. RespondTime string `json:"respond_time"`
  640. Signtype interface{} `json:"signtype"`
  641. WarnMsg interface{} `json:"warn_msg"`
  642. }
  643. type ResultEight struct {
  644. Cainfo string `json:"cainfo"`
  645. ErrMsg string `json:"err_msg"`
  646. InfRefmsgid string `json:"inf_refmsgid"`
  647. Infcode int64 `json:"infcode"`
  648. Output struct {
  649. Stmtinfo struct {
  650. SetlOptins string `json:"setl_optins"`
  651. StmtRslt string `json:"stmt_rslt"`
  652. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  653. } `json:"stmtinfo"`
  654. } `json:"output"`
  655. RefmsgTime string `json:"refmsg_time"`
  656. RespondTime string `json:"respond_time"`
  657. Signtype interface{} `json:"signtype"`
  658. WarnMsg interface{} `json:"warn_msg"`
  659. }
  660. type ResultNine struct {
  661. Cainfo string `json:"cainfo"`
  662. ErrMsg string `json:"err_msg"`
  663. InfRefmsgid string `json:"inf_refmsgid"`
  664. Infcode int64 `json:"infcode"`
  665. Output struct {
  666. FileQuryNo string `json:"file_qury_no"`
  667. } `json:"output"`
  668. RefmsgTime string `json:"refmsg_time"`
  669. RespondTime string `json:"respond_time"`
  670. Signtype interface{} `json:"signtype"`
  671. WarnMsg interface{} `json:"warn_msg"`
  672. }
  673. type ResultTen struct {
  674. Cainfo string `json:"cainfo"`
  675. ErrMsg string `json:"err_msg"`
  676. InfRefmsgid string `json:"inf_refmsgid"`
  677. Infcode int64 `json:"infcode"`
  678. Output struct {
  679. DldEndtime string `json:"dld_endtime"`
  680. FileQuryNo string `json:"file_qury_no"`
  681. Filename string `json:"filename"`
  682. } `json:"output"`
  683. RefmsgTime string `json:"refmsg_time"`
  684. RespondTime string `json:"respond_time"`
  685. Signtype interface{} `json:"signtype"`
  686. WarnMsg interface{} `json:"warn_msg"`
  687. }
  688. type ResultEleven struct {
  689. Cainfo string `json:"cainfo"`
  690. ErrMsg string `json:"err_msg"`
  691. InfRefmsgid string `json:"inf_refmsgid"`
  692. Infcode int64 `json:"infcode"`
  693. Output struct {
  694. Setlinfo struct {
  695. FixmedinsName string `json:"fixmedins_name"`
  696. FixmedinsCode string `json:"fixmedins_code"`
  697. PsnNo string `json:"psn_no"`
  698. PsnName string `json:"psn_name"`
  699. HifobPay float64 `json:"hifob_pay"`
  700. Gend string `json:"gend"`
  701. Brdy string `json:"brdy"`
  702. PsnCertType string `json:"psn_cert_type"`
  703. PsnType string `json:"psn_type"`
  704. EmpName string `json:"emp_name"`
  705. Certno string `json:"certno"`
  706. Insutype string `json:"insutype"`
  707. MedfeeSumamt float64 `json:"medfee_sumamt"`
  708. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  709. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  710. PreselfpayAmt float64 `json:"preselfpay_amt"`
  711. InscpScpAmt float64 `json:"inscp_scp_amt"`
  712. ActPayDedc float64 `json:"act_pay_dedc"`
  713. HifpPay float64 `json:"hifp_pay"`
  714. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  715. CvlservPay float64 `json:"cvlserv_pay"`
  716. HifesPay float64 `json:"hifes_pay"`
  717. HifmiPay float64 `json:"hifmi_pay"`
  718. MafPay float64 `json:"maf_pay"`
  719. OthPay float64 `json:"oth_pay"`
  720. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  721. PsnPay float64 `json:"psn_pay"`
  722. AcctPay float64 `json:"acct_pay"`
  723. CashPayamt float64 `json:"cash_payamt"`
  724. Balc float64 `json:"balc"`
  725. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  726. MedinsSetlId string `json:"medins_setl_id"`
  727. RefdSetlFlag string `json:"refd_setl_flag"`
  728. SetlTime string `json:"setl_time"`
  729. MedType string `json:"med_type"`
  730. HospLv string `json:"hosp_lv"`
  731. } `json:"setlinfo"`
  732. } `json:"output"`
  733. RefmsgTime string `json:"refmsg_time"`
  734. RespondTime string `json:"respond_time"`
  735. Signtype interface{} `json:"signtype"`
  736. WarnMsg interface{} `json:"warn_msg"`
  737. }
  738. type ResultTwelve struct {
  739. Cainfo string `json:"cainfo"`
  740. ErrMsg string `json:"err_msg"`
  741. InfRefmsgid string `json:"inf_refmsgid"`
  742. Infcode int64 `json:"infcode"`
  743. Output struct {
  744. MdtrtId string `json:"mdtrt_id"`
  745. ChrgBchno string `json:"chrg_bchno"`
  746. PsnNo string `json:"psn_no"`
  747. } `json:"output"`
  748. RefmsgTime string `json:"refmsg_time"`
  749. RespondTime string `json:"respond_time"`
  750. Signtype interface{} `json:"signtype"`
  751. WarnMsg interface{} `json:"warn_msg"`
  752. }
  753. type ResultThirteen struct {
  754. ErrMsg string `json:"err_msg"`
  755. InfRefmsgid string `json:"inf_refmsgid"`
  756. Infcode int64 `json:"infcode"`
  757. Output struct {
  758. Result struct {
  759. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  760. } `json:"result"`
  761. } `json:"output"`
  762. RefmsgTime string `json:"refmsg_time"`
  763. RespondTime string `json:"respond_time"`
  764. Signtype interface{} `json:"signtype"`
  765. WarnInfo interface{} `json:"warn_info"`
  766. }
  767. type ResultFourteen struct {
  768. ErrMsg string `json:"err_msg"`
  769. InfRefmsgid string `json:"inf_refmsgid"`
  770. Infcode int64 `json:"infcode"`
  771. Output struct {
  772. } `json:"output"`
  773. RefmsgTime string `json:"refmsg_time"`
  774. RespondTime string `json:"respond_time"`
  775. Signtype interface{} `json:"signtype"`
  776. WarnInfo interface{} `json:"warn_info"`
  777. }
  778. type Custom struct {
  779. DetItemFeeSumamt string
  780. Cut string
  781. FeedetlSn string
  782. Price string
  783. MedListCodg string
  784. Type int64
  785. AdviceId int64
  786. ProjectId int64
  787. ItemId int64
  788. }
  789. //获取个人信息----挂号-----上传就诊信息
  790. func (c *HisApiController) GetRegisterInfo() {
  791. id, _ := c.GetInt64("id")
  792. record_time := c.GetString("record_time")
  793. settlementValue, _ := c.GetInt64("settlement_value")
  794. medical_insurance_card := c.GetString("medical_insurance_card")
  795. name := c.GetString("name")
  796. id_card_type, _ := c.GetInt64("id_card_type")
  797. certificates, _ := c.GetInt64("certificates")
  798. medical_care, _ := c.GetInt64("medical_care")
  799. birthday := c.GetString("birthday")
  800. age, _ := c.GetInt64("age")
  801. id_card := c.GetString("id_card")
  802. register_type, _ := c.GetInt64("register")
  803. doctor, _ := c.GetInt64("doctor")
  804. department, _ := c.GetInt64("department")
  805. gender, _ := c.GetInt64("sex")
  806. phone := c.GetString("phone")
  807. registration_fee, _ := c.GetFloat("registration_fee")
  808. medical_expenses, _ := c.GetFloat("medical_expenses")
  809. social_type, _ := c.GetInt64("social_type")
  810. admin_user_id, _ := c.GetInt64("admin_user_id")
  811. diagnosis_id, _ := c.GetInt64("diagnosis")
  812. sick_type, _ := c.GetInt64("sick_type")
  813. reg_type := c.GetString("p_type")
  814. timeLayout := "2006-01-02"
  815. loc, _ := time.LoadLocation("Local")
  816. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  817. birthUnix := birthdays.Unix()
  818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  819. if err != nil {
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  821. return
  822. }
  823. recordDateTime := theTime.Unix()
  824. adminInfo := c.GetAdminUserInfo()
  825. var patient service.Patients
  826. if id == 0 {
  827. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  828. } else {
  829. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  830. }
  831. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  832. if patientPrescription.ID == 0 {
  833. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  834. }
  835. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  836. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  837. sickConfig, _ := service.FindSickById(sick_type)
  838. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  839. if patient.ID == 0 {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  841. return
  842. }
  843. if len(patient.IdCardNo) == 0 {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  845. return
  846. }
  847. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  848. if config.IsOpen == 1 {
  849. 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
  850. resp, requestErr := http.Get(api)
  851. if requestErr != nil {
  852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  853. return
  854. }
  855. defer resp.Body.Close()
  856. body, ioErr := ioutil.ReadAll(resp.Body)
  857. if ioErr != nil {
  858. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. var respJSON map[string]interface{}
  863. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  864. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  866. return
  867. }
  868. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  869. userJSONBytes, _ := json.Marshal(userJSON)
  870. var res ResultTwo
  871. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  872. utils.ErrorLog("解析失败:%v", err)
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  874. return
  875. }
  876. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  877. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  878. infoStr := string(Iinfos)
  879. idetinfoStr := string(Idetinfos)
  880. if res.Infcode == 0 {
  881. his := models.VMHisPatient{
  882. Name: name,
  883. Gender: gender,
  884. Birthday: birthUnix,
  885. MedicalTreatmentType: medical_care,
  886. IdType: certificates,
  887. IdCardNo: id_card,
  888. BalanceAccountsType: settlementValue,
  889. SocialType: social_type,
  890. MedicalInsuranceNumber: medical_insurance_card,
  891. RegisterType: register_type,
  892. RegisterCost: registration_fee,
  893. TreatmentCost: medical_expenses,
  894. Status: 1,
  895. Ctime: time.Now().Unix(),
  896. Mtime: time.Now().Unix(),
  897. PsnNo: res.Output.Baseinfo.PsnNo,
  898. PsnCertType: res.Output.Baseinfo.PsnCertType,
  899. Certno: res.Output.Baseinfo.Certno,
  900. PsnName: res.Output.Baseinfo.PsnName,
  901. Gend: res.Output.Baseinfo.Gend,
  902. Naty: res.Output.Baseinfo.Naty,
  903. Brdy: res.Output.Baseinfo.Brdy,
  904. Age: res.Output.Baseinfo.Age,
  905. Iinfo: infoStr,
  906. Idetinfo: idetinfoStr,
  907. PatientId: patient.ID,
  908. RecordDate: theTime.Unix(),
  909. UserOrgId: adminInfo.CurrentOrgId,
  910. AdminUserId: admin_user_id,
  911. IsReturn: 1,
  912. IdCardType: id_card_type,
  913. Doctor: doctor,
  914. Departments: department,
  915. }
  916. timestamp := time.Now().Unix()
  917. tempTime := time.Unix(timestamp, 0)
  918. timeFormat := tempTime.Format("20060102150405")
  919. chrgBchno := rand.Intn(100000) + 10000
  920. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  921. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  922. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  923. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  924. IdCardNo := ""
  925. if id_card_type == 1 {
  926. IdCardNo = medical_insurance_card
  927. } else {
  928. IdCardNo = patient.IdCardNo
  929. }
  930. var insutypes []string
  931. var insutype string
  932. var is390 int = 0
  933. var is310 int = 0
  934. for _, item := range res.Output.Iinfo {
  935. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  936. insutypes = append(insutypes, item.Insutype)
  937. }
  938. }
  939. if len(insutypes) == 1 {
  940. insutype = insutypes[0]
  941. } else {
  942. for _, i := range insutypes {
  943. if i == "390" {
  944. is390 = 1
  945. }
  946. if i == "310" {
  947. is310 = 1
  948. }
  949. }
  950. }
  951. if is390 == 1 {
  952. insutype = "390"
  953. }
  954. if is310 == 1 {
  955. insutype = "310"
  956. }
  957. fmt.Println(insutype)
  958. if count <= 0 {
  959. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  960. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  961. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  962. "&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)
  963. resp, requestErr := http.Get(api)
  964. if requestErr != nil {
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  966. return
  967. }
  968. defer resp.Body.Close()
  969. body, ioErr := ioutil.ReadAll(resp.Body)
  970. if ioErr != nil {
  971. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  973. return
  974. }
  975. var respJSON map[string]interface{}
  976. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  977. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  979. return
  980. }
  981. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  982. userJSONBytes, _ := json.Marshal(respJSON)
  983. var res ResultThree
  984. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  985. utils.ErrorLog("解析失败:%v", err)
  986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  987. return
  988. }
  989. if res.Infcode == -1 {
  990. adminUser := c.GetAdminUserInfo()
  991. errlog := &models.HisOrderError{
  992. UserOrgId: adminUser.CurrentOrgId,
  993. Ctime: time.Now().Unix(),
  994. Mtime: time.Now().Unix(),
  995. ErrMsg: res.ErrMsg,
  996. Status: 1,
  997. PatientId: id,
  998. RecordTime: recordDateTime,
  999. Stage: 2,
  1000. }
  1001. service.CreateErrMsgLog(errlog)
  1002. c.ServeSuccessJSON(map[string]interface{}{
  1003. "failed_code": -10,
  1004. "msg": res.ErrMsg,
  1005. })
  1006. return
  1007. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1008. //return
  1009. }
  1010. his.Number = res.Output.Data.MdtrtID
  1011. his.PsnNo = res.Output.Data.PsnNo
  1012. his.IptOtpNo = res.Output.Data.IptOtpNo
  1013. his.IdCardNo = patient.IdCardNo
  1014. his.PhoneNumber = patient.Phone
  1015. his.UserOrgId = adminInfo.CurrentOrgId
  1016. his.Ctime = time.Now().Unix()
  1017. his.Mtime = time.Now().Unix()
  1018. his.Status = 1
  1019. err := service.CreateHisPatientTwo(&his)
  1020. if err == nil {
  1021. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1022. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1023. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + reg_type + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  1024. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1025. resp2, requestErr2 := http.Get(api2)
  1026. if requestErr2 != nil {
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1028. return
  1029. }
  1030. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1031. if ioErr2 != nil {
  1032. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1034. return
  1035. }
  1036. var respJSON2 map[string]interface{}
  1037. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1038. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1040. return
  1041. }
  1042. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1043. userJSONBytes2, _ := json.Marshal(respJSON2)
  1044. var res2 ResultSix
  1045. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1046. utils.ErrorLog("解析失败:%v", err)
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1048. return
  1049. }
  1050. if res2.Infcode == -1 {
  1051. adminUser := c.GetAdminUserInfo()
  1052. errlog := &models.HisOrderError{
  1053. UserOrgId: adminUser.CurrentOrgId,
  1054. Ctime: time.Now().Unix(),
  1055. Mtime: time.Now().Unix(),
  1056. ErrMsg: res2.ErrMsg,
  1057. Status: 1,
  1058. PatientId: id,
  1059. RecordTime: recordDateTime,
  1060. Stage: 3,
  1061. }
  1062. service.CreateErrMsgLog(errlog)
  1063. c.ServeSuccessJSON(map[string]interface{}{
  1064. "failed_code": -10,
  1065. "msg": res2.ErrMsg,
  1066. })
  1067. return
  1068. } else {
  1069. c.ServeSuccessJSON(map[string]interface{}{
  1070. "his_info": his,
  1071. })
  1072. }
  1073. } else {
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1075. return
  1076. }
  1077. } else {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1079. return
  1080. }
  1081. } else {
  1082. adminUser := c.GetAdminUserInfo()
  1083. errlog := &models.HisOrderError{
  1084. UserOrgId: adminUser.CurrentOrgId,
  1085. Ctime: time.Now().Unix(),
  1086. Mtime: time.Now().Unix(),
  1087. ErrMsg: res.ErrMsg,
  1088. Status: 1,
  1089. PatientId: id,
  1090. RecordTime: recordDateTime,
  1091. Stage: 1,
  1092. }
  1093. service.CreateErrMsgLog(errlog)
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "failed_code": -10,
  1096. "msg": res.ErrMsg,
  1097. })
  1098. return
  1099. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1100. }
  1101. } else {
  1102. timeStr := time.Now().Format("2006-01-02")
  1103. timeArr := strings.Split(timeStr, "-")
  1104. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1105. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1106. var hisPatient models.XtHisPatient
  1107. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1108. hisPatient = models.XtHisPatient{
  1109. Name: name,
  1110. Age: age,
  1111. Gender: gender,
  1112. Birthday: birthUnix,
  1113. Phone: phone,
  1114. MedicalTreatmentType: medical_care,
  1115. IdType: certificates,
  1116. IdCardNo: id_card,
  1117. BalanceAccountsType: settlementValue,
  1118. SocialType: social_type,
  1119. MedicalInsuranceNumber: medical_insurance_card,
  1120. RegisterType: register_type,
  1121. RegisterCost: registration_fee,
  1122. TreatmentCost: medical_expenses,
  1123. AdminUserId: admin_user_id,
  1124. UserOrgId: adminInfo.CurrentOrgId,
  1125. Status: 1,
  1126. RecordDate: recordDateTime,
  1127. IsReturn: 1,
  1128. PatientId: patient.ID,
  1129. Ctime: time.Now().Unix(),
  1130. Mtime: time.Now().Unix(),
  1131. Number: str,
  1132. }
  1133. service.CreateHisPatient(&hisPatient)
  1134. }
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "his_info": hisPatient,
  1137. })
  1138. }
  1139. }
  1140. //上传明细----预结算----确认订单
  1141. func (c *HisApiController) GetUploadInfo() {
  1142. id, _ := c.GetInt64("id")
  1143. record_time := c.GetString("record_time")
  1144. pay_way, _ := c.GetInt64("pay_way")
  1145. pay_price, _ := c.GetFloat("pay_price")
  1146. pay_card_no := c.GetString("pay_card_no")
  1147. discount_price, _ := c.GetFloat("discount_price")
  1148. preferential_price, _ := c.GetFloat("preferential_price")
  1149. reality_price, _ := c.GetFloat("reality_price")
  1150. found_price, _ := c.GetFloat("found_price")
  1151. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1152. private_price, _ := c.GetFloat("private_price")
  1153. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1154. admin_user_id, _ := c.GetInt64("admin_user_id")
  1155. timeLayout := "2006-01-02"
  1156. loc, _ := time.LoadLocation("Local")
  1157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1158. if err != nil {
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1160. return
  1161. }
  1162. recordDateTime := theTime.Unix()
  1163. adminUser := c.GetAdminUserInfo()
  1164. var prescriptions []*models.HisPrescription
  1165. var start_time int64
  1166. var end_time int64
  1167. data := make(map[string]interface{})
  1168. if settle_accounts_type == 1 { //日结
  1169. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1170. data["pre"] = prescriptions
  1171. } else { //月结
  1172. start_time_str := c.GetString("start_time")
  1173. end_time_str := c.GetString("end_time")
  1174. timeLayout := "2006-01-02"
  1175. loc, _ := time.LoadLocation("Local")
  1176. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1177. if err != nil {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1179. return
  1180. }
  1181. recordStartTime := theStartTime.Unix()
  1182. start_time = recordStartTime
  1183. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1184. if err != nil {
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. recordEndTime := theEndTime.Unix()
  1189. end_time = recordEndTime
  1190. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1191. data["pre"] = prescriptions
  1192. }
  1193. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1194. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1195. timestamp := time.Now().Unix()
  1196. tempTime := time.Unix(timestamp, 0)
  1197. timeFormat := tempTime.Format("20060102150405")
  1198. chrgBchno := rand.Intn(100000) + 10000
  1199. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1200. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1201. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1202. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1203. strconv.FormatInt(his.PatientId, 10)
  1204. client := &http.Client{}
  1205. data["psn_no"] = his.PsnNo
  1206. data["mdtrt_id"] = his.Number
  1207. data["chrg_bchno"] = chrg_bchno
  1208. data["org_name"] = miConfig.OrgName
  1209. data["doctor"] = roles.UserName
  1210. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1211. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1212. data["fixmedins_code"] = miConfig.Code
  1213. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1214. data["dept_code"] = "15"
  1215. } else {
  1216. data["dept_code"] = department.Number
  1217. }
  1218. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1219. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1220. data["secret_key"] = miConfig.SecretKey
  1221. var ids []int64
  1222. for _, item := range prescriptions {
  1223. ids = append(ids, item.ID)
  1224. }
  1225. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1226. if config.IsOpen == 1 { //对接了医保,走医保流程
  1227. bytesData, _ := json.Marshal(data)
  1228. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1229. resp, _ := client.Do(req)
  1230. defer resp.Body.Close()
  1231. body, ioErr := ioutil.ReadAll(resp.Body)
  1232. if ioErr != nil {
  1233. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1235. return
  1236. }
  1237. var respJSON map[string]interface{}
  1238. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1239. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1241. return
  1242. }
  1243. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1244. userJSONBytes, _ := json.Marshal(respJSON)
  1245. var res ResultFour
  1246. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1247. utils.ErrorLog("解析失败:%v", err)
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1249. return
  1250. }
  1251. if res.Infcode == 0 {
  1252. order := &models.HisOrder{
  1253. UserOrgId: adminUser.CurrentOrgId,
  1254. HisPatientId: his.ID,
  1255. PatientId: his.PatientId,
  1256. SettleAccountsDate: recordDateTime,
  1257. Ctime: time.Now().Unix(),
  1258. Mtime: time.Now().Unix(),
  1259. Status: 1,
  1260. Number: chrg_bchno,
  1261. Infcode: res.Infcode,
  1262. WarnMsg: res.WarnMsg,
  1263. Cainfo: res.Cainfo,
  1264. ErrMsg: res.ErrMsg,
  1265. RespondTime: res.RefmsgTime,
  1266. InfRefmsgid: res.InfRefmsgid,
  1267. OrderStatus: 1,
  1268. PayWay: pay_way,
  1269. PayPrice: pay_price,
  1270. PayCardNo: pay_card_no,
  1271. DiscountPrice: discount_price,
  1272. PreferentialPrice: preferential_price,
  1273. RealityPrice: reality_price,
  1274. FoundPrice: found_price,
  1275. MedicalInsurancePrice: medical_insurance_price,
  1276. PrivatePrice: private_price,
  1277. IsMedicineInsurance: 1,
  1278. SettleType: settle_accounts_type,
  1279. SettleStartTime: start_time,
  1280. SettleEndTime: end_time,
  1281. Creator: roles.ID,
  1282. Modify: roles.ID,
  1283. }
  1284. err = service.CreateOrder(order)
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1287. return
  1288. }
  1289. for _, item := range res.Output.Result {
  1290. temp := strings.Split(item.FeedetlSn, "-")
  1291. var advice_id int64 = 0
  1292. var project_id int64 = 0
  1293. var types int64 = 0
  1294. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1295. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1296. if temp[1] == "1" {
  1297. advice_id = id
  1298. project_id = 0
  1299. } else if temp[1] == "2" {
  1300. advice_id = 0
  1301. project_id = id
  1302. }
  1303. info := &models.HisOrderInfo{
  1304. OrderNumber: order.Number,
  1305. FeedetlSn: item.FeedetlSn,
  1306. UploadDate: time.Now().Unix(),
  1307. AdviceId: advice_id,
  1308. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1309. Cnt: item.Cnt,
  1310. Pric: float64(item.Pric),
  1311. PatientId: his.PatientId,
  1312. PricUplmtAmt: item.PricUplmtAmt,
  1313. SelfpayProp: item.SelfpayProp,
  1314. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1315. OverlmtAmt: item.OverlmtAmt,
  1316. PreselfpayAmt: item.PreselfpayAmt,
  1317. BasMednFlag: item.BasMednFlag,
  1318. MedChrgitmType: item.MedChrgitmType,
  1319. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1320. Status: 1,
  1321. Memo: item.Memo,
  1322. Mtime: time.Now().Unix(),
  1323. InscpScpAmt: item.InscpScpAmt,
  1324. DrtReimFlag: item.DrtReimFlag,
  1325. Ctime: time.Now().Unix(),
  1326. ListSpItemFlag: item.ListSpItemFlag,
  1327. ChldMedcFlag: item.ChldMedcFlag,
  1328. LmtUsedFlag: item.LmtUsedFlag,
  1329. ChrgitmLv: item.ChrgitmLv,
  1330. UserOrgId: adminUser.CurrentOrgId,
  1331. HisPatientId: his.ID,
  1332. OrderId: order.ID,
  1333. ProjectId: project_id,
  1334. Type: types,
  1335. }
  1336. service.CreateOrderInfo(info)
  1337. }
  1338. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1339. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1340. var total float64
  1341. for _, item := range prescriptions {
  1342. if item.Type == 1 { //药品
  1343. for _, subItem := range item.HisDoctorAdviceInfo {
  1344. total = total + (subItem.Price * subItem.PrescribingNumber)
  1345. }
  1346. }
  1347. if item.Type == 2 { //项目
  1348. for _, subItem := range item.HisPrescriptionProject {
  1349. total = total + (subItem.Price * float64(subItem.Count))
  1350. }
  1351. }
  1352. }
  1353. for _, item := range prescriptions {
  1354. for _, subItem := range item.HisAdditionalCharge {
  1355. total = total + (subItem.Price * float64(subItem.Count))
  1356. }
  1357. }
  1358. allTotal := fmt.Sprintf("%.2f", total)
  1359. if res.Infcode == 0 {
  1360. var rf []*ResultFive
  1361. json.Unmarshal([]byte(his.Iinfo), &rf)
  1362. psn_no := his.PsnNo
  1363. mdtrt_id := his.Number
  1364. chrg_bchno := chrg_bchno
  1365. cert_no := his.Certno
  1366. var insutypes []string
  1367. var insutype string
  1368. var is390 int = 0
  1369. var is310 int = 0
  1370. for _, item := range rf {
  1371. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1372. insutypes = append(insutypes, item.Insutype)
  1373. }
  1374. }
  1375. if len(insutypes) == 1 {
  1376. insutype = insutypes[0]
  1377. } else {
  1378. for _, i := range insutypes {
  1379. if i == "390" {
  1380. is390 = 1
  1381. }
  1382. if i == "310" {
  1383. is310 = 1
  1384. }
  1385. }
  1386. }
  1387. if is390 == 1 {
  1388. insutype = "390"
  1389. }
  1390. if is310 == 1 {
  1391. insutype = "310"
  1392. }
  1393. if his.IdCardType == 1 {
  1394. cert_no = his.MedicalInsuranceNumber
  1395. } else {
  1396. cert_no = his.Certno
  1397. }
  1398. fmt.Println(insutype)
  1399. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1400. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1401. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1402. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1403. resp, requestErr := http.Get(api)
  1404. if requestErr != nil {
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1406. return
  1407. }
  1408. defer resp.Body.Close()
  1409. body, ioErr := ioutil.ReadAll(resp.Body)
  1410. if ioErr != nil {
  1411. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1413. return
  1414. }
  1415. var respJSON map[string]interface{}
  1416. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1417. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1419. return
  1420. }
  1421. fmt.Println(respJSON)
  1422. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1423. userJSONBytes, _ := json.Marshal(respJSON)
  1424. var res ResultSeven
  1425. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1426. utils.ErrorLog("解析失败:%v", err)
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1428. return
  1429. }
  1430. if res.Infcode == -1 {
  1431. errlog := &models.HisOrderError{
  1432. UserOrgId: adminUser.CurrentOrgId,
  1433. Ctime: time.Now().Unix(),
  1434. Mtime: time.Now().Unix(),
  1435. Number: chrg_bchno,
  1436. ErrMsg: res.ErrMsg,
  1437. Status: 1,
  1438. PatientId: id,
  1439. RecordTime: recordDateTime,
  1440. Stage: 6,
  1441. }
  1442. c.ServeSuccessJSON(map[string]interface{}{
  1443. "failed_code": -10,
  1444. "msg": res.ErrMsg,
  1445. })
  1446. return
  1447. service.CreateErrMsgLog(errlog)
  1448. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1449. return
  1450. } else {
  1451. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1452. order.OrderStatus = 2
  1453. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1454. order.SetlId = res.Output.Setlinfo.SetlID
  1455. order.PsnNo = res.Output.Setlinfo.PsnNo
  1456. order.PsnName = res.Output.Setlinfo.PsnName
  1457. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1458. order.Certno = res.Output.Setlinfo.Certno
  1459. order.Gend = res.Output.Setlinfo.Gend
  1460. order.Naty = res.Output.Setlinfo.Naty
  1461. order.Age = res.Output.Setlinfo.Age
  1462. order.Insutype = res.Output.Setlinfo.Insutype
  1463. order.PsnType = res.Output.Setlinfo.PsnType
  1464. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1465. order.SetlTime = res.Output.Setlinfo.SetlTime
  1466. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1467. order.MedType = res.Output.Setlinfo.MedType
  1468. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1469. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1470. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1471. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1472. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1473. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1474. order.HifpPay = res.Output.Setlinfo.HifpPay
  1475. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1476. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1477. order.HifesPay = res.Output.Setlinfo.HifesPay
  1478. order.HifobPay = res.Output.Setlinfo.HifobPay
  1479. order.MafPay = res.Output.Setlinfo.MafPay
  1480. order.OthPay = res.Output.Setlinfo.OthPay
  1481. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1482. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1483. order.AcctPay = res.Output.Setlinfo.AcctPay
  1484. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1485. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1486. order.Balc = res.Output.Setlinfo.Balc
  1487. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1488. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1489. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1490. order.ClrWay = res.Output.Setlinfo.ClrWay
  1491. order.Creator = order.Creator
  1492. order.Modify = roles.ID
  1493. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1494. detailStr := string(setlDetail)
  1495. order.SetlDetail = detailStr
  1496. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1497. err = service.UpDateOrder(order)
  1498. if err == nil {
  1499. c.ServeSuccessJSON(map[string]interface{}{
  1500. "msg": "结算成功",
  1501. })
  1502. } else {
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1504. return
  1505. }
  1506. }
  1507. } else {
  1508. adminUser := c.GetAdminUserInfo()
  1509. errlog := &models.HisOrderError{
  1510. UserOrgId: adminUser.CurrentOrgId,
  1511. Ctime: time.Now().Unix(),
  1512. Mtime: time.Now().Unix(),
  1513. ErrMsg: res.ErrMsg,
  1514. Status: 1,
  1515. PatientId: id,
  1516. RecordTime: recordDateTime,
  1517. Stage: 4,
  1518. }
  1519. service.CreateErrMsgLog(errlog)
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1521. return
  1522. }
  1523. } else {
  1524. adminUser := c.GetAdminUserInfo()
  1525. errlog := &models.HisOrderError{
  1526. UserOrgId: adminUser.CurrentOrgId,
  1527. Ctime: time.Now().Unix(),
  1528. Mtime: time.Now().Unix(),
  1529. ErrMsg: res.ErrMsg,
  1530. Status: 1,
  1531. PatientId: id,
  1532. RecordTime: recordDateTime,
  1533. Stage: 4,
  1534. }
  1535. service.CreateErrMsgLog(errlog)
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "failed_code": -10,
  1538. "msg": res.ErrMsg,
  1539. })
  1540. return
  1541. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1542. //return
  1543. }
  1544. } else {
  1545. var total float64
  1546. for _, item := range prescriptions {
  1547. if item.Type == 1 { //药品
  1548. for _, subItem := range item.HisDoctorAdviceInfo {
  1549. total = total + (subItem.Price * subItem.PrescribingNumber)
  1550. }
  1551. }
  1552. if item.Type == 2 { //项目
  1553. for _, subItem := range item.HisPrescriptionProject {
  1554. total = total + (subItem.Price * float64(subItem.Count))
  1555. }
  1556. }
  1557. for _, subItem := range item.HisAdditionalCharge {
  1558. total = total + (subItem.Price * float64(subItem.Count))
  1559. }
  1560. }
  1561. allTotal := fmt.Sprintf("%.2f", total)
  1562. totals, _ := strconv.ParseFloat(allTotal, 64)
  1563. order := &models.HisOrder{
  1564. UserOrgId: adminUser.CurrentOrgId,
  1565. HisPatientId: his.ID,
  1566. PatientId: id,
  1567. SettleAccountsDate: recordDateTime,
  1568. Ctime: time.Now().Unix(),
  1569. Mtime: time.Now().Unix(),
  1570. Status: 1,
  1571. OrderStatus: 2,
  1572. Number: chrg_bchno,
  1573. MedfeeSumamt: totals,
  1574. PayWay: pay_way,
  1575. PayPrice: pay_price,
  1576. PayCardNo: pay_card_no,
  1577. DiscountPrice: discount_price,
  1578. PreferentialPrice: preferential_price,
  1579. RealityPrice: reality_price,
  1580. FoundPrice: found_price,
  1581. MedicalInsurancePrice: medical_insurance_price,
  1582. PrivatePrice: private_price,
  1583. }
  1584. err = service.CreateOrder(order)
  1585. if err != nil {
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1587. return
  1588. }
  1589. var customs []*Custom
  1590. for _, item := range prescriptions {
  1591. if item.Type == 1 { //药品
  1592. for _, subItem := range item.HisDoctorAdviceInfo {
  1593. cus := &Custom{
  1594. AdviceId: subItem.ID,
  1595. ProjectId: 0,
  1596. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1597. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1598. FeedetlSn: subItem.FeedetlSn,
  1599. Price: fmt.Sprintf("%.2f", subItem.Price),
  1600. MedListCodg: subItem.MedListCodg,
  1601. Type: 1,
  1602. }
  1603. customs = append(customs, cus)
  1604. }
  1605. }
  1606. if item.Type == 2 { //项目
  1607. for _, subItem := range item.HisPrescriptionProject {
  1608. cus := &Custom{
  1609. AdviceId: 0,
  1610. ProjectId: subItem.ID,
  1611. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1612. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1613. FeedetlSn: subItem.FeedetlSn,
  1614. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1615. MedListCodg: subItem.MedListCodg,
  1616. Type: 2,
  1617. }
  1618. customs = append(customs, cus)
  1619. }
  1620. }
  1621. for _, item := range item.HisAdditionalCharge {
  1622. cus := &Custom{
  1623. ItemId: item.ID,
  1624. AdviceId: 0,
  1625. ProjectId: 0,
  1626. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1627. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1628. FeedetlSn: item.FeedetlSn,
  1629. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1630. MedListCodg: item.XtHisAddtionConfig.Code,
  1631. Type: 3,
  1632. }
  1633. customs = append(customs, cus)
  1634. }
  1635. }
  1636. for _, item := range customs {
  1637. var advice_id int64 = 0
  1638. var project_id int64 = 0
  1639. var item_id int64 = 0
  1640. var types int64 = 0
  1641. if item.Type == 1 {
  1642. advice_id = item.AdviceId
  1643. project_id = 0
  1644. item_id = 0
  1645. } else if item.Type == 2 {
  1646. advice_id = 0
  1647. item_id = 0
  1648. project_id = item.ProjectId
  1649. } else if item.Type == 3 {
  1650. advice_id = 0
  1651. item_id = item.ItemId
  1652. project_id = 0
  1653. }
  1654. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1655. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1656. pric, _ := strconv.ParseFloat(item.Price, 32)
  1657. info := &models.HisOrderInfo{
  1658. OrderNumber: order.Number,
  1659. UploadDate: time.Now().Unix(),
  1660. AdviceId: advice_id,
  1661. DetItemFeeSumamt: detItemFeeSumamt,
  1662. Cnt: cut,
  1663. Pric: pric,
  1664. PatientId: id,
  1665. Status: 1,
  1666. Mtime: time.Now().Unix(),
  1667. Ctime: time.Now().Unix(),
  1668. UserOrgId: adminUser.CurrentOrgId,
  1669. HisPatientId: his.ID,
  1670. OrderId: order.ID,
  1671. ProjectId: project_id,
  1672. Type: types,
  1673. ItemId: item_id,
  1674. }
  1675. service.CreateOrderInfo(info)
  1676. }
  1677. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1678. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1679. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1680. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1681. if err == nil {
  1682. c.ServeSuccessJSON(map[string]interface{}{
  1683. "msg": "结算成功",
  1684. })
  1685. } else {
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1687. return
  1688. }
  1689. }
  1690. }
  1691. func (c *HisApiController) GetPreUploadInfo() {
  1692. id, _ := c.GetInt64("id")
  1693. record_time := c.GetString("record_time")
  1694. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1695. admin_user_id, _ := c.GetInt64("admin_user_id")
  1696. timeLayout := "2006-01-02"
  1697. loc, _ := time.LoadLocation("Local")
  1698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1699. if err != nil {
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1701. return
  1702. }
  1703. recordDateTime := theTime.Unix()
  1704. adminUser := c.GetAdminUserInfo()
  1705. var prescriptions []*models.HisPrescription
  1706. var start_time int64
  1707. var end_time int64
  1708. data := make(map[string]interface{})
  1709. if settle_accounts_type == 1 { //日结
  1710. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1711. data["pre"] = prescriptions
  1712. } else { //月结
  1713. start_time_str := c.GetString("start_time")
  1714. end_time_str := c.GetString("end_time")
  1715. timeLayout := "2006-01-02"
  1716. loc, _ := time.LoadLocation("Local")
  1717. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1718. if err != nil {
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1720. return
  1721. }
  1722. recordStartTime := theStartTime.Unix()
  1723. start_time = recordStartTime
  1724. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1725. if err != nil {
  1726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1727. return
  1728. }
  1729. recordEndTime := theEndTime.Unix()
  1730. end_time = recordEndTime
  1731. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1732. data["pre"] = prescriptions
  1733. }
  1734. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1735. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1736. timestamp := time.Now().Unix()
  1737. tempTime := time.Unix(timestamp, 0)
  1738. timeFormat := tempTime.Format("20060102150405")
  1739. chrgBchno := rand.Intn(100000) + 10000
  1740. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1741. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1742. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1743. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1744. strconv.FormatInt(his.PatientId, 10)
  1745. client := &http.Client{}
  1746. data["psn_no"] = his.PsnNo
  1747. data["mdtrt_id"] = his.Number
  1748. data["chrg_bchno"] = chrg_bchno
  1749. data["org_name"] = miConfig.OrgName
  1750. data["doctor"] = roles.UserName
  1751. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1752. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1753. data["fixmedins_code"] = miConfig.Code
  1754. data["dept_code"] = department.Number
  1755. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1756. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1757. data["secret_key"] = miConfig.SecretKey
  1758. var ids []int64
  1759. for _, item := range prescriptions {
  1760. ids = append(ids, item.ID)
  1761. }
  1762. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1763. if config.IsOpen == 1 { //对接了医保,走医保流程
  1764. bytesData, _ := json.Marshal(data)
  1765. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1766. resp, _ := client.Do(req)
  1767. defer resp.Body.Close()
  1768. body, ioErr := ioutil.ReadAll(resp.Body)
  1769. if ioErr != nil {
  1770. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1772. return
  1773. }
  1774. var respJSON map[string]interface{}
  1775. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1776. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1778. return
  1779. }
  1780. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1781. userJSONBytes, _ := json.Marshal(respJSON)
  1782. var res ResultFour
  1783. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1784. utils.ErrorLog("解析失败:%v", err)
  1785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1786. return
  1787. }
  1788. if res.Infcode == 0 {
  1789. order := &models.HisOrder{
  1790. UserOrgId: adminUser.CurrentOrgId,
  1791. HisPatientId: his.ID,
  1792. PatientId: his.PatientId,
  1793. SettleAccountsDate: recordDateTime,
  1794. Ctime: time.Now().Unix(),
  1795. Mtime: time.Now().Unix(),
  1796. Status: 1,
  1797. Number: chrg_bchno,
  1798. Infcode: res.Infcode,
  1799. WarnMsg: res.WarnMsg,
  1800. Cainfo: res.Cainfo,
  1801. ErrMsg: res.ErrMsg,
  1802. RespondTime: res.RefmsgTime,
  1803. InfRefmsgid: res.InfRefmsgid,
  1804. OrderStatus: 1,
  1805. IsMedicineInsurance: 1,
  1806. SettleType: settle_accounts_type,
  1807. SettleStartTime: start_time,
  1808. SettleEndTime: end_time,
  1809. Creator: roles.ID,
  1810. Modify: roles.ID,
  1811. }
  1812. err = service.CreateOrder(order)
  1813. if err != nil {
  1814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1815. return
  1816. }
  1817. for _, item := range res.Output.Result {
  1818. temp := strings.Split(item.FeedetlSn, "-")
  1819. var advice_id int64 = 0
  1820. var project_id int64 = 0
  1821. var types int64 = 0
  1822. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1823. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1824. if temp[1] == "1" {
  1825. advice_id = id
  1826. project_id = 0
  1827. } else if temp[1] == "2" {
  1828. advice_id = 0
  1829. project_id = id
  1830. }
  1831. info := &models.HisOrderInfo{
  1832. OrderNumber: order.Number,
  1833. FeedetlSn: item.FeedetlSn,
  1834. UploadDate: time.Now().Unix(),
  1835. AdviceId: advice_id,
  1836. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1837. Cnt: item.Cnt,
  1838. Pric: float64(item.Pric),
  1839. PatientId: his.PatientId,
  1840. PricUplmtAmt: item.PricUplmtAmt,
  1841. SelfpayProp: item.SelfpayProp,
  1842. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1843. OverlmtAmt: item.OverlmtAmt,
  1844. PreselfpayAmt: item.PreselfpayAmt,
  1845. BasMednFlag: item.BasMednFlag,
  1846. MedChrgitmType: item.MedChrgitmType,
  1847. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1848. Status: 1,
  1849. Memo: item.Memo,
  1850. Mtime: time.Now().Unix(),
  1851. InscpScpAmt: item.InscpScpAmt,
  1852. DrtReimFlag: item.DrtReimFlag,
  1853. Ctime: time.Now().Unix(),
  1854. ListSpItemFlag: item.ListSpItemFlag,
  1855. ChldMedcFlag: item.ChldMedcFlag,
  1856. LmtUsedFlag: item.LmtUsedFlag,
  1857. ChrgitmLv: item.ChrgitmLv,
  1858. UserOrgId: adminUser.CurrentOrgId,
  1859. HisPatientId: his.ID,
  1860. OrderId: order.ID,
  1861. ProjectId: project_id,
  1862. Type: types,
  1863. }
  1864. service.CreateOrderInfo(info)
  1865. }
  1866. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1867. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1868. var total float64
  1869. for _, item := range prescriptions {
  1870. if item.Type == 1 { //药品
  1871. for _, subItem := range item.HisDoctorAdviceInfo {
  1872. total = total + (subItem.Price * subItem.PrescribingNumber)
  1873. }
  1874. }
  1875. if item.Type == 2 { //项目
  1876. for _, subItem := range item.HisPrescriptionProject {
  1877. total = total + (subItem.Price * float64(subItem.Count))
  1878. }
  1879. }
  1880. }
  1881. for _, item := range prescriptions {
  1882. for _, subItem := range item.HisAdditionalCharge {
  1883. total = total + (subItem.Price * float64(subItem.Count))
  1884. }
  1885. }
  1886. allTotal := fmt.Sprintf("%.2f", total)
  1887. if res.Infcode == 0 {
  1888. var rf []*ResultFive
  1889. json.Unmarshal([]byte(his.Iinfo), &rf)
  1890. psn_no := his.PsnNo
  1891. mdtrt_id := his.Number
  1892. chrg_bchno := chrg_bchno
  1893. cert_no := his.Certno
  1894. insutype := rf[0].Insutype
  1895. if his.IdCardType == 1 {
  1896. cert_no = his.MedicalInsuranceNumber
  1897. } else {
  1898. cert_no = his.Certno
  1899. }
  1900. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1901. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1902. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1903. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1904. resp, requestErr := http.Get(api)
  1905. if requestErr != nil {
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. defer resp.Body.Close()
  1910. body, ioErr := ioutil.ReadAll(resp.Body)
  1911. if ioErr != nil {
  1912. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1914. return
  1915. }
  1916. var respJSON map[string]interface{}
  1917. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1918. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1920. return
  1921. }
  1922. fmt.Println(respJSON)
  1923. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1924. userJSONBytes, _ := json.Marshal(respJSON)
  1925. var res ResultSeven
  1926. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1927. utils.ErrorLog("解析失败:%v", err)
  1928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1929. return
  1930. }
  1931. if res.Infcode == -1 {
  1932. errlog := &models.HisOrderError{
  1933. UserOrgId: adminUser.CurrentOrgId,
  1934. Ctime: time.Now().Unix(),
  1935. Mtime: time.Now().Unix(),
  1936. Number: chrg_bchno,
  1937. ErrMsg: res.ErrMsg,
  1938. Status: 1,
  1939. PatientId: id,
  1940. RecordTime: recordDateTime,
  1941. Stage: 7,
  1942. }
  1943. service.CreateErrMsgLog(errlog)
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1945. return
  1946. } else {
  1947. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1948. order.OrderStatus = 1
  1949. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1950. order.SetlId = res.Output.Setlinfo.SetlID
  1951. order.PsnNo = res.Output.Setlinfo.PsnNo
  1952. order.PsnName = res.Output.Setlinfo.PsnName
  1953. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1954. order.Certno = res.Output.Setlinfo.Certno
  1955. order.Gend = res.Output.Setlinfo.Gend
  1956. order.Naty = res.Output.Setlinfo.Naty
  1957. order.Age = res.Output.Setlinfo.Age
  1958. order.Insutype = res.Output.Setlinfo.Insutype
  1959. order.PsnType = res.Output.Setlinfo.PsnType
  1960. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1961. order.SetlTime = res.Output.Setlinfo.SetlTime
  1962. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1963. order.MedType = res.Output.Setlinfo.MedType
  1964. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1965. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1966. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1967. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1968. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1969. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1970. order.HifpPay = res.Output.Setlinfo.HifpPay
  1971. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1972. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1973. order.HifesPay = res.Output.Setlinfo.HifesPay
  1974. order.HifobPay = res.Output.Setlinfo.HifobPay
  1975. order.MafPay = res.Output.Setlinfo.MafPay
  1976. order.OthPay = res.Output.Setlinfo.OthPay
  1977. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1978. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1979. order.AcctPay = res.Output.Setlinfo.AcctPay
  1980. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1981. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1982. order.Balc = res.Output.Setlinfo.Balc
  1983. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1984. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1985. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1986. order.ClrWay = res.Output.Setlinfo.ClrWay
  1987. order.Creator = order.Creator
  1988. order.Modify = roles.ID
  1989. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1990. detailStr := string(setlDetail)
  1991. order.SetlDetail = detailStr
  1992. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1993. err = service.UpDateOrder(order)
  1994. if err == nil {
  1995. c.ServeSuccessJSON(map[string]interface{}{
  1996. "msg": "预结算成功",
  1997. })
  1998. } else {
  1999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2000. return
  2001. }
  2002. }
  2003. } else {
  2004. adminUser := c.GetAdminUserInfo()
  2005. errlog := &models.HisOrderError{
  2006. UserOrgId: adminUser.CurrentOrgId,
  2007. Ctime: time.Now().Unix(),
  2008. Mtime: time.Now().Unix(),
  2009. ErrMsg: res.ErrMsg,
  2010. Status: 1,
  2011. PatientId: id,
  2012. RecordTime: recordDateTime,
  2013. Stage: 4,
  2014. }
  2015. service.CreateErrMsgLog(errlog)
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2017. return
  2018. }
  2019. } else {
  2020. adminUser := c.GetAdminUserInfo()
  2021. errlog := &models.HisOrderError{
  2022. UserOrgId: adminUser.CurrentOrgId,
  2023. Ctime: time.Now().Unix(),
  2024. Mtime: time.Now().Unix(),
  2025. ErrMsg: res.ErrMsg,
  2026. Status: 1,
  2027. PatientId: id,
  2028. RecordTime: recordDateTime,
  2029. Stage: 4,
  2030. }
  2031. service.CreateErrMsgLog(errlog)
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2033. return
  2034. }
  2035. } else {
  2036. var total float64
  2037. for _, item := range prescriptions {
  2038. if item.Type == 1 { //药品
  2039. for _, subItem := range item.HisDoctorAdviceInfo {
  2040. total = total + (subItem.Price * subItem.PrescribingNumber)
  2041. }
  2042. }
  2043. if item.Type == 2 { //项目
  2044. for _, subItem := range item.HisPrescriptionProject {
  2045. total = total + (subItem.Price * float64(subItem.Count))
  2046. }
  2047. }
  2048. for _, subItem := range item.HisAdditionalCharge {
  2049. total = total + (subItem.Price * float64(subItem.Count))
  2050. }
  2051. }
  2052. allTotal := fmt.Sprintf("%.2f", total)
  2053. totals, _ := strconv.ParseFloat(allTotal, 64)
  2054. order := &models.HisOrder{
  2055. UserOrgId: adminUser.CurrentOrgId,
  2056. HisPatientId: his.ID,
  2057. PatientId: id,
  2058. SettleAccountsDate: recordDateTime,
  2059. Ctime: time.Now().Unix(),
  2060. Mtime: time.Now().Unix(),
  2061. Status: 1,
  2062. OrderStatus: 2,
  2063. Number: chrg_bchno,
  2064. MedfeeSumamt: totals,
  2065. }
  2066. err = service.CreateOrder(order)
  2067. if err != nil {
  2068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2069. return
  2070. }
  2071. var customs []*Custom
  2072. for _, item := range prescriptions {
  2073. if item.Type == 1 { //药品
  2074. for _, subItem := range item.HisDoctorAdviceInfo {
  2075. cus := &Custom{
  2076. AdviceId: subItem.ID,
  2077. ProjectId: 0,
  2078. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2079. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2080. FeedetlSn: subItem.FeedetlSn,
  2081. Price: fmt.Sprintf("%.2f", subItem.Price),
  2082. MedListCodg: subItem.MedListCodg,
  2083. Type: 1,
  2084. }
  2085. customs = append(customs, cus)
  2086. }
  2087. }
  2088. if item.Type == 2 { //项目
  2089. for _, subItem := range item.HisPrescriptionProject {
  2090. cus := &Custom{
  2091. AdviceId: 0,
  2092. ProjectId: subItem.ID,
  2093. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2094. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2095. FeedetlSn: subItem.FeedetlSn,
  2096. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2097. MedListCodg: subItem.MedListCodg,
  2098. Type: 2,
  2099. }
  2100. customs = append(customs, cus)
  2101. }
  2102. }
  2103. for _, item := range item.HisAdditionalCharge {
  2104. cus := &Custom{
  2105. ItemId: item.ID,
  2106. AdviceId: 0,
  2107. ProjectId: 0,
  2108. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2109. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2110. FeedetlSn: item.FeedetlSn,
  2111. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2112. MedListCodg: item.XtHisAddtionConfig.Code,
  2113. Type: 3,
  2114. }
  2115. customs = append(customs, cus)
  2116. }
  2117. }
  2118. for _, item := range customs {
  2119. var advice_id int64 = 0
  2120. var project_id int64 = 0
  2121. var item_id int64 = 0
  2122. var types int64 = 0
  2123. if item.Type == 1 {
  2124. advice_id = item.AdviceId
  2125. project_id = 0
  2126. item_id = 0
  2127. } else if item.Type == 2 {
  2128. advice_id = 0
  2129. item_id = 0
  2130. project_id = item.ProjectId
  2131. } else if item.Type == 3 {
  2132. advice_id = 0
  2133. item_id = item.ItemId
  2134. project_id = 0
  2135. }
  2136. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2137. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2138. pric, _ := strconv.ParseFloat(item.Price, 32)
  2139. info := &models.HisOrderInfo{
  2140. OrderNumber: order.Number,
  2141. UploadDate: time.Now().Unix(),
  2142. AdviceId: advice_id,
  2143. DetItemFeeSumamt: detItemFeeSumamt,
  2144. Cnt: cut,
  2145. Pric: pric,
  2146. PatientId: id,
  2147. Status: 1,
  2148. Mtime: time.Now().Unix(),
  2149. Ctime: time.Now().Unix(),
  2150. UserOrgId: adminUser.CurrentOrgId,
  2151. HisPatientId: his.ID,
  2152. OrderId: order.ID,
  2153. ProjectId: project_id,
  2154. Type: types,
  2155. ItemId: item_id,
  2156. }
  2157. service.CreateOrderInfo(info)
  2158. }
  2159. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2160. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2161. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2162. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2163. if err == nil {
  2164. c.ServeSuccessJSON(map[string]interface{}{
  2165. "msg": "结算成功",
  2166. })
  2167. } else {
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2169. return
  2170. }
  2171. }
  2172. }
  2173. func (c *HisApiController) GetSettleInfo() {
  2174. id, _ := c.GetInt64("id")
  2175. order_id, _ := c.GetInt64("order_id")
  2176. record_time := c.GetString("record_time")
  2177. pay_way, _ := c.GetInt64("pay_way")
  2178. pay_price, _ := c.GetFloat("pay_price")
  2179. pay_card_no := c.GetString("pay_card_no")
  2180. discount_price, _ := c.GetFloat("discount_price")
  2181. preferential_price, _ := c.GetFloat("preferential_price")
  2182. reality_price, _ := c.GetFloat("reality_price")
  2183. found_price, _ := c.GetFloat("found_price")
  2184. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2185. private_price, _ := c.GetFloat("private_price")
  2186. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2187. admin_user_id, _ := c.GetInt64("admin_user_id")
  2188. timeLayout := "2006-01-02"
  2189. loc, _ := time.LoadLocation("Local")
  2190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2191. if err != nil {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2193. return
  2194. }
  2195. recordDateTime := theTime.Unix()
  2196. adminUser := c.GetAdminUserInfo()
  2197. var prescriptions []*models.HisPrescription
  2198. data := make(map[string]interface{})
  2199. if settle_accounts_type == 1 { //日结
  2200. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2201. data["pre"] = prescriptions
  2202. } else { //月结
  2203. start_time_str := c.GetString("start_time")
  2204. end_time_str := c.GetString("end_time")
  2205. timeLayout := "2006-01-02"
  2206. loc, _ := time.LoadLocation("Local")
  2207. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2208. if err != nil {
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2210. return
  2211. }
  2212. recordStartTime := theStartTime.Unix()
  2213. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2214. if err != nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2216. return
  2217. }
  2218. recordEndTime := theEndTime.Unix()
  2219. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2220. data["pre"] = prescriptions
  2221. }
  2222. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2223. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2224. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2225. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2226. strconv.FormatInt(his.PatientId, 10)
  2227. order_src, _ := service.GetHisOrderByID(order_id)
  2228. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2229. if config.IsOpen == 1 { //对接了医保,走医保流程
  2230. var total float64
  2231. for _, item := range prescriptions {
  2232. if item.Type == 1 { //药品
  2233. for _, subItem := range item.HisDoctorAdviceInfo {
  2234. total = total + (subItem.Price * subItem.PrescribingNumber)
  2235. }
  2236. }
  2237. if item.Type == 2 { //项目
  2238. for _, subItem := range item.HisPrescriptionProject {
  2239. total = total + (subItem.Price * float64(subItem.Count))
  2240. }
  2241. }
  2242. }
  2243. for _, item := range prescriptions {
  2244. for _, subItem := range item.HisAdditionalCharge {
  2245. total = total + (subItem.Price * float64(subItem.Count))
  2246. }
  2247. }
  2248. allTotal := fmt.Sprintf("%.2f", total)
  2249. var rf []*ResultFive
  2250. json.Unmarshal([]byte(his.Iinfo), &rf)
  2251. psn_no := order_src.PsnNo
  2252. mdtrt_id := order_src.MdtrtId
  2253. chrg_bchno := order_src.Number
  2254. cert_no := order_src.Certno
  2255. insutype := rf[0].Insutype
  2256. if his.IdCardType == 1 {
  2257. cert_no = his.MedicalInsuranceNumber
  2258. } else {
  2259. cert_no = his.Certno
  2260. }
  2261. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  2262. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2263. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2264. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10) + "&fulamt_ownpay_amt=" + strconv.FormatFloat(order_src.FulamtOwnpayAmt, 'E', -1, 64) + "&overlmt_selfpay=" + strconv.FormatFloat(order_src.OverlmtSelfPay, 'E', -1, 64) + "&preselfpay_amt=" + strconv.FormatFloat(order_src.PreselfpayAmt, 'E', -1, 64) + "&inscp_scp_amt=" + strconv.FormatFloat(order_src.InscpScpAmt, 'E', -1, 64)
  2265. resp, requestErr := http.Get(api)
  2266. if requestErr != nil {
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2268. return
  2269. }
  2270. defer resp.Body.Close()
  2271. body, ioErr := ioutil.ReadAll(resp.Body)
  2272. if ioErr != nil {
  2273. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2275. return
  2276. }
  2277. var respJSON map[string]interface{}
  2278. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2279. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2281. return
  2282. }
  2283. fmt.Println(respJSON)
  2284. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2285. userJSONBytes, _ := json.Marshal(respJSON)
  2286. var res ResultSeven
  2287. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2288. utils.ErrorLog("解析失败:%v", err)
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2290. return
  2291. }
  2292. if res.Infcode == -1 {
  2293. errlog := &models.HisOrderError{
  2294. UserOrgId: adminUser.CurrentOrgId,
  2295. Ctime: time.Now().Unix(),
  2296. Mtime: time.Now().Unix(),
  2297. Number: chrg_bchno,
  2298. ErrMsg: res.ErrMsg,
  2299. Status: 1,
  2300. PatientId: id,
  2301. RecordTime: recordDateTime,
  2302. Stage: 6,
  2303. }
  2304. service.CreateErrMsgLog(errlog)
  2305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2306. return
  2307. } else {
  2308. order_src.OrderStatus = 2
  2309. order_src.PayWay = pay_way
  2310. order_src.PayPrice = pay_price
  2311. order_src.PayCardNo = pay_card_no
  2312. order_src.DiscountPrice = discount_price
  2313. order_src.PreferentialPrice = preferential_price
  2314. order_src.RealityPrice = reality_price
  2315. order_src.FoundPrice = found_price
  2316. order_src.MedicalInsurancePrice = medical_insurance_price
  2317. order_src.PrivatePrice = private_price
  2318. order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2319. order_src.SetlId = res.Output.Setlinfo.SetlID
  2320. order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2321. order_src.PsnName = res.Output.Setlinfo.PsnName
  2322. order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2323. order_src.Certno = res.Output.Setlinfo.Certno
  2324. order_src.Gend = res.Output.Setlinfo.Gend
  2325. order_src.Naty = res.Output.Setlinfo.Naty
  2326. order_src.Age = res.Output.Setlinfo.Age
  2327. order_src.Insutype = res.Output.Setlinfo.Insutype
  2328. order_src.PsnType = res.Output.Setlinfo.PsnType
  2329. order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2330. order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2331. order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2332. order_src.MedType = res.Output.Setlinfo.MedType
  2333. order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2334. order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2335. order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2336. order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2337. order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2338. order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2339. order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2340. order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2341. order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2342. order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2343. order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2344. order_src.MafPay = res.Output.Setlinfo.MafPay
  2345. order_src.OthPay = res.Output.Setlinfo.OthPay
  2346. order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2347. order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2348. order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2349. order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2350. order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2351. order_src.Balc = res.Output.Setlinfo.Balc
  2352. order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2353. order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2354. order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2355. order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2356. order_src.Creator = order_src.Creator
  2357. order_src.Modify = roles.ID
  2358. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2359. detailStr := string(setlDetail)
  2360. order_src.SetlDetail = detailStr
  2361. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2362. err = service.UpDateOrder(order_src)
  2363. if err == nil {
  2364. c.ServeSuccessJSON(map[string]interface{}{
  2365. "msg": "结算成功",
  2366. })
  2367. } else {
  2368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2369. return
  2370. }
  2371. }
  2372. }
  2373. }
  2374. //退款
  2375. func (c *HisApiController) Refund() {
  2376. order_id, _ := c.GetInt64("order_id")
  2377. admin_user_id, _ := c.GetInt64("admin_user_id")
  2378. number := c.GetString("number")
  2379. record_time := c.GetString("record_time")
  2380. patient_id, _ := c.GetInt64("patient_id")
  2381. timeLayout := "2006-01-02"
  2382. loc, _ := time.LoadLocation("Local")
  2383. adminUser := c.GetAdminUserInfo()
  2384. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2385. fmt.Println(err)
  2386. if err != nil {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2388. return
  2389. }
  2390. recordDateTime := theTime.Unix()
  2391. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2392. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2393. var order models.HisOrder
  2394. order, _ = service.GetHisOrderByID(order_id)
  2395. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2396. if order.ID == 0 {
  2397. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2398. }
  2399. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2400. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2401. if config.IsOpen == 1 { //对接了医保,走医保流程
  2402. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  2403. "&mdtrt_id=" + his.Number + "&doctor=" + roles.UserName + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2404. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2405. resp, requestErr := http.Get(api)
  2406. if requestErr != nil {
  2407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2408. return
  2409. }
  2410. body, ioErr := ioutil.ReadAll(resp.Body)
  2411. if ioErr != nil {
  2412. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2414. return
  2415. }
  2416. var respJSON map[string]interface{}
  2417. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2418. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2420. return
  2421. }
  2422. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2423. userJSONBytes, _ := json.Marshal(respJSON)
  2424. fmt.Println(respJSON)
  2425. fmt.Println(userJSONBytes)
  2426. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2427. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2428. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2429. resp2, requestErr2 := http.Get(api2)
  2430. if requestErr2 != nil {
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2432. return
  2433. }
  2434. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2435. if ioErr2 != nil {
  2436. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2438. return
  2439. }
  2440. var respJSON2 map[string]interface{}
  2441. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2442. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2444. return
  2445. }
  2446. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2447. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2448. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2449. //resp3, requestErr3 := http.Get(api3)
  2450. //if requestErr3 != nil {
  2451. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2452. // return
  2453. //}
  2454. //
  2455. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2456. //if ioErr3 != nil {
  2457. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2458. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2459. // return
  2460. //}
  2461. //var respJSON3 map[string]interface{}
  2462. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2463. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2464. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2465. // return
  2466. //}
  2467. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2468. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2469. if err == nil {
  2470. c.ServeSuccessJSON(map[string]interface{}{
  2471. "msg": "退费成功",
  2472. })
  2473. } else {
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2475. return
  2476. }
  2477. } else {
  2478. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2479. if err == nil {
  2480. c.ServeSuccessJSON(map[string]interface{}{
  2481. "msg": "退费成功",
  2482. })
  2483. } else {
  2484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2485. return
  2486. }
  2487. }
  2488. }
  2489. func (c *HisApiController) RefundNumber() {
  2490. record_time := c.GetString("record_time")
  2491. patient_id, _ := c.GetInt64("patient_id")
  2492. admin_user_id, _ := c.GetInt64("admin_user_id")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. adminUser := c.GetAdminUserInfo()
  2496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2497. fmt.Println(err)
  2498. if err != nil {
  2499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2500. return
  2501. }
  2502. recordDateTime := theTime.Unix()
  2503. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2504. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2505. //order, _ := service.GetHisOrderByID(order_id)
  2506. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2507. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2508. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2509. if config.IsOpen == 1 { //对接了医保,走医保流程
  2510. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2511. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2512. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2513. resp3, requestErr3 := http.Get(api3)
  2514. if requestErr3 != nil {
  2515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2516. return
  2517. }
  2518. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2519. if ioErr3 != nil {
  2520. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2522. return
  2523. }
  2524. var respJSON3 map[string]interface{}
  2525. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2526. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. return
  2529. }
  2530. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2531. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2532. if err == nil {
  2533. c.ServeSuccessJSON(map[string]interface{}{
  2534. "msg": "退号成功",
  2535. })
  2536. } else {
  2537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2538. return
  2539. }
  2540. } else {
  2541. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2542. //if err == nil {
  2543. // c.ServeSuccessJSON(map[string]interface{}{
  2544. // "msg": "退费成功",
  2545. // })
  2546. //} else {
  2547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2548. // return
  2549. //}
  2550. }
  2551. }
  2552. func (c *HisApiController) RefundDetail() {
  2553. order_id, _ := c.GetInt64("order_id")
  2554. number := c.GetString("number")
  2555. record_time := c.GetString("record_time")
  2556. patient_id, _ := c.GetInt64("patient_id")
  2557. timeLayout := "2006-01-02"
  2558. loc, _ := time.LoadLocation("Local")
  2559. adminUser := c.GetAdminUserInfo()
  2560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2561. fmt.Println(err)
  2562. if err != nil {
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. recordDateTime := theTime.Unix()
  2567. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2568. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2569. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2570. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2571. var order models.HisOrder
  2572. order, _ = service.GetHisOrderByID(order_id)
  2573. if order.ID == 0 {
  2574. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2575. }
  2576. if config.IsOpen == 1 { //对接了医保,走医保流程
  2577. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2578. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2579. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2580. resp2, requestErr2 := http.Get(api2)
  2581. if requestErr2 != nil {
  2582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2583. return
  2584. }
  2585. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2586. if ioErr2 != nil {
  2587. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2589. return
  2590. }
  2591. var respJSON2 map[string]interface{}
  2592. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2593. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2595. return
  2596. }
  2597. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2598. if err == nil {
  2599. c.ServeSuccessJSON(map[string]interface{}{
  2600. "msg": "退费成功",
  2601. })
  2602. } else {
  2603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2604. return
  2605. }
  2606. } else {
  2607. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2608. if err == nil {
  2609. c.ServeSuccessJSON(map[string]interface{}{
  2610. "msg": "退费成功",
  2611. })
  2612. } else {
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2614. return
  2615. }
  2616. }
  2617. }
  2618. //对账
  2619. func (c *HisApiController) GetCheckAccount() {
  2620. start_time := c.GetString("start_time")
  2621. end_time := c.GetString("end_time")
  2622. insutype := c.GetString("insutype")
  2623. clr_type := c.GetString("clr_type")
  2624. admin_user_id, _ := c.GetInt64("admin_user_id")
  2625. adminUser := c.GetAdminUserInfo()
  2626. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2627. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2628. timeLayout := "2006-01-02"
  2629. loc, _ := time.LoadLocation("Local")
  2630. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2631. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2632. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2633. orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2634. fixmedins_setl_cnt := int64(len(orders_two))
  2635. //撤销的算2条数据为一笔
  2636. for _, item := range orders_two {
  2637. if item.OrderStatus == 3 {
  2638. fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  2639. }
  2640. }
  2641. var medfee_sumamt float64
  2642. var acct_pay float64
  2643. var fund_pay_sumamt float64
  2644. for _, item := range orders {
  2645. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2646. acct_pay = acct_pay + item.AcctPay
  2647. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2648. }
  2649. var user_name string
  2650. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2651. if role.ID == 0 {
  2652. user_name = "xxx"
  2653. } else {
  2654. user_name = role.UserName
  2655. }
  2656. if config.IsOpen == 1 {
  2657. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2658. "insutype=" + insutype +
  2659. "&clr_type=" + clr_type +
  2660. "&setl_optins=" + "定点医保中心" +
  2661. "&stmt_begndate=" + start_time +
  2662. "&stm_enddate=" + end_time +
  2663. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2664. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2665. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2666. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2667. "&fixmedins_code=" + miConfig.Code +
  2668. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2669. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2670. "&secret_key=" + miConfig.SecretKey +
  2671. "&org_name=" + miConfig.OrgName +
  2672. "&doctor=" + user_name
  2673. fmt.Println(api)
  2674. resp, requestErr := http.Get(api)
  2675. if requestErr != nil {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2677. return
  2678. }
  2679. body, ioErr := ioutil.ReadAll(resp.Body)
  2680. fmt.Println(body)
  2681. if ioErr != nil {
  2682. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2684. return
  2685. }
  2686. var respJSON map[string]interface{}
  2687. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2688. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2690. return
  2691. }
  2692. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2693. userJSONBytes, _ := json.Marshal(respJSON)
  2694. var res ResultEight
  2695. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2696. utils.ErrorLog("解析失败:%v", err)
  2697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2698. return
  2699. }
  2700. if res.Infcode == 0 {
  2701. if res.Output.Stmtinfo.StmtRslt == "0" {
  2702. micc := &models.MedicalInsuranceCostCompare{
  2703. StartTime: startime.Unix(),
  2704. EndTime: endtime.Unix(),
  2705. Insutype: insutype,
  2706. CheckType: 1,
  2707. Num: fixmedins_setl_cnt,
  2708. Mtime: time.Now().Unix(),
  2709. Status: 1,
  2710. UserOrgId: adminUser.CurrentOrgId,
  2711. CostTotal: medfee_sumamt,
  2712. FuncTotal: fund_pay_sumamt,
  2713. PsnPay: acct_pay,
  2714. Creator: admin_user_id,
  2715. Ctime: time.Now().Unix(),
  2716. }
  2717. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2718. if err == nil {
  2719. c.ServeSuccessJSON(map[string]interface{}{
  2720. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2721. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2722. })
  2723. } else {
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2725. }
  2726. } else {
  2727. c.ServeSuccessJSON(map[string]interface{}{
  2728. "code": -10,
  2729. "msg": res.ErrMsg,
  2730. })
  2731. }
  2732. } else {
  2733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. }
  2735. }
  2736. }
  2737. func (c *HisApiController) Check310() {
  2738. adminUser := c.GetAdminUserInfo()
  2739. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2740. var user_name string
  2741. user_name = "xxx"
  2742. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2743. "insutype=" + "310" +
  2744. "&clr_type=" + "11" +
  2745. "&setl_optins=" + "定点医保中心" +
  2746. "&stmt_begndate=" + "2021-03-01" +
  2747. "&stm_enddate=" + "2021-03-31" +
  2748. "&medfee_sumamt=" + "11521" +
  2749. "&fund_pay_sumamt=" + "10166.66" +
  2750. "&acct_pay=" + "0" +
  2751. "&fixmedins_setl_cnt=" + "7" +
  2752. "&fixmedins_code=" + miConfig.Code +
  2753. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2754. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2755. "&secret_key=" + miConfig.SecretKey +
  2756. "&org_name=" + miConfig.OrgName +
  2757. "&doctor=" + user_name
  2758. fmt.Println(api)
  2759. resp, requestErr := http.Get(api)
  2760. if requestErr != nil {
  2761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2762. return
  2763. }
  2764. body, ioErr := ioutil.ReadAll(resp.Body)
  2765. fmt.Println(body)
  2766. if ioErr != nil {
  2767. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2769. return
  2770. }
  2771. var respJSON map[string]interface{}
  2772. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2773. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2775. return
  2776. }
  2777. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2778. userJSONBytes, _ := json.Marshal(respJSON)
  2779. var res ResultEight
  2780. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2781. utils.ErrorLog("解析失败:%v", err)
  2782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2783. return
  2784. }
  2785. }
  2786. func (c *HisApiController) Check390() {
  2787. adminUser := c.GetAdminUserInfo()
  2788. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2789. var user_name string
  2790. user_name = "张俊杰"
  2791. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2792. "insutype=" + "390" +
  2793. "&clr_type=" + "11" +
  2794. "&setl_optins=" + "定点医保中心" +
  2795. "&stmt_begndate=" + "2021-03-01" +
  2796. "&stm_enddate=" + "2021-03-31" +
  2797. "&medfee_sumamt=" + "209318.43" +
  2798. "&fund_pay_sumamt=" + "188029.12" +
  2799. "&acct_pay=" + "0" +
  2800. "&fixmedins_setl_cnt=" + "48" +
  2801. "&fixmedins_code=" + miConfig.Code +
  2802. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2803. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2804. "&secret_key=" + miConfig.SecretKey +
  2805. "&org_name=" + miConfig.OrgName +
  2806. "&doctor=" + user_name
  2807. fmt.Println(api)
  2808. resp, requestErr := http.Get(api)
  2809. if requestErr != nil {
  2810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2811. return
  2812. }
  2813. body, ioErr := ioutil.ReadAll(resp.Body)
  2814. fmt.Println(body)
  2815. if ioErr != nil {
  2816. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2818. return
  2819. }
  2820. var respJSON map[string]interface{}
  2821. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2822. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2824. return
  2825. }
  2826. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2827. userJSONBytes, _ := json.Marshal(respJSON)
  2828. var res ResultEight
  2829. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2830. utils.ErrorLog("解析失败:%v", err)
  2831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2832. return
  2833. }
  2834. }
  2835. //对账明细
  2836. func (c *HisApiController) GetCheckDetailAccount() {
  2837. start_time := c.GetString("start_time")
  2838. end_time := c.GetString("end_time")
  2839. admin_user_id, _ := c.GetInt64("admin_user_id")
  2840. adminUser := c.GetAdminUserInfo()
  2841. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2842. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2843. timeLayout := "2006-01-02"
  2844. loc, _ := time.LoadLocation("Local")
  2845. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2846. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2847. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2848. Mkdir(miConfig.OrgName)
  2849. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2850. file_name := file + ".txt"
  2851. zip_name := file + ".zip"
  2852. zip_path := miConfig.OrgName + "/" + zip_name
  2853. file_path := miConfig.OrgName + "/" + file_name
  2854. decimal.DivisionPrecision = 2
  2855. var medfee_sumamt float64
  2856. var psn_cash_pay float64
  2857. var fund_pay_sumamt float64
  2858. fixmedins_setl_cnt := int64(len(orders))
  2859. for _, item := range orders {
  2860. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2861. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  2862. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2863. }
  2864. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2865. defer f.Close()
  2866. if err != nil {
  2867. fmt.Println(err.Error())
  2868. } else {
  2869. for _, item := range orders {
  2870. var refd_setl_flag string
  2871. if item.OrderStatus == 2 {
  2872. refd_setl_flag = "0"
  2873. }
  2874. if item.OrderStatus == 3 {
  2875. refd_setl_flag = "1"
  2876. }
  2877. var str string
  2878. str = item.SetlId + " " +
  2879. item.MdtrtId + " " +
  2880. item.PsnNo + " " +
  2881. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2882. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2883. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2884. _, err = f.Write([]byte(str))
  2885. }
  2886. }
  2887. Zip(file_path, zip_path)
  2888. fmt.Println(ReadFile(zip_path))
  2889. fmt.Println(string(ReadFile(zip_path)))
  2890. if config.IsOpen == 1 {
  2891. var user_name string
  2892. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2893. if role.ID == 0 {
  2894. user_name = "管理员"
  2895. } else {
  2896. user_name = role.UserName
  2897. }
  2898. baseParams := models.BaseParams{
  2899. SecretKey: miConfig.SecretKey,
  2900. FixmedinsCode: miConfig.Code,
  2901. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2902. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2903. OrgName: miConfig.OrgName,
  2904. Doctor: user_name,
  2905. }
  2906. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2907. var dat map[string]interface{}
  2908. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2909. fmt.Println(dat)
  2910. } else {
  2911. fmt.Println(err)
  2912. }
  2913. userJSONBytes, _ := json.Marshal(dat)
  2914. var res ResultNine
  2915. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2916. utils.ErrorLog("解析失败:%v", err)
  2917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2918. return
  2919. }
  2920. if res.Infcode == 0 {
  2921. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2922. "file_qury_no=" + res.Output.FileQuryNo +
  2923. "&setl_optins=" + "定点医保中心" +
  2924. "&stmt_begndate=" + start_time +
  2925. "&stm_enddate=" + end_time +
  2926. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2927. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2928. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2929. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2930. "&fixmedins_code=" + miConfig.Code +
  2931. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2932. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2933. "&secret_key=" + miConfig.SecretKey +
  2934. "&org_name=" + miConfig.OrgName +
  2935. "&doctor=" + user_name
  2936. resp, requestErr := http.Get(api)
  2937. if requestErr != nil {
  2938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2939. return
  2940. }
  2941. body, ioErr := ioutil.ReadAll(resp.Body)
  2942. if ioErr != nil {
  2943. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2945. return
  2946. }
  2947. var respJSON map[string]interface{}
  2948. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2949. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2951. return
  2952. }
  2953. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2954. userJSONBytes, _ := json.Marshal(respJSON)
  2955. var res ResultTen
  2956. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2957. utils.ErrorLog("解析失败:%v", err)
  2958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2959. return
  2960. }
  2961. if res.Infcode == 0 {
  2962. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2963. micc := &models.MedicalInsuranceCostCompare{
  2964. StartTime: startime.Unix(),
  2965. EndTime: endtime.Unix(),
  2966. Insutype: "0",
  2967. CheckType: 2,
  2968. Num: fixmedins_setl_cnt,
  2969. Mtime: time.Now().Unix(),
  2970. Status: 1,
  2971. UserOrgId: adminUser.CurrentOrgId,
  2972. CostTotal: medfee_sumamt,
  2973. FuncTotal: fund_pay_sumamt,
  2974. PsnPay: psn_cash_pay,
  2975. Creator: admin_user_id,
  2976. Ctime: time.Now().Unix(),
  2977. }
  2978. service.CreateMedicalInsuranceCostCompareRecord(micc)
  2979. c.ServeSuccessJSON(map[string]interface{}{
  2980. "msg": "明细对账成功",
  2981. })
  2982. }
  2983. } else {
  2984. }
  2985. }
  2986. }
  2987. func (c *HisApiController) GetSettleAccounts() {
  2988. //id, _ := c.GetInt64("id")
  2989. //record_time := c.GetString("record_time")
  2990. order_id, _ := c.GetInt64("order_id")
  2991. admin_user_id, _ := c.GetInt64("admin_user_id")
  2992. //timeLayout := "2006-01-02"
  2993. //loc, _ := time.LoadLocation("Local")
  2994. //
  2995. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2996. //if err != nil {
  2997. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2998. // return
  2999. //}
  3000. //recordDateTime := theTime.Unix()
  3001. adminUser := c.GetAdminUserInfo()
  3002. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3003. order, _ := service.GetHisOrderByID(order_id)
  3004. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3005. var bedCostTotal float64 = 0 //床位总费
  3006. var bedCostSelfTotal float64 = 0 //床位自费
  3007. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3008. var operationCostTotal float64 = 0 //手术费
  3009. var operationCostSelfTotal float64 = 0 //手术费
  3010. var operationCostPartSelfTotal float64 = 0 //手术费
  3011. var otherCostTotal float64 = 0 //其他费用
  3012. var otherCostSelfTotal float64 = 0 //其他费用
  3013. var otherCostPartSelfTotal float64 = 0 //其他费用
  3014. var materialCostTotal float64 = 0 //材料费
  3015. var materialCostSelfTotal float64 = 0 //材料费
  3016. var materialCostPartSelfTotal float64 = 0 //材料费
  3017. var westernMedicineCostTotal float64 = 0 //西药费
  3018. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3019. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3020. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3021. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3022. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3023. var checkCostTotal float64 = 0 //检查费
  3024. var checkCostSelfTotal float64 = 0 //检查费
  3025. var checkCostPartSelfTotal float64 = 0 //检查费
  3026. var laboratoryCostTotal float64 = 0 //化验费
  3027. var laboratoryCostSelfTotal float64 = 0 //化验费
  3028. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3029. var treatCostTotal float64 = 0 //治疗费用
  3030. var treatCostSelfTotal float64 = 0 //治疗费用
  3031. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3032. decimal.DivisionPrecision = 2
  3033. for _, item := range orderInfos {
  3034. if item.MedChrgitmType == "01" { //床位费
  3035. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3036. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3037. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3038. }
  3039. if item.MedChrgitmType == "03" { //检查费
  3040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3041. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3042. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3043. }
  3044. if item.MedChrgitmType == "04" { //化验费
  3045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3046. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3047. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3048. }
  3049. if item.MedChrgitmType == "05" { //治疗费
  3050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3051. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3052. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3053. }
  3054. if item.MedChrgitmType == "06" { //手术费
  3055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3056. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3057. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3058. }
  3059. if item.MedChrgitmType == "08" { //材料费
  3060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3061. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3062. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3063. }
  3064. if item.MedChrgitmType == "09" { //西药费
  3065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3066. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3067. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3068. }
  3069. if item.MedChrgitmType == "11" { //中成费
  3070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3071. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3072. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3073. }
  3074. if item.MedChrgitmType == "14" { //其他费
  3075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3076. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3077. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3078. }
  3079. }
  3080. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3081. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3082. var user_name string
  3083. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3084. if role.ID == 0 {
  3085. user_name = "管理员"
  3086. } else {
  3087. user_name = role.UserName
  3088. }
  3089. baseParams := models.BaseParams{
  3090. SecretKey: miConfig.SecretKey,
  3091. FixmedinsCode: miConfig.Code,
  3092. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3093. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3094. OrgName: miConfig.OrgName,
  3095. Doctor: user_name,
  3096. }
  3097. businessParams := models.BusinessParams{
  3098. PsnNo: order.PsnNo,
  3099. MdtrtId: order.MdtrtId,
  3100. SetlId: order.SetlId,
  3101. }
  3102. if config.IsOpen == 1 {
  3103. result := service.Gdyb5203(baseParams, businessParams)
  3104. var dat map[string]interface{}
  3105. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3106. fmt.Println(dat)
  3107. } else {
  3108. fmt.Println(err)
  3109. }
  3110. userJSONBytes, _ := json.Marshal(dat)
  3111. var res ResultEleven
  3112. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3113. utils.ErrorLog("解析失败:%v", err)
  3114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3115. return
  3116. }
  3117. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3118. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3119. if res.Infcode == 0 {
  3120. c.ServeSuccessJSON(map[string]interface{}{
  3121. "charge_admin": charge_admin,
  3122. "printor_admin": printor_admin,
  3123. "info": res.Output.Setlinfo,
  3124. "bedCostTotal": bedCostTotal,
  3125. "bedCostSelfTotal": bedCostSelfTotal,
  3126. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3127. "operationCostTotal": operationCostTotal,
  3128. "operationCostSelfTotal": operationCostSelfTotal,
  3129. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3130. "otherCostTotal": otherCostTotal,
  3131. "otherCostSelfTotal": otherCostSelfTotal,
  3132. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3133. "materialCostTotal": materialCostTotal,
  3134. "materialCostSelfTotal": materialCostSelfTotal,
  3135. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3136. "westernMedicineCostTotal": westernMedicineCostTotal,
  3137. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3138. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3139. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3140. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3141. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3142. "checkCostTotal": checkCostTotal,
  3143. "checkCostSelfTotal": checkCostSelfTotal,
  3144. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3145. "laboratoryCostTotal": laboratoryCostTotal,
  3146. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3147. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3148. "treatCostTotal": treatCostTotal,
  3149. "treatCostSelfTotal": treatCostSelfTotal,
  3150. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3151. })
  3152. }
  3153. }
  3154. }
  3155. func (c *HisApiController) CheckTreatment() {
  3156. patient_id, _ := c.GetInt64("patient_id", 0)
  3157. record_time := c.GetString("record_time")
  3158. insutype := c.GetString("insutype")
  3159. timeLayout := "2006-01-02"
  3160. loc, _ := time.LoadLocation("Local")
  3161. adminUser := c.GetAdminUserInfo()
  3162. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3163. fmt.Println(err)
  3164. if err != nil {
  3165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3166. return
  3167. }
  3168. recordDateTime := theTime.Unix()
  3169. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3170. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3171. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3172. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3173. var user_name string
  3174. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3175. if role.ID == 0 {
  3176. user_name = "xxx"
  3177. } else {
  3178. user_name = role.UserName
  3179. }
  3180. baseParams := models.BaseParams{
  3181. SecretKey: miConfig.SecretKey,
  3182. FixmedinsCode: miConfig.Code,
  3183. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3184. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3185. OrgName: miConfig.OrgName,
  3186. Doctor: user_name,
  3187. }
  3188. if config.IsOpen == 1 {
  3189. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3190. var dat map[string]interface{}
  3191. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3192. fmt.Println(dat)
  3193. } else {
  3194. fmt.Println(err)
  3195. }
  3196. }
  3197. }
  3198. func (c *HisApiController) PutRecord() {
  3199. id, _ := c.GetInt64("id")
  3200. record_time := c.GetString("record_time")
  3201. timeLayout := "2006-01-02"
  3202. loc, _ := time.LoadLocation("Local")
  3203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3204. if err != nil {
  3205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3206. return
  3207. }
  3208. recordDateTime := theTime.Unix()
  3209. adminInfo := c.GetAdminUserInfo()
  3210. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3211. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3212. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3213. fmt.Println(miConfig.SecretKey)
  3214. if patient == nil {
  3215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3216. return
  3217. }
  3218. if len(patient.IdCardNo) == 0 {
  3219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3220. return
  3221. }
  3222. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3223. if config.IsOpen == 1 {
  3224. 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
  3225. resp, requestErr := http.Get(api)
  3226. if requestErr != nil {
  3227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3228. return
  3229. }
  3230. defer resp.Body.Close()
  3231. body, ioErr := ioutil.ReadAll(resp.Body)
  3232. if ioErr != nil {
  3233. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3235. return
  3236. }
  3237. var respJSON map[string]interface{}
  3238. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3239. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3241. return
  3242. }
  3243. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3244. userJSONBytes, _ := json.Marshal(userJSON)
  3245. var res ResultTwo
  3246. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3247. utils.ErrorLog("解析失败:%v", err)
  3248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3249. return
  3250. }
  3251. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3252. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3253. infoStr := string(Iinfos)
  3254. idetinfoStr := string(Idetinfos)
  3255. if res.Infcode == 0 {
  3256. his := models.VMHisPatient{
  3257. Status: 1,
  3258. Ctime: time.Now().Unix(),
  3259. Mtime: time.Now().Unix(),
  3260. PsnNo: res.Output.Baseinfo.PsnNo,
  3261. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3262. Certno: res.Output.Baseinfo.Certno,
  3263. PsnName: res.Output.Baseinfo.PsnName,
  3264. Gend: res.Output.Baseinfo.Gend,
  3265. Naty: res.Output.Baseinfo.Naty,
  3266. Brdy: res.Output.Baseinfo.Brdy,
  3267. Age: res.Output.Baseinfo.Age,
  3268. Iinfo: infoStr,
  3269. Idetinfo: idetinfoStr,
  3270. PatientId: patient.ID,
  3271. RecordDate: theTime.Unix(),
  3272. UserOrgId: adminInfo.CurrentOrgId,
  3273. AdminUserId: adminInfo.AdminUser.Id,
  3274. IsReturn: 1,
  3275. }
  3276. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3277. 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")
  3278. 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")
  3279. var dat map[string]interface{}
  3280. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3281. fmt.Println(dat)
  3282. } else {
  3283. fmt.Println(err)
  3284. }
  3285. var dat2 map[string]interface{}
  3286. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3287. fmt.Println(dat2)
  3288. } else {
  3289. fmt.Println(err)
  3290. }
  3291. } else {
  3292. adminUser := c.GetAdminUserInfo()
  3293. errlog := &models.HisOrderError{
  3294. UserOrgId: adminUser.CurrentOrgId,
  3295. Ctime: time.Now().Unix(),
  3296. Mtime: time.Now().Unix(),
  3297. ErrMsg: res.ErrMsg,
  3298. Status: 1,
  3299. PatientId: id,
  3300. RecordTime: recordDateTime,
  3301. Stage: 1,
  3302. }
  3303. service.CreateErrMsgLog(errlog)
  3304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3305. return
  3306. }
  3307. }
  3308. }
  3309. func (c *HisApiController) GetUploadDiag() {
  3310. id, _ := c.GetInt64("id")
  3311. record_time := c.GetString("record_time")
  3312. diagnosis_id, _ := c.GetInt64("diagnosis")
  3313. sick_type, _ := c.GetInt64("sick_type")
  3314. reg_type, _ := c.GetInt64("reg_type")
  3315. timeLayout := "2006-01-02"
  3316. loc, _ := time.LoadLocation("Local")
  3317. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3318. if err != nil {
  3319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3320. return
  3321. }
  3322. var patientPrescription models.HisPrescriptionInfo
  3323. recordDateTime := theTime.Unix()
  3324. adminInfo := c.GetAdminUserInfo()
  3325. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3326. if patientPrescription.ID == 0 {
  3327. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3328. }
  3329. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3330. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3331. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3332. sickConfig, _ := service.FindSickById(sick_type)
  3333. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3334. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3335. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3336. "&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 +
  3337. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3338. resp2, requestErr2 := http.Get(api2)
  3339. if requestErr2 != nil {
  3340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3341. return
  3342. }
  3343. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3344. if ioErr2 != nil {
  3345. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3347. return
  3348. }
  3349. var respJSON2 map[string]interface{}
  3350. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3351. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3353. return
  3354. }
  3355. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3356. userJSONBytes2, _ := json.Marshal(respJSON2)
  3357. var res2 ResultSix
  3358. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3359. utils.ErrorLog("解析失败:%v", err)
  3360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. }
  3363. if res2.Infcode == -1 {
  3364. adminUser := c.GetAdminUserInfo()
  3365. errlog := &models.HisOrderError{
  3366. UserOrgId: adminUser.CurrentOrgId,
  3367. Ctime: time.Now().Unix(),
  3368. Mtime: time.Now().Unix(),
  3369. ErrMsg: res2.ErrMsg,
  3370. Status: 1,
  3371. PatientId: id,
  3372. RecordTime: recordDateTime,
  3373. Stage: 3,
  3374. }
  3375. service.CreateErrMsgLog(errlog)
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3377. return
  3378. }
  3379. c.ServeSuccessJSON(map[string]interface{}{
  3380. "msg": "上传成功",
  3381. })
  3382. }
  3383. type QueryResult struct {
  3384. ID int64
  3385. Name string
  3386. Code string
  3387. List_type_code string
  3388. }
  3389. func (c *HisApiController) GetCheckCode() {
  3390. ids_str := c.GetString("ids")
  3391. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3392. ids_arr := strings.Split(ids_str, ",")
  3393. var queryResult []QueryResult
  3394. ids := make([]int64, 0)
  3395. for _, item := range ids_arr {
  3396. id, _ := strconv.ParseInt(item, 10, 64)
  3397. ids = append(ids, id)
  3398. }
  3399. if record_type == 1 {
  3400. drugs, _ := service.GetBatchDrugList(ids)
  3401. for _, item := range drugs {
  3402. result := QueryResult{
  3403. ID: item.ID,
  3404. Name: item.DrugName,
  3405. Code: item.MedicalInsuranceNumber,
  3406. List_type_code: "101",
  3407. }
  3408. queryResult = append(queryResult, result)
  3409. }
  3410. } else if record_type == 2 {
  3411. goods, _ := service.GetBatchGoodInformationList(ids)
  3412. for _, item := range goods {
  3413. result := QueryResult{
  3414. ID: item.ID,
  3415. Name: item.GoodName,
  3416. Code: item.MedicalInsuranceNumber,
  3417. List_type_code: "301",
  3418. }
  3419. queryResult = append(queryResult, result)
  3420. }
  3421. } else if record_type == 3 {
  3422. projects, _ := service.GetBathchMyPorjecgList(ids)
  3423. for _, item := range projects {
  3424. result := QueryResult{
  3425. ID: item.ID,
  3426. Name: item.ProjectName,
  3427. Code: item.MedicalCode,
  3428. List_type_code: "201",
  3429. }
  3430. queryResult = append(queryResult, result)
  3431. }
  3432. }
  3433. admin_user_id, _ := c.GetInt64("admin_user_id")
  3434. adminUser := c.GetAdminUserInfo()
  3435. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3436. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3437. var user_name string
  3438. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3439. if role.ID == 0 {
  3440. user_name = "xxx"
  3441. } else {
  3442. user_name = role.UserName
  3443. }
  3444. baseParams := &models.BaseParams{
  3445. SecretKey: miConfig.SecretKey,
  3446. FixmedinsCode: miConfig.Code,
  3447. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3448. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3449. OrgName: miConfig.OrgName,
  3450. Doctor: user_name,
  3451. }
  3452. if config.IsOpen == 1 {
  3453. for _, item := range queryResult {
  3454. var result string
  3455. if record_type == 1 {
  3456. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3457. } else if record_type == 2 {
  3458. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3459. } else if record_type == 3 {
  3460. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3461. }
  3462. var dat map[string]interface{}
  3463. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3464. fmt.Println(dat)
  3465. } else {
  3466. fmt.Println(err)
  3467. }
  3468. userJSONBytes, _ := json.Marshal(dat)
  3469. var res ResultSix
  3470. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3471. utils.ErrorLog("解析失败:%v", err)
  3472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3473. return
  3474. }
  3475. if res.Infcode == 0 {
  3476. if record_type == 1 {
  3477. service.UpdateBaseDrugById(item.ID)
  3478. } else if record_type == 2 {
  3479. service.UpdateGoodInformaitonByDetail(item.ID)
  3480. } else if record_type == 3 {
  3481. service.UpdateProjectById(item.ID)
  3482. }
  3483. c.ServeSuccessJSON(map[string]interface{}{
  3484. "failed_code": 0,
  3485. "msg": "目录对照成功",
  3486. })
  3487. } else {
  3488. c.ServeSuccessJSON(map[string]interface{}{
  3489. "failed_code": -10,
  3490. "msg": res.ErrMsg,
  3491. })
  3492. }
  3493. }
  3494. }
  3495. }
  3496. func (c *HisApiController) UnCheckCode() {
  3497. ids_str := c.GetString("ids")
  3498. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3499. admin_user_id, _ := c.GetInt64("admin_user_id")
  3500. ids_arr := strings.Split(ids_str, ",")
  3501. var queryResult []QueryResult
  3502. ids := make([]int64, 0)
  3503. for _, item := range ids_arr {
  3504. id, _ := strconv.ParseInt(item, 10, 64)
  3505. ids = append(ids, id)
  3506. }
  3507. if record_type == 1 {
  3508. drugs, _ := service.GetBatchDrugList(ids)
  3509. for _, item := range drugs {
  3510. result := QueryResult{
  3511. ID: item.ID,
  3512. Name: item.DrugName,
  3513. Code: item.MedicalInsuranceNumber,
  3514. List_type_code: "101",
  3515. }
  3516. queryResult = append(queryResult, result)
  3517. }
  3518. } else if record_type == 2 {
  3519. goods, _ := service.GetBatchGoodInformationList(ids)
  3520. for _, item := range goods {
  3521. result := QueryResult{
  3522. ID: item.ID,
  3523. Name: item.GoodName,
  3524. Code: item.MedicalInsuranceNumber,
  3525. List_type_code: "301",
  3526. }
  3527. queryResult = append(queryResult, result)
  3528. }
  3529. } else if record_type == 3 {
  3530. projects, _ := service.GetBathchMyPorjecgList(ids)
  3531. for _, item := range projects {
  3532. result := QueryResult{
  3533. ID: item.ID,
  3534. Name: item.ProjectName,
  3535. Code: item.MedicalCode,
  3536. List_type_code: "201",
  3537. }
  3538. queryResult = append(queryResult, result)
  3539. }
  3540. }
  3541. adminUser := c.GetAdminUserInfo()
  3542. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3543. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3544. var user_name string
  3545. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3546. if role.ID == 0 {
  3547. user_name = "xxx"
  3548. } else {
  3549. user_name = role.UserName
  3550. }
  3551. baseParams := &models.BaseParams{
  3552. SecretKey: miConfig.SecretKey,
  3553. FixmedinsCode: miConfig.Code,
  3554. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3555. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3556. OrgName: miConfig.OrgName,
  3557. Doctor: user_name,
  3558. }
  3559. if config.IsOpen == 1 {
  3560. for _, item := range queryResult {
  3561. var result string
  3562. if record_type == 1 {
  3563. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3564. } else if record_type == 2 {
  3565. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3566. } else if record_type == 3 {
  3567. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3568. }
  3569. var dat2 map[string]interface{}
  3570. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  3571. fmt.Println(dat2)
  3572. } else {
  3573. fmt.Println(err)
  3574. }
  3575. userJSONBytes, _ := json.Marshal(dat2)
  3576. var res ResultSix
  3577. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3578. utils.ErrorLog("解析失败:%v", err)
  3579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3580. return
  3581. }
  3582. if res.Infcode == 0 {
  3583. if record_type == 1 {
  3584. service.UpdateDrugByIdDetail(item.ID)
  3585. } else if record_type == 2 {
  3586. service.UpdateGoodInfoById(item.ID)
  3587. } else if record_type == 3 {
  3588. service.UpdateMyProjectById(item.ID)
  3589. }
  3590. c.ServeSuccessJSON(map[string]interface{}{
  3591. "failed_code": 0,
  3592. "msg": "撤销目录对照成功",
  3593. })
  3594. } else {
  3595. c.ServeSuccessJSON(map[string]interface{}{
  3596. "failed_code": -10,
  3597. "msg": res.ErrMsg,
  3598. })
  3599. }
  3600. }
  3601. }
  3602. }
  3603. func (c *HisApiController) GetPatientInfo() {
  3604. id_card_no := c.GetString("id_card_no")
  3605. admin_user_id, _ := c.GetInt64("admin_user_id")
  3606. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3607. if patient.ID == 0 {
  3608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3609. return
  3610. }
  3611. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3612. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3613. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  3614. if config.IsOpen == 1 {
  3615. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  3616. var dat map[string]interface{}
  3617. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3618. fmt.Println(dat)
  3619. } else {
  3620. fmt.Println(err)
  3621. }
  3622. userJSONBytes, _ := json.Marshal(dat)
  3623. var res ResultTwo
  3624. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3625. utils.ErrorLog("解析失败:%v", err)
  3626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3627. return
  3628. }
  3629. if res.Infcode == -1 {
  3630. c.ServeSuccessJSON(map[string]interface{}{
  3631. "failed_code": -10,
  3632. "msg": res.ErrMsg,
  3633. })
  3634. } else {
  3635. c.ServeSuccessJSON(map[string]interface{}{
  3636. "failed_code": 0,
  3637. "info": res,
  3638. })
  3639. }
  3640. }
  3641. }
  3642. func (c *HisApiController) PsnPutOnRecord() {
  3643. record_type, _ := c.GetInt64("type")
  3644. patient_id, _ := c.GetInt64("patient_id")
  3645. admin_user_id, _ := c.GetInt64("admin_user_id")
  3646. start_time := c.GetString("start_time")
  3647. end_time := c.GetString("end_time")
  3648. adminUser := c.GetAdminUserInfo()
  3649. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3650. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3651. var patients []*models.Patients
  3652. if record_type == 1 { //全部备案
  3653. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  3654. patients = append(patients, patient...)
  3655. } else { //单个备案
  3656. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3657. patients = append(patients, patient)
  3658. }
  3659. var user_name string
  3660. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3661. if role.ID == 0 {
  3662. user_name = "xxx"
  3663. } else {
  3664. user_name = role.UserName
  3665. }
  3666. if config.IsOpen == 1 {
  3667. for _, item := range patients {
  3668. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3669. resp, requestErr := http.Get(api)
  3670. if requestErr != nil {
  3671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3672. return
  3673. }
  3674. defer resp.Body.Close()
  3675. body, ioErr := ioutil.ReadAll(resp.Body)
  3676. if ioErr != nil {
  3677. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3679. return
  3680. }
  3681. var respJSON map[string]interface{}
  3682. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3683. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3685. return
  3686. }
  3687. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3688. userJSONBytes, _ := json.Marshal(userJSON)
  3689. var res ResultTwo
  3690. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3691. utils.ErrorLog("解析失败:%v", err)
  3692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3693. return
  3694. }
  3695. if res.Infcode == 0 {
  3696. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  3697. var dat map[string]interface{}
  3698. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3699. fmt.Println(dat)
  3700. } else {
  3701. fmt.Println(err)
  3702. }
  3703. userJSONBytes, _ := json.Marshal(dat)
  3704. var res2 ResultThirteen
  3705. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3706. utils.ErrorLog("解析失败:%v", err)
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3708. return
  3709. }
  3710. if res2.Infcode == 0 {
  3711. psnResult := &models.GdybPsnRecord{
  3712. UserOrgId: adminUser.CurrentOrgId,
  3713. PatientId: item.ID,
  3714. PsnNo: res.Output.Baseinfo.PsnNo,
  3715. Ctime: time.Now().Unix(),
  3716. Mtime: time.Now().Unix(),
  3717. Status: 1,
  3718. IsCancel: 1,
  3719. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3720. }
  3721. service.CreatePsnRecord(psnResult)
  3722. } else {
  3723. c.ServeSuccessJSON(map[string]interface{}{
  3724. "failed_code": -10,
  3725. "msg": res2.ErrMsg,
  3726. })
  3727. return
  3728. }
  3729. }
  3730. }
  3731. }
  3732. }
  3733. func (c *HisApiController) PsnUnPutOnRecord() {
  3734. id, _ := c.GetInt64("id")
  3735. //record_type, _ := c.GetInt64("type")
  3736. admin_user_id, _ := c.GetInt64("admin_user_id")
  3737. adminUser := c.GetAdminUserInfo()
  3738. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3739. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3740. var user_name string
  3741. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3742. if role.ID == 0 {
  3743. user_name = "xxx"
  3744. } else {
  3745. user_name = role.UserName
  3746. }
  3747. psn_record, _ := service.GetPsnRecordById(id)
  3748. if psn_record.ID == 0 {
  3749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3750. return
  3751. }
  3752. if config.IsOpen == 1 {
  3753. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3754. var dat map[string]interface{}
  3755. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3756. fmt.Println(dat)
  3757. } else {
  3758. fmt.Println(err)
  3759. }
  3760. userJSONBytes, _ := json.Marshal(dat)
  3761. var res ResultFourteen
  3762. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3763. utils.ErrorLog("解析失败:%v", err)
  3764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3765. return
  3766. }
  3767. if res.Infcode == 0 {
  3768. psn_record.IsCancel = 2
  3769. service.CreatePsnRecord(&psn_record)
  3770. } else {
  3771. c.ServeSuccessJSON(map[string]interface{}{
  3772. "failed_code": -10,
  3773. "msg": res.ErrMsg,
  3774. })
  3775. return
  3776. }
  3777. }
  3778. }
  3779. func (c *HisApiController) PsnPutNCDSOnRecord() {
  3780. patient_id, _ := c.GetInt64("patient_id")
  3781. insutype := c.GetString("insutype")
  3782. psn_no := c.GetString("psn_no")
  3783. doctor_id, _ := c.GetInt64("doctor_id")
  3784. sick_id, _ := c.GetInt64("sick_id")
  3785. department_id, _ := c.GetInt64("department_id")
  3786. adminUser := c.GetAdminUserInfo()
  3787. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3788. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3789. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3790. sick, _ := service.FindSickById(sick_id)
  3791. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  3792. if config.IsOpen == 1 {
  3793. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.CountryCode)
  3794. var dat map[string]interface{}
  3795. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3796. fmt.Println(dat)
  3797. } else {
  3798. fmt.Println(err)
  3799. }
  3800. userJSONBytes, _ := json.Marshal(dat)
  3801. var res2 ResultThirteen
  3802. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3803. utils.ErrorLog("解析失败:%v", err)
  3804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3805. return
  3806. }
  3807. if res2.Infcode == 0 {
  3808. psnResult := &models.GdybPsnNcdsRecord{
  3809. UserOrgId: adminUser.CurrentOrgId,
  3810. PatientId: patient.ID,
  3811. PsnNo: psn_no,
  3812. DoctorId: doctor.AdminUserId,
  3813. DepartmentId: department_id,
  3814. SickType: sick_id,
  3815. Insutype: insutype,
  3816. Ctime: time.Now().Unix(),
  3817. Mtime: time.Now().Unix(),
  3818. Status: 1,
  3819. IsCancel: 1,
  3820. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3821. }
  3822. service.CreatePsnNCDSRecord(psnResult)
  3823. c.ServeSuccessJSON(map[string]interface{}{
  3824. "failed_code": 0,
  3825. "msg": "备案成功",
  3826. "result": psnResult,
  3827. })
  3828. } else {
  3829. c.ServeSuccessJSON(map[string]interface{}{
  3830. "failed_code": -10,
  3831. "msg": res2.ErrMsg,
  3832. })
  3833. return
  3834. }
  3835. }
  3836. }
  3837. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  3838. id, _ := c.GetInt64("id")
  3839. admin_user_id, _ := c.GetInt64("admin_user_id")
  3840. adminUser := c.GetAdminUserInfo()
  3841. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3842. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3843. var user_name string
  3844. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3845. if role.ID == 0 {
  3846. user_name = "xxx"
  3847. } else {
  3848. user_name = role.UserName
  3849. }
  3850. psn_record, _ := service.GetPsnNCDSRecordById(id)
  3851. if psn_record.ID == 0 {
  3852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3853. return
  3854. }
  3855. if config.IsOpen == 1 {
  3856. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3857. var dat map[string]interface{}
  3858. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3859. fmt.Println(dat)
  3860. } else {
  3861. fmt.Println(err)
  3862. }
  3863. userJSONBytes, _ := json.Marshal(dat)
  3864. var res ResultFourteen
  3865. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3866. utils.ErrorLog("解析失败:%v", err)
  3867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3868. return
  3869. }
  3870. if res.Infcode == 0 {
  3871. psn_record.IsCancel = 2
  3872. service.CreatePsnNCDSRecord(&psn_record)
  3873. c.ServeSuccessJSON(map[string]interface{}{
  3874. "failed_code": 0,
  3875. "msg": "撤销备案成功",
  3876. })
  3877. } else {
  3878. c.ServeSuccessJSON(map[string]interface{}{
  3879. "failed_code": -10,
  3880. "msg": res.ErrMsg,
  3881. })
  3882. return
  3883. }
  3884. }
  3885. }
  3886. func PathExists(path string) (bool, error) {
  3887. _, err := os.Stat(path)
  3888. if err == nil {
  3889. return true, nil
  3890. }
  3891. if os.IsNotExist(err) {
  3892. return false, nil
  3893. }
  3894. return false, err
  3895. }
  3896. //创建文件夹
  3897. func Mkdir(dir string) {
  3898. // 创建文件夹
  3899. exist, err := PathExists(dir)
  3900. if err != nil {
  3901. fmt.Println(err.Error())
  3902. } else {
  3903. if exist {
  3904. fmt.Println(dir + "文件夹已存在!")
  3905. } else {
  3906. // 文件夹名称,权限
  3907. err := os.Mkdir(dir, os.ModePerm)
  3908. if err != nil {
  3909. fmt.Println(dir+"文件夹创建失败:", err.Error())
  3910. } else {
  3911. fmt.Println(dir + "文件夹创建成功!")
  3912. }
  3913. }
  3914. }
  3915. }
  3916. //压缩文件
  3917. func Zip(srcFile string, destZip string) error {
  3918. zipfile, err := os.Create(destZip)
  3919. if err != nil {
  3920. return err
  3921. }
  3922. defer zipfile.Close()
  3923. archive := zip.NewWriter(zipfile)
  3924. defer archive.Close()
  3925. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  3926. if err != nil {
  3927. return err
  3928. }
  3929. header, err := zip.FileInfoHeader(info)
  3930. if err != nil {
  3931. return err
  3932. }
  3933. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  3934. // header.Name = path
  3935. if info.IsDir() {
  3936. header.Name += "/"
  3937. } else {
  3938. header.Method = zip.Deflate
  3939. }
  3940. writer, err := archive.CreateHeader(header)
  3941. if err != nil {
  3942. return err
  3943. }
  3944. if !info.IsDir() {
  3945. file, err := os.Open(path)
  3946. if err != nil {
  3947. return err
  3948. }
  3949. defer file.Close()
  3950. _, err = io.Copy(writer, file)
  3951. }
  3952. return err
  3953. })
  3954. return err
  3955. }
  3956. func ReadFile(filePath string) []byte {
  3957. f, err := os.Open(filePath)
  3958. if err != nil {
  3959. fmt.Println("read file fail", err)
  3960. return nil
  3961. }
  3962. defer f.Close()
  3963. fd, err := ioutil.ReadAll(f)
  3964. if err != nil {
  3965. fmt.Println("read to fd fail", err)
  3966. return nil
  3967. }
  3968. return fd
  3969. }
  3970. func RemoveRepeatedCode(arr []string) (newArr []string) {
  3971. newArr = make([]string, 0)
  3972. for i := 0; i < len(arr); i++ {
  3973. repeat := false
  3974. for j := i + 1; j < len(arr); j++ {
  3975. if arr[i] == arr[j] {
  3976. repeat = true
  3977. break
  3978. }
  3979. }
  3980. if !repeat {
  3981. newArr = append(newArr, arr[i])
  3982. }
  3983. }
  3984. return
  3985. }