his_api_controller.go 159KB

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