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