his_api_controller.go 154KB

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