his_api_controller.go 159KB

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