his_api_controller.go 159KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761
  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 + "&certificates=" + strconv.FormatInt(certificates, 10)
  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. if len(insutypes) == 0 {
  1056. insutype = "310"
  1057. }
  1058. if count == 1 {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1060. return
  1061. }
  1062. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  1063. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1064. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1065. "&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)
  1066. resp, requestErr := http.Get(api)
  1067. if requestErr != nil {
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1069. return
  1070. }
  1071. defer resp.Body.Close()
  1072. body, ioErr := ioutil.ReadAll(resp.Body)
  1073. if ioErr != nil {
  1074. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1076. return
  1077. }
  1078. var respJSON map[string]interface{}
  1079. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1080. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1082. return
  1083. }
  1084. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1085. userJSONBytes, _ := json.Marshal(respJSON)
  1086. var res ResultThree
  1087. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1088. utils.ErrorLog("解析失败:%v", err)
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1090. return
  1091. }
  1092. if res.Infcode == -1 {
  1093. adminUser := c.GetAdminUserInfo()
  1094. errlog := &models.HisOrderError{
  1095. UserOrgId: adminUser.CurrentOrgId,
  1096. Ctime: time.Now().Unix(),
  1097. Mtime: time.Now().Unix(),
  1098. ErrMsg: res.ErrMsg,
  1099. Status: 1,
  1100. PatientId: id,
  1101. RecordTime: recordDateTime,
  1102. Stage: 2,
  1103. }
  1104. service.CreateErrMsgLog(errlog)
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "failed_code": -10,
  1107. "msg": res.ErrMsg,
  1108. })
  1109. return
  1110. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1111. //return
  1112. }
  1113. his.Number = res.Output.Data.MdtrtID
  1114. his.PsnNo = res.Output.Data.PsnNo
  1115. his.IptOtpNo = res.Output.Data.IptOtpNo
  1116. his.IdCardNo = patient.IdCardNo
  1117. his.PhoneNumber = patient.Phone
  1118. his.UserOrgId = adminInfo.CurrentOrgId
  1119. his.Ctime = time.Now().Unix()
  1120. his.Mtime = time.Now().Unix()
  1121. his.Status = 1
  1122. err := service.CreateHisPatientTwo(&his)
  1123. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1124. if len(lists) == 1 {
  1125. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1126. }
  1127. if err == nil {
  1128. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1129. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1130. "&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 +
  1131. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1132. resp2, requestErr2 := http.Get(api2)
  1133. if requestErr2 != nil {
  1134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1135. return
  1136. }
  1137. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1138. if ioErr2 != nil {
  1139. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. var respJSON2 map[string]interface{}
  1144. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1145. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1147. return
  1148. }
  1149. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1150. userJSONBytes2, _ := json.Marshal(respJSON2)
  1151. var res2 ResultSix
  1152. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1153. utils.ErrorLog("解析失败:%v", err)
  1154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1155. return
  1156. }
  1157. if res2.Infcode == -1 {
  1158. adminUser := c.GetAdminUserInfo()
  1159. errlog := &models.HisOrderError{
  1160. UserOrgId: adminUser.CurrentOrgId,
  1161. Ctime: time.Now().Unix(),
  1162. Mtime: time.Now().Unix(),
  1163. ErrMsg: res2.ErrMsg,
  1164. Status: 1,
  1165. PatientId: id,
  1166. RecordTime: recordDateTime,
  1167. Stage: 3,
  1168. }
  1169. service.CreateErrMsgLog(errlog)
  1170. c.ServeSuccessJSON(map[string]interface{}{
  1171. "failed_code": -10,
  1172. "msg": res2.ErrMsg,
  1173. })
  1174. return
  1175. } else {
  1176. c.ServeSuccessJSON(map[string]interface{}{
  1177. "his_info": his,
  1178. })
  1179. }
  1180. } else {
  1181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1182. return
  1183. }
  1184. } else {
  1185. adminUser := c.GetAdminUserInfo()
  1186. errlog := &models.HisOrderError{
  1187. UserOrgId: adminUser.CurrentOrgId,
  1188. Ctime: time.Now().Unix(),
  1189. Mtime: time.Now().Unix(),
  1190. ErrMsg: res.ErrMsg,
  1191. Status: 1,
  1192. PatientId: id,
  1193. RecordTime: recordDateTime,
  1194. Stage: 1,
  1195. }
  1196. service.CreateErrMsgLog(errlog)
  1197. c.ServeSuccessJSON(map[string]interface{}{
  1198. "failed_code": -10,
  1199. "msg": res.ErrMsg,
  1200. })
  1201. return
  1202. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1203. }
  1204. } else {
  1205. timeStr := time.Now().Format("2006-01-02")
  1206. timeArr := strings.Split(timeStr, "-")
  1207. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1208. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1209. var hisPatient models.XtHisPatient
  1210. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1211. hisPatient = models.XtHisPatient{
  1212. Name: name,
  1213. Age: age,
  1214. Gender: gender,
  1215. Birthday: birthUnix,
  1216. Phone: phone,
  1217. MedicalTreatmentType: medical_care,
  1218. IdType: certificates,
  1219. IdCardNo: id_card,
  1220. BalanceAccountsType: settlementValue,
  1221. SocialType: social_type,
  1222. MedicalInsuranceNumber: medical_insurance_card,
  1223. RegisterType: register_type,
  1224. RegisterCost: registration_fee,
  1225. TreatmentCost: medical_expenses,
  1226. AdminUserId: admin_user_id,
  1227. UserOrgId: adminInfo.CurrentOrgId,
  1228. Status: 1,
  1229. RecordDate: recordDateTime,
  1230. IsReturn: 1,
  1231. PatientId: patient.ID,
  1232. Ctime: time.Now().Unix(),
  1233. Mtime: time.Now().Unix(),
  1234. Number: str,
  1235. }
  1236. service.CreateHisPatient(&hisPatient)
  1237. }
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "his_info": hisPatient,
  1240. })
  1241. }
  1242. }
  1243. //上传明细----预结算----确认订单
  1244. func (c *HisApiController) GetUploadInfo() {
  1245. id, _ := c.GetInt64("id")
  1246. record_time := c.GetString("record_time")
  1247. his_patient_id, _ := c.GetInt64("his_patient_id")
  1248. pay_way, _ := c.GetInt64("pay_way")
  1249. pay_price, _ := c.GetFloat("pay_price")
  1250. pay_card_no := c.GetString("pay_card_no")
  1251. discount_price, _ := c.GetFloat("discount_price")
  1252. preferential_price, _ := c.GetFloat("preferential_price")
  1253. reality_price, _ := c.GetFloat("reality_price")
  1254. found_price, _ := c.GetFloat("found_price")
  1255. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1256. private_price, _ := c.GetFloat("private_price")
  1257. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1258. admin_user_id, _ := c.GetInt64("admin_user_id")
  1259. timeLayout := "2006-01-02"
  1260. loc, _ := time.LoadLocation("Local")
  1261. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1262. if err != nil {
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1264. return
  1265. }
  1266. recordDateTime := theTime.Unix()
  1267. adminUser := c.GetAdminUserInfo()
  1268. var prescriptions []*models.HisPrescription
  1269. var start_time int64
  1270. var end_time int64
  1271. data := make(map[string]interface{})
  1272. if settle_accounts_type == 1 { //日结
  1273. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1274. data["pre"] = prescriptions
  1275. } else { //月结
  1276. start_time_str := c.GetString("start_time")
  1277. end_time_str := c.GetString("end_time")
  1278. timeLayout := "2006-01-02"
  1279. loc, _ := time.LoadLocation("Local")
  1280. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1281. if err != nil {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1283. return
  1284. }
  1285. recordStartTime := theStartTime.Unix()
  1286. start_time = recordStartTime
  1287. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1288. if err != nil {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. recordEndTime := theEndTime.Unix()
  1293. end_time = recordEndTime
  1294. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1295. data["pre"] = prescriptions
  1296. }
  1297. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1298. fmt.Println(his_patient_id)
  1299. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1300. timestamp := time.Now().Unix()
  1301. tempTime := time.Unix(timestamp, 0)
  1302. timeFormat := tempTime.Format("20060102150405")
  1303. chrgBchno := rand.Intn(100000) + 10000
  1304. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1305. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1306. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1307. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1308. strconv.FormatInt(his.PatientId, 10)
  1309. client := &http.Client{}
  1310. data["psn_no"] = his.PsnNo
  1311. data["mdtrt_id"] = his.Number
  1312. data["chrg_bchno"] = chrg_bchno
  1313. data["org_name"] = miConfig.OrgName
  1314. data["doctor"] = roles.UserName
  1315. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1316. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1317. data["fixmedins_code"] = miConfig.Code
  1318. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1319. data["dept_code"] = "15"
  1320. } else {
  1321. data["dept_code"] = department.Number
  1322. }
  1323. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1324. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1325. data["secret_key"] = miConfig.SecretKey
  1326. var ids []int64
  1327. for _, item := range prescriptions {
  1328. ids = append(ids, item.ID)
  1329. }
  1330. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1331. if config.IsOpen == 1 { //对接了医保,走医保流程
  1332. bytesData, _ := json.Marshal(data)
  1333. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1334. resp, _ := client.Do(req)
  1335. defer resp.Body.Close()
  1336. body, ioErr := ioutil.ReadAll(resp.Body)
  1337. if ioErr != nil {
  1338. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1340. return
  1341. }
  1342. var respJSON map[string]interface{}
  1343. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1344. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1346. return
  1347. }
  1348. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1349. userJSONBytes, _ := json.Marshal(respJSON)
  1350. var res ResultFour
  1351. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1352. utils.ErrorLog("解析失败:%v", err)
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1354. return
  1355. }
  1356. if res.Infcode == 0 {
  1357. order := &models.HisOrder{
  1358. UserOrgId: adminUser.CurrentOrgId,
  1359. HisPatientId: his.ID,
  1360. PatientId: his.PatientId,
  1361. SettleAccountsDate: recordDateTime,
  1362. Ctime: time.Now().Unix(),
  1363. Mtime: time.Now().Unix(),
  1364. Status: 1,
  1365. Number: chrg_bchno,
  1366. Infcode: res.Infcode,
  1367. WarnMsg: res.WarnMsg,
  1368. Cainfo: res.Cainfo,
  1369. ErrMsg: res.ErrMsg,
  1370. RespondTime: res.RefmsgTime,
  1371. InfRefmsgid: res.InfRefmsgid,
  1372. OrderStatus: 1,
  1373. PayWay: pay_way,
  1374. PayPrice: pay_price,
  1375. PayCardNo: pay_card_no,
  1376. DiscountPrice: discount_price,
  1377. PreferentialPrice: preferential_price,
  1378. RealityPrice: reality_price,
  1379. FoundPrice: found_price,
  1380. MedicalInsurancePrice: medical_insurance_price,
  1381. PrivatePrice: private_price,
  1382. IsMedicineInsurance: 1,
  1383. SettleType: settle_accounts_type,
  1384. SettleStartTime: start_time,
  1385. SettleEndTime: end_time,
  1386. Creator: roles.AdminUserId,
  1387. Modify: roles.AdminUserId,
  1388. }
  1389. err = service.CreateOrder(order)
  1390. if err != nil {
  1391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1392. return
  1393. }
  1394. for _, item := range res.Output.Result {
  1395. temp := strings.Split(item.FeedetlSn, "-")
  1396. var advice_id int64 = 0
  1397. var project_id int64 = 0
  1398. var types int64 = 0
  1399. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1400. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1401. if temp[1] == "1" {
  1402. advice_id = id
  1403. project_id = 0
  1404. } else if temp[1] == "2" {
  1405. advice_id = 0
  1406. project_id = id
  1407. }
  1408. info := &models.HisOrderInfo{
  1409. OrderNumber: order.Number,
  1410. FeedetlSn: item.FeedetlSn,
  1411. UploadDate: time.Now().Unix(),
  1412. AdviceId: advice_id,
  1413. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1414. Cnt: item.Cnt,
  1415. Pric: float64(item.Pric),
  1416. PatientId: his.PatientId,
  1417. PricUplmtAmt: item.PricUplmtAmt,
  1418. SelfpayProp: item.SelfpayProp,
  1419. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1420. OverlmtAmt: item.OverlmtAmt,
  1421. PreselfpayAmt: item.PreselfpayAmt,
  1422. BasMednFlag: item.BasMednFlag,
  1423. MedChrgitmType: item.MedChrgitmType,
  1424. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1425. Status: 1,
  1426. Memo: item.Memo,
  1427. Mtime: time.Now().Unix(),
  1428. InscpScpAmt: item.InscpScpAmt,
  1429. DrtReimFlag: item.DrtReimFlag,
  1430. Ctime: time.Now().Unix(),
  1431. ListSpItemFlag: item.ListSpItemFlag,
  1432. ChldMedcFlag: item.ChldMedcFlag,
  1433. LmtUsedFlag: item.LmtUsedFlag,
  1434. ChrgitmLv: item.ChrgitmLv,
  1435. UserOrgId: adminUser.CurrentOrgId,
  1436. HisPatientId: his.ID,
  1437. OrderId: order.ID,
  1438. ProjectId: project_id,
  1439. Type: types,
  1440. }
  1441. service.CreateOrderInfo(info)
  1442. }
  1443. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1444. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1445. var total float64
  1446. for _, item := range prescriptions {
  1447. if item.Type == 1 { //药品
  1448. for _, subItem := range item.HisDoctorAdviceInfo {
  1449. total = total + (subItem.Price * subItem.PrescribingNumber)
  1450. }
  1451. }
  1452. if item.Type == 2 { //项目
  1453. for _, subItem := range item.HisPrescriptionProject {
  1454. total = total + (subItem.Price * float64(subItem.Count))
  1455. }
  1456. }
  1457. }
  1458. for _, item := range prescriptions {
  1459. for _, subItem := range item.HisAdditionalCharge {
  1460. total = total + (subItem.Price * float64(subItem.Count))
  1461. }
  1462. }
  1463. allTotal := fmt.Sprintf("%.2f", total)
  1464. if res.Infcode == 0 {
  1465. var rf []*ResultFive
  1466. json.Unmarshal([]byte(his.Iinfo), &rf)
  1467. chrg_bchno := chrg_bchno
  1468. cert_no := his.Certno
  1469. var insutypes []string
  1470. var insutype string
  1471. var is390 int = 0
  1472. var is310 int = 0
  1473. for _, item := range rf {
  1474. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1475. insutypes = append(insutypes, item.Insutype)
  1476. }
  1477. }
  1478. if len(insutypes) == 1 {
  1479. insutype = insutypes[0]
  1480. } else {
  1481. for _, i := range insutypes {
  1482. if i == "390" {
  1483. is390 = 1
  1484. }
  1485. if i == "310" {
  1486. is310 = 1
  1487. }
  1488. }
  1489. }
  1490. if is390 == 1 {
  1491. insutype = "390"
  1492. }
  1493. if is310 == 1 {
  1494. insutype = "310"
  1495. }
  1496. if len(insutypes) == 0 {
  1497. insutype = "310"
  1498. }
  1499. if his.IdCardType == 1 {
  1500. cert_no = his.MedicalInsuranceNumber
  1501. } else {
  1502. cert_no = his.Certno
  1503. }
  1504. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  1505. var dat map[string]interface{}
  1506. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1507. fmt.Println(dat)
  1508. } else {
  1509. fmt.Println(err)
  1510. }
  1511. userJSONBytes, _ := json.Marshal(dat)
  1512. var res ResultSeven
  1513. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1514. utils.ErrorLog("解析失败:%v", err)
  1515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1516. return
  1517. }
  1518. if res.Infcode == -1 {
  1519. errlog := &models.HisOrderError{
  1520. UserOrgId: adminUser.CurrentOrgId,
  1521. Ctime: time.Now().Unix(),
  1522. Mtime: time.Now().Unix(),
  1523. Number: chrg_bchno,
  1524. ErrMsg: res.ErrMsg,
  1525. Status: 1,
  1526. PatientId: id,
  1527. RecordTime: recordDateTime,
  1528. Stage: 6,
  1529. }
  1530. service.CreateErrMsgLog(errlog)
  1531. c.ServeSuccessJSON(map[string]interface{}{
  1532. "failed_code": -10,
  1533. "msg": res.ErrMsg,
  1534. })
  1535. return
  1536. } else {
  1537. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1538. order.OrderStatus = 2
  1539. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1540. order.SetlId = res.Output.Setlinfo.SetlID
  1541. order.PsnNo = res.Output.Setlinfo.PsnNo
  1542. order.PsnName = res.Output.Setlinfo.PsnName
  1543. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1544. order.Certno = res.Output.Setlinfo.Certno
  1545. order.Gend = res.Output.Setlinfo.Gend
  1546. order.Naty = res.Output.Setlinfo.Naty
  1547. order.Age = res.Output.Setlinfo.Age
  1548. order.Insutype = res.Output.Setlinfo.Insutype
  1549. order.PsnType = res.Output.Setlinfo.PsnType
  1550. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1551. order.SetlTime = res.Output.Setlinfo.SetlTime
  1552. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1553. order.MedType = res.Output.Setlinfo.MedType
  1554. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1555. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1556. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1557. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1558. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1559. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1560. order.HifpPay = res.Output.Setlinfo.HifpPay
  1561. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1562. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1563. order.HifesPay = res.Output.Setlinfo.HifesPay
  1564. order.HifobPay = res.Output.Setlinfo.HifobPay
  1565. order.MafPay = res.Output.Setlinfo.MafPay
  1566. order.OthPay = res.Output.Setlinfo.OthPay
  1567. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1568. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1569. order.AcctPay = res.Output.Setlinfo.AcctPay
  1570. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1571. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1572. order.Balc = res.Output.Setlinfo.Balc
  1573. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1574. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1575. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1576. order.ClrWay = res.Output.Setlinfo.ClrWay
  1577. order.Creator = order.Creator
  1578. order.Modify = roles.AdminUserId
  1579. order.RequestLog = src_resquest
  1580. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1581. detailStr := string(setlDetail)
  1582. order.SetlDetail = detailStr
  1583. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1584. err = service.UpDateOrder(order)
  1585. if err == nil {
  1586. c.ServeSuccessJSON(map[string]interface{}{
  1587. "msg": "结算成功",
  1588. })
  1589. } else {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1591. return
  1592. }
  1593. }
  1594. } else {
  1595. adminUser := c.GetAdminUserInfo()
  1596. errlog := &models.HisOrderError{
  1597. UserOrgId: adminUser.CurrentOrgId,
  1598. Ctime: time.Now().Unix(),
  1599. Mtime: time.Now().Unix(),
  1600. ErrMsg: res.ErrMsg,
  1601. Status: 1,
  1602. PatientId: id,
  1603. RecordTime: recordDateTime,
  1604. Stage: 4,
  1605. }
  1606. service.CreateErrMsgLog(errlog)
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1608. return
  1609. }
  1610. } else {
  1611. adminUser := c.GetAdminUserInfo()
  1612. errlog := &models.HisOrderError{
  1613. UserOrgId: adminUser.CurrentOrgId,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: time.Now().Unix(),
  1616. ErrMsg: res.ErrMsg,
  1617. Status: 1,
  1618. PatientId: id,
  1619. RecordTime: recordDateTime,
  1620. Stage: 4,
  1621. }
  1622. service.CreateErrMsgLog(errlog)
  1623. c.ServeSuccessJSON(map[string]interface{}{
  1624. "failed_code": -10,
  1625. "msg": res.ErrMsg,
  1626. })
  1627. return
  1628. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1629. //return
  1630. }
  1631. } else {
  1632. var total float64
  1633. for _, item := range prescriptions {
  1634. if item.Type == 1 { //药品
  1635. for _, subItem := range item.HisDoctorAdviceInfo {
  1636. total = total + (subItem.Price * subItem.PrescribingNumber)
  1637. }
  1638. }
  1639. if item.Type == 2 { //项目
  1640. for _, subItem := range item.HisPrescriptionProject {
  1641. total = total + (subItem.Price * float64(subItem.Count))
  1642. }
  1643. }
  1644. for _, subItem := range item.HisAdditionalCharge {
  1645. total = total + (subItem.Price * float64(subItem.Count))
  1646. }
  1647. }
  1648. allTotal := fmt.Sprintf("%.2f", total)
  1649. totals, _ := strconv.ParseFloat(allTotal, 64)
  1650. order := &models.HisOrder{
  1651. UserOrgId: adminUser.CurrentOrgId,
  1652. HisPatientId: his.ID,
  1653. PatientId: id,
  1654. SettleAccountsDate: recordDateTime,
  1655. Ctime: time.Now().Unix(),
  1656. Mtime: time.Now().Unix(),
  1657. Status: 1,
  1658. OrderStatus: 2,
  1659. Number: chrg_bchno,
  1660. MedfeeSumamt: totals,
  1661. PayWay: pay_way,
  1662. PayPrice: pay_price,
  1663. PayCardNo: pay_card_no,
  1664. DiscountPrice: discount_price,
  1665. PreferentialPrice: preferential_price,
  1666. RealityPrice: reality_price,
  1667. FoundPrice: found_price,
  1668. MedicalInsurancePrice: medical_insurance_price,
  1669. PrivatePrice: private_price,
  1670. }
  1671. err = service.CreateOrder(order)
  1672. if err != nil {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1674. return
  1675. }
  1676. var customs []*Custom
  1677. for _, item := range prescriptions {
  1678. if item.Type == 1 { //药品
  1679. for _, subItem := range item.HisDoctorAdviceInfo {
  1680. cus := &Custom{
  1681. AdviceId: subItem.ID,
  1682. ProjectId: 0,
  1683. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1684. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1685. FeedetlSn: subItem.FeedetlSn,
  1686. Price: fmt.Sprintf("%.2f", subItem.Price),
  1687. MedListCodg: subItem.MedListCodg,
  1688. Type: 1,
  1689. }
  1690. customs = append(customs, cus)
  1691. }
  1692. }
  1693. if item.Type == 2 { //项目
  1694. for _, subItem := range item.HisPrescriptionProject {
  1695. cus := &Custom{
  1696. AdviceId: 0,
  1697. ProjectId: subItem.ID,
  1698. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1699. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1700. FeedetlSn: subItem.FeedetlSn,
  1701. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1702. MedListCodg: subItem.MedListCodg,
  1703. Type: 2,
  1704. }
  1705. customs = append(customs, cus)
  1706. }
  1707. }
  1708. for _, item := range item.HisAdditionalCharge {
  1709. cus := &Custom{
  1710. ItemId: item.ID,
  1711. AdviceId: 0,
  1712. ProjectId: 0,
  1713. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1714. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1715. FeedetlSn: item.FeedetlSn,
  1716. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1717. MedListCodg: item.XtHisAddtionConfig.Code,
  1718. Type: 3,
  1719. }
  1720. customs = append(customs, cus)
  1721. }
  1722. }
  1723. for _, item := range customs {
  1724. var advice_id int64 = 0
  1725. var project_id int64 = 0
  1726. var item_id int64 = 0
  1727. var types int64 = 0
  1728. if item.Type == 1 {
  1729. advice_id = item.AdviceId
  1730. project_id = 0
  1731. item_id = 0
  1732. } else if item.Type == 2 {
  1733. advice_id = 0
  1734. item_id = 0
  1735. project_id = item.ProjectId
  1736. } else if item.Type == 3 {
  1737. advice_id = 0
  1738. item_id = item.ItemId
  1739. project_id = 0
  1740. }
  1741. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1742. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1743. pric, _ := strconv.ParseFloat(item.Price, 32)
  1744. info := &models.HisOrderInfo{
  1745. OrderNumber: order.Number,
  1746. UploadDate: time.Now().Unix(),
  1747. AdviceId: advice_id,
  1748. DetItemFeeSumamt: detItemFeeSumamt,
  1749. Cnt: cut,
  1750. Pric: pric,
  1751. PatientId: id,
  1752. Status: 1,
  1753. Mtime: time.Now().Unix(),
  1754. Ctime: time.Now().Unix(),
  1755. UserOrgId: adminUser.CurrentOrgId,
  1756. HisPatientId: his.ID,
  1757. OrderId: order.ID,
  1758. ProjectId: project_id,
  1759. Type: types,
  1760. ItemId: item_id,
  1761. }
  1762. service.CreateOrderInfo(info)
  1763. }
  1764. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1765. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1766. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1767. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1768. if err == nil {
  1769. c.ServeSuccessJSON(map[string]interface{}{
  1770. "msg": "结算成功",
  1771. })
  1772. } else {
  1773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1774. return
  1775. }
  1776. }
  1777. }
  1778. func (c *HisApiController) GetPreUploadInfo() {
  1779. id, _ := c.GetInt64("id")
  1780. record_time := c.GetString("record_time")
  1781. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1782. admin_user_id, _ := c.GetInt64("admin_user_id")
  1783. timeLayout := "2006-01-02"
  1784. loc, _ := time.LoadLocation("Local")
  1785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1786. if err != nil {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1788. return
  1789. }
  1790. recordDateTime := theTime.Unix()
  1791. adminUser := c.GetAdminUserInfo()
  1792. var prescriptions []*models.HisPrescription
  1793. var start_time int64
  1794. var end_time int64
  1795. data := make(map[string]interface{})
  1796. if settle_accounts_type == 1 { //日结
  1797. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1798. data["pre"] = prescriptions
  1799. } else { //月结
  1800. start_time_str := c.GetString("start_time")
  1801. end_time_str := c.GetString("end_time")
  1802. timeLayout := "2006-01-02"
  1803. loc, _ := time.LoadLocation("Local")
  1804. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1805. if err != nil {
  1806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1807. return
  1808. }
  1809. recordStartTime := theStartTime.Unix()
  1810. start_time = recordStartTime
  1811. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1812. if err != nil {
  1813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1814. return
  1815. }
  1816. recordEndTime := theEndTime.Unix()
  1817. end_time = recordEndTime
  1818. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1819. data["pre"] = prescriptions
  1820. }
  1821. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1822. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1823. timestamp := time.Now().Unix()
  1824. tempTime := time.Unix(timestamp, 0)
  1825. timeFormat := tempTime.Format("20060102150405")
  1826. chrgBchno := rand.Intn(100000) + 10000
  1827. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1828. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1829. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1830. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1831. strconv.FormatInt(his.PatientId, 10)
  1832. client := &http.Client{}
  1833. data["psn_no"] = his.PsnNo
  1834. data["mdtrt_id"] = his.Number
  1835. data["chrg_bchno"] = chrg_bchno
  1836. data["org_name"] = miConfig.OrgName
  1837. data["doctor"] = roles.UserName
  1838. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1839. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1840. data["fixmedins_code"] = miConfig.Code
  1841. data["dept_code"] = department.Number
  1842. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1843. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1844. data["secret_key"] = miConfig.SecretKey
  1845. var ids []int64
  1846. for _, item := range prescriptions {
  1847. ids = append(ids, item.ID)
  1848. }
  1849. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1850. if config.IsOpen == 1 { //对接了医保,走医保流程
  1851. bytesData, _ := json.Marshal(data)
  1852. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1853. resp, _ := client.Do(req)
  1854. defer resp.Body.Close()
  1855. body, ioErr := ioutil.ReadAll(resp.Body)
  1856. if ioErr != nil {
  1857. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1859. return
  1860. }
  1861. var respJSON map[string]interface{}
  1862. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1863. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1865. return
  1866. }
  1867. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1868. userJSONBytes, _ := json.Marshal(respJSON)
  1869. var res ResultFour
  1870. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1871. utils.ErrorLog("解析失败:%v", err)
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1873. return
  1874. }
  1875. if res.Infcode == 0 {
  1876. order := &models.HisOrder{
  1877. UserOrgId: adminUser.CurrentOrgId,
  1878. HisPatientId: his.ID,
  1879. PatientId: his.PatientId,
  1880. SettleAccountsDate: recordDateTime,
  1881. Ctime: time.Now().Unix(),
  1882. Mtime: time.Now().Unix(),
  1883. Status: 1,
  1884. Number: chrg_bchno,
  1885. Infcode: res.Infcode,
  1886. WarnMsg: res.WarnMsg,
  1887. Cainfo: res.Cainfo,
  1888. ErrMsg: res.ErrMsg,
  1889. RespondTime: res.RefmsgTime,
  1890. InfRefmsgid: res.InfRefmsgid,
  1891. OrderStatus: 1,
  1892. IsMedicineInsurance: 1,
  1893. SettleType: settle_accounts_type,
  1894. SettleStartTime: start_time,
  1895. SettleEndTime: end_time,
  1896. Creator: roles.ID,
  1897. Modify: roles.ID,
  1898. }
  1899. err = service.CreateOrder(order)
  1900. if err != nil {
  1901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1902. return
  1903. }
  1904. for _, item := range res.Output.Result {
  1905. temp := strings.Split(item.FeedetlSn, "-")
  1906. var advice_id int64 = 0
  1907. var project_id int64 = 0
  1908. var types int64 = 0
  1909. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1910. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1911. if temp[1] == "1" {
  1912. advice_id = id
  1913. project_id = 0
  1914. } else if temp[1] == "2" {
  1915. advice_id = 0
  1916. project_id = id
  1917. }
  1918. info := &models.HisOrderInfo{
  1919. OrderNumber: order.Number,
  1920. FeedetlSn: item.FeedetlSn,
  1921. UploadDate: time.Now().Unix(),
  1922. AdviceId: advice_id,
  1923. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1924. Cnt: item.Cnt,
  1925. Pric: float64(item.Pric),
  1926. PatientId: his.PatientId,
  1927. PricUplmtAmt: item.PricUplmtAmt,
  1928. SelfpayProp: item.SelfpayProp,
  1929. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1930. OverlmtAmt: item.OverlmtAmt,
  1931. PreselfpayAmt: item.PreselfpayAmt,
  1932. BasMednFlag: item.BasMednFlag,
  1933. MedChrgitmType: item.MedChrgitmType,
  1934. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1935. Status: 1,
  1936. Memo: item.Memo,
  1937. Mtime: time.Now().Unix(),
  1938. InscpScpAmt: item.InscpScpAmt,
  1939. DrtReimFlag: item.DrtReimFlag,
  1940. Ctime: time.Now().Unix(),
  1941. ListSpItemFlag: item.ListSpItemFlag,
  1942. ChldMedcFlag: item.ChldMedcFlag,
  1943. LmtUsedFlag: item.LmtUsedFlag,
  1944. ChrgitmLv: item.ChrgitmLv,
  1945. UserOrgId: adminUser.CurrentOrgId,
  1946. HisPatientId: his.ID,
  1947. OrderId: order.ID,
  1948. ProjectId: project_id,
  1949. Type: types,
  1950. }
  1951. service.CreateOrderInfo(info)
  1952. }
  1953. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1954. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1955. var total float64
  1956. for _, item := range prescriptions {
  1957. if item.Type == 1 { //药品
  1958. for _, subItem := range item.HisDoctorAdviceInfo {
  1959. total = total + (subItem.Price * subItem.PrescribingNumber)
  1960. }
  1961. }
  1962. if item.Type == 2 { //项目
  1963. for _, subItem := range item.HisPrescriptionProject {
  1964. total = total + (subItem.Price * float64(subItem.Count))
  1965. }
  1966. }
  1967. }
  1968. for _, item := range prescriptions {
  1969. for _, subItem := range item.HisAdditionalCharge {
  1970. total = total + (subItem.Price * float64(subItem.Count))
  1971. }
  1972. }
  1973. allTotal := fmt.Sprintf("%.2f", total)
  1974. if res.Infcode == 0 {
  1975. var rf []*ResultFive
  1976. json.Unmarshal([]byte(his.Iinfo), &rf)
  1977. psn_no := his.PsnNo
  1978. mdtrt_id := his.Number
  1979. chrg_bchno := chrg_bchno
  1980. cert_no := his.Certno
  1981. insutype := rf[0].Insutype
  1982. if his.IdCardType == 1 {
  1983. cert_no = his.MedicalInsuranceNumber
  1984. } else {
  1985. cert_no = his.Certno
  1986. }
  1987. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1988. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1989. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1990. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1991. resp, requestErr := http.Get(api)
  1992. if requestErr != nil {
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1994. return
  1995. }
  1996. defer resp.Body.Close()
  1997. body, ioErr := ioutil.ReadAll(resp.Body)
  1998. if ioErr != nil {
  1999. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2001. return
  2002. }
  2003. var respJSON map[string]interface{}
  2004. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2005. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2007. return
  2008. }
  2009. fmt.Println(respJSON)
  2010. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2011. userJSONBytes, _ := json.Marshal(respJSON)
  2012. var res ResultSeven
  2013. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2014. utils.ErrorLog("解析失败:%v", err)
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. return
  2017. }
  2018. if res.Infcode == -1 {
  2019. errlog := &models.HisOrderError{
  2020. UserOrgId: adminUser.CurrentOrgId,
  2021. Ctime: time.Now().Unix(),
  2022. Mtime: time.Now().Unix(),
  2023. Number: chrg_bchno,
  2024. ErrMsg: res.ErrMsg,
  2025. Status: 1,
  2026. PatientId: id,
  2027. RecordTime: recordDateTime,
  2028. Stage: 7,
  2029. }
  2030. service.CreateErrMsgLog(errlog)
  2031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2032. return
  2033. } else {
  2034. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2035. order.OrderStatus = 1
  2036. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2037. order.SetlId = res.Output.Setlinfo.SetlID
  2038. order.PsnNo = res.Output.Setlinfo.PsnNo
  2039. order.PsnName = res.Output.Setlinfo.PsnName
  2040. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2041. order.Certno = res.Output.Setlinfo.Certno
  2042. order.Gend = res.Output.Setlinfo.Gend
  2043. order.Naty = res.Output.Setlinfo.Naty
  2044. order.Age = res.Output.Setlinfo.Age
  2045. order.Insutype = res.Output.Setlinfo.Insutype
  2046. order.PsnType = res.Output.Setlinfo.PsnType
  2047. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2048. order.SetlTime = res.Output.Setlinfo.SetlTime
  2049. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2050. order.MedType = res.Output.Setlinfo.MedType
  2051. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2052. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2053. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2054. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2055. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2056. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2057. order.HifpPay = res.Output.Setlinfo.HifpPay
  2058. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2059. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2060. order.HifesPay = res.Output.Setlinfo.HifesPay
  2061. order.HifobPay = res.Output.Setlinfo.HifobPay
  2062. order.MafPay = res.Output.Setlinfo.MafPay
  2063. order.OthPay = res.Output.Setlinfo.OthPay
  2064. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2065. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2066. order.AcctPay = res.Output.Setlinfo.AcctPay
  2067. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2068. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2069. order.Balc = res.Output.Setlinfo.Balc
  2070. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2071. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2072. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2073. order.ClrWay = res.Output.Setlinfo.ClrWay
  2074. order.Creator = order.Creator
  2075. order.Modify = roles.ID
  2076. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2077. detailStr := string(setlDetail)
  2078. order.SetlDetail = detailStr
  2079. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2080. err = service.UpDateOrder(order)
  2081. if err == nil {
  2082. c.ServeSuccessJSON(map[string]interface{}{
  2083. "msg": "预结算成功",
  2084. })
  2085. } else {
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2087. return
  2088. }
  2089. }
  2090. } else {
  2091. adminUser := c.GetAdminUserInfo()
  2092. errlog := &models.HisOrderError{
  2093. UserOrgId: adminUser.CurrentOrgId,
  2094. Ctime: time.Now().Unix(),
  2095. Mtime: time.Now().Unix(),
  2096. ErrMsg: res.ErrMsg,
  2097. Status: 1,
  2098. PatientId: id,
  2099. RecordTime: recordDateTime,
  2100. Stage: 4,
  2101. }
  2102. service.CreateErrMsgLog(errlog)
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2104. return
  2105. }
  2106. } else {
  2107. adminUser := c.GetAdminUserInfo()
  2108. errlog := &models.HisOrderError{
  2109. UserOrgId: adminUser.CurrentOrgId,
  2110. Ctime: time.Now().Unix(),
  2111. Mtime: time.Now().Unix(),
  2112. ErrMsg: res.ErrMsg,
  2113. Status: 1,
  2114. PatientId: id,
  2115. RecordTime: recordDateTime,
  2116. Stage: 4,
  2117. }
  2118. service.CreateErrMsgLog(errlog)
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2120. return
  2121. }
  2122. } else {
  2123. var total float64
  2124. for _, item := range prescriptions {
  2125. if item.Type == 1 { //药品
  2126. for _, subItem := range item.HisDoctorAdviceInfo {
  2127. total = total + (subItem.Price * subItem.PrescribingNumber)
  2128. }
  2129. }
  2130. if item.Type == 2 { //项目
  2131. for _, subItem := range item.HisPrescriptionProject {
  2132. total = total + (subItem.Price * float64(subItem.Count))
  2133. }
  2134. }
  2135. for _, subItem := range item.HisAdditionalCharge {
  2136. total = total + (subItem.Price * float64(subItem.Count))
  2137. }
  2138. }
  2139. allTotal := fmt.Sprintf("%.2f", total)
  2140. totals, _ := strconv.ParseFloat(allTotal, 64)
  2141. order := &models.HisOrder{
  2142. UserOrgId: adminUser.CurrentOrgId,
  2143. HisPatientId: his.ID,
  2144. PatientId: id,
  2145. SettleAccountsDate: recordDateTime,
  2146. Ctime: time.Now().Unix(),
  2147. Mtime: time.Now().Unix(),
  2148. Status: 1,
  2149. OrderStatus: 2,
  2150. Number: chrg_bchno,
  2151. MedfeeSumamt: totals,
  2152. }
  2153. err = service.CreateOrder(order)
  2154. if err != nil {
  2155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2156. return
  2157. }
  2158. var customs []*Custom
  2159. for _, item := range prescriptions {
  2160. if item.Type == 1 { //药品
  2161. for _, subItem := range item.HisDoctorAdviceInfo {
  2162. cus := &Custom{
  2163. AdviceId: subItem.ID,
  2164. ProjectId: 0,
  2165. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2166. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2167. FeedetlSn: subItem.FeedetlSn,
  2168. Price: fmt.Sprintf("%.2f", subItem.Price),
  2169. MedListCodg: subItem.MedListCodg,
  2170. Type: 1,
  2171. }
  2172. customs = append(customs, cus)
  2173. }
  2174. }
  2175. if item.Type == 2 { //项目
  2176. for _, subItem := range item.HisPrescriptionProject {
  2177. cus := &Custom{
  2178. AdviceId: 0,
  2179. ProjectId: subItem.ID,
  2180. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2181. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2182. FeedetlSn: subItem.FeedetlSn,
  2183. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2184. MedListCodg: subItem.MedListCodg,
  2185. Type: 2,
  2186. }
  2187. customs = append(customs, cus)
  2188. }
  2189. }
  2190. for _, item := range item.HisAdditionalCharge {
  2191. cus := &Custom{
  2192. ItemId: item.ID,
  2193. AdviceId: 0,
  2194. ProjectId: 0,
  2195. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2196. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2197. FeedetlSn: item.FeedetlSn,
  2198. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2199. MedListCodg: item.XtHisAddtionConfig.Code,
  2200. Type: 3,
  2201. }
  2202. customs = append(customs, cus)
  2203. }
  2204. }
  2205. for _, item := range customs {
  2206. var advice_id int64 = 0
  2207. var project_id int64 = 0
  2208. var item_id int64 = 0
  2209. var types int64 = 0
  2210. if item.Type == 1 {
  2211. advice_id = item.AdviceId
  2212. project_id = 0
  2213. item_id = 0
  2214. } else if item.Type == 2 {
  2215. advice_id = 0
  2216. item_id = 0
  2217. project_id = item.ProjectId
  2218. } else if item.Type == 3 {
  2219. advice_id = 0
  2220. item_id = item.ItemId
  2221. project_id = 0
  2222. }
  2223. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2224. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2225. pric, _ := strconv.ParseFloat(item.Price, 32)
  2226. info := &models.HisOrderInfo{
  2227. OrderNumber: order.Number,
  2228. UploadDate: time.Now().Unix(),
  2229. AdviceId: advice_id,
  2230. DetItemFeeSumamt: detItemFeeSumamt,
  2231. Cnt: cut,
  2232. Pric: pric,
  2233. PatientId: id,
  2234. Status: 1,
  2235. Mtime: time.Now().Unix(),
  2236. Ctime: time.Now().Unix(),
  2237. UserOrgId: adminUser.CurrentOrgId,
  2238. HisPatientId: his.ID,
  2239. OrderId: order.ID,
  2240. ProjectId: project_id,
  2241. Type: types,
  2242. ItemId: item_id,
  2243. }
  2244. service.CreateOrderInfo(info)
  2245. }
  2246. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2247. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2248. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2249. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2250. if err == nil {
  2251. c.ServeSuccessJSON(map[string]interface{}{
  2252. "msg": "结算成功",
  2253. })
  2254. } else {
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2256. return
  2257. }
  2258. }
  2259. }
  2260. //func (c *HisApiController) GetSettleInfo() {
  2261. // id, _ := c.GetInt64("id")
  2262. // order_id, _ := c.GetInt64("order_id")
  2263. //
  2264. // record_time := c.GetString("record_time")
  2265. // pay_way, _ := c.GetInt64("pay_way")
  2266. // pay_price, _ := c.GetFloat("pay_price")
  2267. // pay_card_no := c.GetString("pay_card_no")
  2268. // discount_price, _ := c.GetFloat("discount_price")
  2269. // preferential_price, _ := c.GetFloat("preferential_price")
  2270. // reality_price, _ := c.GetFloat("reality_price")
  2271. // found_price, _ := c.GetFloat("found_price")
  2272. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2273. // private_price, _ := c.GetFloat("private_price")
  2274. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2275. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2276. //
  2277. // timeLayout := "2006-01-02"
  2278. // loc, _ := time.LoadLocation("Local")
  2279. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2280. // if err != nil {
  2281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2282. // return
  2283. // }
  2284. // recordDateTime := theTime.Unix()
  2285. // adminUser := c.GetAdminUserInfo()
  2286. //
  2287. // var prescriptions []*models.HisPrescription
  2288. //
  2289. // data := make(map[string]interface{})
  2290. // if settle_accounts_type == 1 { //日结
  2291. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2292. // data["pre"] = prescriptions
  2293. //
  2294. // } else { //月结
  2295. // start_time_str := c.GetString("start_time")
  2296. // end_time_str := c.GetString("end_time")
  2297. // timeLayout := "2006-01-02"
  2298. // loc, _ := time.LoadLocation("Local")
  2299. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2300. // if err != nil {
  2301. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2302. // return
  2303. // }
  2304. // recordStartTime := theStartTime.Unix()
  2305. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2306. // if err != nil {
  2307. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2308. // return
  2309. // }
  2310. // recordEndTime := theEndTime.Unix()
  2311. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2312. // data["pre"] = prescriptions
  2313. //
  2314. // }
  2315. //
  2316. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2317. //
  2318. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2319. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2320. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2321. // strconv.FormatInt(his.PatientId, 10)
  2322. //
  2323. // order_src, _ := service.GetHisOrderByID(order_id)
  2324. //
  2325. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2326. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2327. //
  2328. // var total float64
  2329. // for _, item := range prescriptions {
  2330. // if item.Type == 1 { //药品
  2331. // for _, subItem := range item.HisDoctorAdviceInfo {
  2332. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2333. // }
  2334. // }
  2335. // if item.Type == 2 { //项目
  2336. // for _, subItem := range item.HisPrescriptionProject {
  2337. // total = total + (subItem.Price * float64(subItem.Count))
  2338. // }
  2339. // }
  2340. // }
  2341. //
  2342. // for _, item := range prescriptions {
  2343. // for _, subItem := range item.HisAdditionalCharge {
  2344. // total = total + (subItem.Price * float64(subItem.Count))
  2345. // }
  2346. // }
  2347. //
  2348. // allTotal := fmt.Sprintf("%.2f", total)
  2349. // var rf []*ResultFive
  2350. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2351. // psn_no := order_src.PsnNo
  2352. // mdtrt_id := order_src.MdtrtId
  2353. // chrg_bchno := order_src.Number
  2354. // cert_no := order_src.Certno
  2355. // insutype := rf[0].Insutype
  2356. //
  2357. // if his.IdCardType == 1 {
  2358. // cert_no = his.MedicalInsuranceNumber
  2359. // } else {
  2360. // cert_no = his.Certno
  2361. // }
  2362. //
  2363. // 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)
  2364. // var dat map[string]interface{}
  2365. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2366. // fmt.Println(dat)
  2367. // } else {
  2368. // fmt.Println(err)
  2369. // }
  2370. //
  2371. // userJSONBytes, _ := json.Marshal(dat)
  2372. //
  2373. //
  2374. //
  2375. // var res ResultSeven
  2376. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2377. // utils.ErrorLog("解析失败:%v", err)
  2378. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2379. // return
  2380. // }
  2381. // if res.Infcode == -1 {
  2382. // errlog := &models.HisOrderError{
  2383. // UserOrgId: adminUser.CurrentOrgId,
  2384. // Ctime: time.Now().Unix(),
  2385. // Mtime: time.Now().Unix(),
  2386. // Number: chrg_bchno,
  2387. // ErrMsg: res.ErrMsg,
  2388. // Status: 1,
  2389. // PatientId: id,
  2390. // RecordTime: recordDateTime,
  2391. // Stage: 6,
  2392. // }
  2393. // service.CreateErrMsgLog(errlog)
  2394. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2395. // return
  2396. // } else {
  2397. // order_src.OrderStatus = 2
  2398. // order_src.PayWay = pay_way
  2399. // order_src.PayPrice = pay_price
  2400. // order_src.PayCardNo = pay_card_no
  2401. // order_src.DiscountPrice = discount_price
  2402. // order_src.PreferentialPrice = preferential_price
  2403. // order_src.RealityPrice = reality_price
  2404. // order_src.FoundPrice = found_price
  2405. // order_src.MedicalInsurancePrice = medical_insurance_price
  2406. // order_src.PrivatePrice = private_price
  2407. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2408. // order_src.SetlId = res.Output.Setlinfo.SetlID
  2409. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2410. // order_src.PsnName = res.Output.Setlinfo.PsnName
  2411. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2412. // order_src.Certno = res.Output.Setlinfo.Certno
  2413. // order_src.Gend = res.Output.Setlinfo.Gend
  2414. // order_src.Naty = res.Output.Setlinfo.Naty
  2415. // order_src.Age = res.Output.Setlinfo.Age
  2416. // order_src.Insutype = res.Output.Setlinfo.Insutype
  2417. // order_src.PsnType = res.Output.Setlinfo.PsnType
  2418. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2419. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2420. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2421. // order_src.MedType = res.Output.Setlinfo.MedType
  2422. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2423. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2424. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2425. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2426. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2427. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2428. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2429. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2430. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2431. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2432. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2433. // order_src.MafPay = res.Output.Setlinfo.MafPay
  2434. // order_src.OthPay = res.Output.Setlinfo.OthPay
  2435. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2436. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2437. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2438. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2439. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2440. // order_src.Balc = res.Output.Setlinfo.Balc
  2441. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2442. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2443. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2444. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2445. // order_src.Creator = order_src.Creator
  2446. // order_src.Modify = roles.ID
  2447. // order_src.RequestLog = src_resquest
  2448. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2449. // detailStr := string(setlDetail)
  2450. // order_src.SetlDetail = detailStr
  2451. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2452. // err = service.UpDateOrder(order_src)
  2453. //
  2454. // if err == nil {
  2455. // c.ServeSuccessJSON(map[string]interface{}{
  2456. // "msg": "结算成功",
  2457. // })
  2458. // } else {
  2459. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2460. // return
  2461. // }
  2462. // }
  2463. // }
  2464. //}
  2465. //退款
  2466. func (c *HisApiController) Refund() {
  2467. order_id, _ := c.GetInt64("order_id")
  2468. admin_user_id, _ := c.GetInt64("admin_user_id")
  2469. record_time := c.GetString("record_time")
  2470. patient_id, _ := c.GetInt64("patient_id")
  2471. timeLayout := "2006-01-02"
  2472. loc, _ := time.LoadLocation("Local")
  2473. adminUser := c.GetAdminUserInfo()
  2474. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2475. if err != nil {
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. recordDateTime := theTime.Unix()
  2480. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2481. var order models.HisOrder
  2482. order, _ = service.GetHisOrderByID(order_id)
  2483. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2484. if order.ID == 0 {
  2485. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2486. }
  2487. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2488. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2489. if config.IsOpen == 1 { //对接了医保,走医保流程
  2490. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2491. var dat map[string]interface{}
  2492. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2493. fmt.Println(dat)
  2494. } else {
  2495. fmt.Println(err)
  2496. }
  2497. userJSONBytes, _ := json.Marshal(dat)
  2498. var res ResultSixteen
  2499. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2500. utils.ErrorLog("解析失败:%v", err)
  2501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2502. return
  2503. }
  2504. if res.Infcode == 0 {
  2505. result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2506. var dat map[string]interface{}
  2507. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2508. fmt.Println(dat)
  2509. } else {
  2510. fmt.Println(err)
  2511. }
  2512. userJSONBytes, _ := json.Marshal(dat)
  2513. var res2 ResultSix
  2514. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2515. utils.ErrorLog("解析失败:%v", err)
  2516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2517. return
  2518. }
  2519. if res2.Infcode == 0 {
  2520. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  2521. if err == nil {
  2522. c.ServeSuccessJSON(map[string]interface{}{
  2523. "msg": "退费成功",
  2524. })
  2525. } else {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2527. return
  2528. }
  2529. } else {
  2530. c.ServeSuccessJSON(map[string]interface{}{
  2531. "code": -10,
  2532. "msg": res2.ErrMsg,
  2533. })
  2534. }
  2535. } else {
  2536. c.ServeSuccessJSON(map[string]interface{}{
  2537. "code": -10,
  2538. "msg": res.ErrMsg,
  2539. })
  2540. }
  2541. } else {
  2542. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2543. if err == nil {
  2544. c.ServeSuccessJSON(map[string]interface{}{
  2545. "msg": "退费成功",
  2546. })
  2547. } else {
  2548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. func (c *HisApiController) RefundNumber() {
  2554. record_time := c.GetString("record_time")
  2555. patient_id, _ := c.GetInt64("patient_id")
  2556. admin_user_id, _ := c.GetInt64("admin_user_id")
  2557. his_patient_id, _ := c.GetInt64("id")
  2558. timeLayout := "2006-01-02"
  2559. loc, _ := time.LoadLocation("Local")
  2560. adminUser := c.GetAdminUserInfo()
  2561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2562. fmt.Println(err)
  2563. if err != nil {
  2564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2565. return
  2566. }
  2567. recordDateTime := theTime.Unix()
  2568. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2569. //his, _ := service.GetNewHisPatientRecord(adminUser.CurrentOrgId, patient_id)
  2570. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2571. //order, _ := service.GetHisOrderByID(order_id)
  2572. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2573. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2574. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2575. if config.IsOpen == 1 { //对接了医保,走医保流程
  2576. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2577. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2578. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2579. resp3, requestErr3 := http.Get(api3)
  2580. if requestErr3 != nil {
  2581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2582. return
  2583. }
  2584. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2585. if ioErr3 != nil {
  2586. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2588. return
  2589. }
  2590. var respJSON3 map[string]interface{}
  2591. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2592. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2594. return
  2595. }
  2596. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2597. userJSONBytes3, _ := json.Marshal(respJSON3)
  2598. var res2 ResultSix
  2599. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  2600. utils.ErrorLog("解析失败:%v", err)
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2602. return
  2603. }
  2604. if res2.Infcode == 0 {
  2605. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2606. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2607. err := service.UpdataRegStatus2(his_patient_id)
  2608. if err == nil {
  2609. c.ServeSuccessJSON(map[string]interface{}{
  2610. "msg": "退号成功",
  2611. })
  2612. } else {
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2614. return
  2615. }
  2616. } else {
  2617. c.ServeSuccessJSON(map[string]interface{}{
  2618. "code": -10,
  2619. "msg": res2.ErrMsg,
  2620. })
  2621. }
  2622. } else {
  2623. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2624. //if err == nil {
  2625. // c.ServeSuccessJSON(map[string]interface{}{
  2626. // "msg": "退费成功",
  2627. // })
  2628. //} else {
  2629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2630. // return
  2631. //}
  2632. }
  2633. }
  2634. func (c *HisApiController) RefundDetail() {
  2635. order_id, _ := c.GetInt64("order_id")
  2636. his_patient_id, _ := c.GetInt64("his_patient_id")
  2637. number := c.GetString("number")
  2638. record_time := c.GetString("record_time")
  2639. patient_id, _ := c.GetInt64("patient_id")
  2640. timeLayout := "2006-01-02"
  2641. loc, _ := time.LoadLocation("Local")
  2642. adminUser := c.GetAdminUserInfo()
  2643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2644. fmt.Println(err)
  2645. if err != nil {
  2646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2647. return
  2648. }
  2649. recordDateTime := theTime.Unix()
  2650. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2651. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2652. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2653. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2654. var order models.HisOrder
  2655. order, _ = service.GetHisOrderByID(order_id)
  2656. if order.ID == 0 {
  2657. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2658. }
  2659. if config.IsOpen == 1 { //对接了医保,走医保流程
  2660. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2661. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2662. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2663. resp2, requestErr2 := http.Get(api2)
  2664. if requestErr2 != nil {
  2665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. }
  2668. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2669. if ioErr2 != nil {
  2670. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2672. return
  2673. }
  2674. var respJSON2 map[string]interface{}
  2675. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2676. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2678. return
  2679. }
  2680. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  2681. if err == nil {
  2682. c.ServeSuccessJSON(map[string]interface{}{
  2683. "msg": "退费成功",
  2684. })
  2685. } else {
  2686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2687. return
  2688. }
  2689. } else {
  2690. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  2691. if err == nil {
  2692. c.ServeSuccessJSON(map[string]interface{}{
  2693. "msg": "退费成功",
  2694. })
  2695. } else {
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2697. return
  2698. }
  2699. }
  2700. }
  2701. //对账
  2702. func (c *HisApiController) GetCheckAccount() {
  2703. start_time := c.GetString("start_time")
  2704. end_time := c.GetString("end_time")
  2705. insutype := c.GetString("insutype")
  2706. clr_type := c.GetString("clr_type")
  2707. admin_user_id, _ := c.GetInt64("admin_user_id")
  2708. adminUser := c.GetAdminUserInfo()
  2709. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2710. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2711. timeLayout := "2006-01-02"
  2712. loc, _ := time.LoadLocation("Local")
  2713. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2714. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2715. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2716. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2717. fixmedins_setl_cnt := int64(len(orders))
  2718. //
  2719. ////撤销的算2条数据为一笔
  2720. //for _, item := range orders_two {
  2721. // if item.OrderStatus == 3 {
  2722. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  2723. // }
  2724. //}
  2725. var medfee_sumamt float64
  2726. var acct_pay float64
  2727. var fund_pay_sumamt float64
  2728. for _, item := range orders {
  2729. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2730. acct_pay = acct_pay + item.AcctPay
  2731. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2732. }
  2733. var user_name string
  2734. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2735. if role.ID == 0 {
  2736. user_name = "xxx"
  2737. } else {
  2738. user_name = role.UserName
  2739. }
  2740. if config.IsOpen == 1 {
  2741. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2742. "insutype=" + insutype +
  2743. "&clr_type=" + clr_type +
  2744. "&setl_optins=" + "定点医保中心" +
  2745. "&stmt_begndate=" + start_time +
  2746. "&stm_enddate=" + end_time +
  2747. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2748. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2749. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2750. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2751. "&fixmedins_code=" + miConfig.Code +
  2752. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2753. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2754. "&secret_key=" + miConfig.SecretKey +
  2755. "&org_name=" + miConfig.OrgName +
  2756. "&doctor=" + user_name
  2757. fmt.Println(api)
  2758. resp, requestErr := http.Get(api)
  2759. if requestErr != nil {
  2760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2761. return
  2762. }
  2763. body, ioErr := ioutil.ReadAll(resp.Body)
  2764. fmt.Println(body)
  2765. if ioErr != nil {
  2766. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2768. return
  2769. }
  2770. var respJSON map[string]interface{}
  2771. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2772. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2774. return
  2775. }
  2776. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2777. userJSONBytes, _ := json.Marshal(respJSON)
  2778. var res ResultEight
  2779. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2780. utils.ErrorLog("解析失败:%v", err)
  2781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2782. return
  2783. }
  2784. if res.Infcode == 0 {
  2785. if res.Output.Stmtinfo.StmtRslt == "0" {
  2786. micc := &models.MedicalInsuranceCostCompare{
  2787. StartTime: startime.Unix(),
  2788. EndTime: endtime.Unix(),
  2789. Insutype: insutype,
  2790. CheckType: 1,
  2791. Num: fixmedins_setl_cnt,
  2792. Mtime: time.Now().Unix(),
  2793. Status: 1,
  2794. UserOrgId: adminUser.CurrentOrgId,
  2795. CostTotal: medfee_sumamt,
  2796. FuncTotal: fund_pay_sumamt,
  2797. PsnPay: acct_pay,
  2798. Creator: admin_user_id,
  2799. Ctime: time.Now().Unix(),
  2800. }
  2801. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2802. if err == nil {
  2803. c.ServeSuccessJSON(map[string]interface{}{
  2804. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2805. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2806. })
  2807. } else {
  2808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2809. }
  2810. } else {
  2811. c.ServeSuccessJSON(map[string]interface{}{
  2812. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2813. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2814. })
  2815. }
  2816. } else {
  2817. c.ServeSuccessJSON(map[string]interface{}{
  2818. "code": -10,
  2819. "msg": res.ErrMsg,
  2820. })
  2821. }
  2822. }
  2823. }
  2824. func (c *HisApiController) Check310() {
  2825. adminUser := c.GetAdminUserInfo()
  2826. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2827. var user_name string
  2828. user_name = "xxx"
  2829. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2830. "insutype=" + "310" +
  2831. "&clr_type=" + "11" +
  2832. "&setl_optins=" + "定点医保中心" +
  2833. "&stmt_begndate=" + "2021-03-01" +
  2834. "&stm_enddate=" + "2021-03-31" +
  2835. "&medfee_sumamt=" + "11521" +
  2836. "&fund_pay_sumamt=" + "10166.66" +
  2837. "&acct_pay=" + "0" +
  2838. "&fixmedins_setl_cnt=" + "7" +
  2839. "&fixmedins_code=" + miConfig.Code +
  2840. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2841. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2842. "&secret_key=" + miConfig.SecretKey +
  2843. "&org_name=" + miConfig.OrgName +
  2844. "&doctor=" + user_name
  2845. fmt.Println(api)
  2846. resp, requestErr := http.Get(api)
  2847. if requestErr != nil {
  2848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2849. return
  2850. }
  2851. body, ioErr := ioutil.ReadAll(resp.Body)
  2852. fmt.Println(body)
  2853. if ioErr != nil {
  2854. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2856. return
  2857. }
  2858. var respJSON map[string]interface{}
  2859. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2860. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2862. return
  2863. }
  2864. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2865. userJSONBytes, _ := json.Marshal(respJSON)
  2866. var res ResultEight
  2867. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2868. utils.ErrorLog("解析失败:%v", err)
  2869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2870. return
  2871. }
  2872. }
  2873. func (c *HisApiController) Check390() {
  2874. adminUser := c.GetAdminUserInfo()
  2875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2876. var user_name string
  2877. user_name = "张俊杰"
  2878. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2879. "insutype=" + "390" +
  2880. "&clr_type=" + "11" +
  2881. "&setl_optins=" + "定点医保中心" +
  2882. "&stmt_begndate=" + "2021-03-01" +
  2883. "&stm_enddate=" + "2021-03-31" +
  2884. "&medfee_sumamt=" + "209318.43" +
  2885. "&fund_pay_sumamt=" + "188029.12" +
  2886. "&acct_pay=" + "0" +
  2887. "&fixmedins_setl_cnt=" + "48" +
  2888. "&fixmedins_code=" + miConfig.Code +
  2889. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2890. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2891. "&secret_key=" + miConfig.SecretKey +
  2892. "&org_name=" + miConfig.OrgName +
  2893. "&doctor=" + user_name
  2894. fmt.Println(api)
  2895. resp, requestErr := http.Get(api)
  2896. if requestErr != nil {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2898. return
  2899. }
  2900. body, ioErr := ioutil.ReadAll(resp.Body)
  2901. fmt.Println(body)
  2902. if ioErr != nil {
  2903. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2905. return
  2906. }
  2907. var respJSON map[string]interface{}
  2908. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2909. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2911. return
  2912. }
  2913. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2914. userJSONBytes, _ := json.Marshal(respJSON)
  2915. var res ResultEight
  2916. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2917. utils.ErrorLog("解析失败:%v", err)
  2918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2919. return
  2920. }
  2921. }
  2922. //对账明细
  2923. func (c *HisApiController) GetCheckDetailAccount() {
  2924. start_time := c.GetString("start_time")
  2925. end_time := c.GetString("end_time")
  2926. admin_user_id, _ := c.GetInt64("admin_user_id")
  2927. adminUser := c.GetAdminUserInfo()
  2928. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2929. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2930. timeLayout := "2006-01-02"
  2931. loc, _ := time.LoadLocation("Local")
  2932. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2933. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2934. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2935. Mkdir(miConfig.OrgName)
  2936. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2937. file_name := file + ".txt"
  2938. zip_name := file + ".zip"
  2939. zip_path := miConfig.OrgName + "/" + zip_name
  2940. file_path := miConfig.OrgName + "/" + file_name
  2941. decimal.DivisionPrecision = 2
  2942. var medfee_sumamt float64
  2943. var psn_cash_pay float64
  2944. var fund_pay_sumamt float64
  2945. fixmedins_setl_cnt := int64(len(orders))
  2946. for _, item := range orders {
  2947. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  2948. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  2949. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  2950. }
  2951. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2952. defer f.Close()
  2953. if err != nil {
  2954. fmt.Println(err.Error())
  2955. } else {
  2956. for _, item := range orders {
  2957. var refd_setl_flag string
  2958. if item.OrderStatus == 2 {
  2959. refd_setl_flag = "0"
  2960. var str string
  2961. str = item.SetlId + " " +
  2962. item.MdtrtId + " " +
  2963. item.PsnNo + " " +
  2964. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2965. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2966. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  2967. _, err = f.Write([]byte(str))
  2968. }
  2969. if item.OrderStatus == 3 {
  2970. var str string
  2971. str = item.SetlId + " " +
  2972. item.MdtrtId + " " +
  2973. item.PsnNo + " " +
  2974. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2975. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2976. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  2977. _, err = f.Write([]byte(str))
  2978. var str2 string
  2979. str2 = item.SetlId + " " +
  2980. item.MdtrtId + " " +
  2981. item.PsnNo + " " +
  2982. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  2983. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  2984. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  2985. _, err = f.Write([]byte(str2))
  2986. }
  2987. }
  2988. }
  2989. Zip(file_path, zip_path)
  2990. fmt.Println(ReadFile(zip_path))
  2991. fmt.Println(string(ReadFile(zip_path)))
  2992. if config.IsOpen == 1 {
  2993. var user_name string
  2994. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2995. if role.ID == 0 {
  2996. user_name = "管理员"
  2997. } else {
  2998. user_name = role.UserName
  2999. }
  3000. baseParams := models.BaseParams{
  3001. SecretKey: miConfig.SecretKey,
  3002. FixmedinsCode: miConfig.Code,
  3003. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3004. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3005. OrgName: miConfig.OrgName,
  3006. Doctor: user_name,
  3007. }
  3008. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  3009. var dat map[string]interface{}
  3010. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3011. fmt.Println(dat)
  3012. } else {
  3013. fmt.Println(err)
  3014. }
  3015. userJSONBytes, _ := json.Marshal(dat)
  3016. var res ResultNine
  3017. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3018. utils.ErrorLog("解析失败:%v", err)
  3019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3020. return
  3021. }
  3022. if res.Infcode == 0 {
  3023. fileNo := res.Output.FileQuryNo
  3024. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  3025. "file_qury_no=" + fileNo +
  3026. "&setl_optins=" + "定点医保中心" +
  3027. "&stmt_begndate=" + start_time +
  3028. "&stm_enddate=" + end_time +
  3029. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3030. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3031. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  3032. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3033. "&fixmedins_code=" + miConfig.Code +
  3034. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3035. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3036. "&secret_key=" + miConfig.SecretKey +
  3037. "&org_name=" + miConfig.OrgName +
  3038. "&doctor=" + user_name
  3039. resp, requestErr := http.Get(api)
  3040. if requestErr != nil {
  3041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3042. return
  3043. }
  3044. body, ioErr := ioutil.ReadAll(resp.Body)
  3045. if ioErr != nil {
  3046. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3048. return
  3049. }
  3050. var respJSON map[string]interface{}
  3051. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3052. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3054. return
  3055. }
  3056. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3057. userJSONBytes, _ := json.Marshal(respJSON)
  3058. var res ResultTen
  3059. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3060. utils.ErrorLog("解析失败:%v", err)
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3062. return
  3063. }
  3064. if res.Infcode == 0 {
  3065. service.Gdyb9102(baseParams, zip_name, fileNo)
  3066. micc := &models.MedicalInsuranceCostCompare{
  3067. StartTime: startime.Unix(),
  3068. EndTime: endtime.Unix(),
  3069. Insutype: "0",
  3070. CheckType: 2,
  3071. Num: fixmedins_setl_cnt,
  3072. Mtime: time.Now().Unix(),
  3073. Status: 1,
  3074. UserOrgId: adminUser.CurrentOrgId,
  3075. CostTotal: medfee_sumamt,
  3076. FuncTotal: fund_pay_sumamt,
  3077. PsnPay: psn_cash_pay,
  3078. Creator: admin_user_id,
  3079. Ctime: time.Now().Unix(),
  3080. }
  3081. service.CreateMedicalInsuranceCostCompareRecord(micc)
  3082. c.ServeSuccessJSON(map[string]interface{}{
  3083. "msg": "明细对账成功",
  3084. })
  3085. }
  3086. } else {
  3087. }
  3088. }
  3089. }
  3090. func (c *HisApiController) GetSettleAccounts() {
  3091. //id, _ := c.GetInt64("id")
  3092. //record_time := c.GetString("record_time")
  3093. order_id, _ := c.GetInt64("order_id")
  3094. admin_user_id, _ := c.GetInt64("admin_user_id")
  3095. //timeLayout := "2006-01-02"
  3096. //loc, _ := time.LoadLocation("Local")
  3097. //
  3098. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3099. //if err != nil {
  3100. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3101. // return
  3102. //}
  3103. //recordDateTime := theTime.Unix()
  3104. adminUser := c.GetAdminUserInfo()
  3105. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3106. order, _ := service.GetHisOrderByID(order_id)
  3107. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3108. var bedCostTotal float64 = 0 //床位总费
  3109. var bedCostSelfTotal float64 = 0 //床位自费
  3110. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3111. var operationCostTotal float64 = 0 //手术费
  3112. var operationCostSelfTotal float64 = 0 //手术费
  3113. var operationCostPartSelfTotal float64 = 0 //手术费
  3114. var otherCostTotal float64 = 0 //其他费用
  3115. var otherCostSelfTotal float64 = 0 //其他费用
  3116. var otherCostPartSelfTotal float64 = 0 //其他费用
  3117. var materialCostTotal float64 = 0 //材料费
  3118. var materialCostSelfTotal float64 = 0 //材料费
  3119. var materialCostPartSelfTotal float64 = 0 //材料费
  3120. var westernMedicineCostTotal float64 = 0 //西药费
  3121. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3122. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3123. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3124. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3125. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3126. var checkCostTotal float64 = 0 //检查费
  3127. var checkCostSelfTotal float64 = 0 //检查费
  3128. var checkCostPartSelfTotal float64 = 0 //检查费
  3129. var laboratoryCostTotal float64 = 0 //化验费
  3130. var laboratoryCostSelfTotal float64 = 0 //化验费
  3131. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3132. var treatCostTotal float64 = 0 //治疗费用
  3133. var treatCostSelfTotal float64 = 0 //治疗费用
  3134. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3135. decimal.DivisionPrecision = 2
  3136. for _, item := range orderInfos {
  3137. if item.MedChrgitmType == "01" { //床位费
  3138. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3139. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3140. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3141. }
  3142. if item.MedChrgitmType == "03" { //检查费
  3143. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3144. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3145. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3146. }
  3147. if item.MedChrgitmType == "04" { //化验费
  3148. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3149. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3150. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3151. }
  3152. if item.MedChrgitmType == "05" { //治疗费
  3153. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3154. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3155. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3156. }
  3157. if item.MedChrgitmType == "06" { //手术费
  3158. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3159. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3160. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3161. }
  3162. if item.MedChrgitmType == "08" { //材料费
  3163. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3164. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3165. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3166. }
  3167. if item.MedChrgitmType == "09" { //西药费
  3168. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3169. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3170. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3171. }
  3172. if item.MedChrgitmType == "11" { //中成费
  3173. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3174. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3175. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3176. }
  3177. if item.MedChrgitmType == "14" { //其他费
  3178. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3179. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3180. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3181. }
  3182. }
  3183. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3184. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3185. var user_name string
  3186. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3187. if role.ID == 0 {
  3188. user_name = "管理员"
  3189. } else {
  3190. user_name = role.UserName
  3191. }
  3192. baseParams := models.BaseParams{
  3193. SecretKey: miConfig.SecretKey,
  3194. FixmedinsCode: miConfig.Code,
  3195. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3196. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3197. OrgName: miConfig.OrgName,
  3198. Doctor: user_name,
  3199. }
  3200. businessParams := models.BusinessParams{
  3201. PsnNo: order.PsnNo,
  3202. MdtrtId: order.MdtrtId,
  3203. SetlId: order.SetlId,
  3204. }
  3205. if config.IsOpen == 1 {
  3206. result := service.Gdyb5203(baseParams, businessParams)
  3207. var dat map[string]interface{}
  3208. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3209. fmt.Println(dat)
  3210. } else {
  3211. fmt.Println(err)
  3212. }
  3213. userJSONBytes, _ := json.Marshal(dat)
  3214. var res ResultEleven
  3215. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3216. utils.ErrorLog("解析失败:%v", err)
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3218. return
  3219. }
  3220. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3221. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3222. if res.Infcode == 0 {
  3223. c.ServeSuccessJSON(map[string]interface{}{
  3224. "charge_admin": charge_admin,
  3225. "printor_admin": printor_admin,
  3226. "info": res.Output.Setlinfo,
  3227. "bedCostTotal": bedCostTotal,
  3228. "bedCostSelfTotal": bedCostSelfTotal,
  3229. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3230. "operationCostTotal": operationCostTotal,
  3231. "operationCostSelfTotal": operationCostSelfTotal,
  3232. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3233. "otherCostTotal": otherCostTotal,
  3234. "otherCostSelfTotal": otherCostSelfTotal,
  3235. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3236. "materialCostTotal": materialCostTotal,
  3237. "materialCostSelfTotal": materialCostSelfTotal,
  3238. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3239. "westernMedicineCostTotal": westernMedicineCostTotal,
  3240. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3241. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3242. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3243. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3244. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3245. "checkCostTotal": checkCostTotal,
  3246. "checkCostSelfTotal": checkCostSelfTotal,
  3247. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3248. "laboratoryCostTotal": laboratoryCostTotal,
  3249. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3250. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3251. "treatCostTotal": treatCostTotal,
  3252. "treatCostSelfTotal": treatCostSelfTotal,
  3253. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3254. })
  3255. }
  3256. }
  3257. }
  3258. func (c *HisApiController) CheckTreatment() {
  3259. patient_id, _ := c.GetInt64("patient_id", 0)
  3260. record_time := c.GetString("record_time")
  3261. insutype := c.GetString("insutype")
  3262. timeLayout := "2006-01-02"
  3263. loc, _ := time.LoadLocation("Local")
  3264. adminUser := c.GetAdminUserInfo()
  3265. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3266. fmt.Println(err)
  3267. if err != nil {
  3268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3269. return
  3270. }
  3271. recordDateTime := theTime.Unix()
  3272. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3273. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3274. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3275. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3276. var user_name string
  3277. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3278. if role.ID == 0 {
  3279. user_name = "xxx"
  3280. } else {
  3281. user_name = role.UserName
  3282. }
  3283. baseParams := models.BaseParams{
  3284. SecretKey: miConfig.SecretKey,
  3285. FixmedinsCode: miConfig.Code,
  3286. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3287. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3288. OrgName: miConfig.OrgName,
  3289. Doctor: user_name,
  3290. }
  3291. if config.IsOpen == 1 {
  3292. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3293. var dat map[string]interface{}
  3294. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3295. fmt.Println(dat)
  3296. } else {
  3297. fmt.Println(err)
  3298. }
  3299. }
  3300. }
  3301. func (c *HisApiController) PutRecord() {
  3302. id, _ := c.GetInt64("id")
  3303. record_time := c.GetString("record_time")
  3304. timeLayout := "2006-01-02"
  3305. loc, _ := time.LoadLocation("Local")
  3306. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3307. if err != nil {
  3308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3309. return
  3310. }
  3311. recordDateTime := theTime.Unix()
  3312. adminInfo := c.GetAdminUserInfo()
  3313. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3314. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3315. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3316. fmt.Println(miConfig.SecretKey)
  3317. if patient == nil {
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3319. return
  3320. }
  3321. if len(patient.IdCardNo) == 0 {
  3322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3323. return
  3324. }
  3325. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3326. if config.IsOpen == 1 {
  3327. 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
  3328. resp, requestErr := http.Get(api)
  3329. if requestErr != nil {
  3330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3331. return
  3332. }
  3333. defer resp.Body.Close()
  3334. body, ioErr := ioutil.ReadAll(resp.Body)
  3335. if ioErr != nil {
  3336. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3338. return
  3339. }
  3340. var respJSON map[string]interface{}
  3341. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3342. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3344. return
  3345. }
  3346. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3347. userJSONBytes, _ := json.Marshal(userJSON)
  3348. var res ResultTwo
  3349. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3350. utils.ErrorLog("解析失败:%v", err)
  3351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3352. return
  3353. }
  3354. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3355. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3356. infoStr := string(Iinfos)
  3357. idetinfoStr := string(Idetinfos)
  3358. if res.Infcode == 0 {
  3359. his := models.VMHisPatient{
  3360. Status: 1,
  3361. Ctime: time.Now().Unix(),
  3362. Mtime: time.Now().Unix(),
  3363. PsnNo: res.Output.Baseinfo.PsnNo,
  3364. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3365. Certno: res.Output.Baseinfo.Certno,
  3366. PsnName: res.Output.Baseinfo.PsnName,
  3367. Gend: res.Output.Baseinfo.Gend,
  3368. Naty: res.Output.Baseinfo.Naty,
  3369. Brdy: res.Output.Baseinfo.Brdy,
  3370. Age: res.Output.Baseinfo.Age,
  3371. Iinfo: infoStr,
  3372. Idetinfo: idetinfoStr,
  3373. PatientId: patient.ID,
  3374. RecordDate: theTime.Unix(),
  3375. UserOrgId: adminInfo.CurrentOrgId,
  3376. AdminUserId: adminInfo.AdminUser.Id,
  3377. IsReturn: 1,
  3378. }
  3379. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3380. 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")
  3381. 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")
  3382. var dat map[string]interface{}
  3383. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3384. fmt.Println(dat)
  3385. } else {
  3386. fmt.Println(err)
  3387. }
  3388. var dat2 map[string]interface{}
  3389. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3390. fmt.Println(dat2)
  3391. } else {
  3392. fmt.Println(err)
  3393. }
  3394. } else {
  3395. adminUser := c.GetAdminUserInfo()
  3396. errlog := &models.HisOrderError{
  3397. UserOrgId: adminUser.CurrentOrgId,
  3398. Ctime: time.Now().Unix(),
  3399. Mtime: time.Now().Unix(),
  3400. ErrMsg: res.ErrMsg,
  3401. Status: 1,
  3402. PatientId: id,
  3403. RecordTime: recordDateTime,
  3404. Stage: 1,
  3405. }
  3406. service.CreateErrMsgLog(errlog)
  3407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3408. return
  3409. }
  3410. }
  3411. }
  3412. func (c *HisApiController) GetUploadDiag() {
  3413. id, _ := c.GetInt64("id")
  3414. record_time := c.GetString("record_time")
  3415. diagnosis_id, _ := c.GetInt64("diagnosis")
  3416. sick_type, _ := c.GetInt64("sick_type")
  3417. reg_type, _ := c.GetInt64("reg_type")
  3418. timeLayout := "2006-01-02"
  3419. loc, _ := time.LoadLocation("Local")
  3420. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3421. if err != nil {
  3422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3423. return
  3424. }
  3425. var patientPrescription models.HisPrescriptionInfo
  3426. recordDateTime := theTime.Unix()
  3427. adminInfo := c.GetAdminUserInfo()
  3428. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3429. if patientPrescription.ID == 0 {
  3430. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3431. }
  3432. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3433. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3434. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3435. sickConfig, _ := service.FindSickById(sick_type)
  3436. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3437. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3438. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3439. "&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 +
  3440. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3441. resp2, requestErr2 := http.Get(api2)
  3442. if requestErr2 != nil {
  3443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3444. return
  3445. }
  3446. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3447. if ioErr2 != nil {
  3448. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3450. return
  3451. }
  3452. var respJSON2 map[string]interface{}
  3453. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3454. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3456. return
  3457. }
  3458. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3459. userJSONBytes2, _ := json.Marshal(respJSON2)
  3460. var res2 ResultSix
  3461. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3462. utils.ErrorLog("解析失败:%v", err)
  3463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3464. return
  3465. }
  3466. if res2.Infcode == -1 {
  3467. adminUser := c.GetAdminUserInfo()
  3468. errlog := &models.HisOrderError{
  3469. UserOrgId: adminUser.CurrentOrgId,
  3470. Ctime: time.Now().Unix(),
  3471. Mtime: time.Now().Unix(),
  3472. ErrMsg: res2.ErrMsg,
  3473. Status: 1,
  3474. PatientId: id,
  3475. RecordTime: recordDateTime,
  3476. Stage: 3,
  3477. }
  3478. service.CreateErrMsgLog(errlog)
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3480. return
  3481. }
  3482. c.ServeSuccessJSON(map[string]interface{}{
  3483. "msg": "上传成功",
  3484. })
  3485. }
  3486. type QueryResult struct {
  3487. ID int64
  3488. Name string
  3489. Code string
  3490. List_type_code string
  3491. }
  3492. func (c *HisApiController) GetCheckCode() {
  3493. ids_str := c.GetString("ids")
  3494. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3495. ids_arr := strings.Split(ids_str, ",")
  3496. var queryResult []QueryResult
  3497. ids := make([]int64, 0)
  3498. for _, item := range ids_arr {
  3499. id, _ := strconv.ParseInt(item, 10, 64)
  3500. ids = append(ids, id)
  3501. }
  3502. if record_type == 1 {
  3503. drugs, _ := service.GetBatchDrugList(ids)
  3504. for _, item := range drugs {
  3505. result := QueryResult{
  3506. ID: item.ID,
  3507. Name: item.DrugName,
  3508. Code: item.MedicalInsuranceNumber,
  3509. List_type_code: "101",
  3510. }
  3511. queryResult = append(queryResult, result)
  3512. }
  3513. } else if record_type == 2 {
  3514. goods, _ := service.GetBatchGoodInformationList(ids)
  3515. for _, item := range goods {
  3516. result := QueryResult{
  3517. ID: item.ID,
  3518. Name: item.GoodName,
  3519. Code: item.MedicalInsuranceNumber,
  3520. List_type_code: "301",
  3521. }
  3522. queryResult = append(queryResult, result)
  3523. }
  3524. } else if record_type == 3 {
  3525. projects, _ := service.GetBathchMyPorjecgList(ids)
  3526. for _, item := range projects {
  3527. result := QueryResult{
  3528. ID: item.ID,
  3529. Name: item.ProjectName,
  3530. Code: item.MedicalCode,
  3531. List_type_code: "201",
  3532. }
  3533. queryResult = append(queryResult, result)
  3534. }
  3535. }
  3536. admin_user_id, _ := c.GetInt64("admin_user_id")
  3537. adminUser := c.GetAdminUserInfo()
  3538. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3539. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3540. var user_name string
  3541. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3542. if role.ID == 0 {
  3543. user_name = "xxx"
  3544. } else {
  3545. user_name = role.UserName
  3546. }
  3547. baseParams := &models.BaseParams{
  3548. SecretKey: miConfig.SecretKey,
  3549. FixmedinsCode: miConfig.Code,
  3550. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3551. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3552. OrgName: miConfig.OrgName,
  3553. Doctor: user_name,
  3554. }
  3555. if config.IsOpen == 1 {
  3556. for _, item := range queryResult {
  3557. var result string
  3558. if record_type == 1 {
  3559. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3560. } else if record_type == 2 {
  3561. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3562. } else if record_type == 3 {
  3563. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  3564. }
  3565. var dat map[string]interface{}
  3566. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3567. fmt.Println(dat)
  3568. } else {
  3569. fmt.Println(err)
  3570. }
  3571. userJSONBytes, _ := json.Marshal(dat)
  3572. var res ResultSix
  3573. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3574. utils.ErrorLog("解析失败:%v", err)
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3576. return
  3577. }
  3578. if res.Infcode == 0 {
  3579. if record_type == 1 {
  3580. service.UpdateBaseDrugById(item.ID)
  3581. } else if record_type == 2 {
  3582. service.UpdateGoodInformaitonByDetail(item.ID)
  3583. } else if record_type == 3 {
  3584. service.UpdateProjectById(item.ID)
  3585. }
  3586. c.ServeSuccessJSON(map[string]interface{}{
  3587. "failed_code": 0,
  3588. "msg": "目录对照成功",
  3589. })
  3590. } else {
  3591. c.ServeSuccessJSON(map[string]interface{}{
  3592. "failed_code": -10,
  3593. "msg": res.ErrMsg,
  3594. })
  3595. }
  3596. }
  3597. }
  3598. }
  3599. func (c *HisApiController) UnCheckCode() {
  3600. ids_str := c.GetString("ids")
  3601. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3602. admin_user_id, _ := c.GetInt64("admin_user_id")
  3603. ids_arr := strings.Split(ids_str, ",")
  3604. var queryResult []QueryResult
  3605. ids := make([]int64, 0)
  3606. for _, item := range ids_arr {
  3607. id, _ := strconv.ParseInt(item, 10, 64)
  3608. ids = append(ids, id)
  3609. }
  3610. if record_type == 1 {
  3611. drugs, _ := service.GetBatchDrugList(ids)
  3612. for _, item := range drugs {
  3613. result := QueryResult{
  3614. ID: item.ID,
  3615. Name: item.DrugName,
  3616. Code: item.MedicalInsuranceNumber,
  3617. List_type_code: "101",
  3618. }
  3619. queryResult = append(queryResult, result)
  3620. }
  3621. } else if record_type == 2 {
  3622. goods, _ := service.GetBatchGoodInformationList(ids)
  3623. for _, item := range goods {
  3624. result := QueryResult{
  3625. ID: item.ID,
  3626. Name: item.GoodName,
  3627. Code: item.MedicalInsuranceNumber,
  3628. List_type_code: "301",
  3629. }
  3630. queryResult = append(queryResult, result)
  3631. }
  3632. } else if record_type == 3 {
  3633. projects, _ := service.GetBathchMyPorjecgList(ids)
  3634. for _, item := range projects {
  3635. result := QueryResult{
  3636. ID: item.ID,
  3637. Name: item.ProjectName,
  3638. Code: item.MedicalCode,
  3639. List_type_code: "201",
  3640. }
  3641. queryResult = append(queryResult, result)
  3642. }
  3643. }
  3644. adminUser := c.GetAdminUserInfo()
  3645. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3646. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3647. var user_name string
  3648. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3649. if role.ID == 0 {
  3650. user_name = "xxx"
  3651. } else {
  3652. user_name = role.UserName
  3653. }
  3654. baseParams := &models.BaseParams{
  3655. SecretKey: miConfig.SecretKey,
  3656. FixmedinsCode: miConfig.Code,
  3657. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3658. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3659. OrgName: miConfig.OrgName,
  3660. Doctor: user_name,
  3661. }
  3662. if config.IsOpen == 1 {
  3663. for _, item := range queryResult {
  3664. var result string
  3665. if record_type == 1 {
  3666. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3667. } else if record_type == 2 {
  3668. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3669. } else if record_type == 3 {
  3670. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  3671. }
  3672. var dat2 map[string]interface{}
  3673. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  3674. fmt.Println(dat2)
  3675. } else {
  3676. fmt.Println(err)
  3677. }
  3678. userJSONBytes, _ := json.Marshal(dat2)
  3679. var res ResultSix
  3680. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3681. utils.ErrorLog("解析失败:%v", err)
  3682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3683. return
  3684. }
  3685. if res.Infcode == 0 {
  3686. if record_type == 1 {
  3687. service.UpdateDrugByIdDetail(item.ID)
  3688. } else if record_type == 2 {
  3689. service.UpdateGoodInfoById(item.ID)
  3690. } else if record_type == 3 {
  3691. service.UpdateMyProjectById(item.ID)
  3692. }
  3693. c.ServeSuccessJSON(map[string]interface{}{
  3694. "failed_code": 0,
  3695. "msg": "撤销目录对照成功",
  3696. })
  3697. } else {
  3698. c.ServeSuccessJSON(map[string]interface{}{
  3699. "failed_code": -10,
  3700. "msg": res.ErrMsg,
  3701. })
  3702. }
  3703. }
  3704. }
  3705. }
  3706. func (c *HisApiController) GetPatientInfo() {
  3707. id_card_no := c.GetString("id_card_no")
  3708. admin_user_id, _ := c.GetInt64("admin_user_id")
  3709. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3710. if patient.ID == 0 {
  3711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3712. return
  3713. }
  3714. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3715. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3716. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  3717. if config.IsOpen == 1 {
  3718. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  3719. var dat map[string]interface{}
  3720. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3721. fmt.Println(dat)
  3722. } else {
  3723. fmt.Println(err)
  3724. }
  3725. userJSONBytes, _ := json.Marshal(dat)
  3726. var res ResultTwo
  3727. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3728. utils.ErrorLog("解析失败:%v", err)
  3729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3730. return
  3731. }
  3732. if res.Infcode == -1 {
  3733. c.ServeSuccessJSON(map[string]interface{}{
  3734. "failed_code": -10,
  3735. "msg": res.ErrMsg,
  3736. })
  3737. } else {
  3738. c.ServeSuccessJSON(map[string]interface{}{
  3739. "failed_code": 0,
  3740. "info": res,
  3741. })
  3742. }
  3743. }
  3744. }
  3745. func (c *HisApiController) PsnPutOnRecord() {
  3746. record_type, _ := c.GetInt64("type")
  3747. patient_id, _ := c.GetInt64("patient_id")
  3748. admin_user_id, _ := c.GetInt64("admin_user_id")
  3749. start_time := c.GetString("start_time")
  3750. end_time := c.GetString("end_time")
  3751. adminUser := c.GetAdminUserInfo()
  3752. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3753. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3754. var patients []*models.Patients
  3755. if record_type == 1 { //全部备案
  3756. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  3757. patients = append(patients, patient...)
  3758. } else { //单个备案
  3759. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3760. patients = append(patients, patient)
  3761. }
  3762. var user_name string
  3763. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3764. if role.ID == 0 {
  3765. user_name = "xxx"
  3766. } else {
  3767. user_name = role.UserName
  3768. }
  3769. if config.IsOpen == 1 {
  3770. for _, item := range patients {
  3771. 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
  3772. resp, requestErr := http.Get(api)
  3773. if requestErr != nil {
  3774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3775. return
  3776. }
  3777. defer resp.Body.Close()
  3778. body, ioErr := ioutil.ReadAll(resp.Body)
  3779. if ioErr != nil {
  3780. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3782. return
  3783. }
  3784. var respJSON map[string]interface{}
  3785. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3786. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3788. return
  3789. }
  3790. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3791. userJSONBytes, _ := json.Marshal(userJSON)
  3792. var res ResultTwo
  3793. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3794. utils.ErrorLog("解析失败:%v", err)
  3795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3796. return
  3797. }
  3798. if res.Infcode == 0 {
  3799. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  3800. var dat map[string]interface{}
  3801. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3802. fmt.Println(dat)
  3803. } else {
  3804. fmt.Println(err)
  3805. }
  3806. userJSONBytes, _ := json.Marshal(dat)
  3807. var res2 ResultThirteen
  3808. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3809. utils.ErrorLog("解析失败:%v", err)
  3810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3811. return
  3812. }
  3813. if res2.Infcode == 0 {
  3814. psnResult := &models.GdybPsnRecord{
  3815. UserOrgId: adminUser.CurrentOrgId,
  3816. PatientId: item.ID,
  3817. PsnNo: res.Output.Baseinfo.PsnNo,
  3818. Ctime: time.Now().Unix(),
  3819. Mtime: time.Now().Unix(),
  3820. Status: 1,
  3821. IsCancel: 1,
  3822. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3823. }
  3824. service.CreatePsnRecord(psnResult)
  3825. } else {
  3826. c.ServeSuccessJSON(map[string]interface{}{
  3827. "failed_code": -10,
  3828. "msg": res2.ErrMsg,
  3829. })
  3830. return
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. func (c *HisApiController) PsnUnPutOnRecord() {
  3837. id, _ := c.GetInt64("id")
  3838. //record_type, _ := c.GetInt64("type")
  3839. admin_user_id, _ := c.GetInt64("admin_user_id")
  3840. adminUser := c.GetAdminUserInfo()
  3841. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3842. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3843. var user_name string
  3844. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3845. if role.ID == 0 {
  3846. user_name = "xxx"
  3847. } else {
  3848. user_name = role.UserName
  3849. }
  3850. psn_record, _ := service.GetPsnRecordById(id)
  3851. if psn_record.ID == 0 {
  3852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3853. return
  3854. }
  3855. if config.IsOpen == 1 {
  3856. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3857. var dat map[string]interface{}
  3858. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3859. fmt.Println(dat)
  3860. } else {
  3861. fmt.Println(err)
  3862. }
  3863. userJSONBytes, _ := json.Marshal(dat)
  3864. var res ResultFourteen
  3865. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3866. utils.ErrorLog("解析失败:%v", err)
  3867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3868. return
  3869. }
  3870. if res.Infcode == 0 {
  3871. psn_record.IsCancel = 2
  3872. service.CreatePsnRecord(&psn_record)
  3873. } else {
  3874. c.ServeSuccessJSON(map[string]interface{}{
  3875. "failed_code": -10,
  3876. "msg": res.ErrMsg,
  3877. })
  3878. return
  3879. }
  3880. }
  3881. }
  3882. func (c *HisApiController) PsnPutNCDSOnRecord() {
  3883. patient_id, _ := c.GetInt64("patient_id")
  3884. insutype := c.GetString("insutype")
  3885. psn_no := c.GetString("psn_no")
  3886. doctor_id, _ := c.GetInt64("doctor_id")
  3887. sick_id, _ := c.GetInt64("sick_id")
  3888. department_id, _ := c.GetInt64("department_id")
  3889. adminUser := c.GetAdminUserInfo()
  3890. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  3891. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3892. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3893. sick, _ := service.FindSickById(sick_id)
  3894. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  3895. if config.IsOpen == 1 {
  3896. 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)
  3897. var dat map[string]interface{}
  3898. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3899. fmt.Println(dat)
  3900. } else {
  3901. fmt.Println(err)
  3902. }
  3903. userJSONBytes, _ := json.Marshal(dat)
  3904. var res2 ResultThirteen
  3905. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3906. utils.ErrorLog("解析失败:%v", err)
  3907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3908. return
  3909. }
  3910. if res2.Infcode == 0 {
  3911. psnResult := &models.GdybPsnNcdsRecord{
  3912. UserOrgId: adminUser.CurrentOrgId,
  3913. PatientId: patient.ID,
  3914. PsnNo: psn_no,
  3915. DoctorId: doctor.AdminUserId,
  3916. DepartmentId: department_id,
  3917. SickType: sick_id,
  3918. Insutype: insutype,
  3919. Ctime: time.Now().Unix(),
  3920. Mtime: time.Now().Unix(),
  3921. Status: 1,
  3922. IsCancel: 1,
  3923. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  3924. }
  3925. service.CreatePsnNCDSRecord(psnResult)
  3926. c.ServeSuccessJSON(map[string]interface{}{
  3927. "failed_code": 0,
  3928. "msg": "备案成功",
  3929. "result": psnResult,
  3930. })
  3931. } else {
  3932. c.ServeSuccessJSON(map[string]interface{}{
  3933. "failed_code": -10,
  3934. "msg": res2.ErrMsg,
  3935. })
  3936. return
  3937. }
  3938. }
  3939. }
  3940. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  3941. id, _ := c.GetInt64("id")
  3942. admin_user_id, _ := c.GetInt64("admin_user_id")
  3943. adminUser := c.GetAdminUserInfo()
  3944. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3945. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3946. var user_name string
  3947. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3948. if role.ID == 0 {
  3949. user_name = "xxx"
  3950. } else {
  3951. user_name = role.UserName
  3952. }
  3953. psn_record, _ := service.GetPsnNCDSRecordById(id)
  3954. if psn_record.ID == 0 {
  3955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  3956. return
  3957. }
  3958. if config.IsOpen == 1 {
  3959. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  3960. var dat map[string]interface{}
  3961. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3962. fmt.Println(dat)
  3963. } else {
  3964. fmt.Println(err)
  3965. }
  3966. userJSONBytes, _ := json.Marshal(dat)
  3967. var res ResultFourteen
  3968. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3969. utils.ErrorLog("解析失败:%v", err)
  3970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3971. return
  3972. }
  3973. if res.Infcode == 0 {
  3974. psn_record.IsCancel = 2
  3975. service.CreatePsnNCDSRecord(&psn_record)
  3976. c.ServeSuccessJSON(map[string]interface{}{
  3977. "failed_code": 0,
  3978. "msg": "撤销备案成功",
  3979. })
  3980. } else {
  3981. c.ServeSuccessJSON(map[string]interface{}{
  3982. "failed_code": -10,
  3983. "msg": res.ErrMsg,
  3984. })
  3985. return
  3986. }
  3987. }
  3988. }
  3989. func (c *HisApiController) TestTest() {
  3990. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  3991. fmt.Println(patient.Iinfo)
  3992. }
  3993. type CustomData struct {
  3994. MsgId string
  3995. PsnNo string
  3996. Info string
  3997. }
  3998. func (c *HisApiController) ReversalData() {
  3999. var customData []*CustomData
  4000. custom := &CustomData{
  4001. MsgId: "H44022900158202103301714472004",
  4002. PsnNo: "44020000001101329945",
  4003. Info: "2207",
  4004. }
  4005. customData = append(customData, custom)
  4006. custom1 := &CustomData{
  4007. MsgId: "H4402290015820210330172057803",
  4008. PsnNo: "44020000001101161813",
  4009. Info: "2207",
  4010. }
  4011. customData = append(customData, custom1)
  4012. custom2 := &CustomData{
  4013. MsgId: "H44022900158202103301705198813",
  4014. PsnNo: "44190000133097375417",
  4015. Info: "2207",
  4016. }
  4017. customData = append(customData, custom2)
  4018. custom3 := &CustomData{
  4019. MsgId: "H44022900158202103301715524756",
  4020. PsnNo: "44020000001100187221",
  4021. Info: "2207",
  4022. }
  4023. customData = append(customData, custom3)
  4024. custom4 := &CustomData{
  4025. MsgId: "H44022900158202103301730376224",
  4026. PsnNo: "44020000001101959155",
  4027. Info: "2207",
  4028. }
  4029. customData = append(customData, custom4)
  4030. custom5 := &CustomData{
  4031. MsgId: "H44022900158202103301748008725",
  4032. PsnNo: "44020000001104246641",
  4033. Info: "2207",
  4034. }
  4035. customData = append(customData, custom5)
  4036. custom6 := &CustomData{
  4037. MsgId: "H44022900158202103301718096755",
  4038. PsnNo: "44020000001102211860",
  4039. Info: "2207",
  4040. }
  4041. customData = append(customData, custom6)
  4042. custom7 := &CustomData{
  4043. MsgId: "H44022900158202103301736551640",
  4044. PsnNo: "44020000001102687718",
  4045. Info: "2207",
  4046. }
  4047. customData = append(customData, custom7)
  4048. custom8 := &CustomData{
  4049. MsgId: "H44022900158202103301743097676",
  4050. PsnNo: "44020000001102127785",
  4051. Info: "2207",
  4052. }
  4053. customData = append(customData, custom8)
  4054. custom9 := &CustomData{
  4055. MsgId: "H44022900158202103301712304203",
  4056. PsnNo: "44020000001101518097",
  4057. Info: "2207",
  4058. }
  4059. customData = append(customData, custom9)
  4060. custom10 := &CustomData{
  4061. MsgId: "H44022900158202103301738448785",
  4062. PsnNo: "44020000001100500813",
  4063. Info: "2207",
  4064. }
  4065. customData = append(customData, custom10)
  4066. custom11 := &CustomData{
  4067. MsgId: "H44022900158202103301732455843",
  4068. PsnNo: "44020000001102690557",
  4069. Info: "2207",
  4070. }
  4071. customData = append(customData, custom11)
  4072. custom12 := &CustomData{
  4073. MsgId: "H44022900158202103301745421708",
  4074. PsnNo: "44020000001102211928",
  4075. Info: "2207",
  4076. }
  4077. customData = append(customData, custom12)
  4078. custom1212 := &CustomData{
  4079. MsgId: "H440229001582021033017351627",
  4080. PsnNo: "44020000001102481733",
  4081. Info: "2207",
  4082. }
  4083. customData = append(customData, custom1212)
  4084. custom13 := &CustomData{
  4085. MsgId: "H44022900158202103301740327951",
  4086. PsnNo: "44020000001103174866",
  4087. Info: "2207",
  4088. }
  4089. customData = append(customData, custom13)
  4090. custom14 := &CustomData{
  4091. MsgId: "H4402290015820210330174922668",
  4092. PsnNo: "44020000001102927272",
  4093. Info: "2207",
  4094. }
  4095. customData = append(customData, custom14)
  4096. custom15 := &CustomData{
  4097. MsgId: "H44022900158202103301752362273",
  4098. PsnNo: "44020000001102942890",
  4099. Info: "2207",
  4100. }
  4101. customData = append(customData, custom15)
  4102. custom16 := &CustomData{
  4103. MsgId: "H44022900158202103301751082917",
  4104. PsnNo: "44020000001101662162",
  4105. Info: "2207",
  4106. }
  4107. customData = append(customData, custom16)
  4108. custom17 := &CustomData{
  4109. MsgId: "H44022900158202103301754147728",
  4110. PsnNo: "44020000000229014511",
  4111. Info: "2207",
  4112. }
  4113. customData = append(customData, custom17)
  4114. adminUser := c.GetAdminUserInfo()
  4115. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4116. for _, item := range customData {
  4117. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4118. fmt.Println(result)
  4119. }
  4120. }
  4121. func (c *HisApiController) ReversalOtherData() {
  4122. var customData []*CustomData
  4123. custom := &CustomData{
  4124. MsgId: "H44022900158202103301714472004",
  4125. PsnNo: "44020000001101329945",
  4126. Info: "2208",
  4127. }
  4128. customData = append(customData, custom)
  4129. custom1 := &CustomData{
  4130. MsgId: "H4402290015820210330172057803",
  4131. PsnNo: "44020000001101161813",
  4132. Info: "2208",
  4133. }
  4134. customData = append(customData, custom1)
  4135. custom2 := &CustomData{
  4136. MsgId: "H44022900158202103301705198813",
  4137. PsnNo: "44190000133097375417",
  4138. Info: "2208",
  4139. }
  4140. customData = append(customData, custom2)
  4141. custom3 := &CustomData{
  4142. MsgId: "H44022900158202103301715524756",
  4143. PsnNo: "44020000001100187221",
  4144. Info: "2208",
  4145. }
  4146. customData = append(customData, custom3)
  4147. custom4 := &CustomData{
  4148. MsgId: "H44022900158202103301730376224",
  4149. PsnNo: "44020000001101959155",
  4150. Info: "2208",
  4151. }
  4152. customData = append(customData, custom4)
  4153. custom5 := &CustomData{
  4154. MsgId: "H44022900158202103301748008725",
  4155. PsnNo: "44020000001104246641",
  4156. Info: "2208",
  4157. }
  4158. customData = append(customData, custom5)
  4159. custom6 := &CustomData{
  4160. MsgId: "H44022900158202103301718096755",
  4161. PsnNo: "44020000001102211860",
  4162. Info: "2208",
  4163. }
  4164. customData = append(customData, custom6)
  4165. custom7 := &CustomData{
  4166. MsgId: "H44022900158202103301736551640",
  4167. PsnNo: "44020000001102687718",
  4168. Info: "2208",
  4169. }
  4170. customData = append(customData, custom7)
  4171. custom8 := &CustomData{
  4172. MsgId: "H44022900158202103301743097676",
  4173. PsnNo: "44020000001102127785",
  4174. Info: "2208",
  4175. }
  4176. customData = append(customData, custom8)
  4177. custom9 := &CustomData{
  4178. MsgId: "H44022900158202103301712304203",
  4179. PsnNo: "44020000001101518097",
  4180. Info: "2208",
  4181. }
  4182. customData = append(customData, custom9)
  4183. custom10 := &CustomData{
  4184. MsgId: "H44022900158202103301738448785",
  4185. PsnNo: "44020000001100500813",
  4186. Info: "2208",
  4187. }
  4188. customData = append(customData, custom10)
  4189. custom11 := &CustomData{
  4190. MsgId: "H44022900158202103301732455843",
  4191. PsnNo: "44020000001102690557",
  4192. Info: "2208",
  4193. }
  4194. customData = append(customData, custom11)
  4195. custom12 := &CustomData{
  4196. MsgId: "H44022900158202103301745421708",
  4197. PsnNo: "44020000001102211928",
  4198. Info: "2208",
  4199. }
  4200. customData = append(customData, custom12)
  4201. custom1212 := &CustomData{
  4202. MsgId: "H440229001582021033017351627",
  4203. PsnNo: "44020000001102481733",
  4204. Info: "2208",
  4205. }
  4206. customData = append(customData, custom1212)
  4207. custom13 := &CustomData{
  4208. MsgId: "H44022900158202103301740327951",
  4209. PsnNo: "44020000001103174866",
  4210. Info: "2208",
  4211. }
  4212. customData = append(customData, custom13)
  4213. custom14 := &CustomData{
  4214. MsgId: "H4402290015820210330174922668",
  4215. PsnNo: "44020000001102927272",
  4216. Info: "2208",
  4217. }
  4218. customData = append(customData, custom14)
  4219. custom15 := &CustomData{
  4220. MsgId: "H44022900158202103301752362273",
  4221. PsnNo: "44020000001102942890",
  4222. Info: "2208",
  4223. }
  4224. customData = append(customData, custom15)
  4225. custom16 := &CustomData{
  4226. MsgId: "H44022900158202103301751082917",
  4227. PsnNo: "44020000001101662162",
  4228. Info: "2208",
  4229. }
  4230. customData = append(customData, custom16)
  4231. custom17 := &CustomData{
  4232. MsgId: "H44022900158202103301754147728",
  4233. PsnNo: "44020000000229014511",
  4234. Info: "2208",
  4235. }
  4236. customData = append(customData, custom17)
  4237. adminUser := c.GetAdminUserInfo()
  4238. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4239. for _, item := range customData {
  4240. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4241. fmt.Println(result)
  4242. }
  4243. }
  4244. func PathExists(path string) (bool, error) {
  4245. _, err := os.Stat(path)
  4246. if err == nil {
  4247. return true, nil
  4248. }
  4249. if os.IsNotExist(err) {
  4250. return false, nil
  4251. }
  4252. return false, err
  4253. }
  4254. //创建文件夹
  4255. func Mkdir(dir string) {
  4256. // 创建文件夹
  4257. exist, err := PathExists(dir)
  4258. if err != nil {
  4259. fmt.Println(err.Error())
  4260. } else {
  4261. if exist {
  4262. fmt.Println(dir + "文件夹已存在!")
  4263. } else {
  4264. // 文件夹名称,权限
  4265. err := os.Mkdir(dir, os.ModePerm)
  4266. if err != nil {
  4267. fmt.Println(dir+"文件夹创建失败:", err.Error())
  4268. } else {
  4269. fmt.Println(dir + "文件夹创建成功!")
  4270. }
  4271. }
  4272. }
  4273. }
  4274. //压缩文件
  4275. func Zip(srcFile string, destZip string) error {
  4276. zipfile, err := os.Create(destZip)
  4277. if err != nil {
  4278. return err
  4279. }
  4280. defer zipfile.Close()
  4281. archive := zip.NewWriter(zipfile)
  4282. defer archive.Close()
  4283. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  4284. if err != nil {
  4285. return err
  4286. }
  4287. header, err := zip.FileInfoHeader(info)
  4288. if err != nil {
  4289. return err
  4290. }
  4291. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  4292. // header.Name = path
  4293. if info.IsDir() {
  4294. header.Name += "/"
  4295. } else {
  4296. header.Method = zip.Deflate
  4297. }
  4298. writer, err := archive.CreateHeader(header)
  4299. if err != nil {
  4300. return err
  4301. }
  4302. if !info.IsDir() {
  4303. file, err := os.Open(path)
  4304. if err != nil {
  4305. return err
  4306. }
  4307. defer file.Close()
  4308. _, err = io.Copy(writer, file)
  4309. }
  4310. return err
  4311. })
  4312. return err
  4313. }
  4314. func ReadFile(filePath string) []byte {
  4315. f, err := os.Open(filePath)
  4316. if err != nil {
  4317. fmt.Println("read file fail", err)
  4318. return nil
  4319. }
  4320. defer f.Close()
  4321. fd, err := ioutil.ReadAll(f)
  4322. if err != nil {
  4323. fmt.Println("read to fd fail", err)
  4324. return nil
  4325. }
  4326. return fd
  4327. }
  4328. func RemoveRepeatedCode(arr []string) (newArr []string) {
  4329. newArr = make([]string, 0)
  4330. for i := 0; i < len(arr); i++ {
  4331. repeat := false
  4332. for j := i + 1; j < len(arr); j++ {
  4333. if arr[i] == arr[j] {
  4334. repeat = true
  4335. break
  4336. }
  4337. }
  4338. if !repeat {
  4339. newArr = append(newArr, arr[i])
  4340. }
  4341. }
  4342. return
  4343. }