his_api_controller.go 157KB

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