his_api_controller.go 210KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120
  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/jinzhu/gorm"
  15. "github.com/shopspring/decimal"
  16. "io"
  17. "io/ioutil"
  18. "math/rand"
  19. "net/http"
  20. "os"
  21. "path/filepath"
  22. "strconv"
  23. "strings"
  24. "syscall"
  25. "time"
  26. "unsafe"
  27. )
  28. type HisApiController struct {
  29. controllers.BaseAuthAPIController
  30. }
  31. func HisManagerApiRegistRouters() {
  32. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  33. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  34. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  35. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  36. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  37. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  38. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  39. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  40. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  41. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  42. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  43. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  44. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  45. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  46. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  47. beego.Router("/api/readcard", &HisApiController{}, "get:ReadCard")
  48. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  49. beego.Router("/api/presettle/get", &HisApiController{}, "get:GetPreUploadInfo")
  50. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  51. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  52. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  53. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  54. //备案撤销相关接口
  55. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  56. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  57. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  58. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  59. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  60. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  61. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  62. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  63. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  64. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  65. beego.Router("/api/pwd/check", &HisApiController{}, "get:CheckCardPWD")
  66. beego.Router("/api/insutype/check", &HisApiController{}, "get:CheckInsutype")
  67. //beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  68. //beego.Router("/api/testinit", &HisApiController{}, "get:TestGetBasBaseInit")
  69. //beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  70. }
  71. func (c *HisApiController) CheckInsutype() {
  72. his_patient_id, _ := c.GetInt64("his_patient_id")
  73. admin_user_id, _ := c.GetInt64("admin_user_id")
  74. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  75. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  76. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  77. result := service.Gdyb90100(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  78. var dat map[string]interface{}
  79. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  80. fmt.Println(dat)
  81. } else {
  82. fmt.Println(err)
  83. }
  84. userJSONBytes, _ := json.Marshal(dat)
  85. var res Result90100
  86. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  87. utils.ErrorLog("解析失败:%v", err)
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  89. return
  90. }
  91. if res.Infcode != 0 {
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "failed_code": -10,
  94. "msg": res.ErrMsg,
  95. })
  96. return
  97. } else {
  98. fmt.Println(res)
  99. }
  100. }
  101. func (c *HisApiController) CheckCardPWD() {
  102. card_pwd := c.GetString("card_pwd")
  103. his_patient_id, _ := c.GetInt64("his_patient_id")
  104. admin_user_id, _ := c.GetInt64("admin_user_id")
  105. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  106. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  107. his, _ := service.GetNewHisPatientInfoFour(c.GetAdminUserInfo().CurrentOrgId, his_patient_id)
  108. result := service.Gdyb90991(his.PsnNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, card_pwd)
  109. var dat map[string]interface{}
  110. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  111. fmt.Println(dat)
  112. } else {
  113. fmt.Println(err)
  114. }
  115. userJSONBytes, _ := json.Marshal(dat)
  116. var res Result90991
  117. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  118. utils.ErrorLog("解析失败:%v", err)
  119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  120. return
  121. }
  122. if res.Infcode != 0 {
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "failed_code": -10,
  125. "msg": res.ErrMsg,
  126. })
  127. return
  128. } else {
  129. if res.Output.Result.CheckStat == "0" {
  130. var msg string
  131. switch res.Output.Result.CardStat {
  132. case "00":
  133. msg = "未激活"
  134. break
  135. case "10":
  136. msg = "激活"
  137. break
  138. case "20":
  139. msg = "窗口挂失"
  140. break
  141. case "21":
  142. msg = "电话挂失"
  143. break
  144. case "22":
  145. msg = "单位网上申报挂失"
  146. break
  147. case "23":
  148. msg = "保健办挂失"
  149. break
  150. case "24":
  151. msg = "个人网上挂失"
  152. break
  153. case "25":
  154. msg = "网上服务大厅挂失"
  155. break
  156. case "30":
  157. msg = "注销"
  158. break
  159. case "40":
  160. msg = "回收"
  161. break
  162. case "99":
  163. msg = "制卡中(无效卡)"
  164. break
  165. }
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "failed_code": -10,
  168. "msg": msg,
  169. })
  170. return
  171. } else {
  172. c.ServeSuccessJSON(map[string]interface{}{
  173. "msg": "校验成功",
  174. })
  175. return
  176. }
  177. }
  178. }
  179. func (c *HisApiController) ReadCard() {
  180. id_card_type, _ := c.GetInt64("id_card_type")
  181. admin_user_id, _ := c.GetInt64("admin_user_id")
  182. certificates, _ := c.GetInt64("certificates")
  183. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  184. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  185. if initFlag == 0 {
  186. c.TestGetBasBaseInit()
  187. }
  188. switch id_card_type {
  189. case 1:
  190. basStr := c.GetBasBaseInfo()
  191. if len(basStr) == 0 {
  192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  193. return
  194. }
  195. fmt.Println(basStr)
  196. bas := strings.Split(basStr, "|")
  197. basNumber := bas[1]
  198. fmt.Println(basNumber)
  199. card_sn := bas[3]
  200. fmt.Println(card_sn)
  201. result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  202. var dat map[string]interface{}
  203. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  204. fmt.Println(dat)
  205. } else {
  206. fmt.Println(err)
  207. }
  208. userJSONBytes, _ := json.Marshal(dat)
  209. var res ResultTwo
  210. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  211. utils.ErrorLog("解析失败:%v", err)
  212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  213. return
  214. }
  215. if res.Infcode == 0 {
  216. patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
  217. if err == gorm.ErrRecordNotFound {
  218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  219. return
  220. } else if err != nil {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  222. return
  223. } else {
  224. c.ServeSuccessJSON(map[string]interface{}{
  225. "patient": patient,
  226. "number": basNumber,
  227. })
  228. }
  229. } else {
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  231. return
  232. }
  233. break
  234. case 2:
  235. SFZStr := c.GetSFZBaseInfo()
  236. id_card_str := strings.Split(SFZStr, "^")
  237. id_card_number := id_card_str[0]
  238. card_sn := ""
  239. result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  240. var dat map[string]interface{}
  241. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  242. fmt.Println(dat)
  243. } else {
  244. fmt.Println(err)
  245. }
  246. userJSONBytes, _ := json.Marshal(dat)
  247. var res ResultTwo
  248. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  249. utils.ErrorLog("解析失败:%v", err)
  250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. if res.Infcode == 0 {
  254. patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
  255. if err == gorm.ErrRecordNotFound {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  257. return
  258. } else if err != nil {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  260. return
  261. } else {
  262. c.ServeSuccessJSON(map[string]interface{}{
  263. "patient": patient,
  264. "number": id_card_number,
  265. })
  266. }
  267. } else {
  268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  269. return
  270. }
  271. break
  272. case 3:
  273. break
  274. }
  275. }
  276. var initFlag int64 = 0
  277. func (c *HisApiController) TestGetBasBaseInit() {
  278. DllDef := syscall.MustLoadDLL("SSCard.dll")
  279. Iinit := DllDef.MustFindProc("Init")
  280. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  281. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr(miConfig.InsuplcAdmdvs))
  282. if ret != 0 {
  283. fmt.Println("SSCard的报错原因:", err)
  284. fmt.Println("SSCard的运算结果为:", ret)
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  286. return
  287. }
  288. result := int(ret)
  289. fmt.Println("SSCard的运算结果为1:", result)
  290. initFlag = 1
  291. return
  292. }
  293. func (c *HisApiController) GetSFZBaseInfo() string {
  294. DllDef := syscall.MustLoadDLL("SSCard.dll")
  295. readCard := DllDef.MustFindProc("ReadSFZ")
  296. if readCard == nil {
  297. fmt.Println("readcard is nil")
  298. readCard = DllDef.MustFindProc("ReadSFZ")
  299. }
  300. str := make([]byte, 256)
  301. str1 := make([]byte, 256)
  302. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  303. fmt.Println(r)
  304. return string(str)
  305. }
  306. func (c *HisApiController) GetBasBaseInfo() string {
  307. DllDef := syscall.MustLoadDLL("SSCard.dll")
  308. readCard := DllDef.MustFindProc("ReadCardBas")
  309. if readCard == nil {
  310. fmt.Println("readcard is nil")
  311. readCard = DllDef.MustFindProc("ReadCardBas")
  312. }
  313. str := make([]byte, 1024)
  314. str1 := make([]byte, 1024)
  315. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  316. fmt.Println(string(str1))
  317. fmt.Println(string(str))
  318. if ret2 != 0 {
  319. return ""
  320. }
  321. return string(str)
  322. }
  323. func prttostr(vcode uintptr) string {
  324. var vbyte []byte
  325. for i := 0; i < 10; i++ {
  326. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  327. if sbyte == 0 {
  328. break
  329. }
  330. vbyte = append(vbyte, sbyte)
  331. vcode += 1
  332. }
  333. return string(vbyte)
  334. }
  335. type CustomFundPay struct {
  336. FundPayType string `json:"fund_pay_type"`
  337. FundPayamt float64 `json:"fund_payamt"`
  338. }
  339. func (c *HisApiController) GetSettleList() {
  340. order_id, _ := c.GetInt64("order_id")
  341. admin_user_id, _ := c.GetInt64("admin_user_id")
  342. order, _ := service.GetHisOrderByIDTwo(order_id)
  343. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  344. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  345. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  346. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  347. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  348. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  349. if order.ID == 0 {
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  351. return
  352. }
  353. struct4101 := service.Struct4101{
  354. PsnNo: order.PsnNo,
  355. MdtrtId: order.MdtrtId,
  356. SetlId: order.SetlId,
  357. PsnName: order.PsnName,
  358. Gend: order.Gend,
  359. Brdy: his.Brdy,
  360. Age: his.Age,
  361. Naty: order.Naty,
  362. PatnCertType: "01",
  363. Certno: order.Certno,
  364. Prfs: "90",
  365. ConerName: roles[0].UserName,
  366. PatnRlts: "99",
  367. ConerAddr: miConfig.OrgName,
  368. ConerTel: admin.Mobile,
  369. HiType: order.Insutype,
  370. Insuplc: miConfig.InsuplcAdmdvs,
  371. MaindiagFlag: "1",
  372. BillCode: order.FaPiaoCode,
  373. BillNo: order.FaPiaoNumber,
  374. BizSn: order.Number,
  375. PsnSelfPay: order.PsnPartAmt,
  376. PsnOwnPay: order.PsnPartAmt,
  377. AcctPay: order.AcctPay,
  378. PsnCashpay: order.PsnCashPay,
  379. HiPaymtd: "1",
  380. Hsorg: miConfig.InsuplcAdmdvs,
  381. HsorgOpter: miConfig.InsuplcAdmdvs,
  382. MedinsFillPsn: curRoles.UserName,
  383. MedinsFillDept: depart.Name,
  384. IptMedType: "2",
  385. }
  386. if order.SettleType == 1 {
  387. t := time.Unix(int64(order.SettleAccountsDate), 0)
  388. dateStr := t.Format("2006-01-02")
  389. struct4101.SetlBegnDate = dateStr
  390. struct4101.SetlEndDate = dateStr
  391. } else {
  392. t := time.Unix(int64(order.SettleStartTime), 0)
  393. t2 := time.Unix(int64(order.SettleEndTime), 0)
  394. dateStartStr := t.Format("2006-01-02")
  395. dateEndStr := t2.Format("2006-01-02")
  396. struct4101.SetlBegnDate = dateStartStr
  397. struct4101.SetlEndDate = dateEndStr
  398. }
  399. var rf []CustomFundPay
  400. json.Unmarshal([]byte(order.SetlDetail), &rf)
  401. var tempFunPays []service.CustomStruct
  402. for _, item := range rf {
  403. var tempFunPay service.CustomStruct
  404. tempFunPay.FundPayamt = item.FundPayamt
  405. tempFunPay.FundPayType = item.FundPayType
  406. tempFunPays = append(tempFunPays, tempFunPay)
  407. }
  408. struct4101.CustomStruct = tempFunPays
  409. var tempOpspdiseinfos []service.OpspdiseinfoStruct
  410. var tempOpspdiseinfo2 service.OpspdiseinfoStruct
  411. //sickConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  412. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  413. var config []*models.HisXtDiagnoseConfig
  414. for _, item := range diagnosis_ids {
  415. id, _ := strconv.ParseInt(item, 10, 64)
  416. diagnosisConfig, _ := service.FindDiagnoseById(id)
  417. config = append(config, diagnosisConfig)
  418. }
  419. for _, item := range config {
  420. var tempOpspdiseinfo service.OpspdiseinfoStruct
  421. tempOpspdiseinfo.DiagCode = item.CountryCode
  422. tempOpspdiseinfo.DiagName = item.CountryContentName
  423. tempOpspdiseinfo.MaindiagFlag = "1"
  424. tempOpspdiseinfo.OprnOprtCode = ""
  425. tempOpspdiseinfo.OprnOprtName = ""
  426. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo)
  427. }
  428. sickConfigTwo, _ := service.FindSickById(his.SickType)
  429. tempOpspdiseinfo2.DiagCode = sickConfigTwo.ContentCode
  430. tempOpspdiseinfo2.DiagName = sickConfigTwo.CountryContentName
  431. tempOpspdiseinfo2.MaindiagFlag = "2"
  432. tempOpspdiseinfo2.OprnOprtCode = ""
  433. tempOpspdiseinfo2.OprnOprtName = ""
  434. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo2)
  435. struct4101.OpspdiseinfoStruct = tempOpspdiseinfos
  436. var iteminfo service.IteminfoStruct
  437. var bedCostTotal float64 = 0 //床位总费
  438. var bedCostSelfTotal float64 = 0 //床位自费
  439. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  440. var operationCostTotal float64 = 0 //手术费
  441. var operationCostSelfTotal float64 = 0 //手术费
  442. var operationCostPartSelfTotal float64 = 0 //手术费
  443. var otherCostTotal float64 = 0 //其他费用
  444. var otherCostSelfTotal float64 = 0 //其他费用
  445. var otherCostPartSelfTotal float64 = 0 //其他费用
  446. var materialCostTotal float64 = 0 //材料费
  447. var materialCostSelfTotal float64 = 0 //材料费
  448. var materialCostPartSelfTotal float64 = 0 //材料费
  449. var westernMedicineCostTotal float64 = 0 //西药费
  450. var westernMedicineCostSelfTotal float64 = 0 //西药费
  451. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  452. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  453. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  454. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  455. var checkCostTotal float64 = 0 //检查费
  456. var checkCostSelfTotal float64 = 0 //检查费
  457. var checkCostPartSelfTotal float64 = 0 //检查费
  458. var laboratoryCostTotal float64 = 0 //化验费
  459. var laboratoryCostSelfTotal float64 = 0 //化验费
  460. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  461. var treatCostTotal float64 = 0 //治疗费用
  462. var treatCostSelfTotal float64 = 0 //治疗费用
  463. var treatCostPartSelfTotal float64 = 0 //治疗费用
  464. decimal.DivisionPrecision = 2
  465. var bed_fulamt_ownpay_amt float64 = 0
  466. var operation_fulamt_ownpay_amt float64 = 0
  467. var other_fulamt_ownpay_amt float64 = 0
  468. var westernMedicine_fulamt_ownpay_amt float64 = 0
  469. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  470. var check_fulamt_ownpay_amt float64 = 0
  471. var material_fulamt_ownpay_amt float64 = 0
  472. var laboratory_fulamt_ownpay_amt float64 = 0
  473. var treat_fulamt_ownpay_amt float64 = 0
  474. var bed_claa_sunmfee float64 = 0
  475. var bed_clab_amt float64 = 0
  476. var bed_other_amt float64 = 0
  477. var operation_claa_sunmfee float64 = 0
  478. var operation_clab_amt float64 = 0
  479. var operation_other_amt float64 = 0
  480. var other_claa_sunmfee float64 = 0
  481. var other_clab_amt float64 = 0
  482. var other_other_amt float64 = 0
  483. var westernMedicine_claa_sunmfee float64 = 0
  484. var westernMedicine_clab_amt float64 = 0
  485. var westernMedicine_other_amt float64 = 0
  486. var chineseTraditional_claa_sunmfee float64 = 0
  487. var chineseTraditional_clab_amt float64 = 0
  488. var chineseTraditional_other_amt float64 = 0
  489. var check_claa_sunmfee float64 = 0
  490. var check_clab_amt float64 = 0
  491. var check_other_amt float64 = 0
  492. var material_claa_sunmfee float64 = 0
  493. var material_clab_amt float64 = 0
  494. var material_other_amt float64 = 0
  495. var laboratory_claa_sunmfee float64 = 0
  496. var laboratory_clab_amt float64 = 0
  497. var laboratory_other_amt float64 = 0
  498. var treat_claa_sunmfee float64 = 0
  499. var treat_clab_amt float64 = 0
  500. var treat_other_amt float64 = 0
  501. for _, item := range order.HisOrderInfo {
  502. if item.MedChrgitmType == "01" { //床位费
  503. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. if item.ChrgitmLv == "1" {
  508. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  509. }
  510. if item.ChrgitmLv == "2" {
  511. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  512. }
  513. if item.ChrgitmLv == "3" {
  514. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  515. }
  516. }
  517. if item.MedChrgitmType == "03" { //检查费
  518. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. if item.ChrgitmLv == "1" {
  523. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  524. }
  525. if item.ChrgitmLv == "2" {
  526. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  527. }
  528. if item.ChrgitmLv == "3" {
  529. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  530. }
  531. }
  532. if item.MedChrgitmType == "04" { //化验费
  533. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  534. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  535. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  536. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  537. if item.ChrgitmLv == "1" {
  538. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  539. }
  540. if item.ChrgitmLv == "2" {
  541. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. }
  543. if item.ChrgitmLv == "3" {
  544. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  545. }
  546. }
  547. if item.MedChrgitmType == "05" { //治疗费
  548. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  549. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  550. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  551. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  552. if item.ChrgitmLv == "1" {
  553. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. }
  555. if item.ChrgitmLv == "2" {
  556. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  557. }
  558. if item.ChrgitmLv == "3" {
  559. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  560. }
  561. }
  562. if item.MedChrgitmType == "06" { //手术费
  563. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  564. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  565. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  566. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  567. if item.ChrgitmLv == "1" {
  568. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  569. }
  570. if item.ChrgitmLv == "2" {
  571. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  572. }
  573. if item.ChrgitmLv == "3" {
  574. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  575. }
  576. }
  577. if item.MedChrgitmType == "08" { //材料费
  578. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  579. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  580. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  581. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  582. if item.ChrgitmLv == "1" {
  583. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  584. }
  585. if item.ChrgitmLv == "2" {
  586. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  587. }
  588. if item.ChrgitmLv == "3" {
  589. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  590. }
  591. }
  592. if item.MedChrgitmType == "09" { //西药费
  593. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  594. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  595. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  596. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  597. if item.ChrgitmLv == "1" {
  598. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  599. }
  600. if item.ChrgitmLv == "2" {
  601. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  602. }
  603. if item.ChrgitmLv == "3" {
  604. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  605. }
  606. }
  607. if item.MedChrgitmType == "11" { //中成费
  608. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  609. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  610. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  611. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  612. if item.ChrgitmLv == "1" {
  613. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  614. }
  615. if item.ChrgitmLv == "2" {
  616. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  617. }
  618. if item.ChrgitmLv == "3" {
  619. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  620. }
  621. }
  622. if item.MedChrgitmType == "14" { //其他费
  623. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  624. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  625. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  626. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  627. if item.ChrgitmLv == "1" {
  628. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. }
  630. if item.ChrgitmLv == "2" {
  631. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. }
  633. if item.ChrgitmLv == "3" {
  634. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  635. }
  636. }
  637. }
  638. var iteminfoStructs []service.IteminfoStruct
  639. if bedCostTotal != 0 {
  640. iteminfo.MedChrgitm = "01"
  641. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  642. iteminfo.Amt = bedCostTotal
  643. iteminfo.ClaaSumfee = bed_claa_sunmfee
  644. iteminfo.ClabAmt = bed_clab_amt
  645. iteminfo.OthAmt = bed_other_amt
  646. iteminfoStructs = append(iteminfoStructs, iteminfo)
  647. }
  648. if checkCostTotal != 0 {
  649. iteminfo.MedChrgitm = "03"
  650. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  651. iteminfo.Amt = checkCostTotal
  652. iteminfo.ClaaSumfee = check_claa_sunmfee
  653. iteminfo.ClabAmt = check_clab_amt
  654. iteminfo.OthAmt = check_other_amt
  655. iteminfoStructs = append(iteminfoStructs, iteminfo)
  656. }
  657. if laboratoryCostTotal != 0 {
  658. iteminfo.MedChrgitm = "04"
  659. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  660. iteminfo.Amt = laboratoryCostTotal
  661. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  662. iteminfo.ClabAmt = laboratory_clab_amt
  663. iteminfo.OthAmt = laboratory_other_amt
  664. iteminfoStructs = append(iteminfoStructs, iteminfo)
  665. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  666. }
  667. if treatCostTotal != 0 {
  668. iteminfo.MedChrgitm = "05"
  669. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  670. iteminfo.Amt = treatCostTotal
  671. iteminfo.ClaaSumfee = treat_claa_sunmfee
  672. iteminfo.ClabAmt = treat_clab_amt
  673. iteminfo.OthAmt = treat_other_amt
  674. iteminfoStructs = append(iteminfoStructs, iteminfo)
  675. // (struct4101.IteminfoStruct, iteminfo)
  676. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  677. }
  678. if operationCostTotal != 0 {
  679. iteminfo.MedChrgitm = "06"
  680. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  681. iteminfo.Amt = operationCostTotal
  682. iteminfo.ClaaSumfee = operation_claa_sunmfee
  683. iteminfo.ClabAmt = operation_clab_amt
  684. iteminfo.OthAmt = operation_other_amt
  685. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  686. iteminfoStructs = append(iteminfoStructs, iteminfo)
  687. }
  688. if materialCostTotal != 0 {
  689. iteminfo.MedChrgitm = "08"
  690. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  691. iteminfo.Amt = materialCostTotal
  692. iteminfo.ClaaSumfee = material_claa_sunmfee
  693. iteminfo.ClabAmt = material_clab_amt
  694. iteminfo.OthAmt = material_other_amt
  695. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  696. iteminfoStructs = append(iteminfoStructs, iteminfo)
  697. }
  698. if westernMedicineCostTotal != 0 {
  699. iteminfo.MedChrgitm = "09"
  700. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  701. iteminfo.Amt = westernMedicineCostTotal
  702. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  703. iteminfo.ClabAmt = westernMedicine_clab_amt
  704. iteminfo.OthAmt = westernMedicine_other_amt
  705. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  706. iteminfoStructs = append(iteminfoStructs, iteminfo)
  707. }
  708. if chineseTraditionalMedicineCostTotal != 0 {
  709. iteminfo.MedChrgitm = "11"
  710. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  711. iteminfo.Amt = westernMedicineCostTotal
  712. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  713. iteminfo.ClabAmt = westernMedicine_clab_amt
  714. iteminfo.OthAmt = westernMedicine_other_amt
  715. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  716. iteminfoStructs = append(iteminfoStructs, iteminfo)
  717. }
  718. if otherCostTotal != 0 {
  719. iteminfo.MedChrgitm = "14"
  720. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  721. iteminfo.Amt = otherCostTotal
  722. iteminfo.ClaaSumfee = other_claa_sunmfee
  723. iteminfo.ClabAmt = other_clab_amt
  724. iteminfo.OthAmt = other_other_amt
  725. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  726. iteminfoStructs = append(iteminfoStructs, iteminfo)
  727. }
  728. struct4101.IteminfoStruct = iteminfoStructs
  729. struct4101.Ntly = "中国"
  730. struct4101.AdmCaty = "A03.06"
  731. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  732. fmt.Println(result)
  733. var dat map[string]interface{}
  734. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  735. fmt.Println(dat)
  736. } else {
  737. fmt.Println(err)
  738. }
  739. userJSONBytes, _ := json.Marshal(dat)
  740. var res ResultSeventeen
  741. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  742. utils.ErrorLog("解析失败:%v", err)
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  744. return
  745. }
  746. if res.Infcode != 0 {
  747. c.ServeSuccessJSON(map[string]interface{}{
  748. "failed_code": -10,
  749. "msg": res.ErrMsg,
  750. })
  751. return
  752. } else {
  753. hisFundSettleListResult := &models.HisFundSettleListResult{
  754. Number: res.Output.SetlListId,
  755. Status: 1,
  756. Ctime: time.Now().Unix(),
  757. Mtime: time.Now().Unix(),
  758. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  759. IsUpload: 1,
  760. OrderId: order_id,
  761. }
  762. service.CreateUploadRecord(hisFundSettleListResult)
  763. c.ServeSuccessJSON(map[string]interface{}{
  764. "msg": "上传成功",
  765. "result": hisFundSettleListResult,
  766. })
  767. return
  768. }
  769. }
  770. //func (c *HisApiController) TestPay() {
  771. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  772. // readCards := DllDef2.MustFindProc("BankTrans")
  773. // inputData := make(map[string]interface{})
  774. // inputData["transId"] = "05"
  775. // inputData["amount"] = "0.01"
  776. // inputData["traceNo"] = "20210227093601325405377"
  777. // inputData["cardNo"] = "F36084348"
  778. // inputData["id"] = "44022919620927046X"
  779. // //jsonStr := `
  780. // // {
  781. // // "transId": "05",
  782. // // "amount":"1.00",
  783. // // "traceNo":"20210227093601325405377",
  784. // // "cardNo":"F36084348",
  785. // // "id":"44022919620927046X"
  786. // //
  787. // // }
  788. // //`
  789. //
  790. // bytes_arr, _ := json.Marshal(inputData)
  791. // str3 := make([]byte, 256)
  792. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  793. // fmt.Println(":", string(str3))
  794. //
  795. // if err4 != nil {
  796. // fmt.Println("SSCard的运算结果为:", ret4)
  797. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  798. // return
  799. // }
  800. //
  801. //}
  802. //func (c *HisApiController) TestGetBasBaseInfo() {
  803. //
  804. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  805. // //fmt.Println(result)
  806. // //cs1 := C.CString("")
  807. // //cs2 := C.CString("")
  808. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  809. // //fmt.Println(cs1)
  810. // //fmt.Println(cs2)
  811. // //C.free(unsafe.Pointer(cs1))
  812. // //C.free(unsafe.Pointer(cs2))
  813. //
  814. // //
  815. //
  816. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  817. // Iinit := DllDef.MustFindProc("Init")
  818. // readCard := DllDef.MustFindProc("ReadCardBas")
  819. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  820. // if ret != 0 {
  821. // fmt.Println("SSCard的报错原因:", err)
  822. // fmt.Println("SSCard的运算结果为:", ret)
  823. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  824. // return
  825. // }
  826. //
  827. // result := int(ret)
  828. // fmt.Println("SSCard的运算结果为1:", result)
  829. //
  830. // //path := ""
  831. // //bytePath := []byte( "\x00")
  832. // //bytePath2 := []byte( "\x00")
  833. // //ssss
  834. //
  835. // str := make([]byte, 256)
  836. // str1 := make([]byte, 256)
  837. // s2 := []byte(string(str))
  838. // s3 := []byte(string(str1))
  839. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  840. // fmt.Println(" Add(4,5)的结果为:", ret2)
  841. // fmt.Println(" str:", s2)
  842. // fmt.Println(" str1:", s3)
  843. // if err2 != nil {
  844. // fmt.Println("SSCard的运算结果为:", ret2)
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  846. // return
  847. // }
  848. //
  849. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  850. //
  851. //}
  852. func (c *HisApiController) GetOrgInfo() {
  853. miConfig, _ := service.FindMedicalInsuranceInfo(4)
  854. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  855. }
  856. func (c *HisApiController) GetHisPatientInfo() {
  857. medical_insurance_card := c.GetString("medical_insurance_card")
  858. id_card_type, _ := c.GetInt64("id_card_type")
  859. id_card := c.GetString("id_card")
  860. adminInfo := c.GetAdminUserInfo()
  861. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  862. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  863. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  864. IdCardNo := ""
  865. if id_card_type == 1 {
  866. IdCardNo = medical_insurance_card
  867. } else if id_card_type == 2 {
  868. IdCardNo = id_card
  869. }
  870. if config.IsOpen == 1 {
  871. 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
  872. resp, requestErr := http.Get(api)
  873. if requestErr != nil {
  874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  875. return
  876. }
  877. defer resp.Body.Close()
  878. body, ioErr := ioutil.ReadAll(resp.Body)
  879. if ioErr != nil {
  880. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  882. return
  883. }
  884. var respJSON map[string]interface{}
  885. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  886. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  888. return
  889. }
  890. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  891. userJSONBytes, _ := json.Marshal(userJSON)
  892. var res ResultTwo
  893. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  894. utils.ErrorLog("解析失败:%v", err)
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  896. return
  897. }
  898. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  899. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  900. infoStr := string(Iinfos)
  901. idetinfoStr := string(Idetinfos)
  902. if res.Infcode == 0 {
  903. his := models.VMHisPatient{
  904. Status: 1,
  905. Ctime: time.Now().Unix(),
  906. Mtime: time.Now().Unix(),
  907. PsnNo: res.Output.Baseinfo.PsnNo,
  908. PsnCertType: res.Output.Baseinfo.PsnCertType,
  909. Certno: res.Output.Baseinfo.Certno,
  910. PsnName: res.Output.Baseinfo.PsnName,
  911. Gend: res.Output.Baseinfo.Gend,
  912. Naty: res.Output.Baseinfo.Naty,
  913. Brdy: res.Output.Baseinfo.Brdy,
  914. Age: res.Output.Baseinfo.Age,
  915. Iinfo: infoStr,
  916. Idetinfo: idetinfoStr,
  917. UserOrgId: adminInfo.CurrentOrgId,
  918. IsReturn: 1,
  919. IdCardType: id_card_type,
  920. }
  921. c.ServeSuccessJSON(map[string]interface{}{
  922. "info": his,
  923. })
  924. } else {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  926. return
  927. }
  928. }
  929. }
  930. //func GetBasBaseInfo() (jsonStr string, err error) {
  931. //
  932. // handle := syscall.NewLazyDLL("SSCard.dll")
  933. // add := handle.NewProc("ReadCardBas")
  934. // str := make([]byte, 1024)
  935. // str1 := make([]byte, 1024)
  936. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  937. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  938. //
  939. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  940. //
  941. // fmt.Println("> Add(4,5)的结果为:", ret)
  942. // handle.Release()
  943. //
  944. // return "", nil
  945. //
  946. //}
  947. //func GetQRBaseInfo() (jsonStr string, err error) {
  948. // handle := syscall.LoadDLL("SSCard.dll")
  949. // ReadCardBas := handle.FindProc("GetQRBase")
  950. //
  951. // str := make([]byte, 256)
  952. // str1 := make([]byte, 256)
  953. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  954. //
  955. // fmt.Println(string(str))
  956. // fmt.Println(r)
  957. // return string(str), nil
  958. //}
  959. //func CardInit() int {
  960. // DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  961. // add := DllTestDef.MustFindProc("Init")
  962. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  963. // if err != nil {
  964. // fmt.Println("SSCard的运算结果为:", ret)
  965. // }
  966. // result := int(ret)
  967. // return result
  968. //}
  969. //func CardInit() int {
  970. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  971. // if err != nil {
  972. // fmt.Println("SSCard的运算结果为:", ret)
  973. // }
  974. // fmt.Println(err)
  975. // result := int(ret)
  976. // return result
  977. //}
  978. func IntPtr(n int) uintptr {
  979. return uintptr(n)
  980. }
  981. func StrPtr(s string) uintptr {
  982. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  983. }
  984. type ResultTwo struct {
  985. ErrMsg string `json:"err_msg"`
  986. InfRefmsgid string `json:"inf_refmsgid"`
  987. Infcode int64 `json:"infcode"`
  988. Output struct {
  989. Baseinfo struct {
  990. Age float64 `json:"age"`
  991. Brdy string `json:"brdy"`
  992. Certno string `json:"certno"`
  993. Gend string `json:"gend"`
  994. Naty string `json:"naty"`
  995. PsnCertType string `json:"psn_cert_type"`
  996. PsnName string `json:"psn_name"`
  997. PsnNo string `json:"psn_no"`
  998. } `json:"baseinfo"`
  999. Idetinfo []interface{} `json:"idetinfo"`
  1000. Iinfo []struct {
  1001. Balc float64 `json:"balc"`
  1002. CvlservFlag string `json:"cvlserv_flag"`
  1003. EmpName string `json:"emp_name"`
  1004. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1005. Insutype string `json:"insutype"`
  1006. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1007. PausInsuDate string `json:"paus_insu_date"`
  1008. PsnInsuDate string `json:"psn_insu_date"`
  1009. PsnInsuStas string `json:"psn_insu_stas"`
  1010. PsnType string `json:"psn_type"`
  1011. } `json:"insuinfo"`
  1012. } `json:"output"`
  1013. RefmsgTime string `json:"refmsg_time"`
  1014. RespondTime string `json:"respond_time"`
  1015. Signtype interface{} `json:"signtype"`
  1016. WarnInfo interface{} `json:"warn_info"`
  1017. }
  1018. type ResultThree struct {
  1019. Cainfo interface{} `json:"cainfo"`
  1020. ErrMsg string `json:"err_msg"`
  1021. InfRefmsgid string `json:"inf_refmsgid"`
  1022. Infcode int64 `json:"infcode"`
  1023. Output struct {
  1024. Data struct {
  1025. IptOtpNo string `json:"ipt_otp_no"`
  1026. MdtrtID string `json:"mdtrt_id"`
  1027. PsnNo string `json:"psn_no"`
  1028. } `json:"data"`
  1029. } `json:"output"`
  1030. RefmsgTime string `json:"refmsg_time"`
  1031. RespondTime string `json:"respond_time"`
  1032. Signtype interface{} `json:"signtype"`
  1033. WarnMsg interface{} `json:"warn_msg"`
  1034. }
  1035. type ResultFour struct {
  1036. Cainfo string `json:"cainfo"`
  1037. ErrMsg string `json:"err_msg"`
  1038. InfRefmsgid string `json:"inf_refmsgid"`
  1039. Infcode int64 `json:"infcode"`
  1040. Output struct {
  1041. Result []struct {
  1042. BasMednFlag string `json:"bas_medn_flag"`
  1043. ChldMedcFlag string `json:"chld_medc_flag"`
  1044. ChrgitmLv string `json:"chrgitm_lv"`
  1045. Cnt float64 `json:"cnt"`
  1046. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1047. DrtReimFlag string `json:"drt_reim_flag"`
  1048. FeedetlSn string `json:"feedetl_sn"`
  1049. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1050. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1051. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1052. ListSpItemFlag string `json:"list_sp_item_flag"`
  1053. LmtUsedFlag string `json:"lmt_used_flag"`
  1054. MedChrgitmType string `json:"med_chrgitm_type"`
  1055. Memo string `json:"memo"`
  1056. OverlmtAmt float64 `json:"overlmt_amt"`
  1057. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1058. Pric float64 `json:"pric"`
  1059. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1060. SelfpayProp float64 `json:"selfpay_prop"`
  1061. } `json:"result"`
  1062. } `json:"output"`
  1063. RefmsgTime string `json:"refmsg_time"`
  1064. RespondTime string `json:"respond_time"`
  1065. Signtype string `json:"signtype"`
  1066. WarnMsg string `json:"warn_msg"`
  1067. }
  1068. type ResultFive struct {
  1069. Balc float64 `json:"balc"`
  1070. CvlservFlag string `json:"cvlserv_flag"`
  1071. EmpName string `json:"emp_name"`
  1072. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1073. Insutype string `json:"insutype"`
  1074. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1075. PausInsuDate string `json:"paus_insu_date"`
  1076. PsnInsuDate string `json:"psn_insu_date"`
  1077. PsnInsuStas string `json:"psn_insu_stas"`
  1078. PsnType string `json:"psn_type"`
  1079. }
  1080. type ResultSix struct {
  1081. Cainfo interface{} `json:"cainfo"`
  1082. ErrMsg string `json:"err_msg"`
  1083. InfRefmsgid string `json:"inf_refmsgid"`
  1084. Infcode int64 `json:"infcode"`
  1085. Output struct {
  1086. } `json:"output"`
  1087. RefmsgTime string `json:"refmsg_time"`
  1088. RespondTime string `json:"respond_time"`
  1089. Signtype interface{} `json:"signtype"`
  1090. WarnMsg interface{} `json:"warn_msg"`
  1091. }
  1092. type ResultSeven struct {
  1093. Cainfo string `json:"cainfo"`
  1094. ErrMsg string `json:"err_msg"`
  1095. InfRefmsgid string `json:"inf_refmsgid"`
  1096. Infcode int64 `json:"infcode"`
  1097. Output struct {
  1098. Setldetail []interface{} `json:"setldetail"`
  1099. Setlinfo struct {
  1100. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1101. AcctPay float64 `json:"acct_pay"`
  1102. ActPayDedc float64 `json:"act_pay_dedc"`
  1103. Age float64 `json:"age"`
  1104. Balc float64 `json:"balc"`
  1105. Brdy string `json:"brdy"`
  1106. Certno string `json:"certno"`
  1107. ClrOptins string `json:"clr_optins"`
  1108. ClrType string `json:"clr_type"`
  1109. ClrWay string `json:"clr_way"`
  1110. CvlservFlag string `json:"cvlserv_flag"`
  1111. CvlservPay float64 `json:"cvlserv_pay"`
  1112. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1113. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1114. Gend string `json:"gend"`
  1115. HifesPay float64 `json:"hifes_pay"`
  1116. HifmiPay float64 `json:"hifmi_pay"`
  1117. HifpPay float64 `json:"hifp_pay"`
  1118. HospPartAmt float64 `json:"hosp_part_amt"`
  1119. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1120. Insutype string `json:"insutype"`
  1121. MafPay float64 `json:"maf_pay"`
  1122. MdtrtCertType string `json:"mdtrt_cert_type"`
  1123. HifobPay float64 `json:"hifob_pay"`
  1124. MdtrtID string `json:"mdtrt_id"`
  1125. MedType string `json:"med_type"`
  1126. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1127. MedinsSetlID string `json:"medins_setl_id"`
  1128. Naty string `json:"naty"`
  1129. OthPay float64 `json:"oth_pay"`
  1130. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1131. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1132. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1133. PsnCashPay float64 `json:"psn_cash_pay"`
  1134. PsnCertType string `json:"psn_cert_type"`
  1135. PsnName string `json:"psn_name"`
  1136. PsnNo string `json:"psn_no"`
  1137. PsnPartAmt float64 `json:"psn_part_amt"`
  1138. PsnType string `json:"psn_type"`
  1139. SetlID string `json:"setl_id"`
  1140. SetlTime string `json:"setl_time"`
  1141. } `json:"setlinfo"`
  1142. } `json:"output"`
  1143. RefmsgTime string `json:"refmsg_time"`
  1144. RespondTime string `json:"respond_time"`
  1145. Signtype interface{} `json:"signtype"`
  1146. WarnMsg interface{} `json:"warn_msg"`
  1147. }
  1148. type ResultEight struct {
  1149. Cainfo string `json:"cainfo"`
  1150. ErrMsg string `json:"err_msg"`
  1151. InfRefmsgid string `json:"inf_refmsgid"`
  1152. Infcode int64 `json:"infcode"`
  1153. Output struct {
  1154. Stmtinfo struct {
  1155. SetlOptins string `json:"setl_optins"`
  1156. StmtRslt string `json:"stmt_rslt"`
  1157. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1158. } `json:"stmtinfo"`
  1159. } `json:"output"`
  1160. RefmsgTime string `json:"refmsg_time"`
  1161. RespondTime string `json:"respond_time"`
  1162. Signtype interface{} `json:"signtype"`
  1163. WarnMsg interface{} `json:"warn_msg"`
  1164. }
  1165. type ResultNine struct {
  1166. Cainfo string `json:"cainfo"`
  1167. ErrMsg string `json:"err_msg"`
  1168. InfRefmsgid string `json:"inf_refmsgid"`
  1169. Infcode int64 `json:"infcode"`
  1170. Output struct {
  1171. FileQuryNo string `json:"file_qury_no"`
  1172. } `json:"output"`
  1173. RefmsgTime string `json:"refmsg_time"`
  1174. RespondTime string `json:"respond_time"`
  1175. Signtype interface{} `json:"signtype"`
  1176. WarnMsg interface{} `json:"warn_msg"`
  1177. }
  1178. type ResultTen struct {
  1179. Cainfo string `json:"cainfo"`
  1180. ErrMsg string `json:"err_msg"`
  1181. InfRefmsgid string `json:"inf_refmsgid"`
  1182. Infcode int64 `json:"infcode"`
  1183. Output struct {
  1184. DldEndtime string `json:"dld_endtime"`
  1185. FileQuryNo string `json:"file_qury_no"`
  1186. Filename string `json:"filename"`
  1187. } `json:"output"`
  1188. RefmsgTime string `json:"refmsg_time"`
  1189. RespondTime string `json:"respond_time"`
  1190. Signtype interface{} `json:"signtype"`
  1191. WarnMsg interface{} `json:"warn_msg"`
  1192. }
  1193. //type Autogenerated struct {
  1194. // Output struct {
  1195. // Setlinfo struct {
  1196. // SetlTime string `json:"setl_time"`
  1197. // CvlservPay float64 `json:"cvlserv_pay"`
  1198. // Year string `json:"year"`
  1199. // MedType string `json:"med_type"`
  1200. // PsnPay float64 `json:"psn_pay"`
  1201. // OpterID string `json:"opter_id"`
  1202. // Begndate string `json:"begndate"`
  1203. // FlxempeFlag string `json:"flxempe_flag"`
  1204. // HifmiPay float64 `json:"hifmi_pay"`
  1205. // PsnNo string `json:"psn_no"`
  1206. // ActPayDedc float64 `json:"act_pay_dedc"`
  1207. // MedinsSetlID interface{} `json:"medins_setl_id"`
  1208. // AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1209. // ClrWay string `json:"clr_way"`
  1210. // OthPay float64 `json:"oth_pay"`
  1211. // Gend string `json:"gend"`
  1212. // MdtrtID string `json:"mdtrt_id"`
  1213. // AcctPay float64 `json:"acct_pay"`
  1214. // InscpScpAmt float64 `json:"inscp_scp_amt"`
  1215. // Insutype string `json:"insutype"`
  1216. // Invono interface{} `json:"invono"`
  1217. // Enddate string `json:"enddate"`
  1218. // CashPayamt float64 `json:"cash_payamt"`
  1219. // PsnType string `json:"psn_type"`
  1220. // FixmedinsName string `json:"fixmedins_name"`
  1221. // HifpPay float64 `json:"hifp_pay"`
  1222. // NewFlag interface{} `json:"new_flag"`
  1223. // OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1224. // PreselfpayAmt float64 `json:"preselfpay_amt"`
  1225. // PayLoc string `json:"pay_loc"`
  1226. // ClrType string `json:"clr_type"`
  1227. // RefdSetlFlag string `json:"refd_setl_flag"`
  1228. // CvlservFlag string `json:"cvlserv_flag"`
  1229. // EmpName string `json:"emp_name"`
  1230. // Brdy string `json:"brdy"`
  1231. // Naty string `json:"naty"`
  1232. // Certno string `json:"certno"`
  1233. // DiseCode string `json:"dise_code"`
  1234. // FixmedinsCode string `json:"fixmedins_code"`
  1235. // DedcHospLv string `json:"dedc_hosp_lv"`
  1236. // OpterName string `json:"opter_name"`
  1237. // Balc float64 `json:"balc"`
  1238. // FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1239. // PsnCertType string `json:"psn_cert_type"`
  1240. // HifobPay float64 `json:"hifob_pay"`
  1241. // MedfeeSumamt float64 `json:"medfee_sumamt"`
  1242. // HifesPay float64 `json:"hifes_pay"`
  1243. // FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1244. // OptTime string `json:"opt_time"`
  1245. // FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1246. // SetlID string `json:"setl_id"`
  1247. // MafPay float64 `json:"maf_pay"`
  1248. // PsnName string `json:"psn_name"`
  1249. // InsuOptins interface{} `json:"insu_optins"`
  1250. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1251. // ClrOptins string `json:"clr_optins"`
  1252. // PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1253. // DiseName string `json:"dise_name"`
  1254. // LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1255. // Age float64 `json:"age"`
  1256. // DtrtCertType string `json:"dtrt_cert_type"`
  1257. // HospLv string `json:"hosp_lv"`
  1258. // } `json:"setlinfo"`
  1259. // Setldetail []struct {
  1260. // FundPayType string `json:"fund_pay_type"`
  1261. // FundPayamt float64 `json:"fund_payamt"`
  1262. // SetlProcInfo interface{} `json:"setl_proc_info"`
  1263. // CrtPaybLmtAmt interface{} `json:"crt_payb_lmt_amt"`
  1264. // InscpScpAmt interface{} `json:"inscp_scp_amt"`
  1265. // FundPayTypeName interface{} `json:"fund_pay_type_name"`
  1266. // PrefFundPay interface{} `json:"pref_fund_pay"`
  1267. // } `json:"setldetail"`
  1268. // } `json:"output"`
  1269. // Infcode int `json:"infcode"`
  1270. // WarnMsg interface{} `json:"warn_msg"`
  1271. // Cainfo interface{} `json:"cainfo"`
  1272. // ErrMsg interface{} `json:"err_msg"`
  1273. // RefmsgTime string `json:"refmsg_time"`
  1274. // Signtype interface{} `json:"signtype"`
  1275. // RespondTime string `json:"respond_time"`
  1276. // InfRefmsgid string `json:"inf_refmsgid"`
  1277. //}
  1278. type ResultEleven struct {
  1279. Cainfo string `json:"cainfo"`
  1280. ErrMsg string `json:"err_msg"`
  1281. InfRefmsgid string `json:"inf_refmsgid"`
  1282. Infcode int64 `json:"infcode"`
  1283. Output struct {
  1284. Setlinfo struct {
  1285. SetlTime string `json:"setl_time"`
  1286. CvlservPay float64 `json:"cvlserv_pay"`
  1287. Year string `json:"year"`
  1288. MedType string `json:"med_type"`
  1289. PsnPay float64 `json:"psn_pay"`
  1290. OpterID string `json:"opter_id"`
  1291. Begndate string `json:"begndate"`
  1292. FlxempeFlag string `json:"flxempe_flag"`
  1293. HifmiPay float64 `json:"hifmi_pay"`
  1294. PsnNo string `json:"psn_no"`
  1295. ActPayDedc float64 `json:"act_pay_dedc"`
  1296. MedinsSetlID interface{} `json:"medins_setl_id"`
  1297. AcctMulaidPay interface{} `json:"acct_mulaid_pay"`
  1298. ClrWay string `json:"clr_way"`
  1299. OthPay float64 `json:"oth_pay"`
  1300. Gend string `json:"gend"`
  1301. MdtrtID string `json:"mdtrt_id"`
  1302. AcctPay float64 `json:"acct_pay"`
  1303. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1304. Insutype string `json:"insutype"`
  1305. Invono interface{} `json:"invono"`
  1306. Enddate string `json:"enddate"`
  1307. CashPayamt float64 `json:"cash_payamt"`
  1308. PsnType string `json:"psn_type"`
  1309. FixmedinsName string `json:"fixmedins_name"`
  1310. HifpPay float64 `json:"hifp_pay"`
  1311. NewFlag interface{} `json:"new_flag"`
  1312. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1314. PayLoc string `json:"pay_loc"`
  1315. ClrType string `json:"clr_type"`
  1316. RefdSetlFlag string `json:"refd_setl_flag"`
  1317. CvlservFlag string `json:"cvlserv_flag"`
  1318. EmpName string `json:"emp_name"`
  1319. Brdy string `json:"brdy"`
  1320. Naty string `json:"naty"`
  1321. Certno string `json:"certno"`
  1322. DiseCode string `json:"dise_code"`
  1323. FixmedinsCode string `json:"fixmedins_code"`
  1324. DedcHospLv string `json:"dedc_hosp_lv"`
  1325. OpterName string `json:"opter_name"`
  1326. Balc float64 `json:"balc"`
  1327. FixmedinsPoolarea string `json:"fixmedins_poolarea"`
  1328. PsnCertType string `json:"psn_cert_type"`
  1329. HifobPay float64 `json:"hifob_pay"`
  1330. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1331. HifesPay float64 `json:"hifes_pay"`
  1332. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1333. OptTime string `json:"opt_time"`
  1334. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1335. SetlID string `json:"setl_id"`
  1336. MafPay float64 `json:"maf_pay"`
  1337. PsnName string `json:"psn_name"`
  1338. InsuOptins interface{} `json:"insu_optins"`
  1339. PrefFundPay interface{} `json:"pref_fund_pay"`
  1340. ClrOptins string `json:"clr_optins"`
  1341. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1342. DiseName string `json:"dise_name"`
  1343. LmtpricHospLv string `json:"lmtpric_hosp_lv"`
  1344. Age float64 `json:"age"`
  1345. DtrtCertType string `json:"dtrt_cert_type"`
  1346. HospLv string `json:"hosp_lv"`
  1347. } `json:"setlinfo"`
  1348. } `json:"output"`
  1349. RefmsgTime string `json:"refmsg_time"`
  1350. RespondTime string `json:"respond_time"`
  1351. Signtype interface{} `json:"signtype"`
  1352. WarnMsg interface{} `json:"warn_msg"`
  1353. }
  1354. type ResultTwelve struct {
  1355. Cainfo string `json:"cainfo"`
  1356. ErrMsg string `json:"err_msg"`
  1357. InfRefmsgid string `json:"inf_refmsgid"`
  1358. Infcode int64 `json:"infcode"`
  1359. Output struct {
  1360. MdtrtId string `json:"mdtrt_id"`
  1361. ChrgBchno string `json:"chrg_bchno"`
  1362. PsnNo string `json:"psn_no"`
  1363. } `json:"output"`
  1364. RefmsgTime string `json:"refmsg_time"`
  1365. RespondTime string `json:"respond_time"`
  1366. Signtype interface{} `json:"signtype"`
  1367. WarnMsg interface{} `json:"warn_msg"`
  1368. }
  1369. type ResultThirteen struct {
  1370. ErrMsg string `json:"err_msg"`
  1371. InfRefmsgid string `json:"inf_refmsgid"`
  1372. Infcode int64 `json:"infcode"`
  1373. Output struct {
  1374. Result struct {
  1375. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1376. } `json:"result"`
  1377. } `json:"output"`
  1378. RefmsgTime string `json:"refmsg_time"`
  1379. RespondTime string `json:"respond_time"`
  1380. Signtype interface{} `json:"signtype"`
  1381. WarnInfo interface{} `json:"warn_info"`
  1382. }
  1383. type ResultFourteen struct {
  1384. ErrMsg string `json:"err_msg"`
  1385. InfRefmsgid string `json:"inf_refmsgid"`
  1386. Infcode int64 `json:"infcode"`
  1387. Output struct {
  1388. } `json:"output"`
  1389. RefmsgTime string `json:"refmsg_time"`
  1390. RespondTime string `json:"respond_time"`
  1391. Signtype interface{} `json:"signtype"`
  1392. WarnInfo interface{} `json:"warn_info"`
  1393. }
  1394. type ResultSixteen struct {
  1395. Cainfo string `json:"cainfo"`
  1396. ErrMsg string `json:"err_msg"`
  1397. InfRefmsgid string `json:"inf_refmsgid"`
  1398. Infcode int64 `json:"infcode"`
  1399. Output struct {
  1400. Setldetail []interface{} `json:"setldetail"`
  1401. Setlinfo struct {
  1402. MdtrtID string `json:"mdtrt_id"`
  1403. SetlID string `json:"setl_id"`
  1404. ClrOptins string `json:"clr_optins"`
  1405. SetlTime string `json:"setl_time"`
  1406. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1407. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1408. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1409. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1410. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1411. ActPayDedc float64 `json:"act_pay_dedc"`
  1412. HifpPay float64 `json:"hifp_pay"`
  1413. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1414. Lfpay float64 `json:"selfpay"`
  1415. CvlservPay float64 `json:"cvlserv_pay"`
  1416. HifesPay float64 `json:"hifes_pay"`
  1417. HifmiPay float64 `json:"hifmi_pay"`
  1418. HifobPay float64 `json:"hifob_pay"`
  1419. MafPay float64 `json:"maf_pay"`
  1420. OthPay float64 `json:"oth_pay"`
  1421. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1422. PsnPartAmt float64 `json:"psn_part_amt"`
  1423. AcctPay float64 `json:"acct_pay"`
  1424. Balc float64 `json:"balc"`
  1425. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1426. HospPartAmt float64 `json:"hosp_part_amt"`
  1427. MedinsSetlID string `json:"medins_setl_id"`
  1428. PdnCashPay string `json:"pdn_cash_pay"`
  1429. } `json:"setlinfo"`
  1430. } `json:"output"`
  1431. RefmsgTime string `json:"refmsg_time"`
  1432. RespondTime string `json:"respond_time"`
  1433. Signtype interface{} `json:"signtype"`
  1434. WarnMsg interface{} `json:"warn_msg"`
  1435. }
  1436. type ResultSeventeen struct {
  1437. ErrMsg string `json:"err_msg"`
  1438. InfRefmsgid string `json:"inf_refmsgid"`
  1439. Infcode int64 `json:"infcode"`
  1440. Output struct {
  1441. SetlListId string `json:"setl_list_id"`
  1442. } `json:"output"`
  1443. RefmsgTime string `json:"refmsg_time"`
  1444. RespondTime string `json:"respond_time"`
  1445. Signtype string `json:"signtype"`
  1446. WarnInfo string `json:"warn_info"`
  1447. }
  1448. type Result90991 struct {
  1449. ErrMsg string `json:"err_msg"`
  1450. InfRefmsgid string `json:"inf_refmsgid"`
  1451. Infcode int64 `json:"infcode"`
  1452. Output struct {
  1453. Result struct {
  1454. PsnNo string `json:"psn_no"`
  1455. CardStat string `json:"card_stat"`
  1456. Certno string `json:"certno"`
  1457. PsnName string `json:"psn_name"`
  1458. CheckStat string `json:"check_stat"`
  1459. } `json:"result"`
  1460. } `json:"output"`
  1461. RefmsgTime string `json:"refmsg_time"`
  1462. RespondTime string `json:"respond_time"`
  1463. Signtype interface{} `json:"signtype"`
  1464. WarnInfo interface{} `json:"warn_info"`
  1465. }
  1466. type Result90100 struct {
  1467. ErrMsg string `json:"err_msg"`
  1468. InfRefmsgid string `json:"inf_refmsgid"`
  1469. Infcode int64 `json:"infcode"`
  1470. Output struct {
  1471. PoolareaNo string `json:"poolarea_no"`
  1472. PoolareaNoName string `json:"poolarea_no_name"`
  1473. Insutype string `json:"insutype"`
  1474. InsutypeName string `json:"insutype_name"`
  1475. ClctType string `json:"clct_type"`
  1476. ClctTypeName string `json:"clct_type_name"`
  1477. ClctFlag string `json:"clct_flag"`
  1478. ClctFlagName string `json:"clct_flag_name"`
  1479. AccrymBegn string `json:"accrym_begn"`
  1480. AccrymEnd string `json:"accrym_end"`
  1481. ClctTime string `json:"clct_time"`
  1482. ClctstdCrtfRuleCodg string `json:"clctstd_crtf_rule_codg"`
  1483. } `json:"output"`
  1484. RefmsgTime string `json:"refmsg_time"`
  1485. RespondTime string `json:"respond_time"`
  1486. Signtype interface{} `json:"signtype"`
  1487. WarnInfo interface{} `json:"warn_info"`
  1488. }
  1489. type Custom struct {
  1490. DetItemFeeSumamt string
  1491. Cut string
  1492. FeedetlSn string
  1493. Price string
  1494. MedListCodg string
  1495. Type int64
  1496. AdviceId int64
  1497. ProjectId int64
  1498. ItemId int64
  1499. }
  1500. //获取个人信息----挂号-----上传就诊信息
  1501. func (c *HisApiController) GetRegisterInfo() {
  1502. id, _ := c.GetInt64("id")
  1503. record_time := c.GetString("record_time")
  1504. settlementValue, _ := c.GetInt64("settlement_value")
  1505. medical_insurance_card := c.GetString("medical_insurance_card")
  1506. name := c.GetString("name")
  1507. id_card_type, _ := c.GetInt64("id_card_type")
  1508. certificates, _ := c.GetInt64("certificates")
  1509. medical_care, _ := c.GetInt64("medical_care")
  1510. birthday := c.GetString("birthday")
  1511. //age, _ := c.GetInt64("age")
  1512. id_card := c.GetString("id_card")
  1513. register_type, _ := c.GetInt64("register")
  1514. doctor, _ := c.GetInt64("doctor")
  1515. department, _ := c.GetInt64("department")
  1516. gender, _ := c.GetInt64("sex")
  1517. //phone := c.GetString("phone")
  1518. registration_fee, _ := c.GetFloat("registration_fee")
  1519. medical_expenses, _ := c.GetFloat("medical_expenses")
  1520. social_type, _ := c.GetInt64("social_type")
  1521. admin_user_id, _ := c.GetInt64("admin_user_id")
  1522. timeLayout := "2006-01-02"
  1523. loc, _ := time.LoadLocation("Local")
  1524. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1525. birthUnix := birthdays.Unix()
  1526. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1527. if err != nil {
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1529. return
  1530. }
  1531. recordDateTime := theTime.Unix()
  1532. adminInfo := c.GetAdminUserInfo()
  1533. var patient service.Patients
  1534. if id == 0 {
  1535. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1536. } else {
  1537. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1538. }
  1539. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1540. if patientPrescription.ID == 0 {
  1541. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1542. }
  1543. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1544. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1545. //sickConfig, _ := service.FindSickById(sick_type)
  1546. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1547. if patient.ID == 0 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1549. return
  1550. }
  1551. if len(patient.IdCardNo) == 0 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1553. return
  1554. }
  1555. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1556. roles, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1557. //就诊结算未完成,不能进行二次挂号
  1558. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1559. if len(his) >= 1 {
  1560. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  1561. if len(his) >= 1 && order.ID == 0 {
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  1563. return
  1564. }
  1565. }
  1566. if config.IsOpen == 1 {
  1567. //service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  1568. result, requestLog := service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10))
  1569. saveLog(result, requestLog)
  1570. var res ResultTwo
  1571. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1572. utils.ErrorLog("解析失败:%v", err)
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1574. return
  1575. }
  1576. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1577. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1578. infoStr := string(Iinfos)
  1579. idetinfoStr := string(Idetinfos)
  1580. if res.Infcode == 0 {
  1581. his := models.VMHisPatient{
  1582. Name: name,
  1583. Gender: gender,
  1584. Birthday: birthUnix,
  1585. MedicalTreatmentType: medical_care,
  1586. IdType: certificates,
  1587. IdCardNo: id_card,
  1588. BalanceAccountsType: settlementValue,
  1589. SocialType: social_type,
  1590. MedicalInsuranceNumber: medical_insurance_card,
  1591. RegisterType: register_type,
  1592. RegisterCost: registration_fee,
  1593. TreatmentCost: medical_expenses,
  1594. Status: 1,
  1595. Ctime: time.Now().Unix(),
  1596. Mtime: time.Now().Unix(),
  1597. PsnNo: res.Output.Baseinfo.PsnNo,
  1598. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1599. Certno: res.Output.Baseinfo.Certno,
  1600. PsnName: res.Output.Baseinfo.PsnName,
  1601. Gend: res.Output.Baseinfo.Gend,
  1602. Naty: res.Output.Baseinfo.Naty,
  1603. Brdy: res.Output.Baseinfo.Brdy,
  1604. Age: res.Output.Baseinfo.Age,
  1605. Iinfo: infoStr,
  1606. Idetinfo: idetinfoStr,
  1607. PatientId: patient.ID,
  1608. RecordDate: theTime.Unix(),
  1609. UserOrgId: adminInfo.CurrentOrgId,
  1610. AdminUserId: admin_user_id,
  1611. IsReturn: 1,
  1612. IdCardType: id_card_type,
  1613. Doctor: doctor,
  1614. Departments: department,
  1615. }
  1616. timestamp := time.Now().Unix()
  1617. tempTime := time.Unix(timestamp, 0)
  1618. timeFormat := tempTime.Format("20060102150405")
  1619. chrgBchno := rand.Intn(100000) + 10000
  1620. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1621. //count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1622. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1623. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1624. IdCardNo := ""
  1625. if id_card_type == 1 {
  1626. // IdCardNo = medical_insurance_card
  1627. IdCardNo = patient.IdCardNo
  1628. } else {
  1629. IdCardNo = patient.IdCardNo
  1630. }
  1631. var insutypes []string
  1632. var insutype string
  1633. var is390 int = 0
  1634. var is310 int = 0
  1635. for _, item := range res.Output.Iinfo {
  1636. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1637. insutypes = append(insutypes, item.Insutype)
  1638. }
  1639. }
  1640. if len(insutypes) == 1 {
  1641. insutype = insutypes[0]
  1642. } else {
  1643. for _, i := range insutypes {
  1644. if i == "390" {
  1645. is390 = 1
  1646. }
  1647. if i == "310" {
  1648. is310 = 1
  1649. }
  1650. }
  1651. }
  1652. if is390 == 1 {
  1653. insutype = "390"
  1654. }
  1655. if is310 == 1 {
  1656. insutype = "310"
  1657. }
  1658. if len(insutypes) == 0 {
  1659. insutype = "310"
  1660. }
  1661. //insutype = "390"
  1662. result, requestLog := service.Gdyb2201(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type)
  1663. saveLog(result, requestLog)
  1664. var res ResultThree
  1665. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1666. utils.ErrorLog("解析失败:%v", err)
  1667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1668. return
  1669. }
  1670. if res.Infcode != 0 {
  1671. adminUser := c.GetAdminUserInfo()
  1672. errlog := &models.HisOrderError{
  1673. UserOrgId: adminUser.CurrentOrgId,
  1674. Ctime: time.Now().Unix(),
  1675. Mtime: time.Now().Unix(),
  1676. ErrMsg: res.ErrMsg,
  1677. Status: 1,
  1678. PatientId: id,
  1679. RecordTime: recordDateTime,
  1680. Stage: 2,
  1681. }
  1682. service.CreateErrMsgLog(errlog)
  1683. c.ServeSuccessJSON(map[string]interface{}{
  1684. "failed_code": -10,
  1685. "msg": res.ErrMsg,
  1686. })
  1687. return
  1688. }
  1689. his.Number = res.Output.Data.MdtrtID
  1690. his.PsnNo = res.Output.Data.PsnNo
  1691. his.IptOtpNo = res.Output.Data.IptOtpNo
  1692. his.IdCardNo = patient.IdCardNo
  1693. his.PhoneNumber = patient.Phone
  1694. his.UserOrgId = adminInfo.CurrentOrgId
  1695. his.Ctime = time.Now().Unix()
  1696. his.Mtime = time.Now().Unix()
  1697. his.Status = 1
  1698. service.UpdateHisPatientStatus(&his)
  1699. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1700. c.ServeSuccessJSON(map[string]interface{}{
  1701. "his_info": his,
  1702. })
  1703. } else {
  1704. adminUser := c.GetAdminUserInfo()
  1705. errlog := &models.HisOrderError{
  1706. UserOrgId: adminUser.CurrentOrgId,
  1707. Ctime: time.Now().Unix(),
  1708. Mtime: time.Now().Unix(),
  1709. ErrMsg: res.ErrMsg,
  1710. Status: 1,
  1711. PatientId: id,
  1712. RecordTime: recordDateTime,
  1713. Stage: 1,
  1714. }
  1715. service.CreateErrMsgLog(errlog)
  1716. c.ServeSuccessJSON(map[string]interface{}{
  1717. "failed_code": -10,
  1718. "msg": res.ErrMsg,
  1719. })
  1720. return
  1721. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1722. }
  1723. }
  1724. }
  1725. //上传明细----预结算----确认订单
  1726. func (c *HisApiController) GetUploadInfo() {
  1727. id, _ := c.GetInt64("id")
  1728. record_time := c.GetString("record_time")
  1729. his_patient_id, _ := c.GetInt64("his_patient_id")
  1730. order_id, _ := c.GetInt64("order_id")
  1731. pay_way, _ := c.GetInt64("pay_way")
  1732. pay_price, _ := c.GetFloat("pay_price")
  1733. pay_card_no := c.GetString("pay_card_no")
  1734. discount_price, _ := c.GetFloat("discount_price")
  1735. preferential_price, _ := c.GetFloat("preferential_price")
  1736. reality_price, _ := c.GetFloat("reality_price")
  1737. found_price, _ := c.GetFloat("found_price")
  1738. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1739. private_price, _ := c.GetFloat("private_price")
  1740. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1741. admin_user_id, _ := c.GetInt64("admin_user_id")
  1742. fapiao_code := c.GetString("fapiao_code")
  1743. fapiao_number := c.GetString("fapiao_number")
  1744. diagnosis_id := c.GetString("diagnosis")
  1745. sick_type, _ := c.GetInt64("sick_type")
  1746. reg_type, _ := c.GetInt64("p_type")
  1747. id_str := c.GetString("ids")
  1748. ids_arr := strings.Split(id_str, ",")
  1749. timeLayout := "2006-01-02"
  1750. loc, _ := time.LoadLocation("Local")
  1751. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1752. if err != nil {
  1753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1754. return
  1755. }
  1756. recordDateTime := theTime.Unix()
  1757. adminUser := c.GetAdminUserInfo()
  1758. var tempOrder models.HisOrder
  1759. tempOrder, _ = service.GetHisOrderByID(order_id)
  1760. var prescriptions []*models.HisPrescription
  1761. var start_time int64
  1762. var end_time int64
  1763. //if adminUser.CurrentOrgId == 10106{
  1764. // if len(fapiao_code) == 0{
  1765. // fapiao_code = "144072080589"
  1766. // }
  1767. // if len(fapiao_number) == 0{
  1768. // order, _ := service.GetLastHisOrder(adminUser.CurrentOrgId)
  1769. // if order.ID == 0{
  1770. // fapiao_number = "00001520"
  1771. // }else{
  1772. // //fapiao_code = "00001520"
  1773. // fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
  1774. // var zero string
  1775. // if fpNumber >= 1000{
  1776. // zero = "0000" + strconv.Itoa(fpNumber)
  1777. // }else if fpNumber >= 10000{
  1778. // zero = "000" + strconv.Itoa(fpNumber)
  1779. // } else if fpNumber >= 100000{
  1780. // zero = "00" + strconv.Itoa(fpNumber)
  1781. // } else if fpNumber >= 1000000{
  1782. // zero = "0" + strconv.Itoa(fpNumber)
  1783. // }else {
  1784. // zero = strconv.Itoa(fpNumber)
  1785. // }
  1786. // fapiao_number = zero
  1787. // }
  1788. // }
  1789. //}
  1790. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1791. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1792. var patientPrescription models.HisPrescriptionInfo
  1793. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  1794. if patientPrescription.ID == 0 {
  1795. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1796. }
  1797. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1798. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1799. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  1800. diagnosis_ids := strings.Split(diagnosis_id, ",")
  1801. var config []*models.HisXtDiagnoseConfig
  1802. for _, item := range diagnosis_ids {
  1803. id, _ := strconv.ParseInt(item, 10, 64)
  1804. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1805. config = append(config, diagnosisConfig)
  1806. }
  1807. sickConfig, _ := service.FindSickById(sick_type)
  1808. if tempOrder.ID == 0 {
  1809. tempOrder, _ = service.GetTodayHisOrder(adminUser.CurrentOrgId, id, recordDateTime, his.Number)
  1810. }
  1811. if tempOrder.ID == 0 {
  1812. var result string
  1813. var requestLog string
  1814. if miConfig.InsuplcAdmdvs == "440781" { //
  1815. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  1816. } else {
  1817. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  1818. }
  1819. saveLog(result, requestLog)
  1820. var respJSON2 map[string]interface{}
  1821. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  1822. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. return
  1825. }
  1826. userJSONBytes2, _ := json.Marshal(respJSON2)
  1827. var res2 ResultSix
  1828. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1829. utils.ErrorLog("解析失败:%v", err)
  1830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1831. return
  1832. }
  1833. if res2.Infcode != 0 {
  1834. adminUser := c.GetAdminUserInfo()
  1835. errlog := &models.HisOrderError{
  1836. UserOrgId: adminUser.CurrentOrgId,
  1837. Ctime: time.Now().Unix(),
  1838. Mtime: time.Now().Unix(),
  1839. ErrMsg: res2.ErrMsg,
  1840. Status: 1,
  1841. PatientId: id,
  1842. RecordTime: recordDateTime,
  1843. Stage: 3,
  1844. }
  1845. service.CreateErrMsgLog(errlog)
  1846. c.ServeSuccessJSON(map[string]interface{}{
  1847. "failed_code": -10,
  1848. "msg": res2.ErrMsg,
  1849. })
  1850. return
  1851. } else {
  1852. his.Diagnosis = diagnosis_id
  1853. his.SickType = sickConfig.ID
  1854. his.PType = fmt.Sprintf("%d", reg_type)
  1855. service.UpdateHisPatientThree(&his)
  1856. data := make(map[string]interface{})
  1857. if settle_accounts_type == 1 { //日结
  1858. if reg_type == 11 {
  1859. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  1860. } else {
  1861. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  1862. }
  1863. //prescriptions, _ = service.GetNewHisPrescriptionTwo(adminUser.CurrentOrgId, his_patient_id, recordDateTime, reg_type)
  1864. data["pre"] = prescriptions
  1865. } else { //月结
  1866. start_time_str := c.GetString("start_time")
  1867. end_time_str := c.GetString("end_time")
  1868. timeLayout := "2006-01-02"
  1869. loc, _ := time.LoadLocation("Local")
  1870. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1871. if err != nil {
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1873. return
  1874. }
  1875. recordStartTime := theStartTime.Unix()
  1876. start_time = recordStartTime
  1877. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1878. if err != nil {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1880. return
  1881. }
  1882. recordEndTime := theEndTime.Unix()
  1883. end_time = recordEndTime
  1884. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  1885. data["pre"] = prescriptions
  1886. }
  1887. if reg_type == 1111 || reg_type == 1112 {
  1888. reg_type = 11
  1889. }
  1890. timestamp := time.Now().Unix()
  1891. tempTime := time.Unix(timestamp, 0)
  1892. timeFormat := tempTime.Format("20060102150405")
  1893. chrgBchno := rand.Intn(100000) + 10000
  1894. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1895. strconv.FormatInt(his.PatientId, 10)
  1896. client := &http.Client{}
  1897. data["psn_no"] = his.PsnNo
  1898. data["mdtrt_id"] = his.Number
  1899. data["chrg_bchno"] = chrg_bchno
  1900. data["org_name"] = miConfig.OrgName
  1901. data["doctor"] = roles.UserName
  1902. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1903. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1904. data["fixmedins_code"] = miConfig.Code
  1905. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1906. data["dept_code"] = "15"
  1907. } else {
  1908. data["dept_code"] = department.Number
  1909. }
  1910. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1911. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1912. data["secret_key"] = miConfig.SecretKey
  1913. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  1914. var ids []int64
  1915. for _, item := range prescriptions {
  1916. ids = append(ids, item.ID)
  1917. }
  1918. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1919. if config.IsOpen == 1 { //对接了医保,走医保流程
  1920. bytesData, _ := json.Marshal(data)
  1921. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1922. resp, _ := client.Do(req)
  1923. defer resp.Body.Close()
  1924. body, ioErr := ioutil.ReadAll(resp.Body)
  1925. if ioErr != nil {
  1926. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1928. return
  1929. }
  1930. var respJSON map[string]interface{}
  1931. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1932. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1934. return
  1935. }
  1936. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1937. userJSONBytes, _ := json.Marshal(respJSON)
  1938. request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  1939. requestJSONBytes, _ := json.Marshal(request_respJSON)
  1940. saveLog(string(userJSONBytes), string(requestJSONBytes))
  1941. var res ResultFour
  1942. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1943. utils.ErrorLog("解析失败:%v", err)
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1945. return
  1946. }
  1947. if res.Infcode == 0 {
  1948. order := &models.HisOrder{
  1949. UserOrgId: adminUser.CurrentOrgId,
  1950. HisPatientId: his.ID,
  1951. PatientId: his.PatientId,
  1952. SettleAccountsDate: recordDateTime,
  1953. Ctime: time.Now().Unix(),
  1954. Mtime: time.Now().Unix(),
  1955. Status: 0,
  1956. Number: chrg_bchno,
  1957. Infcode: res.Infcode,
  1958. WarnMsg: res.WarnMsg,
  1959. Cainfo: res.Cainfo,
  1960. ErrMsg: res.ErrMsg,
  1961. RespondTime: res.RefmsgTime,
  1962. InfRefmsgid: res.InfRefmsgid,
  1963. OrderStatus: 1,
  1964. PayWay: pay_way,
  1965. PayPrice: pay_price,
  1966. PayCardNo: pay_card_no,
  1967. DiscountPrice: discount_price,
  1968. PreferentialPrice: preferential_price,
  1969. RealityPrice: reality_price,
  1970. FoundPrice: found_price,
  1971. MedicalInsurancePrice: medical_insurance_price,
  1972. PrivatePrice: private_price,
  1973. IsMedicineInsurance: 1,
  1974. SettleType: settle_accounts_type,
  1975. SettleStartTime: start_time,
  1976. SettleEndTime: end_time,
  1977. Creator: roles.AdminUserId,
  1978. Modify: roles.AdminUserId,
  1979. FaPiaoNumber: fapiao_number,
  1980. FaPiaoCode: fapiao_code,
  1981. PType: 2,
  1982. Diagnosis: diagnosis_id,
  1983. }
  1984. err = service.CreateOrder(order)
  1985. if err != nil {
  1986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1987. return
  1988. }
  1989. for _, item := range res.Output.Result {
  1990. temp := strings.Split(item.FeedetlSn, "-")
  1991. var advice_id int64 = 0
  1992. var project_id int64 = 0
  1993. var types int64 = 0
  1994. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1995. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1996. if temp[1] == "1" {
  1997. advice_id = id
  1998. project_id = 0
  1999. } else if temp[1] == "2" {
  2000. advice_id = 0
  2001. project_id = id
  2002. }
  2003. info := &models.HisOrderInfo{
  2004. OrderNumber: order.Number,
  2005. FeedetlSn: item.FeedetlSn,
  2006. UploadDate: time.Now().Unix(),
  2007. AdviceId: advice_id,
  2008. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2009. Cnt: item.Cnt,
  2010. Pric: float64(item.Pric),
  2011. PatientId: his.PatientId,
  2012. PricUplmtAmt: item.PricUplmtAmt,
  2013. SelfpayProp: item.SelfpayProp,
  2014. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2015. OverlmtAmt: item.OverlmtAmt,
  2016. PreselfpayAmt: item.PreselfpayAmt,
  2017. BasMednFlag: item.BasMednFlag,
  2018. MedChrgitmType: item.MedChrgitmType,
  2019. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2020. Status: 1,
  2021. Memo: item.Memo,
  2022. Mtime: time.Now().Unix(),
  2023. InscpScpAmt: item.InscpScpAmt,
  2024. DrtReimFlag: item.DrtReimFlag,
  2025. Ctime: time.Now().Unix(),
  2026. ListSpItemFlag: item.ListSpItemFlag,
  2027. ChldMedcFlag: item.ChldMedcFlag,
  2028. LmtUsedFlag: item.LmtUsedFlag,
  2029. ChrgitmLv: item.ChrgitmLv,
  2030. UserOrgId: adminUser.CurrentOrgId,
  2031. HisPatientId: his.ID,
  2032. OrderId: order.ID,
  2033. ProjectId: project_id,
  2034. Type: types,
  2035. }
  2036. service.CreateOrderInfo(info)
  2037. }
  2038. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2039. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  2040. var total float64
  2041. for _, item := range prescriptions {
  2042. if item.Type == 1 { //药品
  2043. for _, subItem := range item.HisDoctorAdviceInfo {
  2044. total = total + (subItem.Price * subItem.PrescribingNumber)
  2045. }
  2046. }
  2047. if item.Type == 2 { //项目
  2048. for _, subItem := range item.HisPrescriptionProject {
  2049. total = total + (subItem.Price * float64(subItem.Count))
  2050. }
  2051. }
  2052. }
  2053. for _, item := range prescriptions {
  2054. for _, subItem := range item.HisAdditionalCharge {
  2055. total = total + (subItem.Price * float64(subItem.Count))
  2056. }
  2057. }
  2058. allTotal := fmt.Sprintf("%.2f", total)
  2059. if res.Infcode == 0 {
  2060. var rf []*ResultFive
  2061. json.Unmarshal([]byte(his.Iinfo), &rf)
  2062. chrg_bchno := chrg_bchno
  2063. cert_no := his.Certno
  2064. var insutypes []string
  2065. var insutype string
  2066. var is390 int = 0
  2067. var is310 int = 0
  2068. for _, item := range rf {
  2069. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2070. insutypes = append(insutypes, item.Insutype)
  2071. }
  2072. }
  2073. if len(insutypes) == 1 {
  2074. insutype = insutypes[0]
  2075. } else {
  2076. for _, i := range insutypes {
  2077. if i == "390" {
  2078. is390 = 1
  2079. }
  2080. if i == "310" {
  2081. is310 = 1
  2082. }
  2083. }
  2084. }
  2085. if is390 == 1 {
  2086. insutype = "390"
  2087. }
  2088. if is310 == 1 {
  2089. insutype = "310"
  2090. }
  2091. if len(insutypes) == 0 {
  2092. insutype = "310"
  2093. }
  2094. //insutype = "390"
  2095. if his.IdCardType == 1 {
  2096. // cert_no = his.MedicalInsuranceNumber
  2097. cert_no = his.Certno
  2098. } else {
  2099. cert_no = his.Certno
  2100. }
  2101. 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(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  2102. var dat map[string]interface{}
  2103. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2104. fmt.Println(dat)
  2105. } else {
  2106. fmt.Println(err)
  2107. }
  2108. saveLog(result, src_resquest)
  2109. userJSONBytes, _ := json.Marshal(dat)
  2110. var res ResultSeven
  2111. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2112. utils.ErrorLog("解析失败:%v", err)
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. return
  2115. }
  2116. if res.Infcode != 0 {
  2117. errlog := &models.HisOrderError{
  2118. UserOrgId: adminUser.CurrentOrgId,
  2119. Ctime: time.Now().Unix(),
  2120. Mtime: time.Now().Unix(),
  2121. Number: chrg_bchno,
  2122. ErrMsg: res.ErrMsg,
  2123. Status: 1,
  2124. PatientId: id,
  2125. RecordTime: recordDateTime,
  2126. Stage: 6,
  2127. }
  2128. service.CreateErrMsgLog(errlog)
  2129. c.ServeSuccessJSON(map[string]interface{}{
  2130. "failed_code": -10,
  2131. "msg": res.ErrMsg,
  2132. })
  2133. return
  2134. } else {
  2135. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2136. order.OrderStatus = 2
  2137. order.Status = 1
  2138. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2139. order.SetlId = res.Output.Setlinfo.SetlID
  2140. order.PsnNo = res.Output.Setlinfo.PsnNo
  2141. order.PsnName = res.Output.Setlinfo.PsnName
  2142. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2143. order.Certno = res.Output.Setlinfo.Certno
  2144. order.Gend = res.Output.Setlinfo.Gend
  2145. order.Naty = res.Output.Setlinfo.Naty
  2146. order.Age = res.Output.Setlinfo.Age
  2147. order.Insutype = res.Output.Setlinfo.Insutype
  2148. order.PsnType = res.Output.Setlinfo.PsnType
  2149. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2150. order.SetlTime = res.Output.Setlinfo.SetlTime
  2151. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2152. order.MedType = res.Output.Setlinfo.MedType
  2153. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2154. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2155. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2156. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2157. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2158. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2159. order.HifpPay = res.Output.Setlinfo.HifpPay
  2160. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2161. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2162. order.HifesPay = res.Output.Setlinfo.HifesPay
  2163. order.HifobPay = res.Output.Setlinfo.HifobPay
  2164. order.MafPay = res.Output.Setlinfo.MafPay
  2165. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2166. order.OthPay = res.Output.Setlinfo.OthPay
  2167. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2168. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2169. order.AcctPay = res.Output.Setlinfo.AcctPay
  2170. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2171. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2172. order.Balc = res.Output.Setlinfo.Balc
  2173. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2174. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2175. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2176. order.ClrWay = res.Output.Setlinfo.ClrWay
  2177. order.Creator = order.Creator
  2178. order.Modify = roles.AdminUserId
  2179. order.RequestLog = src_resquest
  2180. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2181. detailStr := string(setlDetail)
  2182. order.SetlDetail = detailStr
  2183. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2184. err = service.UpDateOrder(order)
  2185. if err == nil {
  2186. c.ServeSuccessJSON(map[string]interface{}{
  2187. "msg": "结算成功",
  2188. })
  2189. } else {
  2190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2191. return
  2192. }
  2193. }
  2194. } else {
  2195. adminUser := c.GetAdminUserInfo()
  2196. errlog := &models.HisOrderError{
  2197. UserOrgId: adminUser.CurrentOrgId,
  2198. Ctime: time.Now().Unix(),
  2199. Mtime: time.Now().Unix(),
  2200. ErrMsg: res.ErrMsg,
  2201. Status: 1,
  2202. PatientId: id,
  2203. RecordTime: recordDateTime,
  2204. Stage: 4,
  2205. }
  2206. service.CreateErrMsgLog(errlog)
  2207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2208. return
  2209. }
  2210. } else {
  2211. adminUser := c.GetAdminUserInfo()
  2212. errlog := &models.HisOrderError{
  2213. UserOrgId: adminUser.CurrentOrgId,
  2214. Ctime: time.Now().Unix(),
  2215. Mtime: time.Now().Unix(),
  2216. ErrMsg: res.ErrMsg,
  2217. Status: 1,
  2218. PatientId: id,
  2219. RecordTime: recordDateTime,
  2220. Stage: 4,
  2221. }
  2222. service.CreateErrMsgLog(errlog)
  2223. c.ServeSuccessJSON(map[string]interface{}{
  2224. "failed_code": -10,
  2225. "msg": res.ErrMsg,
  2226. })
  2227. return
  2228. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2229. //return
  2230. }
  2231. }
  2232. }
  2233. } else if tempOrder.ID > 0 {
  2234. if tempOrder.IsPre == 1 {
  2235. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  2236. var rf []*ResultFive
  2237. json.Unmarshal([]byte(his.Iinfo), &rf)
  2238. chrg_bchno := tempOrder.Number
  2239. cert_no := his.Certno
  2240. var insutypes []string
  2241. var insutype string
  2242. var is390 int = 0
  2243. var is310 int = 0
  2244. for _, item := range rf {
  2245. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  2246. insutypes = append(insutypes, item.Insutype)
  2247. }
  2248. }
  2249. if len(insutypes) == 1 {
  2250. insutype = insutypes[0]
  2251. } else {
  2252. for _, i := range insutypes {
  2253. if i == "390" {
  2254. is390 = 1
  2255. }
  2256. if i == "310" {
  2257. is310 = 1
  2258. }
  2259. }
  2260. }
  2261. if is390 == 1 {
  2262. insutype = "390"
  2263. }
  2264. if is310 == 1 {
  2265. insutype = "310"
  2266. }
  2267. if len(insutypes) == 0 {
  2268. insutype = "310"
  2269. }
  2270. //insutype = "390"
  2271. if his.IdCardType == 1 {
  2272. // cert_no = his.MedicalInsuranceNumber
  2273. cert_no = his.Certno
  2274. } else {
  2275. cert_no = his.Certno
  2276. }
  2277. 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(reg_type, 10), his.IdCardType, tempOrder.FulamtOwnpayAmt, tempOrder.OverlmtSelfPay, tempOrder.PreselfpayAmt, tempOrder.InscpScpAmt, his.IdType)
  2278. var dat map[string]interface{}
  2279. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2280. fmt.Println(dat)
  2281. } else {
  2282. fmt.Println(err)
  2283. }
  2284. saveLog(result, src_resquest)
  2285. userJSONBytes, _ := json.Marshal(dat)
  2286. var res ResultSeven
  2287. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2288. utils.ErrorLog("解析失败:%v", err)
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2290. return
  2291. }
  2292. if res.Infcode != 0 {
  2293. errlog := &models.HisOrderError{
  2294. UserOrgId: adminUser.CurrentOrgId,
  2295. Ctime: time.Now().Unix(),
  2296. Mtime: time.Now().Unix(),
  2297. Number: chrg_bchno,
  2298. ErrMsg: res.ErrMsg,
  2299. Status: 1,
  2300. PatientId: id,
  2301. RecordTime: recordDateTime,
  2302. Stage: 6,
  2303. }
  2304. service.CreateErrMsgLog(errlog)
  2305. c.ServeSuccessJSON(map[string]interface{}{
  2306. "failed_code": -10,
  2307. "msg": res.ErrMsg,
  2308. })
  2309. return
  2310. } else {
  2311. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2312. order.OrderStatus = 2
  2313. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2314. order.SetlId = res.Output.Setlinfo.SetlID
  2315. order.PsnNo = res.Output.Setlinfo.PsnNo
  2316. order.PsnName = res.Output.Setlinfo.PsnName
  2317. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2318. order.Certno = res.Output.Setlinfo.Certno
  2319. order.Gend = res.Output.Setlinfo.Gend
  2320. order.Naty = res.Output.Setlinfo.Naty
  2321. order.Age = res.Output.Setlinfo.Age
  2322. order.Insutype = res.Output.Setlinfo.Insutype
  2323. order.PsnType = res.Output.Setlinfo.PsnType
  2324. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2325. order.SetlTime = res.Output.Setlinfo.SetlTime
  2326. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2327. order.MedType = res.Output.Setlinfo.MedType
  2328. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2329. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2330. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2331. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2332. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2333. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2334. order.HifpPay = res.Output.Setlinfo.HifpPay
  2335. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2336. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2337. order.HifesPay = res.Output.Setlinfo.HifesPay
  2338. order.HifobPay = res.Output.Setlinfo.HifobPay
  2339. order.MafPay = res.Output.Setlinfo.MafPay
  2340. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2341. order.OthPay = res.Output.Setlinfo.OthPay
  2342. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2343. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2344. order.AcctPay = res.Output.Setlinfo.AcctPay
  2345. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2346. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2347. order.Balc = res.Output.Setlinfo.Balc
  2348. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2349. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2350. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2351. order.ClrWay = res.Output.Setlinfo.ClrWay
  2352. order.Creator = order.Creator
  2353. order.Modify = roles.AdminUserId
  2354. order.RequestLog = src_resquest
  2355. order.Diagnosis = diagnosis_id
  2356. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2357. detailStr := string(setlDetail)
  2358. order.SetlDetail = detailStr
  2359. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2360. err = service.UpDateOrder(order)
  2361. if err == nil {
  2362. c.ServeSuccessJSON(map[string]interface{}{
  2363. "msg": "结算成功",
  2364. })
  2365. } else {
  2366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2367. return
  2368. }
  2369. }
  2370. }
  2371. }
  2372. }
  2373. //func (c *HisApiController) GetPreUploadInfo() {
  2374. // id, _ := c.GetInt64("id")
  2375. // record_time := c.GetString("record_time")
  2376. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2377. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2378. //
  2379. // timeLayout := "2006-01-02"
  2380. // loc, _ := time.LoadLocation("Local")
  2381. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2382. // if err != nil {
  2383. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2384. // return
  2385. // }
  2386. // recordDateTime := theTime.Unix()
  2387. // adminUser := c.GetAdminUserInfo()
  2388. //
  2389. // var prescriptions []*models.HisPrescription
  2390. //
  2391. // var start_time int64
  2392. // var end_time int64
  2393. //
  2394. // data := make(map[string]interface{})
  2395. // if settle_accounts_type == 1 { //日结
  2396. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2397. // data["pre"] = prescriptions
  2398. //
  2399. // } else { //月结
  2400. // start_time_str := c.GetString("start_time")
  2401. // end_time_str := c.GetString("end_time")
  2402. // timeLayout := "2006-01-02"
  2403. // loc, _ := time.LoadLocation("Local")
  2404. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2405. // if err != nil {
  2406. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. // return
  2408. // }
  2409. // recordStartTime := theStartTime.Unix()
  2410. // start_time = recordStartTime
  2411. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2412. // if err != nil {
  2413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2414. // return
  2415. // }
  2416. // recordEndTime := theEndTime.Unix()
  2417. // end_time = recordEndTime
  2418. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2419. // data["pre"] = prescriptions
  2420. //
  2421. // }
  2422. //
  2423. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2424. //
  2425. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2426. // timestamp := time.Now().Unix()
  2427. // tempTime := time.Unix(timestamp, 0)
  2428. // timeFormat := tempTime.Format("20060102150405")
  2429. // chrgBchno := rand.Intn(100000) + 10000
  2430. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2431. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2432. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2433. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2434. // strconv.FormatInt(his.PatientId, 10)
  2435. // client := &http.Client{}
  2436. // data["psn_no"] = his.PsnNo
  2437. // data["mdtrt_id"] = his.Number
  2438. // data["chrg_bchno"] = chrg_bchno
  2439. // data["org_name"] = miConfig.OrgName
  2440. // data["doctor"] = roles.UserName
  2441. // data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2442. // data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2443. // data["fixmedins_code"] = miConfig.Code
  2444. // data["dept_code"] = department.Number
  2445. // data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2446. // data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2447. // data["secret_key"] = miConfig.SecretKey
  2448. // var ids []int64
  2449. //
  2450. // for _, item := range prescriptions {
  2451. // ids = append(ids, item.ID)
  2452. // }
  2453. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2454. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2455. // bytesData, _ := json.Marshal(data)
  2456. // req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2457. // resp, _ := client.Do(req)
  2458. // defer resp.Body.Close()
  2459. // body, ioErr := ioutil.ReadAll(resp.Body)
  2460. // if ioErr != nil {
  2461. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2462. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2463. // return
  2464. // }
  2465. // var respJSON map[string]interface{}
  2466. // if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2467. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2468. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2469. // return
  2470. // }
  2471. //
  2472. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2473. // userJSONBytes, _ := json.Marshal(respJSON)
  2474. // var res ResultFour
  2475. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2476. // utils.ErrorLog("解析失败:%v", err)
  2477. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2478. // return
  2479. // }
  2480. //
  2481. // if res.Infcode == 0 {
  2482. // order := &models.HisOrder{
  2483. // UserOrgId: adminUser.CurrentOrgId,
  2484. // HisPatientId: his.ID,
  2485. // PatientId: his.PatientId,
  2486. // SettleAccountsDate: recordDateTime,
  2487. // Ctime: time.Now().Unix(),
  2488. // Mtime: time.Now().Unix(),
  2489. // Status: 1,
  2490. // Number: chrg_bchno,
  2491. // Infcode: res.Infcode,
  2492. // WarnMsg: res.WarnMsg,
  2493. // Cainfo: res.Cainfo,
  2494. // ErrMsg: res.ErrMsg,
  2495. // RespondTime: res.RefmsgTime,
  2496. // InfRefmsgid: res.InfRefmsgid,
  2497. // OrderStatus: 1,
  2498. // IsMedicineInsurance: 1,
  2499. // SettleType: settle_accounts_type,
  2500. // SettleStartTime: start_time,
  2501. // SettleEndTime: end_time,
  2502. // Creator: roles.ID,
  2503. // Modify: roles.ID,
  2504. // PType: 2,
  2505. // }
  2506. // err = service.CreateOrder(order)
  2507. // if err != nil {
  2508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2509. // return
  2510. // }
  2511. //
  2512. // for _, item := range res.Output.Result {
  2513. // temp := strings.Split(item.FeedetlSn, "-")
  2514. // var advice_id int64 = 0
  2515. // var project_id int64 = 0
  2516. // var types int64 = 0
  2517. //
  2518. // id, _ := strconv.ParseInt(temp[2], 10, 64)
  2519. // types, _ = strconv.ParseInt(temp[1], 10, 64)
  2520. //
  2521. // if temp[1] == "1" {
  2522. // advice_id = id
  2523. // project_id = 0
  2524. // } else if temp[1] == "2" {
  2525. // advice_id = 0
  2526. // project_id = id
  2527. // }
  2528. //
  2529. // info := &models.HisOrderInfo{
  2530. // OrderNumber: order.Number,
  2531. // FeedetlSn: item.FeedetlSn,
  2532. // UploadDate: time.Now().Unix(),
  2533. // AdviceId: advice_id,
  2534. // DetItemFeeSumamt: item.DetItemFeeSumamt,
  2535. // Cnt: item.Cnt,
  2536. // Pric: float64(item.Pric),
  2537. // PatientId: his.PatientId,
  2538. // PricUplmtAmt: item.PricUplmtAmt,
  2539. // SelfpayProp: item.SelfpayProp,
  2540. // FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2541. // OverlmtAmt: item.OverlmtAmt,
  2542. // PreselfpayAmt: item.PreselfpayAmt,
  2543. // BasMednFlag: item.BasMednFlag,
  2544. // MedChrgitmType: item.MedChrgitmType,
  2545. // HiNegoDrugFlag: item.HiNegoDrugFlag,
  2546. // Status: 1,
  2547. // Memo: item.Memo,
  2548. // Mtime: time.Now().Unix(),
  2549. // InscpScpAmt: item.InscpScpAmt,
  2550. // DrtReimFlag: item.DrtReimFlag,
  2551. // Ctime: time.Now().Unix(),
  2552. // ListSpItemFlag: item.ListSpItemFlag,
  2553. // ChldMedcFlag: item.ChldMedcFlag,
  2554. // LmtUsedFlag: item.LmtUsedFlag,
  2555. // ChrgitmLv: item.ChrgitmLv,
  2556. // UserOrgId: adminUser.CurrentOrgId,
  2557. // HisPatientId: his.ID,
  2558. // OrderId: order.ID,
  2559. // ProjectId: project_id,
  2560. // Type: types,
  2561. // }
  2562. // service.CreateOrderInfo(info)
  2563. //
  2564. // }
  2565. // service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2566. // service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2567. //
  2568. // var total float64
  2569. // for _, item := range prescriptions {
  2570. // if item.Type == 1 { //药品
  2571. // for _, subItem := range item.HisDoctorAdviceInfo {
  2572. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2573. // }
  2574. // }
  2575. // if item.Type == 2 { //项目
  2576. // for _, subItem := range item.HisPrescriptionProject {
  2577. // total = total + (subItem.Price * float64(subItem.Count))
  2578. // }
  2579. // }
  2580. // }
  2581. //
  2582. // for _, item := range prescriptions {
  2583. // for _, subItem := range item.HisAdditionalCharge {
  2584. // total = total + (subItem.Price * float64(subItem.Count))
  2585. // }
  2586. // }
  2587. //
  2588. // allTotal := fmt.Sprintf("%.2f", total)
  2589. // if res.Infcode == 0 {
  2590. // var rf []*ResultFive
  2591. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2592. // psn_no := his.PsnNo
  2593. // mdtrt_id := his.Number
  2594. // chrg_bchno := chrg_bchno
  2595. // cert_no := his.Certno
  2596. // insutype := rf[0].Insutype
  2597. //
  2598. // if his.IdCardType == 1 {
  2599. // cert_no = his.MedicalInsuranceNumber
  2600. //
  2601. // } else {
  2602. //
  2603. // cert_no = his.Certno
  2604. //
  2605. // }
  2606. //
  2607. // api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2608. // insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2609. // "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2610. // miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2611. // resp, requestErr := http.Get(api)
  2612. // if requestErr != nil {
  2613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2614. // return
  2615. // }
  2616. // defer resp.Body.Close()
  2617. // body, ioErr := ioutil.ReadAll(resp.Body)
  2618. // if ioErr != nil {
  2619. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2620. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2621. // return
  2622. // }
  2623. // var respJSON map[string]interface{}
  2624. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2625. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2626. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. // return
  2628. // }
  2629. // fmt.Println(respJSON)
  2630. // respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2631. // userJSONBytes, _ := json.Marshal(respJSON)
  2632. // var res ResultSeven
  2633. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2634. // utils.ErrorLog("解析失败:%v", err)
  2635. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2636. // return
  2637. // }
  2638. // if res.Infcode != 0 {
  2639. // errlog := &models.HisOrderError{
  2640. // UserOrgId: adminUser.CurrentOrgId,
  2641. // Ctime: time.Now().Unix(),
  2642. // Mtime: time.Now().Unix(),
  2643. // Number: chrg_bchno,
  2644. // ErrMsg: res.ErrMsg,
  2645. // Status: 1,
  2646. // PatientId: id,
  2647. // RecordTime: recordDateTime,
  2648. // Stage: 7,
  2649. // }
  2650. // service.CreateErrMsgLog(errlog)
  2651. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2652. // return
  2653. // } else {
  2654. // order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2655. // order.OrderStatus = 1
  2656. // order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2657. // order.SetlId = res.Output.Setlinfo.SetlID
  2658. // order.PsnNo = res.Output.Setlinfo.PsnNo
  2659. // order.PsnName = res.Output.Setlinfo.PsnName
  2660. // order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2661. // order.Certno = res.Output.Setlinfo.Certno
  2662. // order.Gend = res.Output.Setlinfo.Gend
  2663. // order.Naty = res.Output.Setlinfo.Naty
  2664. // order.Age = res.Output.Setlinfo.Age
  2665. // order.Insutype = res.Output.Setlinfo.Insutype
  2666. // order.PsnType = res.Output.Setlinfo.PsnType
  2667. // order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2668. // order.SetlTime = res.Output.Setlinfo.SetlTime
  2669. // order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2670. // order.MedType = res.Output.Setlinfo.MedType
  2671. // order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2672. // order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2673. // order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2674. // order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2675. // order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2676. // order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2677. // order.HifpPay = res.Output.Setlinfo.HifpPay
  2678. // order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2679. // order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2680. // order.HifesPay = res.Output.Setlinfo.HifesPay
  2681. // order.HifobPay = res.Output.Setlinfo.HifobPay
  2682. // order.MafPay = res.Output.Setlinfo.MafPay
  2683. // order.OthPay = res.Output.Setlinfo.OthPay
  2684. // order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2685. // order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2686. // order.AcctPay = res.Output.Setlinfo.AcctPay
  2687. // order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2688. // order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2689. // order.Balc = res.Output.Setlinfo.Balc
  2690. // order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2691. // order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2692. // order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2693. // order.ClrWay = res.Output.Setlinfo.ClrWay
  2694. // order.Creator = order.Creator
  2695. // order.Modify = roles.ID
  2696. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2697. // detailStr := string(setlDetail)
  2698. // order.SetlDetail = detailStr
  2699. // //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2700. // err = service.UpDateOrder(order)
  2701. // if err == nil {
  2702. // c.ServeSuccessJSON(map[string]interface{}{
  2703. // "msg": "预结算成功",
  2704. // })
  2705. // } else {
  2706. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2707. // return
  2708. // }
  2709. // }
  2710. // } else {
  2711. // adminUser := c.GetAdminUserInfo()
  2712. // errlog := &models.HisOrderError{
  2713. // UserOrgId: adminUser.CurrentOrgId,
  2714. // Ctime: time.Now().Unix(),
  2715. // Mtime: time.Now().Unix(),
  2716. // ErrMsg: res.ErrMsg,
  2717. // Status: 1,
  2718. // PatientId: id,
  2719. // RecordTime: recordDateTime,
  2720. // Stage: 4,
  2721. // }
  2722. // service.CreateErrMsgLog(errlog)
  2723. //
  2724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2725. // return
  2726. // }
  2727. // } else {
  2728. // adminUser := c.GetAdminUserInfo()
  2729. // errlog := &models.HisOrderError{
  2730. // UserOrgId: adminUser.CurrentOrgId,
  2731. // Ctime: time.Now().Unix(),
  2732. // Mtime: time.Now().Unix(),
  2733. // ErrMsg: res.ErrMsg,
  2734. // Status: 1,
  2735. // PatientId: id,
  2736. // RecordTime: recordDateTime,
  2737. // Stage: 4,
  2738. // }
  2739. // service.CreateErrMsgLog(errlog)
  2740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2741. // return
  2742. // }
  2743. //
  2744. // } else {
  2745. // var total float64
  2746. // for _, item := range prescriptions {
  2747. // if item.Type == 1 { //药品
  2748. // for _, subItem := range item.HisDoctorAdviceInfo {
  2749. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2750. // }
  2751. // }
  2752. // if item.Type == 2 { //项目
  2753. // for _, subItem := range item.HisPrescriptionProject {
  2754. // total = total + (subItem.Price * float64(subItem.Count))
  2755. // }
  2756. // }
  2757. //
  2758. // for _, subItem := range item.HisAdditionalCharge {
  2759. // total = total + (subItem.Price * float64(subItem.Count))
  2760. // }
  2761. // }
  2762. //
  2763. // allTotal := fmt.Sprintf("%.2f", total)
  2764. // totals, _ := strconv.ParseFloat(allTotal, 64)
  2765. // order := &models.HisOrder{
  2766. // UserOrgId: adminUser.CurrentOrgId,
  2767. // HisPatientId: his.ID,
  2768. // PatientId: id,
  2769. // SettleAccountsDate: recordDateTime,
  2770. // Ctime: time.Now().Unix(),
  2771. // Mtime: time.Now().Unix(),
  2772. // Status: 1,
  2773. // OrderStatus: 2,
  2774. // Number: chrg_bchno,
  2775. // MedfeeSumamt: totals,
  2776. // }
  2777. // err = service.CreateOrder(order)
  2778. // if err != nil {
  2779. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2780. // return
  2781. // }
  2782. //
  2783. // var customs []*Custom
  2784. // for _, item := range prescriptions {
  2785. //
  2786. // if item.Type == 1 { //药品
  2787. // for _, subItem := range item.HisDoctorAdviceInfo {
  2788. // cus := &Custom{
  2789. // AdviceId: subItem.ID,
  2790. // ProjectId: 0,
  2791. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2792. // Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2793. // FeedetlSn: subItem.FeedetlSn,
  2794. // Price: fmt.Sprintf("%.2f", subItem.Price),
  2795. // MedListCodg: subItem.MedListCodg,
  2796. // Type: 1,
  2797. // }
  2798. // customs = append(customs, cus)
  2799. // }
  2800. // }
  2801. //
  2802. // if item.Type == 2 { //项目
  2803. // for _, subItem := range item.HisPrescriptionProject {
  2804. //
  2805. // cus := &Custom{
  2806. // AdviceId: 0,
  2807. // ProjectId: subItem.ID,
  2808. // DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2809. // Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2810. // FeedetlSn: subItem.FeedetlSn,
  2811. // Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2812. // MedListCodg: subItem.MedListCodg,
  2813. // Type: 2,
  2814. // }
  2815. //
  2816. // customs = append(customs, cus)
  2817. // }
  2818. // }
  2819. //
  2820. // for _, item := range item.HisAdditionalCharge {
  2821. // cus := &Custom{
  2822. // ItemId: item.ID,
  2823. // AdviceId: 0,
  2824. // ProjectId: 0,
  2825. // DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2826. // Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2827. // FeedetlSn: item.FeedetlSn,
  2828. // Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2829. // MedListCodg: item.XtHisAddtionConfig.Code,
  2830. // Type: 3,
  2831. // }
  2832. //
  2833. // customs = append(customs, cus)
  2834. // }
  2835. //
  2836. // }
  2837. //
  2838. // for _, item := range customs {
  2839. // var advice_id int64 = 0
  2840. // var project_id int64 = 0
  2841. // var item_id int64 = 0
  2842. //
  2843. // var types int64 = 0
  2844. //
  2845. // if item.Type == 1 {
  2846. // advice_id = item.AdviceId
  2847. // project_id = 0
  2848. // item_id = 0
  2849. // } else if item.Type == 2 {
  2850. // advice_id = 0
  2851. // item_id = 0
  2852. //
  2853. // project_id = item.ProjectId
  2854. // } else if item.Type == 3 {
  2855. // advice_id = 0
  2856. // item_id = item.ItemId
  2857. // project_id = 0
  2858. // }
  2859. //
  2860. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2861. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  2862. // pric, _ := strconv.ParseFloat(item.Price, 32)
  2863. //
  2864. // info := &models.HisOrderInfo{
  2865. // OrderNumber: order.Number,
  2866. // UploadDate: time.Now().Unix(),
  2867. // AdviceId: advice_id,
  2868. // DetItemFeeSumamt: detItemFeeSumamt,
  2869. // Cnt: cut,
  2870. // Pric: pric,
  2871. // PatientId: id,
  2872. // Status: 1,
  2873. // Mtime: time.Now().Unix(),
  2874. // Ctime: time.Now().Unix(),
  2875. // UserOrgId: adminUser.CurrentOrgId,
  2876. // HisPatientId: his.ID,
  2877. // OrderId: order.ID,
  2878. // ProjectId: project_id,
  2879. // Type: types,
  2880. // ItemId: item_id,
  2881. // }
  2882. // service.CreateOrderInfo(info)
  2883. // }
  2884. // //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2885. // err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2886. // err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2887. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2888. // if err == nil {
  2889. // c.ServeSuccessJSON(map[string]interface{}{
  2890. // "msg": "结算成功",
  2891. // })
  2892. // } else {
  2893. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2894. // return
  2895. // }
  2896. // }
  2897. //}
  2898. //上传明细-预结算-
  2899. func (c *HisApiController) GetPreUploadInfo() {
  2900. id, _ := c.GetInt64("id")
  2901. record_time := c.GetString("record_time")
  2902. his_patient_id, _ := c.GetInt64("his_patient_id")
  2903. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2904. admin_user_id, _ := c.GetInt64("admin_user_id")
  2905. diagnosis_id := c.GetString("diagnosis")
  2906. sick_type, _ := c.GetInt64("sick_type")
  2907. reg_type, _ := c.GetInt64("p_type")
  2908. id_str := c.GetString("ids")
  2909. ids_arr := strings.Split(id_str, ",")
  2910. timeLayout := "2006-01-02"
  2911. loc, _ := time.LoadLocation("Local")
  2912. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2913. if err != nil {
  2914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2915. return
  2916. }
  2917. recordDateTime := theTime.Unix()
  2918. adminUser := c.GetAdminUserInfo()
  2919. diagnosis_ids := strings.Split(diagnosis_id, ",")
  2920. var config []*models.HisXtDiagnoseConfig
  2921. for _, item := range diagnosis_ids {
  2922. id, _ := strconv.ParseInt(item, 10, 64)
  2923. diagnosisConfig, _ := service.FindDiagnoseById(id)
  2924. config = append(config, diagnosisConfig)
  2925. }
  2926. //diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2927. sickConfig, _ := service.FindSickById(sick_type)
  2928. var prescriptions []*models.HisPrescription
  2929. var start_time int64
  2930. var end_time int64
  2931. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2932. fmt.Println(his_patient_id)
  2933. his, _ := service.GetNewHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2934. timestamp := time.Now().Unix()
  2935. tempTime := time.Unix(timestamp, 0)
  2936. timeFormat := tempTime.Format("20060102150405")
  2937. chrgBchno := rand.Intn(100000) + 10000
  2938. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2939. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2940. var patientPrescription models.HisPrescriptionInfo
  2941. patientPrescription, _ = service.FindHisPatientPrescriptionInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2942. if patientPrescription.ID == 0 {
  2943. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2944. }
  2945. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2946. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2947. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  2948. strconv.FormatInt(his.PatientId, 10)
  2949. var result string
  2950. var requestLog string
  2951. if miConfig.InsuplcAdmdvs == "440781" { //
  2952. result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
  2953. } else {
  2954. result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.CountryCode, sickConfig.ClassName, roles.UserName, config)
  2955. }
  2956. saveLog(result, requestLog)
  2957. var respJSON2 map[string]interface{}
  2958. if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
  2959. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2961. return
  2962. }
  2963. userJSONBytes2, _ := json.Marshal(respJSON2)
  2964. var res2 ResultSix
  2965. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2966. utils.ErrorLog("解析失败:%v", err)
  2967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2968. return
  2969. }
  2970. if res2.Infcode != 0 {
  2971. adminUser := c.GetAdminUserInfo()
  2972. errlog := &models.HisOrderError{
  2973. UserOrgId: adminUser.CurrentOrgId,
  2974. Ctime: time.Now().Unix(),
  2975. Mtime: time.Now().Unix(),
  2976. ErrMsg: res2.ErrMsg,
  2977. Status: 1,
  2978. PatientId: id,
  2979. RecordTime: recordDateTime,
  2980. Stage: 3,
  2981. }
  2982. service.CreateErrMsgLog(errlog)
  2983. c.ServeSuccessJSON(map[string]interface{}{
  2984. "failed_code": -10,
  2985. "msg": res2.ErrMsg,
  2986. })
  2987. return
  2988. } else {
  2989. his.Diagnosis = diagnosis_id
  2990. his.SickType = sickConfig.ID
  2991. his.PType = fmt.Sprintf("%d", reg_type)
  2992. service.UpdateHisPatientThree(&his)
  2993. data := make(map[string]interface{})
  2994. if settle_accounts_type == 1 { //日结
  2995. if reg_type == 11 {
  2996. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  2997. } else {
  2998. prescriptions, _ = service.GetNewHisPrescription(adminUser.CurrentOrgId, his_patient_id, recordDateTime, strconv.Itoa(int(reg_type)))
  2999. }
  3000. data["pre"] = prescriptions
  3001. } else { //月结
  3002. start_time_str := c.GetString("start_time")
  3003. end_time_str := c.GetString("end_time")
  3004. timeLayout := "2006-01-02"
  3005. loc, _ := time.LoadLocation("Local")
  3006. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3007. if err != nil {
  3008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. return
  3010. }
  3011. recordStartTime := theStartTime.Unix()
  3012. start_time = recordStartTime
  3013. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3014. if err != nil {
  3015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3016. return
  3017. }
  3018. recordEndTime := theEndTime.Unix()
  3019. end_time = recordEndTime
  3020. prescriptions, _ = service.GetMonthHisPrescriptionTwo(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3021. data["pre"] = prescriptions
  3022. }
  3023. if reg_type == 1111 || reg_type == 1112 {
  3024. reg_type = 11
  3025. }
  3026. client := &http.Client{}
  3027. data["psn_no"] = his.PsnNo
  3028. data["mdtrt_id"] = his.Number
  3029. data["chrg_bchno"] = chrg_bchno
  3030. data["org_name"] = miConfig.OrgName
  3031. data["doctor"] = roles.UserName
  3032. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  3033. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  3034. data["fixmedins_code"] = miConfig.Code
  3035. data["balance_accounts_type"] = strconv.FormatInt(his.BalanceAccountsType, 10)
  3036. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  3037. data["dept_code"] = "15"
  3038. } else {
  3039. data["dept_code"] = department.Number
  3040. }
  3041. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  3042. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  3043. data["secret_key"] = miConfig.SecretKey
  3044. var ids []int64
  3045. for _, item := range prescriptions {
  3046. ids = append(ids, item.ID)
  3047. }
  3048. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3049. if config.IsOpen == 1 { //对接了医保,走医保流程
  3050. bytesData, _ := json.Marshal(data)
  3051. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  3052. resp, _ := client.Do(req)
  3053. defer resp.Body.Close()
  3054. body, ioErr := ioutil.ReadAll(resp.Body)
  3055. if ioErr != nil {
  3056. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3058. return
  3059. }
  3060. var respJSON map[string]interface{}
  3061. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  3062. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3064. return
  3065. }
  3066. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3067. userJSONBytes, _ := json.Marshal(respJSON)
  3068. request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
  3069. requestJSONBytes, _ := json.Marshal(request_respJSON)
  3070. saveLog(string(userJSONBytes), string(requestJSONBytes))
  3071. var res ResultFour
  3072. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3073. utils.ErrorLog("解析失败:%v", err)
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3075. return
  3076. }
  3077. if res.Infcode == 0 {
  3078. order := &models.HisOrder{
  3079. UserOrgId: adminUser.CurrentOrgId,
  3080. HisPatientId: his.ID,
  3081. PatientId: his.PatientId,
  3082. SettleAccountsDate: recordDateTime,
  3083. Ctime: time.Now().Unix(),
  3084. Mtime: time.Now().Unix(),
  3085. Status: 0,
  3086. Number: chrg_bchno,
  3087. Infcode: res.Infcode,
  3088. WarnMsg: res.WarnMsg,
  3089. Cainfo: res.Cainfo,
  3090. ErrMsg: res.ErrMsg,
  3091. RespondTime: res.RefmsgTime,
  3092. InfRefmsgid: res.InfRefmsgid,
  3093. OrderStatus: 1,
  3094. IsMedicineInsurance: 1,
  3095. SettleType: settle_accounts_type,
  3096. SettleStartTime: start_time,
  3097. SettleEndTime: end_time,
  3098. Creator: roles.AdminUserId,
  3099. Modify: roles.AdminUserId,
  3100. PType: 2,
  3101. Diagnosis: diagnosis_id,
  3102. }
  3103. err = service.CreateOrder(order)
  3104. if err != nil {
  3105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  3106. return
  3107. }
  3108. for _, item := range res.Output.Result {
  3109. temp := strings.Split(item.FeedetlSn, "-")
  3110. var advice_id int64 = 0
  3111. var project_id int64 = 0
  3112. var types int64 = 0
  3113. id, _ := strconv.ParseInt(temp[2], 10, 64)
  3114. types, _ = strconv.ParseInt(temp[1], 10, 64)
  3115. if temp[1] == "1" {
  3116. advice_id = id
  3117. project_id = 0
  3118. } else if temp[1] == "2" {
  3119. advice_id = 0
  3120. project_id = id
  3121. }
  3122. info := &models.HisOrderInfo{
  3123. OrderNumber: order.Number,
  3124. FeedetlSn: item.FeedetlSn,
  3125. UploadDate: time.Now().Unix(),
  3126. AdviceId: advice_id,
  3127. DetItemFeeSumamt: item.DetItemFeeSumamt,
  3128. Cnt: item.Cnt,
  3129. Pric: float64(item.Pric),
  3130. PatientId: his.PatientId,
  3131. PricUplmtAmt: item.PricUplmtAmt,
  3132. SelfpayProp: item.SelfpayProp,
  3133. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  3134. OverlmtAmt: item.OverlmtAmt,
  3135. PreselfpayAmt: item.PreselfpayAmt,
  3136. BasMednFlag: item.BasMednFlag,
  3137. MedChrgitmType: item.MedChrgitmType,
  3138. HiNegoDrugFlag: item.HiNegoDrugFlag,
  3139. Status: 1,
  3140. Memo: item.Memo,
  3141. Mtime: time.Now().Unix(),
  3142. InscpScpAmt: item.InscpScpAmt,
  3143. DrtReimFlag: item.DrtReimFlag,
  3144. Ctime: time.Now().Unix(),
  3145. ListSpItemFlag: item.ListSpItemFlag,
  3146. ChldMedcFlag: item.ChldMedcFlag,
  3147. LmtUsedFlag: item.LmtUsedFlag,
  3148. ChrgitmLv: item.ChrgitmLv,
  3149. UserOrgId: adminUser.CurrentOrgId,
  3150. HisPatientId: his.ID,
  3151. OrderId: order.ID,
  3152. ProjectId: project_id,
  3153. Type: types,
  3154. }
  3155. service.CreateOrderInfo(info)
  3156. }
  3157. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  3158. service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, his_patient_id, chrg_bchno, recordDateTime)
  3159. var total float64
  3160. for _, item := range prescriptions {
  3161. if item.Type == 1 { //药品
  3162. for _, subItem := range item.HisDoctorAdviceInfo {
  3163. total = total + (subItem.Price * subItem.PrescribingNumber)
  3164. }
  3165. }
  3166. if item.Type == 2 { //项目
  3167. for _, subItem := range item.HisPrescriptionProject {
  3168. total = total + (subItem.Price * float64(subItem.Count))
  3169. }
  3170. }
  3171. }
  3172. for _, item := range prescriptions {
  3173. for _, subItem := range item.HisAdditionalCharge {
  3174. total = total + (subItem.Price * float64(subItem.Count))
  3175. }
  3176. }
  3177. allTotal := fmt.Sprintf("%.2f", total)
  3178. if res.Infcode == 0 {
  3179. var rf []*ResultFive
  3180. json.Unmarshal([]byte(his.Iinfo), &rf)
  3181. chrg_bchno := chrg_bchno
  3182. cert_no := his.Certno
  3183. var insutypes []string
  3184. var insutype string
  3185. var is390 int = 0
  3186. var is310 int = 0
  3187. for _, item := range rf {
  3188. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3189. insutypes = append(insutypes, item.Insutype)
  3190. }
  3191. }
  3192. if len(insutypes) == 1 {
  3193. insutype = insutypes[0]
  3194. } else {
  3195. for _, i := range insutypes {
  3196. if i == "390" {
  3197. is390 = 1
  3198. }
  3199. if i == "310" {
  3200. is310 = 1
  3201. }
  3202. }
  3203. }
  3204. if is390 == 1 {
  3205. insutype = "390"
  3206. }
  3207. if is310 == 1 {
  3208. insutype = "310"
  3209. }
  3210. if len(insutypes) == 0 {
  3211. insutype = "310"
  3212. }
  3213. //insutype = "390"
  3214. if his.IdCardType == 1 {
  3215. cert_no = his.MedicalInsuranceNumber
  3216. } else {
  3217. cert_no = his.Certno
  3218. }
  3219. result, request_log := service.Gdyb2206(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  3220. var dat map[string]interface{}
  3221. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3222. fmt.Println(dat)
  3223. } else {
  3224. fmt.Println(err)
  3225. }
  3226. saveLog(result, request_log)
  3227. userJSONBytes, _ := json.Marshal(dat)
  3228. var res ResultSeven
  3229. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3230. utils.ErrorLog("解析失败:%v", err)
  3231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3232. return
  3233. }
  3234. if res.Infcode != 0 {
  3235. errlog := &models.HisOrderError{
  3236. UserOrgId: adminUser.CurrentOrgId,
  3237. Ctime: time.Now().Unix(),
  3238. Mtime: time.Now().Unix(),
  3239. Number: chrg_bchno,
  3240. ErrMsg: res.ErrMsg,
  3241. Status: 1,
  3242. PatientId: id,
  3243. RecordTime: recordDateTime,
  3244. Stage: 20,
  3245. }
  3246. service.CreateErrMsgLog(errlog)
  3247. c.ServeSuccessJSON(map[string]interface{}{
  3248. "failed_code": -10,
  3249. "msg": res.ErrMsg,
  3250. })
  3251. return
  3252. } else {
  3253. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  3254. order.OrderStatus = 1
  3255. order.IsPre = 1
  3256. order.Status = 1
  3257. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  3258. order.SetlId = res.Output.Setlinfo.SetlID
  3259. order.PsnNo = res.Output.Setlinfo.PsnNo
  3260. order.PsnName = res.Output.Setlinfo.PsnName
  3261. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  3262. order.Certno = res.Output.Setlinfo.Certno
  3263. order.Gend = res.Output.Setlinfo.Gend
  3264. order.Naty = res.Output.Setlinfo.Naty
  3265. order.Age = res.Output.Setlinfo.Age
  3266. order.Insutype = res.Output.Setlinfo.Insutype
  3267. order.PsnType = res.Output.Setlinfo.PsnType
  3268. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3269. order.SetlTime = res.Output.Setlinfo.SetlTime
  3270. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3271. order.MedType = res.Output.Setlinfo.MedType
  3272. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3273. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3274. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3275. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3276. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3277. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3278. order.HifpPay = res.Output.Setlinfo.HifpPay
  3279. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  3280. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3281. order.HifesPay = res.Output.Setlinfo.HifesPay
  3282. order.HifobPay = res.Output.Setlinfo.HifobPay
  3283. order.MafPay = res.Output.Setlinfo.MafPay
  3284. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  3285. order.OthPay = res.Output.Setlinfo.OthPay
  3286. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3287. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3288. order.AcctPay = res.Output.Setlinfo.AcctPay
  3289. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3290. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3291. order.Balc = res.Output.Setlinfo.Balc
  3292. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3293. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3294. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  3295. order.ClrWay = res.Output.Setlinfo.ClrWay
  3296. order.Creator = order.Creator
  3297. order.Modify = roles.AdminUserId
  3298. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3299. detailStr := string(setlDetail)
  3300. order.SetlDetail = detailStr
  3301. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3302. err = service.UpDateOrder(order)
  3303. if err == nil {
  3304. c.ServeSuccessJSON(map[string]interface{}{
  3305. "msg": "预结算成功",
  3306. })
  3307. } else {
  3308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3309. return
  3310. }
  3311. }
  3312. } else {
  3313. adminUser := c.GetAdminUserInfo()
  3314. errlog := &models.HisOrderError{
  3315. UserOrgId: adminUser.CurrentOrgId,
  3316. Ctime: time.Now().Unix(),
  3317. Mtime: time.Now().Unix(),
  3318. ErrMsg: res.ErrMsg,
  3319. Status: 1,
  3320. PatientId: id,
  3321. RecordTime: recordDateTime,
  3322. Stage: 4,
  3323. }
  3324. service.CreateErrMsgLog(errlog)
  3325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3326. return
  3327. }
  3328. } else {
  3329. adminUser := c.GetAdminUserInfo()
  3330. errlog := &models.HisOrderError{
  3331. UserOrgId: adminUser.CurrentOrgId,
  3332. Ctime: time.Now().Unix(),
  3333. Mtime: time.Now().Unix(),
  3334. ErrMsg: res.ErrMsg,
  3335. Status: 1,
  3336. PatientId: id,
  3337. RecordTime: recordDateTime,
  3338. Stage: 4,
  3339. }
  3340. service.CreateErrMsgLog(errlog)
  3341. c.ServeSuccessJSON(map[string]interface{}{
  3342. "failed_code": -10,
  3343. "msg": res.ErrMsg,
  3344. })
  3345. return
  3346. }
  3347. }
  3348. }
  3349. }
  3350. //func (c *HisApiController) GetSettleInfo() {
  3351. // id, _ := c.GetInt64("id")
  3352. // order_id, _ := c.GetInt64("order_id")
  3353. //
  3354. // record_time := c.GetString("record_time")
  3355. // pay_way, _ := c.GetInt64("pay_way")
  3356. // pay_price, _ := c.GetFloat("pay_price")
  3357. // pay_card_no := c.GetString("pay_card_no")
  3358. // discount_price, _ := c.GetFloat("discount_price")
  3359. // preferential_price, _ := c.GetFloat("preferential_price")
  3360. // reality_price, _ := c.GetFloat("reality_price")
  3361. // found_price, _ := c.GetFloat("found_price")
  3362. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3363. // private_price, _ := c.GetFloat("private_price")
  3364. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3365. // admin_user_id, _ := c.GetInt64("admin_user_id")
  3366. //
  3367. // timeLayout := "2006-01-02"
  3368. // loc, _ := time.LoadLocation("Local")
  3369. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3370. // if err != nil {
  3371. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3372. // return
  3373. // }
  3374. // recordDateTime := theTime.Unix()
  3375. // adminUser := c.GetAdminUserInfo()
  3376. //
  3377. // var prescriptions []*models.HisPrescription
  3378. //
  3379. // data := make(map[string]interface{})
  3380. // if settle_accounts_type == 1 { //日结
  3381. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  3382. // data["pre"] = prescriptions
  3383. //
  3384. // } else { //月结
  3385. // start_time_str := c.GetString("start_time")
  3386. // end_time_str := c.GetString("end_time")
  3387. // timeLayout := "2006-01-02"
  3388. // loc, _ := time.LoadLocation("Local")
  3389. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3390. // if err != nil {
  3391. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3392. // return
  3393. // }
  3394. // recordStartTime := theStartTime.Unix()
  3395. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3396. // if err != nil {
  3397. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3398. // return
  3399. // }
  3400. // recordEndTime := theEndTime.Unix()
  3401. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  3402. // data["pre"] = prescriptions
  3403. //
  3404. // }
  3405. //
  3406. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3407. //
  3408. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3409. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3410. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  3411. // strconv.FormatInt(his.PatientId, 10)
  3412. //
  3413. // order_src, _ := service.GetHisOrderByID(order_id)
  3414. //
  3415. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3416. // if config.IsOpen == 1 { //对接了医保,走医保流程
  3417. //
  3418. // var total float64
  3419. // for _, item := range prescriptions {
  3420. // if item.Type == 1 { //药品
  3421. // for _, subItem := range item.HisDoctorAdviceInfo {
  3422. // total = total + (subItem.Price * subItem.PrescribingNumber)
  3423. // }
  3424. // }
  3425. // if item.Type == 2 { //项目
  3426. // for _, subItem := range item.HisPrescriptionProject {
  3427. // total = total + (subItem.Price * float64(subItem.Count))
  3428. // }
  3429. // }
  3430. // }
  3431. //
  3432. // for _, item := range prescriptions {
  3433. // for _, subItem := range item.HisAdditionalCharge {
  3434. // total = total + (subItem.Price * float64(subItem.Count))
  3435. // }
  3436. // }
  3437. //
  3438. // allTotal := fmt.Sprintf("%.2f", total)
  3439. // var rf []*ResultFive
  3440. // json.Unmarshal([]byte(his.Iinfo), &rf)
  3441. // psn_no := order_src.PsnNo
  3442. // mdtrt_id := order_src.MdtrtId
  3443. // chrg_bchno := order_src.Number
  3444. // cert_no := order_src.Certno
  3445. // insutype := rf[0].Insutype
  3446. //
  3447. // if his.IdCardType == 1 {
  3448. // cert_no = his.MedicalInsuranceNumber
  3449. // } else {
  3450. // cert_no = his.Certno
  3451. // }
  3452. //
  3453. // 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)
  3454. // var dat map[string]interface{}
  3455. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3456. // fmt.Println(dat)
  3457. // } else {
  3458. // fmt.Println(err)
  3459. // }
  3460. //
  3461. // userJSONBytes, _ := json.Marshal(dat)
  3462. //
  3463. //
  3464. //
  3465. // var res ResultSeven
  3466. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3467. // utils.ErrorLog("解析失败:%v", err)
  3468. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3469. // return
  3470. // }
  3471. // if res.Infcode == -1 {
  3472. // errlog := &models.HisOrderError{
  3473. // UserOrgId: adminUser.CurrentOrgId,
  3474. // Ctime: time.Now().Unix(),
  3475. // Mtime: time.Now().Unix(),
  3476. // Number: chrg_bchno,
  3477. // ErrMsg: res.ErrMsg,
  3478. // Status: 1,
  3479. // PatientId: id,
  3480. // RecordTime: recordDateTime,
  3481. // Stage: 6,
  3482. // }
  3483. // service.CreateErrMsgLog(errlog)
  3484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  3485. // return
  3486. // } else {
  3487. // order_src.OrderStatus = 2
  3488. // order_src.PayWay = pay_way
  3489. // order_src.PayPrice = pay_price
  3490. // order_src.PayCardNo = pay_card_no
  3491. // order_src.DiscountPrice = discount_price
  3492. // order_src.PreferentialPrice = preferential_price
  3493. // order_src.RealityPrice = reality_price
  3494. // order_src.FoundPrice = found_price
  3495. // order_src.MedicalInsurancePrice = medical_insurance_price
  3496. // order_src.PrivatePrice = private_price
  3497. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  3498. // order_src.SetlId = res.Output.Setlinfo.SetlID
  3499. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  3500. // order_src.PsnName = res.Output.Setlinfo.PsnName
  3501. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  3502. // order_src.Certno = res.Output.Setlinfo.Certno
  3503. // order_src.Gend = res.Output.Setlinfo.Gend
  3504. // order_src.Naty = res.Output.Setlinfo.Naty
  3505. // order_src.Age = res.Output.Setlinfo.Age
  3506. // order_src.Insutype = res.Output.Setlinfo.Insutype
  3507. // order_src.PsnType = res.Output.Setlinfo.PsnType
  3508. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  3509. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  3510. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  3511. // order_src.MedType = res.Output.Setlinfo.MedType
  3512. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  3513. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  3514. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  3515. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  3516. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  3517. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  3518. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  3519. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  3520. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  3521. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  3522. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  3523. // order_src.MafPay = res.Output.Setlinfo.MafPay
  3524. // order_src.OthPay = res.Output.Setlinfo.OthPay
  3525. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  3526. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  3527. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  3528. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  3529. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  3530. // order_src.Balc = res.Output.Setlinfo.Balc
  3531. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  3532. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  3533. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  3534. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  3535. // order_src.Creator = order_src.Creator
  3536. // order_src.Modify = roles.ID
  3537. // order_src.RequestLog = src_resquest
  3538. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  3539. // detailStr := string(setlDetail)
  3540. // order_src.SetlDetail = detailStr
  3541. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  3542. // err = service.UpDateOrder(order_src)
  3543. //
  3544. // if err == nil {
  3545. // c.ServeSuccessJSON(map[string]interface{}{
  3546. // "msg": "结算成功",
  3547. // })
  3548. // } else {
  3549. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  3550. // return
  3551. // }
  3552. // }
  3553. // }
  3554. //}
  3555. //退款
  3556. func (c *HisApiController) Refund() {
  3557. order_id, _ := c.GetInt64("order_id")
  3558. admin_user_id, _ := c.GetInt64("admin_user_id")
  3559. //record_time := c.GetString("record_time")
  3560. //patient_id, _ := c.GetInt64("patient_id")
  3561. //timeLayout := "2006-01-02"
  3562. //loc, _ := time.LoadLocation("Local")
  3563. adminUser := c.GetAdminUserInfo()
  3564. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3565. //if err != nil {
  3566. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3567. // return
  3568. //}
  3569. //recordDateTime := theTime.Unix()
  3570. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3571. var order models.HisOrder
  3572. order, _ = service.GetHisOrderByID(order_id)
  3573. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3574. if order.ID == 0 {
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3576. return
  3577. //order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3578. }
  3579. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3580. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3581. if config.IsOpen == 1 { //对接了医保,走医保流程
  3582. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3583. var dat map[string]interface{}
  3584. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3585. fmt.Println(dat)
  3586. } else {
  3587. fmt.Println(err)
  3588. }
  3589. saveLog(result, src_resquest)
  3590. userJSONBytes, _ := json.Marshal(dat)
  3591. var res ResultSixteen
  3592. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3593. utils.ErrorLog("解析失败:%v", err)
  3594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3595. return
  3596. }
  3597. if res.Infcode == 0 {
  3598. result, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  3599. var dat map[string]interface{}
  3600. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3601. fmt.Println(dat)
  3602. } else {
  3603. fmt.Println(err)
  3604. }
  3605. saveLog(result, src_request)
  3606. userJSONBytes, _ := json.Marshal(dat)
  3607. var res2 ResultSix
  3608. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3609. utils.ErrorLog("解析失败:%v", err)
  3610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3611. return
  3612. }
  3613. if res2.Infcode == 0 {
  3614. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  3615. if err == nil {
  3616. c.ServeSuccessJSON(map[string]interface{}{
  3617. "msg": "退费成功",
  3618. })
  3619. } else {
  3620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3621. return
  3622. }
  3623. } else {
  3624. c.ServeSuccessJSON(map[string]interface{}{
  3625. "code": -10,
  3626. "msg": res2.ErrMsg,
  3627. })
  3628. }
  3629. } else {
  3630. c.ServeSuccessJSON(map[string]interface{}{
  3631. "code": -10,
  3632. "msg": res.ErrMsg,
  3633. })
  3634. }
  3635. }
  3636. }
  3637. func (c *HisApiController) RefundNumber() {
  3638. record_time := c.GetString("record_time")
  3639. //patient_id, _ := c.GetInt64("patient_id")
  3640. admin_user_id, _ := c.GetInt64("admin_user_id")
  3641. his_patient_id, _ := c.GetInt64("id")
  3642. timeLayout := "2006-01-02"
  3643. loc, _ := time.LoadLocation("Local")
  3644. adminUser := c.GetAdminUserInfo()
  3645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3646. fmt.Println(err)
  3647. if err != nil {
  3648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3649. return
  3650. }
  3651. recordDateTime := theTime.Unix()
  3652. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3653. his, _ := service.GetHisPatientRecord(adminUser.CurrentOrgId, his_patient_id)
  3654. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3655. //order, _ := service.GetHisOrderByID(order_id)
  3656. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3657. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3658. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3659. count, _ := service.GetOrderCountByNumber(adminUser.CurrentOrgId, his.PatientId, recordDateTime, his.Number)
  3660. if count > 0 {
  3661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  3662. return
  3663. }
  3664. if config.IsOpen == 1 { //对接了医保,走医保流程
  3665. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3666. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3667. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3668. resp3, requestErr3 := http.Get(api3)
  3669. if requestErr3 != nil {
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3671. return
  3672. }
  3673. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3674. if ioErr3 != nil {
  3675. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3677. return
  3678. }
  3679. var respJSON3 map[string]interface{}
  3680. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3681. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3683. return
  3684. }
  3685. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3686. userJSONBytes3, _ := json.Marshal(respJSON3)
  3687. var res2 ResultSix
  3688. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3689. utils.ErrorLog("解析失败:%v", err)
  3690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3691. return
  3692. }
  3693. if res2.Infcode == 0 {
  3694. if err == nil {
  3695. c.ServeSuccessJSON(map[string]interface{}{
  3696. "msg": "退号成功",
  3697. })
  3698. service.UpdataRegStatusTwo(his_patient_id, recordDateTime, adminUser.CurrentOrgId)
  3699. } else {
  3700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3701. return
  3702. }
  3703. } else {
  3704. c.ServeSuccessJSON(map[string]interface{}{
  3705. "code": -10,
  3706. "msg": res2.ErrMsg,
  3707. })
  3708. }
  3709. } else {
  3710. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3711. //if err == nil {
  3712. // c.ServeSuccessJSON(map[string]interface{}{
  3713. // "msg": "退费成功",
  3714. // })
  3715. //} else {
  3716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3717. // return
  3718. //}
  3719. }
  3720. }
  3721. func (c *HisApiController) RefundDetail() {
  3722. order_id, _ := c.GetInt64("order_id")
  3723. his_patient_id, _ := c.GetInt64("his_patient_id")
  3724. number := c.GetString("number")
  3725. record_time := c.GetString("record_time")
  3726. patient_id, _ := c.GetInt64("patient_id")
  3727. timeLayout := "2006-01-02"
  3728. loc, _ := time.LoadLocation("Local")
  3729. adminUser := c.GetAdminUserInfo()
  3730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3731. fmt.Println(err)
  3732. if err != nil {
  3733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3734. return
  3735. }
  3736. recordDateTime := theTime.Unix()
  3737. his, _ := service.GetNewVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3738. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3739. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3740. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3741. var order models.HisOrder
  3742. order, _ = service.GetHisOrderByID(order_id)
  3743. if order.ID == 0 {
  3744. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3745. }
  3746. if config.IsOpen == 1 { //对接了医保,走医保流程
  3747. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3748. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3749. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3750. resp2, requestErr2 := http.Get(api2)
  3751. if requestErr2 != nil {
  3752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3753. return
  3754. }
  3755. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3756. if ioErr2 != nil {
  3757. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3759. return
  3760. }
  3761. var respJSON2 map[string]interface{}
  3762. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3763. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3765. return
  3766. }
  3767. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3768. if err == nil {
  3769. c.ServeSuccessJSON(map[string]interface{}{
  3770. "msg": "退费成功",
  3771. })
  3772. } else {
  3773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3774. return
  3775. }
  3776. } else {
  3777. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3778. if err == nil {
  3779. c.ServeSuccessJSON(map[string]interface{}{
  3780. "msg": "退费成功",
  3781. })
  3782. } else {
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3784. return
  3785. }
  3786. }
  3787. }
  3788. //对账
  3789. func (c *HisApiController) GetCheckAccount() {
  3790. start_time := c.GetString("start_time")
  3791. end_time := c.GetString("end_time")
  3792. insutype := c.GetString("insutype")
  3793. clr_type := c.GetString("clr_type")
  3794. admin_user_id, _ := c.GetInt64("admin_user_id")
  3795. adminUser := c.GetAdminUserInfo()
  3796. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3797. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3798. timeLayout := "2006-01-02"
  3799. loc, _ := time.LoadLocation("Local")
  3800. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3801. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3802. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3803. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3804. fixmedins_setl_cnt := int64(len(orders))
  3805. //
  3806. ////撤销的算2条数据为一笔
  3807. //for _, item := range orders_two {
  3808. // if item.OrderStatus == 3 {
  3809. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3810. // }
  3811. //}
  3812. var medfee_sumamt float64
  3813. var acct_pay float64
  3814. var fund_pay_sumamt float64
  3815. for _, item := range orders {
  3816. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3817. acct_pay = acct_pay + item.AcctPay
  3818. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3819. }
  3820. var user_name string
  3821. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3822. if role.ID == 0 {
  3823. user_name = "xxx"
  3824. } else {
  3825. user_name = role.UserName
  3826. }
  3827. if config.IsOpen == 1 {
  3828. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3829. "insutype=" + insutype +
  3830. "&clr_type=" + clr_type +
  3831. "&setl_optins=" + "定点医保中心" +
  3832. "&stmt_begndate=" + start_time +
  3833. "&stm_enddate=" + end_time +
  3834. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3835. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3836. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3837. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3838. "&fixmedins_code=" + miConfig.Code +
  3839. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3840. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3841. "&secret_key=" + miConfig.SecretKey +
  3842. "&org_name=" + miConfig.OrgName +
  3843. "&doctor=" + user_name
  3844. fmt.Println(api)
  3845. resp, requestErr := http.Get(api)
  3846. if requestErr != nil {
  3847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3848. return
  3849. }
  3850. body, ioErr := ioutil.ReadAll(resp.Body)
  3851. fmt.Println(body)
  3852. if ioErr != nil {
  3853. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3855. return
  3856. }
  3857. var respJSON map[string]interface{}
  3858. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3859. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3861. return
  3862. }
  3863. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3864. userJSONBytes, _ := json.Marshal(respJSON)
  3865. var res ResultEight
  3866. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3867. utils.ErrorLog("解析失败:%v", err)
  3868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3869. return
  3870. }
  3871. if res.Infcode == 0 {
  3872. if res.Output.Stmtinfo.StmtRslt == "0" {
  3873. micc := &models.MedicalInsuranceCostCompare{
  3874. StartTime: startime.Unix(),
  3875. EndTime: endtime.Unix(),
  3876. Insutype: insutype,
  3877. CheckType: 1,
  3878. Num: fixmedins_setl_cnt,
  3879. Mtime: time.Now().Unix(),
  3880. Status: 1,
  3881. UserOrgId: adminUser.CurrentOrgId,
  3882. CostTotal: medfee_sumamt,
  3883. FuncTotal: fund_pay_sumamt,
  3884. PsnPay: acct_pay,
  3885. Creator: admin_user_id,
  3886. Ctime: time.Now().Unix(),
  3887. }
  3888. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3889. if err == nil {
  3890. c.ServeSuccessJSON(map[string]interface{}{
  3891. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3892. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3893. })
  3894. } else {
  3895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3896. }
  3897. } else {
  3898. c.ServeSuccessJSON(map[string]interface{}{
  3899. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3900. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3901. })
  3902. }
  3903. } else {
  3904. c.ServeSuccessJSON(map[string]interface{}{
  3905. "code": -10,
  3906. "msg": res.ErrMsg,
  3907. })
  3908. }
  3909. }
  3910. }
  3911. func (c *HisApiController) Check310() {
  3912. adminUser := c.GetAdminUserInfo()
  3913. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3914. var user_name string
  3915. user_name = "xxx"
  3916. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3917. "insutype=" + "310" +
  3918. "&clr_type=" + "11" +
  3919. "&setl_optins=" + "定点医保中心" +
  3920. "&stmt_begndate=" + "2021-03-01" +
  3921. "&stm_enddate=" + "2021-03-31" +
  3922. "&medfee_sumamt=" + "11521" +
  3923. "&fund_pay_sumamt=" + "10166.66" +
  3924. "&acct_pay=" + "0" +
  3925. "&fixmedins_setl_cnt=" + "7" +
  3926. "&fixmedins_code=" + miConfig.Code +
  3927. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3928. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3929. "&secret_key=" + miConfig.SecretKey +
  3930. "&org_name=" + miConfig.OrgName +
  3931. "&doctor=" + user_name
  3932. fmt.Println(api)
  3933. resp, requestErr := http.Get(api)
  3934. if requestErr != nil {
  3935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3936. return
  3937. }
  3938. body, ioErr := ioutil.ReadAll(resp.Body)
  3939. fmt.Println(body)
  3940. if ioErr != nil {
  3941. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3943. return
  3944. }
  3945. var respJSON map[string]interface{}
  3946. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3947. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3949. return
  3950. }
  3951. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3952. userJSONBytes, _ := json.Marshal(respJSON)
  3953. var res ResultEight
  3954. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3955. utils.ErrorLog("解析失败:%v", err)
  3956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3957. return
  3958. }
  3959. }
  3960. func (c *HisApiController) Check390() {
  3961. adminUser := c.GetAdminUserInfo()
  3962. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3963. var user_name string
  3964. user_name = "张俊杰"
  3965. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3966. "insutype=" + "390" +
  3967. "&clr_type=" + "11" +
  3968. "&setl_optins=" + "定点医保中心" +
  3969. "&stmt_begndate=" + "2021-03-01" +
  3970. "&stm_enddate=" + "2021-03-31" +
  3971. "&medfee_sumamt=" + "209318.43" +
  3972. "&fund_pay_sumamt=" + "188029.12" +
  3973. "&acct_pay=" + "0" +
  3974. "&fixmedins_setl_cnt=" + "48" +
  3975. "&fixmedins_code=" + miConfig.Code +
  3976. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3977. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3978. "&secret_key=" + miConfig.SecretKey +
  3979. "&org_name=" + miConfig.OrgName +
  3980. "&doctor=" + user_name
  3981. fmt.Println(api)
  3982. resp, requestErr := http.Get(api)
  3983. if requestErr != nil {
  3984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3985. return
  3986. }
  3987. body, ioErr := ioutil.ReadAll(resp.Body)
  3988. fmt.Println(body)
  3989. if ioErr != nil {
  3990. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3992. return
  3993. }
  3994. var respJSON map[string]interface{}
  3995. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3996. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3998. return
  3999. }
  4000. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4001. userJSONBytes, _ := json.Marshal(respJSON)
  4002. var res ResultEight
  4003. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4004. utils.ErrorLog("解析失败:%v", err)
  4005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4006. return
  4007. }
  4008. }
  4009. //对账明细
  4010. func (c *HisApiController) GetCheckDetailAccount() {
  4011. start_time := c.GetString("start_time")
  4012. end_time := c.GetString("end_time")
  4013. admin_user_id, _ := c.GetInt64("admin_user_id")
  4014. adminUser := c.GetAdminUserInfo()
  4015. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4016. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4017. timeLayout := "2006-01-02"
  4018. loc, _ := time.LoadLocation("Local")
  4019. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4020. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4021. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  4022. Mkdir(miConfig.OrgName)
  4023. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  4024. file_name := file + ".txt"
  4025. zip_name := file + ".zip"
  4026. zip_path := miConfig.OrgName + "/" + zip_name
  4027. file_path := miConfig.OrgName + "/" + file_name
  4028. decimal.DivisionPrecision = 2
  4029. var medfee_sumamt float64
  4030. var psn_cash_pay float64
  4031. var fund_pay_sumamt float64
  4032. fixmedins_setl_cnt := int64(len(orders))
  4033. for _, item := range orders {
  4034. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  4035. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  4036. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  4037. }
  4038. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  4039. defer f.Close()
  4040. if err != nil {
  4041. fmt.Println(err.Error())
  4042. } else {
  4043. for _, item := range orders {
  4044. var refd_setl_flag string
  4045. if item.OrderStatus == 2 {
  4046. refd_setl_flag = "0"
  4047. var str string
  4048. str = item.SetlId + " " +
  4049. item.MdtrtId + " " +
  4050. item.PsnNo + " " +
  4051. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4052. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4053. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  4054. _, err = f.Write([]byte(str))
  4055. }
  4056. if item.OrderStatus == 3 {
  4057. var str string
  4058. str = item.SetlId + " " +
  4059. item.MdtrtId + " " +
  4060. item.PsnNo + " " +
  4061. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  4062. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  4063. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  4064. _, err = f.Write([]byte(str))
  4065. var str2 string
  4066. str2 = item.SetlId + " " +
  4067. item.MdtrtId + " " +
  4068. item.PsnNo + " " +
  4069. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  4070. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  4071. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  4072. _, err = f.Write([]byte(str2))
  4073. }
  4074. }
  4075. }
  4076. Zip(file_path, zip_path)
  4077. fmt.Println(ReadFile(zip_path))
  4078. fmt.Println(string(ReadFile(zip_path)))
  4079. if config.IsOpen == 1 {
  4080. var user_name string
  4081. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4082. if role.ID == 0 {
  4083. user_name = "管理员"
  4084. } else {
  4085. user_name = role.UserName
  4086. }
  4087. baseParams := models.BaseParams{
  4088. SecretKey: miConfig.SecretKey,
  4089. FixmedinsCode: miConfig.Code,
  4090. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4091. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4092. OrgName: miConfig.OrgName,
  4093. Doctor: user_name,
  4094. }
  4095. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  4096. var dat map[string]interface{}
  4097. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4098. fmt.Println(dat)
  4099. } else {
  4100. fmt.Println(err)
  4101. }
  4102. userJSONBytes, _ := json.Marshal(dat)
  4103. var res ResultNine
  4104. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4105. utils.ErrorLog("解析失败:%v", err)
  4106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4107. return
  4108. }
  4109. if res.Infcode == 0 {
  4110. fileNo := res.Output.FileQuryNo
  4111. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  4112. "file_qury_no=" + fileNo +
  4113. "&setl_optins=" + "定点医保中心" +
  4114. "&stmt_begndate=" + start_time +
  4115. "&stm_enddate=" + end_time +
  4116. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  4117. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  4118. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  4119. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  4120. "&fixmedins_code=" + miConfig.Code +
  4121. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  4122. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  4123. "&secret_key=" + miConfig.SecretKey +
  4124. "&org_name=" + miConfig.OrgName +
  4125. "&doctor=" + user_name
  4126. resp, requestErr := http.Get(api)
  4127. if requestErr != nil {
  4128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4129. return
  4130. }
  4131. body, ioErr := ioutil.ReadAll(resp.Body)
  4132. if ioErr != nil {
  4133. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4135. return
  4136. }
  4137. var respJSON map[string]interface{}
  4138. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4139. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4141. return
  4142. }
  4143. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4144. userJSONBytes, _ := json.Marshal(respJSON)
  4145. var res ResultTen
  4146. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4147. utils.ErrorLog("解析失败:%v", err)
  4148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4149. return
  4150. }
  4151. if res.Infcode == 0 {
  4152. service.Gdyb9102(baseParams, zip_name, fileNo)
  4153. micc := &models.MedicalInsuranceCostCompare{
  4154. StartTime: startime.Unix(),
  4155. EndTime: endtime.Unix(),
  4156. Insutype: "0",
  4157. CheckType: 2,
  4158. Num: fixmedins_setl_cnt,
  4159. Mtime: time.Now().Unix(),
  4160. Status: 1,
  4161. UserOrgId: adminUser.CurrentOrgId,
  4162. CostTotal: medfee_sumamt,
  4163. FuncTotal: fund_pay_sumamt,
  4164. PsnPay: psn_cash_pay,
  4165. Creator: admin_user_id,
  4166. Ctime: time.Now().Unix(),
  4167. }
  4168. service.CreateMedicalInsuranceCostCompareRecord(micc)
  4169. c.ServeSuccessJSON(map[string]interface{}{
  4170. "msg": "明细对账成功",
  4171. })
  4172. }
  4173. } else {
  4174. }
  4175. }
  4176. }
  4177. func (c *HisApiController) GetSettleAccounts() {
  4178. //id, _ := c.GetInt64("id")
  4179. //record_time := c.GetString("record_time")
  4180. order_id, _ := c.GetInt64("order_id")
  4181. admin_user_id, _ := c.GetInt64("admin_user_id")
  4182. //timeLayout := "2006-01-02"
  4183. //loc, _ := time.LoadLocation("Local")
  4184. //
  4185. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4186. //if err != nil {
  4187. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4188. // return
  4189. //}
  4190. //recordDateTime := theTime.Unix()
  4191. adminUser := c.GetAdminUserInfo()
  4192. order, _ := service.GetHisOrderByID(order_id)
  4193. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  4194. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4195. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  4196. orderInfos = append(orderInfos, orderInfos_two...)
  4197. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  4198. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  4199. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  4200. //var config []*models.HisXtDiagnoseConfig
  4201. var name string
  4202. for _, item := range diagnosis_ids {
  4203. id, _ := strconv.ParseInt(item, 10, 64)
  4204. diagnosisConfig, _ := service.FindDiagnoseById(id)
  4205. if len(name) == 0 {
  4206. name = diagnosisConfig.ClassName
  4207. } else {
  4208. name = name + "," + diagnosisConfig.ClassName
  4209. }
  4210. }
  4211. var bedCostTotal float64 = 0 //床位总费
  4212. var bedCostSelfTotal float64 = 0 //床位自费
  4213. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4214. var operationCostTotal float64 = 0 //手术费
  4215. var operationCostSelfTotal float64 = 0 //手术费
  4216. var operationCostPartSelfTotal float64 = 0 //手术费
  4217. var otherCostTotal float64 = 0 //其他费用
  4218. var otherCostSelfTotal float64 = 0 //其他费用
  4219. var otherCostPartSelfTotal float64 = 0 //其他费用
  4220. var materialCostTotal float64 = 0 //材料费
  4221. var materialCostSelfTotal float64 = 0 //材料费
  4222. var materialCostPartSelfTotal float64 = 0 //材料费
  4223. var westernMedicineCostTotal float64 = 0 //西药费
  4224. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4225. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4226. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4227. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4228. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4229. var checkCostTotal float64 = 0 //检查费
  4230. var checkCostSelfTotal float64 = 0 //检查费
  4231. var checkCostPartSelfTotal float64 = 0 //检查费
  4232. var laboratoryCostTotal float64 = 0 //化验费
  4233. var laboratoryCostSelfTotal float64 = 0 //化验费
  4234. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4235. var treatCostTotal float64 = 0 //治疗费用
  4236. var treatCostSelfTotal float64 = 0 //治疗费用
  4237. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4238. decimal.DivisionPrecision = 2
  4239. for _, item := range orderInfos {
  4240. if item.MedChrgitmType == "01" { //床位费
  4241. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4242. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4243. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4244. }
  4245. if item.MedChrgitmType == "03" { //检查费
  4246. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4247. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4248. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4249. }
  4250. if item.MedChrgitmType == "04" { //化验费
  4251. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4252. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4253. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4254. }
  4255. if item.MedChrgitmType == "05" { //治疗费
  4256. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4257. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4258. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4259. }
  4260. if item.MedChrgitmType == "06" { //手术费
  4261. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4262. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4263. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4264. }
  4265. if item.MedChrgitmType == "08" { //材料费
  4266. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4267. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4268. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4269. }
  4270. if item.MedChrgitmType == "09" { //西药费
  4271. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4272. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4273. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4274. }
  4275. if item.MedChrgitmType == "11" { //中成费
  4276. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4277. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4278. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4279. }
  4280. if item.MedChrgitmType == "14" { //其他费
  4281. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4282. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4283. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4284. }
  4285. }
  4286. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4287. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4288. var user_name string
  4289. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4290. if role.ID == 0 {
  4291. user_name = "管理员"
  4292. } else {
  4293. user_name = role.UserName
  4294. }
  4295. baseParams := models.BaseParams{
  4296. SecretKey: miConfig.SecretKey,
  4297. FixmedinsCode: miConfig.Code,
  4298. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4299. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4300. OrgName: miConfig.OrgName,
  4301. Doctor: user_name,
  4302. }
  4303. businessParams := models.BusinessParams{
  4304. PsnNo: order.PsnNo,
  4305. MdtrtId: order.MdtrtId,
  4306. SetlId: order.SetlId,
  4307. }
  4308. if config.IsOpen == 1 {
  4309. result := service.Gdyb5203(baseParams, businessParams)
  4310. var dat map[string]interface{}
  4311. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4312. fmt.Println(dat)
  4313. } else {
  4314. fmt.Println(err)
  4315. }
  4316. userJSONBytes, _ := json.Marshal(dat)
  4317. var res ResultEleven
  4318. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4319. utils.ErrorLog("解析失败:%v", err)
  4320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4321. return
  4322. }
  4323. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4324. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  4325. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, order.PatientId, order.SettleAccountsDate)
  4326. adminRole_two, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.DoctorId)
  4327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4328. var doctor_name string
  4329. if roles.ID == 0 {
  4330. doctor_name = "管理员"
  4331. } else {
  4332. doctor_name = roles.UserName
  4333. }
  4334. yiliao_leibie := ""
  4335. switch order.MedType {
  4336. case "11":
  4337. yiliao_leibie = "普通门诊"
  4338. break
  4339. case "12":
  4340. yiliao_leibie = "门诊挂号"
  4341. break
  4342. case "13":
  4343. yiliao_leibie = "急诊"
  4344. break
  4345. case "14":
  4346. yiliao_leibie = "门诊特殊病"
  4347. break
  4348. case "15":
  4349. yiliao_leibie = "门诊统筹"
  4350. break
  4351. case "16":
  4352. yiliao_leibie = "门诊慢性病"
  4353. break
  4354. case "21":
  4355. yiliao_leibie = "普通住院"
  4356. break
  4357. }
  4358. departments, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4359. if res.Infcode == 0 {
  4360. c.ServeSuccessJSON(map[string]interface{}{
  4361. "diagnosis": name,
  4362. "order_infos": orderInfos,
  4363. "number": order.MdtrtId,
  4364. "date": order.SettleAccountsDate,
  4365. "charge_admin": charge_admin,
  4366. "printor_admin": printor_admin,
  4367. "info": res.Output.Setlinfo,
  4368. "bedCostTotal": bedCostTotal,
  4369. "bedCostSelfTotal": bedCostSelfTotal,
  4370. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4371. "operationCostTotal": operationCostTotal,
  4372. "operationCostSelfTotal": operationCostSelfTotal,
  4373. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4374. "otherCostTotal": otherCostTotal,
  4375. "otherCostSelfTotal": otherCostSelfTotal,
  4376. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4377. "materialCostTotal": materialCostTotal,
  4378. "materialCostSelfTotal": materialCostSelfTotal,
  4379. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4380. "westernMedicineCostTotal": westernMedicineCostTotal,
  4381. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4382. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4383. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4384. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4385. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4386. "checkCostTotal": checkCostTotal,
  4387. "checkCostSelfTotal": checkCostSelfTotal,
  4388. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4389. "laboratoryCostTotal": laboratoryCostTotal,
  4390. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4391. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4392. "treatCostTotal": treatCostTotal,
  4393. "treatCostSelfTotal": treatCostSelfTotal,
  4394. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4395. "doctor_code": adminRole_two.DoctorCode,
  4396. "doctor_name": doctor_name,
  4397. "health_card_no": order.PsnNo,
  4398. "department": departments.Name,
  4399. "yiliao_leibie": yiliao_leibie,
  4400. "after_money": order.AccountPrice,
  4401. "patient": patient,
  4402. "org_name": miConfig.OrgName,
  4403. "org_code": miConfig.Code,
  4404. "order_number": order.Number,
  4405. })
  4406. }
  4407. }
  4408. }
  4409. func (c *HisApiController) CheckTreatment() {
  4410. patient_id, _ := c.GetInt64("patient_id", 0)
  4411. record_time := c.GetString("record_time")
  4412. insutype := c.GetString("insutype")
  4413. timeLayout := "2006-01-02"
  4414. loc, _ := time.LoadLocation("Local")
  4415. adminUser := c.GetAdminUserInfo()
  4416. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4417. fmt.Println(err)
  4418. if err != nil {
  4419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4420. return
  4421. }
  4422. recordDateTime := theTime.Unix()
  4423. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4424. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  4425. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4426. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4427. var user_name string
  4428. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4429. if role.ID == 0 {
  4430. user_name = "xxx"
  4431. } else {
  4432. user_name = role.UserName
  4433. }
  4434. baseParams := models.BaseParams{
  4435. SecretKey: miConfig.SecretKey,
  4436. FixmedinsCode: miConfig.Code,
  4437. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4438. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4439. OrgName: miConfig.OrgName,
  4440. Doctor: user_name,
  4441. }
  4442. if config.IsOpen == 1 {
  4443. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  4444. var dat map[string]interface{}
  4445. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4446. fmt.Println(dat)
  4447. } else {
  4448. fmt.Println(err)
  4449. }
  4450. }
  4451. }
  4452. func (c *HisApiController) PutRecord() {
  4453. id, _ := c.GetInt64("id")
  4454. record_time := c.GetString("record_time")
  4455. timeLayout := "2006-01-02"
  4456. loc, _ := time.LoadLocation("Local")
  4457. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4458. if err != nil {
  4459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4460. return
  4461. }
  4462. recordDateTime := theTime.Unix()
  4463. adminInfo := c.GetAdminUserInfo()
  4464. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  4465. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4466. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4467. fmt.Println(miConfig.SecretKey)
  4468. if patient == nil {
  4469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4470. return
  4471. }
  4472. if len(patient.IdCardNo) == 0 {
  4473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4474. return
  4475. }
  4476. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  4477. if config.IsOpen == 1 {
  4478. 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
  4479. resp, requestErr := http.Get(api)
  4480. if requestErr != nil {
  4481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4482. return
  4483. }
  4484. defer resp.Body.Close()
  4485. body, ioErr := ioutil.ReadAll(resp.Body)
  4486. if ioErr != nil {
  4487. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4489. return
  4490. }
  4491. var respJSON map[string]interface{}
  4492. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4493. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4495. return
  4496. }
  4497. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4498. userJSONBytes, _ := json.Marshal(userJSON)
  4499. var res ResultTwo
  4500. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4501. utils.ErrorLog("解析失败:%v", err)
  4502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4503. return
  4504. }
  4505. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  4506. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  4507. infoStr := string(Iinfos)
  4508. idetinfoStr := string(Idetinfos)
  4509. if res.Infcode == 0 {
  4510. his := models.VMHisPatient{
  4511. Status: 1,
  4512. Ctime: time.Now().Unix(),
  4513. Mtime: time.Now().Unix(),
  4514. PsnNo: res.Output.Baseinfo.PsnNo,
  4515. PsnCertType: res.Output.Baseinfo.PsnCertType,
  4516. Certno: res.Output.Baseinfo.Certno,
  4517. PsnName: res.Output.Baseinfo.PsnName,
  4518. Gend: res.Output.Baseinfo.Gend,
  4519. Naty: res.Output.Baseinfo.Naty,
  4520. Brdy: res.Output.Baseinfo.Brdy,
  4521. Age: res.Output.Baseinfo.Age,
  4522. Iinfo: infoStr,
  4523. Idetinfo: idetinfoStr,
  4524. PatientId: patient.ID,
  4525. RecordDate: theTime.Unix(),
  4526. UserOrgId: adminInfo.CurrentOrgId,
  4527. AdminUserId: adminInfo.AdminUser.Id,
  4528. IsReturn: 1,
  4529. }
  4530. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  4531. 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")
  4532. 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")
  4533. var dat map[string]interface{}
  4534. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4535. fmt.Println(dat)
  4536. } else {
  4537. fmt.Println(err)
  4538. }
  4539. var dat2 map[string]interface{}
  4540. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  4541. fmt.Println(dat2)
  4542. } else {
  4543. fmt.Println(err)
  4544. }
  4545. } else {
  4546. adminUser := c.GetAdminUserInfo()
  4547. errlog := &models.HisOrderError{
  4548. UserOrgId: adminUser.CurrentOrgId,
  4549. Ctime: time.Now().Unix(),
  4550. Mtime: time.Now().Unix(),
  4551. ErrMsg: res.ErrMsg,
  4552. Status: 1,
  4553. PatientId: id,
  4554. RecordTime: recordDateTime,
  4555. Stage: 1,
  4556. }
  4557. service.CreateErrMsgLog(errlog)
  4558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  4559. return
  4560. }
  4561. }
  4562. }
  4563. func (c *HisApiController) GetUploadDiag() {
  4564. id, _ := c.GetInt64("id")
  4565. record_time := c.GetString("record_time")
  4566. diagnosis_id, _ := c.GetInt64("diagnosis")
  4567. sick_type, _ := c.GetInt64("sick_type")
  4568. reg_type, _ := c.GetInt64("reg_type")
  4569. timeLayout := "2006-01-02"
  4570. loc, _ := time.LoadLocation("Local")
  4571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4572. if err != nil {
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4574. return
  4575. }
  4576. var patientPrescription models.HisPrescriptionInfo
  4577. recordDateTime := theTime.Unix()
  4578. adminInfo := c.GetAdminUserInfo()
  4579. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4580. if patientPrescription.ID == 0 {
  4581. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4582. }
  4583. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  4584. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  4585. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  4586. sickConfig, _ := service.FindSickById(sick_type)
  4587. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4588. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  4589. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  4590. "&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 +
  4591. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.ContentCode + "&sick_name=" + sickConfig.ClassName
  4592. resp2, requestErr2 := http.Get(api2)
  4593. if requestErr2 != nil {
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4595. return
  4596. }
  4597. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  4598. if ioErr2 != nil {
  4599. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  4600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4601. return
  4602. }
  4603. var respJSON2 map[string]interface{}
  4604. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  4605. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4607. return
  4608. }
  4609. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4610. userJSONBytes2, _ := json.Marshal(respJSON2)
  4611. var res2 ResultSix
  4612. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  4613. utils.ErrorLog("解析失败:%v", err)
  4614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4615. return
  4616. }
  4617. if res2.Infcode != 0 {
  4618. adminUser := c.GetAdminUserInfo()
  4619. errlog := &models.HisOrderError{
  4620. UserOrgId: adminUser.CurrentOrgId,
  4621. Ctime: time.Now().Unix(),
  4622. Mtime: time.Now().Unix(),
  4623. ErrMsg: res2.ErrMsg,
  4624. Status: 1,
  4625. PatientId: id,
  4626. RecordTime: recordDateTime,
  4627. Stage: 3,
  4628. }
  4629. service.CreateErrMsgLog(errlog)
  4630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  4631. return
  4632. }
  4633. c.ServeSuccessJSON(map[string]interface{}{
  4634. "msg": "上传成功",
  4635. })
  4636. }
  4637. type QueryResult struct {
  4638. ID int64
  4639. Name string
  4640. Code string
  4641. List_type_code string
  4642. }
  4643. func (c *HisApiController) GetCheckCode() {
  4644. ids_str := c.GetString("ids")
  4645. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4646. ids_arr := strings.Split(ids_str, ",")
  4647. var queryResult []QueryResult
  4648. ids := make([]int64, 0)
  4649. for _, item := range ids_arr {
  4650. id, _ := strconv.ParseInt(item, 10, 64)
  4651. ids = append(ids, id)
  4652. }
  4653. if record_type == 1 {
  4654. drugs, _ := service.GetBatchDrugList(ids)
  4655. for _, item := range drugs {
  4656. result := QueryResult{
  4657. ID: item.ID,
  4658. Name: item.DrugName,
  4659. Code: item.MedicalInsuranceNumber,
  4660. List_type_code: "101",
  4661. }
  4662. queryResult = append(queryResult, result)
  4663. }
  4664. } else if record_type == 2 {
  4665. goods, _ := service.GetBatchGoodInformationList(ids)
  4666. for _, item := range goods {
  4667. result := QueryResult{
  4668. ID: item.ID,
  4669. Name: item.GoodName,
  4670. Code: item.MedicalInsuranceNumber,
  4671. List_type_code: "301",
  4672. }
  4673. queryResult = append(queryResult, result)
  4674. }
  4675. } else if record_type == 3 {
  4676. projects, _ := service.GetBathchMyPorjecgList(ids)
  4677. for _, item := range projects {
  4678. result := QueryResult{
  4679. ID: item.ID,
  4680. Name: item.ProjectName,
  4681. Code: item.MedicalCode,
  4682. List_type_code: "201",
  4683. }
  4684. queryResult = append(queryResult, result)
  4685. }
  4686. }
  4687. admin_user_id, _ := c.GetInt64("admin_user_id")
  4688. adminUser := c.GetAdminUserInfo()
  4689. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4690. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4691. var user_name string
  4692. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4693. if role.ID == 0 {
  4694. user_name = "xxx"
  4695. } else {
  4696. user_name = role.UserName
  4697. }
  4698. baseParams := &models.BaseParams{
  4699. SecretKey: miConfig.SecretKey,
  4700. FixmedinsCode: miConfig.Code,
  4701. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4702. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4703. OrgName: miConfig.OrgName,
  4704. Doctor: user_name,
  4705. }
  4706. if config.IsOpen == 1 {
  4707. for _, item := range queryResult {
  4708. var result string
  4709. if record_type == 1 {
  4710. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4711. } else if record_type == 2 {
  4712. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4713. } else if record_type == 3 {
  4714. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4715. }
  4716. var dat map[string]interface{}
  4717. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4718. fmt.Println(dat)
  4719. } else {
  4720. fmt.Println(err)
  4721. }
  4722. userJSONBytes, _ := json.Marshal(dat)
  4723. var res ResultSix
  4724. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4725. utils.ErrorLog("解析失败:%v", err)
  4726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4727. return
  4728. }
  4729. if res.Infcode == 0 {
  4730. if record_type == 1 {
  4731. service.UpdateBaseDrugById(item.ID)
  4732. } else if record_type == 2 {
  4733. service.UpdateGoodInformaitonByDetail(item.ID)
  4734. } else if record_type == 3 {
  4735. service.UpdateProjectById(item.ID)
  4736. }
  4737. c.ServeSuccessJSON(map[string]interface{}{
  4738. "failed_code": 0,
  4739. "msg": "目录对照成功",
  4740. })
  4741. } else {
  4742. c.ServeSuccessJSON(map[string]interface{}{
  4743. "failed_code": -10,
  4744. "msg": res.ErrMsg,
  4745. })
  4746. }
  4747. }
  4748. }
  4749. }
  4750. func (c *HisApiController) UnCheckCode() {
  4751. ids_str := c.GetString("ids")
  4752. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4753. admin_user_id, _ := c.GetInt64("admin_user_id")
  4754. ids_arr := strings.Split(ids_str, ",")
  4755. var queryResult []QueryResult
  4756. ids := make([]int64, 0)
  4757. for _, item := range ids_arr {
  4758. id, _ := strconv.ParseInt(item, 10, 64)
  4759. ids = append(ids, id)
  4760. }
  4761. if record_type == 1 {
  4762. drugs, _ := service.GetBatchDrugList(ids)
  4763. for _, item := range drugs {
  4764. result := QueryResult{
  4765. ID: item.ID,
  4766. Name: item.DrugName,
  4767. Code: item.MedicalInsuranceNumber,
  4768. List_type_code: "101",
  4769. }
  4770. queryResult = append(queryResult, result)
  4771. }
  4772. } else if record_type == 2 {
  4773. goods, _ := service.GetBatchGoodInformationList(ids)
  4774. for _, item := range goods {
  4775. result := QueryResult{
  4776. ID: item.ID,
  4777. Name: item.GoodName,
  4778. Code: item.MedicalInsuranceNumber,
  4779. List_type_code: "301",
  4780. }
  4781. queryResult = append(queryResult, result)
  4782. }
  4783. } else if record_type == 3 {
  4784. projects, _ := service.GetBathchMyPorjecgList(ids)
  4785. for _, item := range projects {
  4786. result := QueryResult{
  4787. ID: item.ID,
  4788. Name: item.ProjectName,
  4789. Code: item.MedicalCode,
  4790. List_type_code: "201",
  4791. }
  4792. queryResult = append(queryResult, result)
  4793. }
  4794. }
  4795. adminUser := c.GetAdminUserInfo()
  4796. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4797. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4798. var user_name string
  4799. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4800. if role.ID == 0 {
  4801. user_name = "xxx"
  4802. } else {
  4803. user_name = role.UserName
  4804. }
  4805. baseParams := &models.BaseParams{
  4806. SecretKey: miConfig.SecretKey,
  4807. FixmedinsCode: miConfig.Code,
  4808. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4809. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4810. OrgName: miConfig.OrgName,
  4811. Doctor: user_name,
  4812. }
  4813. if config.IsOpen == 1 {
  4814. for _, item := range queryResult {
  4815. var result string
  4816. if record_type == 1 {
  4817. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4818. } else if record_type == 2 {
  4819. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4820. } else if record_type == 3 {
  4821. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4822. }
  4823. var dat2 map[string]interface{}
  4824. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4825. fmt.Println(dat2)
  4826. } else {
  4827. fmt.Println(err)
  4828. }
  4829. userJSONBytes, _ := json.Marshal(dat2)
  4830. var res ResultSix
  4831. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4832. utils.ErrorLog("解析失败:%v", err)
  4833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4834. return
  4835. }
  4836. if res.Infcode == 0 {
  4837. if record_type == 1 {
  4838. service.UpdateDrugByIdDetail(item.ID)
  4839. } else if record_type == 2 {
  4840. service.UpdateGoodInfoById(item.ID)
  4841. } else if record_type == 3 {
  4842. service.UpdateMyProjectById(item.ID)
  4843. }
  4844. c.ServeSuccessJSON(map[string]interface{}{
  4845. "failed_code": 0,
  4846. "msg": "撤销目录对照成功",
  4847. })
  4848. } else {
  4849. c.ServeSuccessJSON(map[string]interface{}{
  4850. "failed_code": -10,
  4851. "msg": res.ErrMsg,
  4852. })
  4853. }
  4854. }
  4855. }
  4856. }
  4857. func (c *HisApiController) GetPatientInfo() {
  4858. id_card_no := c.GetString("id_card_no")
  4859. admin_user_id, _ := c.GetInt64("admin_user_id")
  4860. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4861. if patient.ID == 0 {
  4862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4863. return
  4864. }
  4865. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4866. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4867. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4868. if config.IsOpen == 1 {
  4869. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4870. var dat map[string]interface{}
  4871. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4872. fmt.Println(dat)
  4873. } else {
  4874. fmt.Println(err)
  4875. }
  4876. userJSONBytes, _ := json.Marshal(dat)
  4877. var res ResultTwo
  4878. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4879. utils.ErrorLog("解析失败:%v", err)
  4880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4881. return
  4882. }
  4883. if res.Infcode != 0 {
  4884. c.ServeSuccessJSON(map[string]interface{}{
  4885. "failed_code": -10,
  4886. "msg": res.ErrMsg,
  4887. })
  4888. } else {
  4889. c.ServeSuccessJSON(map[string]interface{}{
  4890. "failed_code": 0,
  4891. "info": res,
  4892. })
  4893. }
  4894. }
  4895. }
  4896. func (c *HisApiController) PsnPutOnRecord() {
  4897. record_type, _ := c.GetInt64("type")
  4898. patient_id, _ := c.GetInt64("patient_id")
  4899. admin_user_id, _ := c.GetInt64("admin_user_id")
  4900. start_time := c.GetString("start_time")
  4901. end_time := c.GetString("end_time")
  4902. adminUser := c.GetAdminUserInfo()
  4903. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4904. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4905. var patients []*models.Patients
  4906. if record_type == 1 { //全部备案
  4907. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4908. patients = append(patients, patient...)
  4909. } else { //单个备案
  4910. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4911. patients = append(patients, patient)
  4912. }
  4913. var user_name string
  4914. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4915. if role.ID == 0 {
  4916. user_name = "xxx"
  4917. } else {
  4918. user_name = role.UserName
  4919. }
  4920. if config.IsOpen == 1 {
  4921. for _, item := range patients {
  4922. 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
  4923. resp, requestErr := http.Get(api)
  4924. if requestErr != nil {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4926. return
  4927. }
  4928. defer resp.Body.Close()
  4929. body, ioErr := ioutil.ReadAll(resp.Body)
  4930. if ioErr != nil {
  4931. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4933. return
  4934. }
  4935. var respJSON map[string]interface{}
  4936. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4937. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4939. return
  4940. }
  4941. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4942. userJSONBytes, _ := json.Marshal(userJSON)
  4943. var res ResultTwo
  4944. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4945. utils.ErrorLog("解析失败:%v", err)
  4946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4947. return
  4948. }
  4949. if res.Infcode == 0 {
  4950. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4951. var dat map[string]interface{}
  4952. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4953. fmt.Println(dat)
  4954. } else {
  4955. fmt.Println(err)
  4956. }
  4957. userJSONBytes, _ := json.Marshal(dat)
  4958. var res2 ResultThirteen
  4959. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4960. utils.ErrorLog("解析失败:%v", err)
  4961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4962. return
  4963. }
  4964. if res2.Infcode == 0 {
  4965. psnResult := &models.GdybPsnRecord{
  4966. UserOrgId: adminUser.CurrentOrgId,
  4967. PatientId: item.ID,
  4968. PsnNo: res.Output.Baseinfo.PsnNo,
  4969. Ctime: time.Now().Unix(),
  4970. Mtime: time.Now().Unix(),
  4971. Status: 1,
  4972. IsCancel: 1,
  4973. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4974. }
  4975. service.CreatePsnRecord(psnResult)
  4976. } else {
  4977. c.ServeSuccessJSON(map[string]interface{}{
  4978. "failed_code": -10,
  4979. "msg": res2.ErrMsg,
  4980. })
  4981. return
  4982. }
  4983. }
  4984. }
  4985. }
  4986. }
  4987. func (c *HisApiController) PsnUnPutOnRecord() {
  4988. id, _ := c.GetInt64("id")
  4989. //record_type, _ := c.GetInt64("type")
  4990. admin_user_id, _ := c.GetInt64("admin_user_id")
  4991. adminUser := c.GetAdminUserInfo()
  4992. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4993. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4994. var user_name string
  4995. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4996. if role.ID == 0 {
  4997. user_name = "xxx"
  4998. } else {
  4999. user_name = role.UserName
  5000. }
  5001. psn_record, _ := service.GetPsnRecordById(id)
  5002. if psn_record.ID == 0 {
  5003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5004. return
  5005. }
  5006. if config.IsOpen == 1 {
  5007. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5008. var dat map[string]interface{}
  5009. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5010. fmt.Println(dat)
  5011. } else {
  5012. fmt.Println(err)
  5013. }
  5014. userJSONBytes, _ := json.Marshal(dat)
  5015. var res ResultFourteen
  5016. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5017. utils.ErrorLog("解析失败:%v", err)
  5018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5019. return
  5020. }
  5021. if res.Infcode == 0 {
  5022. psn_record.IsCancel = 2
  5023. service.CreatePsnRecord(&psn_record)
  5024. } else {
  5025. c.ServeSuccessJSON(map[string]interface{}{
  5026. "failed_code": -10,
  5027. "msg": res.ErrMsg,
  5028. })
  5029. return
  5030. }
  5031. }
  5032. }
  5033. func (c *HisApiController) PsnPutNCDSOnRecord() {
  5034. patient_id, _ := c.GetInt64("patient_id")
  5035. insutype := c.GetString("insutype")
  5036. psn_no := c.GetString("psn_no")
  5037. doctor_id, _ := c.GetInt64("doctor_id")
  5038. sick_id, _ := c.GetInt64("sick_id")
  5039. department_id, _ := c.GetInt64("department_id")
  5040. adminUser := c.GetAdminUserInfo()
  5041. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  5042. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5043. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5044. sick, _ := service.FindSickById(sick_id)
  5045. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  5046. if config.IsOpen == 1 {
  5047. 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.ContentCode)
  5048. var dat map[string]interface{}
  5049. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5050. fmt.Println(dat)
  5051. } else {
  5052. fmt.Println(err)
  5053. }
  5054. userJSONBytes, _ := json.Marshal(dat)
  5055. var res2 ResultThirteen
  5056. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  5057. utils.ErrorLog("解析失败:%v", err)
  5058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5059. return
  5060. }
  5061. if res2.Infcode == 0 {
  5062. psnResult := &models.GdybPsnNcdsRecord{
  5063. UserOrgId: adminUser.CurrentOrgId,
  5064. PatientId: patient.ID,
  5065. PsnNo: psn_no,
  5066. DoctorId: doctor.AdminUserId,
  5067. DepartmentId: department_id,
  5068. SickType: sick_id,
  5069. Insutype: insutype,
  5070. Ctime: time.Now().Unix(),
  5071. Mtime: time.Now().Unix(),
  5072. Status: 1,
  5073. IsCancel: 1,
  5074. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  5075. }
  5076. service.CreatePsnNCDSRecord(psnResult)
  5077. c.ServeSuccessJSON(map[string]interface{}{
  5078. "failed_code": 0,
  5079. "msg": "备案成功",
  5080. "result": psnResult,
  5081. })
  5082. } else {
  5083. c.ServeSuccessJSON(map[string]interface{}{
  5084. "failed_code": -10,
  5085. "msg": res2.ErrMsg,
  5086. })
  5087. return
  5088. }
  5089. }
  5090. }
  5091. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  5092. id, _ := c.GetInt64("id")
  5093. admin_user_id, _ := c.GetInt64("admin_user_id")
  5094. adminUser := c.GetAdminUserInfo()
  5095. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5096. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5097. var user_name string
  5098. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  5099. if role.ID == 0 {
  5100. user_name = "xxx"
  5101. } else {
  5102. user_name = role.UserName
  5103. }
  5104. psn_record, _ := service.GetPsnNCDSRecordById(id)
  5105. if psn_record.ID == 0 {
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  5107. return
  5108. }
  5109. if config.IsOpen == 1 {
  5110. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  5111. var dat map[string]interface{}
  5112. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  5113. fmt.Println(dat)
  5114. } else {
  5115. fmt.Println(err)
  5116. }
  5117. userJSONBytes, _ := json.Marshal(dat)
  5118. var res ResultFourteen
  5119. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  5120. utils.ErrorLog("解析失败:%v", err)
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5122. return
  5123. }
  5124. if res.Infcode == 0 {
  5125. psn_record.IsCancel = 2
  5126. service.CreatePsnNCDSRecord(&psn_record)
  5127. c.ServeSuccessJSON(map[string]interface{}{
  5128. "failed_code": 0,
  5129. "msg": "撤销备案成功",
  5130. })
  5131. } else {
  5132. c.ServeSuccessJSON(map[string]interface{}{
  5133. "failed_code": -10,
  5134. "msg": res.ErrMsg,
  5135. })
  5136. return
  5137. }
  5138. }
  5139. }
  5140. func (c *HisApiController) TestTest() {
  5141. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  5142. fmt.Println(patient.Iinfo)
  5143. }
  5144. type CustomData struct {
  5145. MsgId string
  5146. PsnNo string
  5147. Info string
  5148. }
  5149. func (c *HisApiController) ReversalData() {
  5150. var customData []*CustomData
  5151. custom := &CustomData{
  5152. MsgId: "H44022900158202103301714472004",
  5153. PsnNo: "44020000001101329945",
  5154. Info: "2207",
  5155. }
  5156. customData = append(customData, custom)
  5157. custom1 := &CustomData{
  5158. MsgId: "H4402290015820210330172057803",
  5159. PsnNo: "44020000001101161813",
  5160. Info: "2207",
  5161. }
  5162. customData = append(customData, custom1)
  5163. custom2 := &CustomData{
  5164. MsgId: "H44022900158202103301705198813",
  5165. PsnNo: "44190000133097375417",
  5166. Info: "2207",
  5167. }
  5168. customData = append(customData, custom2)
  5169. custom3 := &CustomData{
  5170. MsgId: "H44022900158202103301715524756",
  5171. PsnNo: "44020000001100187221",
  5172. Info: "2207",
  5173. }
  5174. customData = append(customData, custom3)
  5175. custom4 := &CustomData{
  5176. MsgId: "H44022900158202103301730376224",
  5177. PsnNo: "44020000001101959155",
  5178. Info: "2207",
  5179. }
  5180. customData = append(customData, custom4)
  5181. custom5 := &CustomData{
  5182. MsgId: "H44022900158202103301748008725",
  5183. PsnNo: "44020000001104246641",
  5184. Info: "2207",
  5185. }
  5186. customData = append(customData, custom5)
  5187. custom6 := &CustomData{
  5188. MsgId: "H44022900158202103301718096755",
  5189. PsnNo: "44020000001102211860",
  5190. Info: "2207",
  5191. }
  5192. customData = append(customData, custom6)
  5193. custom7 := &CustomData{
  5194. MsgId: "H44022900158202103301736551640",
  5195. PsnNo: "44020000001102687718",
  5196. Info: "2207",
  5197. }
  5198. customData = append(customData, custom7)
  5199. custom8 := &CustomData{
  5200. MsgId: "H44022900158202103301743097676",
  5201. PsnNo: "44020000001102127785",
  5202. Info: "2207",
  5203. }
  5204. customData = append(customData, custom8)
  5205. custom9 := &CustomData{
  5206. MsgId: "H44022900158202103301712304203",
  5207. PsnNo: "44020000001101518097",
  5208. Info: "2207",
  5209. }
  5210. customData = append(customData, custom9)
  5211. custom10 := &CustomData{
  5212. MsgId: "H44022900158202103301738448785",
  5213. PsnNo: "44020000001100500813",
  5214. Info: "2207",
  5215. }
  5216. customData = append(customData, custom10)
  5217. custom11 := &CustomData{
  5218. MsgId: "H44022900158202103301732455843",
  5219. PsnNo: "44020000001102690557",
  5220. Info: "2207",
  5221. }
  5222. customData = append(customData, custom11)
  5223. custom12 := &CustomData{
  5224. MsgId: "H44022900158202103301745421708",
  5225. PsnNo: "44020000001102211928",
  5226. Info: "2207",
  5227. }
  5228. customData = append(customData, custom12)
  5229. custom1212 := &CustomData{
  5230. MsgId: "H440229001582021033017351627",
  5231. PsnNo: "44020000001102481733",
  5232. Info: "2207",
  5233. }
  5234. customData = append(customData, custom1212)
  5235. custom13 := &CustomData{
  5236. MsgId: "H44022900158202103301740327951",
  5237. PsnNo: "44020000001103174866",
  5238. Info: "2207",
  5239. }
  5240. customData = append(customData, custom13)
  5241. custom14 := &CustomData{
  5242. MsgId: "H4402290015820210330174922668",
  5243. PsnNo: "44020000001102927272",
  5244. Info: "2207",
  5245. }
  5246. customData = append(customData, custom14)
  5247. custom15 := &CustomData{
  5248. MsgId: "H44022900158202103301752362273",
  5249. PsnNo: "44020000001102942890",
  5250. Info: "2207",
  5251. }
  5252. customData = append(customData, custom15)
  5253. custom16 := &CustomData{
  5254. MsgId: "H44022900158202103301751082917",
  5255. PsnNo: "44020000001101662162",
  5256. Info: "2207",
  5257. }
  5258. customData = append(customData, custom16)
  5259. custom17 := &CustomData{
  5260. MsgId: "H44022900158202103301754147728",
  5261. PsnNo: "44020000000229014511",
  5262. Info: "2207",
  5263. }
  5264. customData = append(customData, custom17)
  5265. adminUser := c.GetAdminUserInfo()
  5266. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5267. for _, item := range customData {
  5268. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5269. fmt.Println(result)
  5270. }
  5271. }
  5272. func (c *HisApiController) ReversalOtherData() {
  5273. var customData []*CustomData
  5274. custom := &CustomData{
  5275. MsgId: "H44022900158202103301714472004",
  5276. PsnNo: "44020000001101329945",
  5277. Info: "2208",
  5278. }
  5279. customData = append(customData, custom)
  5280. custom1 := &CustomData{
  5281. MsgId: "H4402290015820210330172057803",
  5282. PsnNo: "44020000001101161813",
  5283. Info: "2208",
  5284. }
  5285. customData = append(customData, custom1)
  5286. custom2 := &CustomData{
  5287. MsgId: "H44022900158202103301705198813",
  5288. PsnNo: "44190000133097375417",
  5289. Info: "2208",
  5290. }
  5291. customData = append(customData, custom2)
  5292. custom3 := &CustomData{
  5293. MsgId: "H44022900158202103301715524756",
  5294. PsnNo: "44020000001100187221",
  5295. Info: "2208",
  5296. }
  5297. customData = append(customData, custom3)
  5298. custom4 := &CustomData{
  5299. MsgId: "H44022900158202103301730376224",
  5300. PsnNo: "44020000001101959155",
  5301. Info: "2208",
  5302. }
  5303. customData = append(customData, custom4)
  5304. custom5 := &CustomData{
  5305. MsgId: "H44022900158202103301748008725",
  5306. PsnNo: "44020000001104246641",
  5307. Info: "2208",
  5308. }
  5309. customData = append(customData, custom5)
  5310. custom6 := &CustomData{
  5311. MsgId: "H44022900158202103301718096755",
  5312. PsnNo: "44020000001102211860",
  5313. Info: "2208",
  5314. }
  5315. customData = append(customData, custom6)
  5316. custom7 := &CustomData{
  5317. MsgId: "H44022900158202103301736551640",
  5318. PsnNo: "44020000001102687718",
  5319. Info: "2208",
  5320. }
  5321. customData = append(customData, custom7)
  5322. custom8 := &CustomData{
  5323. MsgId: "H44022900158202103301743097676",
  5324. PsnNo: "44020000001102127785",
  5325. Info: "2208",
  5326. }
  5327. customData = append(customData, custom8)
  5328. custom9 := &CustomData{
  5329. MsgId: "H44022900158202103301712304203",
  5330. PsnNo: "44020000001101518097",
  5331. Info: "2208",
  5332. }
  5333. customData = append(customData, custom9)
  5334. custom10 := &CustomData{
  5335. MsgId: "H44022900158202103301738448785",
  5336. PsnNo: "44020000001100500813",
  5337. Info: "2208",
  5338. }
  5339. customData = append(customData, custom10)
  5340. custom11 := &CustomData{
  5341. MsgId: "H44022900158202103301732455843",
  5342. PsnNo: "44020000001102690557",
  5343. Info: "2208",
  5344. }
  5345. customData = append(customData, custom11)
  5346. custom12 := &CustomData{
  5347. MsgId: "H44022900158202103301745421708",
  5348. PsnNo: "44020000001102211928",
  5349. Info: "2208",
  5350. }
  5351. customData = append(customData, custom12)
  5352. custom1212 := &CustomData{
  5353. MsgId: "H440229001582021033017351627",
  5354. PsnNo: "44020000001102481733",
  5355. Info: "2208",
  5356. }
  5357. customData = append(customData, custom1212)
  5358. custom13 := &CustomData{
  5359. MsgId: "H44022900158202103301740327951",
  5360. PsnNo: "44020000001103174866",
  5361. Info: "2208",
  5362. }
  5363. customData = append(customData, custom13)
  5364. custom14 := &CustomData{
  5365. MsgId: "H4402290015820210330174922668",
  5366. PsnNo: "44020000001102927272",
  5367. Info: "2208",
  5368. }
  5369. customData = append(customData, custom14)
  5370. custom15 := &CustomData{
  5371. MsgId: "H44022900158202103301752362273",
  5372. PsnNo: "44020000001102942890",
  5373. Info: "2208",
  5374. }
  5375. customData = append(customData, custom15)
  5376. custom16 := &CustomData{
  5377. MsgId: "H44022900158202103301751082917",
  5378. PsnNo: "44020000001101662162",
  5379. Info: "2208",
  5380. }
  5381. customData = append(customData, custom16)
  5382. custom17 := &CustomData{
  5383. MsgId: "H44022900158202103301754147728",
  5384. PsnNo: "44020000000229014511",
  5385. Info: "2208",
  5386. }
  5387. customData = append(customData, custom17)
  5388. adminUser := c.GetAdminUserInfo()
  5389. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  5390. for _, item := range customData {
  5391. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  5392. fmt.Println(result)
  5393. }
  5394. }
  5395. func PathExists(path string) (bool, error) {
  5396. _, err := os.Stat(path)
  5397. if err == nil {
  5398. return true, nil
  5399. }
  5400. if os.IsNotExist(err) {
  5401. return false, nil
  5402. }
  5403. return false, err
  5404. }
  5405. //创建文件夹
  5406. func Mkdir(dir string) {
  5407. // 创建文件夹
  5408. exist, err := PathExists(dir)
  5409. if err != nil {
  5410. fmt.Println(err.Error())
  5411. } else {
  5412. if exist {
  5413. fmt.Println(dir + "文件夹已存在!")
  5414. } else {
  5415. // 文件夹名称,权限
  5416. err := os.Mkdir(dir, os.ModePerm)
  5417. if err != nil {
  5418. fmt.Println(dir+"文件夹创建失败:", err.Error())
  5419. } else {
  5420. fmt.Println(dir + "文件夹创建成功!")
  5421. }
  5422. }
  5423. }
  5424. }
  5425. //压缩文件
  5426. func Zip(srcFile string, destZip string) error {
  5427. zipfile, err := os.Create(destZip)
  5428. if err != nil {
  5429. return err
  5430. }
  5431. defer zipfile.Close()
  5432. archive := zip.NewWriter(zipfile)
  5433. defer archive.Close()
  5434. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  5435. if err != nil {
  5436. return err
  5437. }
  5438. header, err := zip.FileInfoHeader(info)
  5439. if err != nil {
  5440. return err
  5441. }
  5442. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  5443. // header.Name = path
  5444. if info.IsDir() {
  5445. header.Name += "/"
  5446. } else {
  5447. header.Method = zip.Deflate
  5448. }
  5449. writer, err := archive.CreateHeader(header)
  5450. if err != nil {
  5451. return err
  5452. }
  5453. if !info.IsDir() {
  5454. file, err := os.Open(path)
  5455. if err != nil {
  5456. return err
  5457. }
  5458. defer file.Close()
  5459. _, err = io.Copy(writer, file)
  5460. }
  5461. return err
  5462. })
  5463. return err
  5464. }
  5465. func ReadFile(filePath string) []byte {
  5466. f, err := os.Open(filePath)
  5467. if err != nil {
  5468. fmt.Println("read file fail", err)
  5469. return nil
  5470. }
  5471. defer f.Close()
  5472. fd, err := ioutil.ReadAll(f)
  5473. if err != nil {
  5474. fmt.Println("read to fd fail", err)
  5475. return nil
  5476. }
  5477. return fd
  5478. }
  5479. func RemoveRepeatedCode(arr []string) (newArr []string) {
  5480. newArr = make([]string, 0)
  5481. for i := 0; i < len(arr); i++ {
  5482. repeat := false
  5483. for j := i + 1; j < len(arr); j++ {
  5484. if arr[i] == arr[j] {
  5485. repeat = true
  5486. break
  5487. }
  5488. }
  5489. if !repeat {
  5490. newArr = append(newArr, arr[i])
  5491. }
  5492. }
  5493. return
  5494. }
  5495. func saveLog(result string, request string) {
  5496. org_id, _ := beego.AppConfig.Int64("org_id")
  5497. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  5498. dir := miConfig.OrgName + "日志"
  5499. utils.Mkdir(dir)
  5500. month := time.Unix(1557042972, 0).Format("1")
  5501. year := time.Now().Format("2006")
  5502. month = time.Now().Format("01")
  5503. day := time.Now().Format("02")
  5504. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  5505. file_name := file + ".txt"
  5506. file_path := miConfig.OrgName + "日志" + "/" + file_name
  5507. exist, _ := utils.PathExists(file_path)
  5508. if exist { //存在
  5509. fmt.Println("存在")
  5510. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  5511. if err != nil {
  5512. fmt.Println("read fail")
  5513. }
  5514. content := "\r" + request + "\r" + result
  5515. n, _ := f.Seek(0, 2)
  5516. _, err = f.WriteAt([]byte(content), n)
  5517. } else { //不存在
  5518. fmt.Println("文件不存在,创建文件")
  5519. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  5520. defer f.Close()
  5521. if err != nil {
  5522. } else {
  5523. _, err = f.Write([]byte("记录日志"))
  5524. }
  5525. }
  5526. }